@Override public TransactionConfiguration get() { TransactionConfigurationBuilder builder = new ConfigurationBuilder().transaction() .lockingMode(this.locking) .cacheStopTimeout(this.timeout) .transactionMode((this.mode == TransactionMode.NONE) ? org.infinispan.transaction.TransactionMode.NON_TRANSACTIONAL : org.infinispan.transaction.TransactionMode.TRANSACTIONAL) .useSynchronization(this.mode == TransactionMode.NON_XA) .recovery().enabled(this.mode == TransactionMode.FULL_XA).transaction() ; switch (this.mode) { case NONE: { break; } case BATCH: { builder.transactionManagerLookup(new TransactionManagerProvider(EmbeddedTransactionManager.getInstance())); break; } case NON_XA: { builder.transactionSynchronizationRegistryLookup(new TransactionSynchronizationRegistryProvider(this.tsrDependency.get())); // fall through } default: { builder.transactionManagerLookup(new TransactionManagerProvider(ContextTransactionManager.getInstance())); } } return builder.create(); } }
protected ConfigurationBuilder getConfigurationBuilder() { ConfigurationBuilder c = new ConfigurationBuilder(); c.clustering().cacheMode(CacheMode.DIST_SYNC); c.transaction().transactionMode(TransactionMode.NON_TRANSACTIONAL); return c; }
static AdvancedCache getTargetCache(EmbeddedCacheManager manager, Properties properties) { StoreProperties props = new StoreProperties(TARGET, properties); ConfigurationBuilder configBuilder = new ConfigurationBuilder(); String segmentCountString = props.get(SEGMENT_COUNT); // 0 means not enabled int segmentCount = 0; if (segmentCountString != null) { segmentCount = Integer.parseInt(segmentCountString); if (segmentCount < 0) { throw new IllegalArgumentException("Segment count must be > 0"); } } if (segmentCount > 0) { configBuilder.clustering().hash().numSegments(segmentCount); } configBuilder.persistence().addStore(getInitializedStoreBuilder(props)) .purgeOnStartup(true) .segmented(segmentCount > 0); configBuilder.invocationBatching().transaction() .transactionMode(TransactionMode.TRANSACTIONAL) .transactionManagerLookup(new EmbeddedTransactionManagerLookup()); String cacheName = props.cacheName(); manager.defineConfiguration(cacheName, configBuilder.build()); return manager.getCache(cacheName).getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD); }
@Override protected void createCacheManagers() throws Throwable { builderUsed = new ConfigurationBuilder(); builderUsed.clustering().cacheMode(cacheMode); if (transactional) { builderUsed.transaction().transactionMode(TransactionMode.TRANSACTIONAL); } if (cacheMode.isClustered()) { builderUsed.clustering().stateTransfer().chunkSize(50); enhanceConfiguration(builderUsed); createClusteredCaches(3, CACHE_NAME, builderUsed); } else { enhanceConfiguration(builderUsed); EmbeddedCacheManager cm = TestCacheManagerFactory.createCacheManager(builderUsed); cacheManagers.add(cm); cm.defineConfiguration(CACHE_NAME, builderUsed.build()); } }
protected EmbeddedCacheManager createCacheManager() throws Exception { EmbeddedCacheManager cm = TestCacheManagerFactory.createCacheManager(false); // also try this test with 'true' so you can tell the difference between DummyTransactionManager and JBoss TM ConfigurationBuilder cb = new ConfigurationBuilder(); cb.transaction().transactionMode(TransactionMode.TRANSACTIONAL) //default to write-skew .locking().lockAcquisitionTimeout(TestingUtil.shortTimeoutMillis()); cm.defineConfiguration("test", cb.build()); cache = cm.getCache("test"); return cm; }
protected void createCacheManagers() throws Throwable { ConfigurationBuilder c = new ConfigurationBuilder(); c.clustering().cacheMode(CacheMode.REPL_SYNC) .remoteTimeout(30000) .transaction().transactionMode(TransactionMode.TRANSACTIONAL) .invocationBatching().enable() .locking().lockAcquisitionTimeout(60000).useLockStriping(false); EmbeddedCacheManager container = TestCacheManagerFactory.createClusteredCacheManager(c); container.start(); registerCacheManager(container); container.defineConfiguration(TEST_CACHE, c.build()); container.startCaches(TEST_CACHE); Cache cache1 = container.getCache(TEST_CACHE); assert cache1.getCacheConfiguration().clustering().cacheMode().equals(CacheMode.REPL_SYNC); cache1.start(); container = TestCacheManagerFactory.createClusteredCacheManager(c); container.start(); registerCacheManager(container); container.defineConfiguration(TEST_CACHE, c.build()); container.startCaches(TEST_CACHE); Cache cache2 = container.getCache(TEST_CACHE); assert cache2.getCacheConfiguration().clustering().cacheMode().equals(CacheMode.REPL_SYNC); }
public void testFineGrainedAtomicMapWithoutTransactionManagerLookupSet() { ConfigurationBuilder builder = buildConfiguration(); builder.transaction().transactionMode(TransactionMode.TRANSACTIONAL).transactionManagerLookup(null); cacheManager.defineConfiguration("fgahm_without_tmlookup", builder.build()); Cache<String, String> fgahmCache = cacheManager.getCache("fgahm_without_tmlookup"); FineGrainedAtomicMap<String, String> map = AtomicMapLookup.getFineGrainedAtomicMap(fgahmCache, "key"); assert map.isEmpty(); map.put("a", "b"); assert map.get("a").equals("b"); // now re-retrieve the map and make sure we see the diffs assert AtomicMapLookup.getFineGrainedAtomicMap(fgahmCache, "key").get("a").equals("b"); }
protected <K, V> Cache<K, V> createCache(String name) { ConfigurationBuilder c = new ConfigurationBuilder(); c.transaction().transactionManagerLookup(new MyDummyTransactionManagerLookup()); c.invocationBatching().enable(); c.transaction().transactionMode(TransactionMode.TRANSACTIONAL); cacheManager.defineConfiguration(name, c.build()); return cacheManager.getCache(name); }
private Cache getCache() { GlobalConfigurationBuilder gc = GlobalConfigurationBuilder.defaultClusteredBuilder(); ConfigurationBuilder c = new ConfigurationBuilder(); c.clustering().cacheMode(CacheMode.REPL_SYNC) .remoteTimeout(30000) .transaction().invocationBatching().enable() .locking().lockAcquisitionTimeout(60000).useLockStriping(false); EmbeddedCacheManager container = TestCacheManagerFactory.createClusteredCacheManager(gc, c); cacheContainers.add(container); container.defineConfiguration("TestCache", c.build()); return container.getCache("TestCache"); } }
private Configuration getInternalCacheConfig() { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); // allow the registry to work for local caches as well as clustered caches CacheMode cacheMode = cacheManager.getGlobalComponentRegistry().getGlobalConfiguration().isClustered() ? CacheMode.REPL_SYNC : CacheMode.LOCAL; configurationBuilder.clustering().cacheMode(cacheMode); // use invocation batching (cache-only transactions) for high consistency as writes are expected to be rare in this cache configurationBuilder.transaction().transactionMode(TransactionMode.TRANSACTIONAL) .transactionManagerLookup(null).invocationBatching().enable(); configurationBuilder.security().authorization().disable(); return configurationBuilder.build(); }
public void testForceUnsharedComponents() { ConfigurationBuilder defaultCfg = getDefaultClusteredCacheConfig(CacheMode.REPL_SYNC); defaultCfg .clustering() .stateTransfer() .fetchInMemoryState(false); // cache manager with default configuration cm = TestCacheManagerFactory.createClusteredCacheManager(defaultCfg); // default cache with no overrides Cache c = cm.getCache(); ConfigurationBuilder overrides = TestCacheManagerFactory.getDefaultCacheConfiguration(true); overrides.transaction().transactionManagerLookup(new EmbeddedTransactionManagerLookup()); cm.defineConfiguration("transactional", overrides.build()); Cache transactional = cm.getCache("transactional"); // assert components. assert TestingUtil.extractComponent(c, EvictionManager.class) != null; assert TestingUtil.extractComponent(transactional, EvictionManager.class) != null; assert TestingUtil.extractComponent(c, EvictionManager.class) != TestingUtil.extractComponent(transactional, EvictionManager.class); }
ConfigurationBuilder confBuilder = new ConfigurationBuilder(); confBuilder.read(defaultConf); confBuilder.locking().isolationLevel(IsolationLevel.READ_COMMITTED).concurrencyLevel(32).useLockStriping(false) .lockAcquisitionTimeout(10000); confBuilder.transaction().transactionMode(TransactionMode.TRANSACTIONAL).syncRollbackPhase(false).cacheStopTimeout(30000) .useSynchronization(true).syncCommitPhase(true).lockingMode(LockingMode.OPTIMISTIC) .use1PcForAutoCommitTransactions(false).autoCommit(false);
@Test(expectedExceptions = CacheConfigurationException.class) public void testRecoveryAndAsyncCaches() { //Note: this configuration uses Xa Enlistment (see configs/recovery-enabled-config.xml). Configuration defaultConfig = cacheManager.getDefaultCacheConfiguration(); ConfigurationBuilder builder = new ConfigurationBuilder().read(defaultConfig); builder.clustering().cacheMode(CacheMode.REPL_ASYNC); builder.transaction().recovery().enable(); //it should throw an exception when try to build this configuration. builder.build(); }
public void testManyTxs() throws Throwable { ConfigurationBuilder cfg = TestCacheManagerFactory.getDefaultCacheConfiguration(true); cfg.clustering().cacheMode(CacheMode.DIST_SYNC) .stateTransfer().awaitInitialTransfer(false) .transaction().lockingMode(LockingMode.OPTIMISTIC); manager(0).defineConfiguration(CACHE_NAME, cfg.build()); manager(1).defineConfiguration(CACHE_NAME, cfg.build());
@Override protected EmbeddedCacheManager createCacheManager() throws Exception { final ConfigurationBuilder config = getDefaultStandaloneCacheConfig(true); config.transaction().lockingMode(LockingMode.PESSIMISTIC) .transactionManagerLookup(new EmbeddedTransactionManagerLookup()) .useSynchronization(false) .recovery().disable(); return TestCacheManagerFactory.createCacheManager(config); }
@BeforeMethod protected void setUp() throws Exception { ConfigurationBuilder configurationBuilder = TestCacheManagerFactory.getDefaultCacheConfiguration(true); configurationBuilder.transaction().invocationBatching().enable() .clustering().cacheMode(CacheMode.DIST_SYNC) .clustering().hash().numOwners(1) .clustering().stateTransfer().fetchInMemoryState(false); manager1 = TestCacheManagerFactory.createClusteredCacheManager(configurationBuilder); manager1.defineConfiguration("test", configurationBuilder.build()); cache1 = manager1.getCache("test").getAdvancedCache(); ex1 = Executors.newSingleThreadExecutor(getTestThreadFactory("KeyGenerator1")); keyAffinityService1 = KeyAffinityServiceFactory.newLocalKeyAffinityService(cache1, new RndKeyGenerator(), ex1, KEY_QUEUE_SIZE); log.trace("Address for manager1: " + manager1.getAddress()); manager2 = TestCacheManagerFactory.createClusteredCacheManager(configurationBuilder); manager2.defineConfiguration("test", configurationBuilder.build()); cache2 = manager2.getCache("test").getAdvancedCache(); ex2 = Executors.newSingleThreadExecutor(getTestThreadFactory("KeyGenerator2")); keyAffinityService2 = KeyAffinityServiceFactory.newLocalKeyAffinityService(cache2, new RndKeyGenerator(), ex2, KEY_QUEUE_SIZE); log.trace("Address for manager2: " + manager2.getAddress()); TestingUtil.blockUntilViewsReceived(60000, cache1, cache2); Thread.sleep(5000); }
@Test(expectedExceptions = IllegalStateException.class) public void testFineGrainedAtomicMapNonTransactionWithoutBatchSet() { ConfigurationBuilder builder = buildConfiguration(); builder.invocationBatching().disable(); builder.transaction().transactionMode(TransactionMode.NON_TRANSACTIONAL); cacheManager.defineConfiguration("fgahm_no_tx_without_batch", builder.build()); Cache<String, String> fgahmCache = cacheManager.getCache("fgahm_no_tx_without_batch"); FineGrainedAtomicMap<String, String> map = AtomicMapLookup.getFineGrainedAtomicMap(fgahmCache, "key"); assert map.isEmpty(); map.put("a", "b"); assert map.get("a").equals("b"); // now re-retrieve the map and make sure we see the diffs assert AtomicMapLookup.getFineGrainedAtomicMap(fgahmCache, "key").get("a").equals("b"); }
@Override protected EmbeddedCacheManager createCacheManager() throws Exception { ConfigurationBuilder builder = new ConfigurationBuilder(); builder .transaction() .transactionManagerLookup(new EmbeddedTransactionManagerLookup()) .transactionMode(TransactionMode.TRANSACTIONAL) .lockingMode(LockingMode.OPTIMISTIC) .locking().lockAcquisitionTimeout(TestingUtil.shortTimeoutMillis()) .isolationLevel(IsolationLevel.REPEATABLE_READ); EmbeddedCacheManager cacheManager = TestCacheManagerFactory.createCacheManager(builder); cacheManager.defineConfiguration("cache", builder.build()); return cacheManager; }
@Override protected EmbeddedCacheManager createCacheManager() throws Exception { EmbeddedCacheManager cm = TestCacheManagerFactory.createClusteredCacheManager(); for (CacheType cacheType : CacheType.values()) { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.persistence() .addStore(DummyInMemoryStoreConfigurationBuilder.class) .preload(true) .storeName(this.getClass().getName()).async().enable(); builder.transaction().transactionMode(cacheType.transactionMode).useSynchronization(cacheType.useSynchronization) .recovery().enabled(cacheType.useRecovery); builder.customInterceptors().addInterceptor().index(0).interceptor(new ExceptionTrackerInterceptor()); cm.defineConfiguration(cacheType.cacheName, builder.build()); } return cm; }
@Override protected void createCacheManagers() throws Throwable { ConfigurationBuilder configurationBuilder = getDefaultClusteredCacheConfig(CacheMode.REPL_SYNC, true); configurationBuilder.clustering().hash().numSegments(60).groups().enabled(); configurationBuilder.transaction() .transactionMode(TransactionMode.TRANSACTIONAL).transactionManagerLookup(new EmbeddedTransactionManagerLookup()) .lockingMode(LockingMode.PESSIMISTIC) .locking().lockAcquisitionTimeout(TestingUtil.shortTimeoutMillis()); createClusteredCaches(2, "atomic", configurationBuilder); }