@BeforeClass public void setUp() { cm = TestCacheManagerFactory.createCacheManager(); globalMarshaller = TestingUtil.extractGlobalMarshaller(cm); }
@BeforeClass @Override public void createCacheStore() throws PersistenceException { cm = TestCacheManagerFactory.createCacheManager(false); marshaller = extractGlobalMarshaller(cm); super.createCacheStore(); }
private void verifyExternalizerForType(Object keySampleType, Class expectedExcternalizerClass) throws IOException { GlobalMarshaller marshaller = TestingUtil.extractGlobalMarshaller(cacheManager); Externalizer<Object> ext = marshaller.findExternalizerFor(keySampleType); AssertJUnit.assertEquals("Registered Externalizers should be wrapped by a ForeignAdvancedExternalizer", ext.getClass().toString(), "class org.infinispan.marshall.core.ExternalExternalizers$ForeignAdvancedExternalizer"); AssertJUnit.assertEquals("Type of delegate used by the adapter doesn't match expected: " + expectedExcternalizerClass.getClass(), "class " + ext.toString(), expectedExcternalizerClass.toString()); }
private int findExternalizerId(Object obj, EmbeddedCacheManager cm) { GlobalMarshaller marshaller = TestingUtil.extractGlobalMarshaller(cm); return ((AdvancedExternalizer<?>) marshaller.findExternalizerFor(obj)).getId(); }
@BeforeClass(alwaysRun=true) public void setUp() { // Manual addition of externalizers to replication what happens in fully functional tests cm = TestCacheManagerFactory.createCacheManager(); marshaller = TestingUtil.extractGlobalMarshaller(cm.getCache().getCacheManager()); }
@BeforeClass public void setUpClass() { cm = TestCacheManagerFactory.createCacheManager(false); marshaller = extractGlobalMarshaller(cm.getCache().getCacheManager()); }
public void testRepeatedLoads() throws PersistenceException { CountingStore countingCS = getCountingCacheStore(); store.write(new MarshalledEntryImpl("k1", "v1", null, extractGlobalMarshaller(cacheManager))); assert countingCS.numLoads == 0; assert countingCS.numContains == 0; assert "v1".equals(cache.get("k1")); assert countingCS.numLoads == 1 : "Expected 1, was " + countingCS.numLoads; assert countingCS.numContains == 0 : "Expected 0, was " + countingCS.numContains; assert "v1".equals(cache.get("k1")); assert countingCS.numLoads == 1 : "Expected 1, was " + countingCS.numLoads; assert countingCS.numContains == 0 : "Expected 0, was " + countingCS.numContains; }
withCacheManager(new CacheManagerCallable(createCacheManager(new ConfigurationBuilder())) { GlobalMarshaller marshaller = TestingUtil.extractGlobalMarshaller(cm);
public void testEqualsAndHashCode() throws Exception { StreamingMarshaller marshaller = extractGlobalMarshaller(cache(0).getCacheManager()); Pojo pojo = new Pojo(); WrappedBytes wb = new WrappedByteArray(marshaller.objectToByteBuffer(pojo)); WrappedBytes wb2 = new WrappedByteArray(marshaller.objectToByteBuffer(pojo)); assertTrue(wb2.hashCode() == wb.hashCode()); assertEquals(wb, wb2); }
private boolean isEntryInStore(String key) throws Exception { Cache<String, String> testCache = cacheManager.getCache(CACHE_NAME); CacheLoader<String, String> loader = TestingUtil.getFirstLoader(testCache); Object loaderKey = key; if (storage == StorageType.OFF_HEAP) { GlobalMarshaller gm = TestingUtil.extractGlobalMarshaller(testCache.getCacheManager()); loaderKey = new WrappedByteArray(gm.objectToByteBuffer(key)); } return loader.contains(loaderKey); }
public void testGetOnlyQueriesCacheOnOwners() throws PersistenceException { // Make a key that own'ers is c1 and c2 final MagicKey k = getMagicKey(); final String v1 = "real-data"; final String v2 = "stale-data"; // Simulate c3 was by itself and someone wrote a value that is now stale CacheWriter store = (CacheWriter) TestingUtil.getFirstLoader(c3); store.write(new MarshalledEntryImpl(k, v2, null, extractGlobalMarshaller(c3.getCacheManager()))); c1.put(k, v1); assertEquals(v1, c3.get(k)); }
public void testGetOnlyQueriesCacheOnOwners() throws PersistenceException { // Make a key that own'ers is c1 and c2 final MagicKey k = getMagicKey(); final String v1 = "real-data"; final String v2 = "stale-data"; // Simulate c3 was by itself and someone wrote a value that is now stale CacheWriter store = (CacheWriter) TestingUtil.getFirstLoader(c3); store.write(new MarshalledEntryImpl(k, v2, null, extractGlobalMarshaller(c3.getCacheManager()))); c1.put(k, v1); assertEquals(v1, c3.get(k)); } }
public static <K, V> void writeToAllStores(K key, V value, Cache<K, V> cache) { AdvancedCache<K, V> advCache = cache.getAdvancedCache(); PersistenceManager pm = advCache.getComponentRegistry().getComponent(PersistenceManager.class); StreamingMarshaller marshaller = extractGlobalMarshaller(advCache.getCacheManager()); KeyPartitioner keyPartitioner = extractComponent(cache, KeyPartitioner.class); pm.writeToAllNonTxStores(new MarshalledEntryImpl<>(key, value, null, marshaller), keyPartitioner.getSegment(key), BOTH); }
@BeforeClass public void setUp() { // Use a clustered cache manager to be able to test global marshaller interaction too GlobalConfigurationBuilder globalBuilder = GlobalConfigurationBuilder.defaultClusteredBuilder(); globalBuilder.serialization().addAdvancedExternalizer(new PojoWithExternalAndInternal.Externalizer()); globalBuilder.serialization().addAdvancedExternalizer(new PojoWithExternalizer.Externalizer()); globalBuilder.serialization().addAdvancedExternalizer(new PojoWithMultiExternalizer.Externalizer()); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.clustering().cacheMode(CacheMode.DIST_SYNC); cm = TestCacheManagerFactory.createClusteredCacheManager(globalBuilder, builder); marshaller = extractGlobalMarshaller(cm); }
private void putIntoStore(String key, String value) throws Exception { Cache<String, String> testCache = cacheManager.getCache(CACHE_NAME); CacheWriter<String, String> writer = TestingUtil.getFirstWriter(testCache); Object writerKey = key; Object writerValue = value; if (storage == StorageType.OFF_HEAP) { GlobalMarshaller gm = TestingUtil.extractGlobalMarshaller(testCache.getCacheManager()); writerKey = new WrappedByteArray(gm.objectToByteBuffer(key)); writerValue = new WrappedByteArray(gm.objectToByteBuffer(value)); } MarshalledEntry entry = new MarshalledEntryImpl(writerKey, writerValue, null, null); writer.write(entry); }
public void testSkipCacheFlagUsage() throws PersistenceException { CountingStore countingCS = getCountingCacheStore(); store.write(new MarshalledEntryImpl("k1", "v1", null, extractGlobalMarshaller(cacheManager))); store.write(new MarshalledEntryImpl("k2", "v2", null, extractGlobalMarshaller(cacheManager))); Object putReturn = cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD).put("k2", "v2-second"); assert putReturn == null;