@Override public String locate(String sessionId) { DistributionManager dist = this.cache.getAdvancedCache().getDistributionManager(); Address address = (dist != null) && !this.cache.getCacheConfiguration().clustering().cacheMode().isScattered() ? dist.getCacheTopology().getDistribution(new Key<>(sessionId)).primary() : this.cache.getCacheManager().getAddress(); Node node = (address != null) ? this.factory.createNode(address) : null; Map.Entry<String, Void> entry = (node != null) ? this.registry.getEntry(node) : null; if (entry == null) { entry = this.registry.getEntry(this.registry.getGroup().getLocalMember()); } return (entry != null) ? entry.getKey() : null; } }
public InfinispanCacheProperties(Configuration config) { this.transactional = config.transaction().transactionMode().isTransactional(); this.lockOnWrite = this.transactional && (config.transaction().lockingMode() == LockingMode.PESSIMISTIC); this.lockOnRead = this.lockOnWrite && (config.locking().isolationLevel() == IsolationLevel.REPEATABLE_READ); boolean clustered = config.clustering().cacheMode().needsStateTransfer(); boolean hasStore = config.persistence().usingStores(); this.marshalling = clustered || hasStore; this.persistent = clustered || (hasStore && !config.persistence().passivation()); }
@SuppressWarnings("unchecked") @Override protected void initializeKeyAndCheckData(Object key, Object value) { assertTrue("A cache store should be configured!", cache.getCacheConfiguration().persistence().usingStores()); cache.put(key, value); DataContainer container = cache.getAdvancedCache().getDataContainer(); InternalCacheEntry entry = container.get(key); CacheLoader<Object, Object> loader = TestingUtil.getFirstLoader(cache); assertNotNull("Key " + key + " does not exist in data container.", entry); assertEquals("Wrong value for key " + key + " in data container.", value, entry.getValue()); MarshalledEntry<Object, Object> entryLoaded = loader.load(key); assertNull("Key " + key + " exists in cache loader.", entryLoaded); }
@Override public void call() { ConfigurationBuilder builder = new ConfigurationBuilder(); CacheMode cacheMode = CacheMode.DIST_ASYNC; // DIST_ASYNC isn't default so it should stay applied builder.clustering().cacheMode(cacheMode); String distCacheName = "dist-cache"; cm.defineConfiguration(distCacheName, builder.build()); String templateName = "template"; cm.defineConfiguration(templateName, new ConfigurationBuilder().template(true).build()); Cache cache = cm.getCache(distCacheName, templateName); assertEquals(cacheMode, cache.getCacheConfiguration().clustering().cacheMode()); } });
public void testBackwardCompatibility() { ConfigurationBuilder c = new ConfigurationBuilder(); c.memory().storageType(StorageType.BINARY); ecm = TestCacheManagerFactory.createCacheManager(c); assertEquals(StorageType.BINARY, ecm.getCache().getCacheConfiguration().memory().storageType()); }
public void testDelayed(Method m) { initAndCheck(m); CountDownLatch release = new CountDownLatch(1); cache(1).getAdvancedCache().getAsyncInterceptorChain().addInterceptor(new DelayingInterceptor(null, release), 0); long requestStart = System.nanoTime(); assertEquals(m.getName(), cache(0).get(key)); long requestEnd = System.nanoTime(); long remoteTimeout = cache(0).getCacheConfiguration().clustering().remoteTimeout(); long delay = TimeUnit.NANOSECONDS.toMillis(requestEnd - requestStart); assertTrue(delay < remoteTimeout); release.countDown(); }
public void testRollbackSpanningCaches2() throws Exception { startAllCaches(); Cache<String, String> c1 = cache(0, "c1"); assertTrue(c1.getCacheConfiguration().clustering().cacheMode().isClustered()); Cache<String, String> c1Replica = cache(1, "c1"); assertTrue(c1.isEmpty()); assertTrue(c1Replica.isEmpty()); c1.put("c1key", "c1value"); assertEquals(c1.get("c1key"), "c1value"); assertEquals(c1Replica.get("c1key"), "c1value"); }
@Override public void call() { ConfigurationBuilder customConfiguration = TestCacheManagerFactory.getDefaultCacheConfiguration(true); customConfiguration.transaction().transactionManagerLookup(new TxManagerLookupA()); Configuration definedConfiguration = cm.defineConfiguration("aCache", customConfiguration.build()); // verify the setting was not lost: assertTrue(definedConfiguration.transaction().transactionManagerLookup() instanceof TxManagerLookupA); // verify it's actually being used: TransactionManager activeTransactionManager = cm.getCache("aCache").getAdvancedCache().getTransactionManager(); assertNotNull(activeTransactionManager); assertTrue(activeTransactionManager instanceof TmA); } });
@Override public void call() { Configuration cfg = cm.getDefaultCacheConfiguration(); assertTrue(cfg.dataContainer().<byte[]>keyEquivalence() instanceof AnyEquivalence); assertTrue(cfg.dataContainer().valueEquivalence() instanceof AnyEquivalence); assertEquals(StorageType.OFF_HEAP, cfg.memory().storageType()); assertEquals(EvictionStrategy.MANUAL, cfg.memory().evictionStrategy()); } });
protected void checkConsistencyAcrossCluster(String cacheName, Configuration configuration) { // Initialize the partitioner to ensure we can compare config equality configuration.clustering().hash().keyPartitioner().init(configuration.clustering().hash()); for (EmbeddedCacheManager m : cacheManagers) { Configuration actualConfiguration = m.getCacheConfiguration(cacheName); assertNotNull("Cache " + cacheName + " missing from " + m, actualConfiguration); assertEquals(configuration, actualConfiguration); Cache<Object, Object> cache = m.getCache(cacheName); assertEquals(cacheManagers.size(), cache.getAdvancedCache().getRpcManager().getMembers().size()); } }
public void testDefaultEnlistment() { ConfigurationBuilder builder = getLocalBuilder(); builder.transaction().transactionMode(TransactionMode.TRANSACTIONAL); dcm = new DefaultCacheManager(getGlobalConfig(), builder.build()); Cache<Object,Object> cache = dcm.getCache(); assertFalse(cache.getCacheConfiguration().transaction().useSynchronization()); assertFalse(cache.getCacheConfiguration().transaction().recovery().enabled()); cache.put("k", "v"); assertEquals("v", cache.get("k")); }
@Override public void call() { GlobalConfiguration globalCfg = cm.getCacheManagerConfiguration(); assertFalse(globalCfg.defaultCacheName().isPresent()); assertNull(cm.getDefaultCacheConfiguration()); assertEquals(CacheMode.REPL_SYNC, cm.getCacheConfiguration("default").clustering().cacheMode()); }
@Override public void call() { GlobalConfiguration globalCfg = cm.getCacheManagerConfiguration(); assertTrue(globalCfg.transport().transport() instanceof JGroupsTransport); assertEquals("demoCluster", globalCfg.transport().clusterName()); Configuration cfg = cm.getDefaultCacheConfiguration(); assertEquals(CacheMode.REPL_SYNC, cfg.clustering().cacheMode()); }
public void testConfig() { assertTrue(cacheManager.getCache("syncEnabled").getCacheConfiguration().transaction().useSynchronization()); assertFalse(cacheManager.getCache("notSpecified").getCacheConfiguration().transaction().useSynchronization()); cacheManager.getCache("syncAndRecovery"); }
/** * Tests that the configuration contains the values expected, as well as immutability of certain elements */ public void testConfiguration() { Configuration c = cache.getCacheConfiguration(); assertEquals(CacheMode.LOCAL, c.clustering().cacheMode()); assertNotNull(c.transaction().transactionManagerLookup()); }
public void testConfigOverride() { ConfigurationBuilder configuration = getDefaultStandaloneCacheConfig(true); configuration.transaction().useSynchronization(true); cacheManager.defineConfiguration("newCache", configuration.build()); assertTrue(cacheManager.getCache("newCache").getCacheConfiguration().transaction().useSynchronization()); } }
@Override public void check(ConfigurationBuilderHolder holder) { Configuration local = getConfiguration(holder, "local"); PersistenceConfiguration persistenceConfiguration = local.persistence(); assertEquals(5, persistenceConfiguration.connectionAttempts()); assertEquals(100, persistenceConfiguration.connectionInterval()); assertEquals(2000, persistenceConfiguration.availabilityInterval()); assertFalse(persistenceConfiguration.stores().isEmpty()); AsyncStoreConfiguration asyncConfig = persistenceConfiguration.stores().iterator().next().async(); assertTrue(asyncConfig.failSilently()); } },
private CacheTopology getCounterCacheTopology(EmbeddedCacheManager cacheManager) { AdvancedCache<?, ?> cache = cacheManager.getCache(CounterModuleLifecycle.COUNTER_CACHE_NAME).getAdvancedCache(); return cache.getCacheConfiguration().clustering().cacheMode().isClustered() ? cache.getComponentRegistry().getDistributionManager().getCacheTopology() : null; //local cache }
@Override protected EmbeddedCacheManager createCacheManager() throws Exception { ConfigurationBuilder cb = getDefaultStandaloneCacheConfig(false); configurePersistence(cb); EmbeddedCacheManager manager = TestCacheManagerFactory.createCacheManager(cb); cache = manager.getCache(); ComponentRegistry componentRegistry = cache.getAdvancedCache().getComponentRegistry(); PersistenceManagerImpl pm = (PersistenceManagerImpl) componentRegistry.getComponent(PersistenceManager.class); sm = pm.getMarshaller(); store = TestingUtil.getFirstLoader(cache); keys = new Set[cache.getCacheConfiguration().clustering().hash().numSegments()]; return manager; }
public void testSpecificCacheManager() throws Exception { assertEquals(largeCache.getCacheConfiguration().memory().size(), 2000); assertEquals(largeCache.getCacheManager().getDefaultCacheConfiguration().memory().size(), 4000); assertEquals(smallCache.getCacheConfiguration().memory().size(), 20); assertEquals(smallCache.getCacheManager().getDefaultCacheConfiguration().memory().size(), 4000); // asserts that the small and large cache are defined in the same cache manager assertTrue(smallCache.getCacheManager().equals(largeCache.getCacheManager())); assertFalse(smallCache.getCacheManager().equals(cache.getCacheManager())); // check that the default configuration has not been modified assertEquals(cache.getCacheConfiguration().memory().size(), -1); } }