Updater(Cache cache, MagicKey key, CountDownLatch latch, boolean tx) { super("Updater-" + key); this.key = key; this.cache = cache; this.latch = latch; if (tx) tm = TestingUtil.getTransactionManager(cache); }
WritingTask(Cache<Object, Object> cache, boolean tx) { this.cache = cache; this.tx = tx; if (tx) tm = TestingUtil.getTransactionManager(cache); }
private Stressor(Cache<String, String> cache, int cacheId, int workerId, Set<String> keysToIgnore) { this.cache = cache; tm = TestingUtil.getTransactionManager(cache); this.cacheId = cacheId; this.workerId = workerId; this.keysToIgnore = keysToIgnore; }
@Override public String call() throws Exception { TransactionManager mgr = TestingUtil.getTransactionManager(nonOwner); mgr.begin(); try { return owner.put(key, otherValue); } finally { mgr.commit(); } } });
private static void clearRunningTx(Cache cache) { if (cache != null) { TransactionManager txm = TestingUtil.getTransactionManager(cache); killTransaction(txm); } }
private void assertNotLocked(Cache<String, String> c, String key) throws SystemException, NotSupportedException { TransactionManager tm = TestingUtil.getTransactionManager(c); tm.begin(); try { c.put(key, "dummy"); // should time out } catch (TimeoutException e) { assert false : "Should not have been locked!"; } finally { tm.rollback(); } } }
private void assertAllHaveNewValue(Object key) throws Exception { for (Cache c : caches()) { Object actual; TestingUtil.getTransactionManager(c).begin(); actual = c.get(key); TestingUtil.getTransactionManager(c).commit(); assertEquals(actual, "newValue"); } }
public void simpleReplicationTest() throws Exception { TransactionManager tm = TestingUtil.getTransactionManager(cache1); tm.begin(); cache1.put("key", "value"); tm.commit(); assertEquals("value", cache2.get("key")); }
public void testTxCommit3() throws Exception { TransactionManager tm = TestingUtil.getTransactionManager(cache); tm.begin(); cache.put("key", "value"); tm.commit(); assertFalse(cache.isEmpty()); }
public void testMarkAsRollbackAfterMods() throws Exception { TransactionManager tm = TestingUtil.getTransactionManager(cache); assert tm != null; tm.begin(); cache.put("k", "v"); assert cache.get("k").equals("v"); tm.setRollbackOnly(); expectException(RollbackException.class, () -> tm.commit()); assert tm.getTransaction() == null : "There should be no transaction in scope anymore!"; assert cache.get("k") == null : "Expected a null but was " + cache.get("k"); }
public void testMarkAsRollbackBeforeMods() throws Exception { TransactionManager tm = TestingUtil.getTransactionManager(cache); assert tm != null; tm.begin(); tm.setRollbackOnly(); expectException(CacheException.class, IllegalStateException.class, () -> cache.put("k", "v")); expectException(RollbackException.class, () -> tm.commit()); assert tm.getTransaction() == null : "There should be no transaction in scope anymore!"; assert cache.get("k") == null : "Expected a null but was " + cache.get("k"); } }
@BeforeClass public void setUp() { ConfigurationBuilder c = new ConfigurationBuilder(); c.invocationBatching().enable(); cacheContainer = TestCacheManagerFactory.createCacheManager(c); cache = cacheContainer.getCache(); tm = TestingUtil.getTransactionManager(cache); }
public void testTxCommit1() throws Exception { TransactionManager tm = TestingUtil.getTransactionManager(cache); tm.begin(); cache.put("key", "value"); Transaction t = tm.suspend(); assertTrue(cache.isEmpty()); tm.resume(t); tm.commit(); assertFalse(cache.isEmpty()); }
@BeforeMethod public void setUp() throws Exception { ConfigurationBuilder builder = TestCacheManagerFactory.getDefaultCacheConfiguration(true); builder.transaction().autoCommit(false) .clustering().cacheMode(CacheMode.LOCAL) .locking().isolationLevel(IsolationLevel.REPEATABLE_READ); cm = TestCacheManagerFactory.createCacheManager(builder); cache = cm.getCache(); tm = TestingUtil.getTransactionManager(cache); mockNotifier = mock(CacheNotifier.class); origNotifier = TestingUtil.replaceComponent(cache, CacheNotifier.class, mockNotifier, true); }
@Override protected EmbeddedCacheManager createCacheManager() throws Exception { ConfigurationBuilder cacheConfiguration = TestCacheManagerFactory.getDefaultCacheConfiguration(true); cacheConfiguration.transaction().lockingMode(LockingMode.PESSIMISTIC); EmbeddedCacheManager cacheManager = TestCacheManagerFactory.createCacheManager(cacheConfiguration); advancedCache = cacheManager.<String, String>getCache().getAdvancedCache(); tm = TestingUtil.getTransactionManager(advancedCache); return cacheManager; }
@BeforeMethod(alwaysRun = true) public void setUp() { cfg = getConfiguration(); configure(cfg); cm = TestCacheManagerFactory.createCacheManager(cfg); cache = getCache(cm); store = TestingUtil.getFirstLoader(cache); writer = TestingUtil.getFirstLoader(cache); tm = TestingUtil.getTransactionManager(cache); sm = cache.getAdvancedCache().getComponentRegistry().getCacheMarshaller(); }
public void testSimpleCommit() throws Exception { startAllCaches(); Cache<String, String> c1 = cache(0, "c1"); Cache<String, String> c1Replica = cache(1, "c1"); assertTrue(c1.isEmpty()); assertTrue(c1Replica.isEmpty()); TransactionManager tm = TestingUtil.getTransactionManager(c1); tm.begin(); c1.put("c1key", "c1value"); tm.commit(); assertEquals(c1.get("c1key"), "c1value"); assertEquals(c1Replica.get("c1key"), "c1value"); }
protected void createCacheManagers() throws Throwable { ConfigurationBuilder cb = getDefaultClusteredCacheConfig(CacheMode.REPL_SYNC, true); cb.invocationBatching().enable(); createClusteredCaches(2, "replSync", cb); Cache c1 = cache(0, "replSync"); Cache c2 = cache(1, "replSync"); tm1 = TestingUtil.getTransactionManager(c1); cache1 = new TreeCacheImpl<Object, Object>(c1); cache2 = new TreeCacheImpl<Object, Object>(c2); }
public void testSizeInExplicitTxWithModification() throws Exception { assertEquals(0, cache.size()); cache.put("k1", "v1"); TransactionManager tm = TestingUtil.getTransactionManager(cache); withTx(tm, () -> { assertNull(cache.put("k2", "v2")); assertEquals(2, cache.size()); tm.setRollbackOnly(); return null; }); }
public void testSizeInExplicitTxWithRemoveExistent() throws Exception { assertEquals(0, cache.size()); cache.put("k", "v"); TransactionManager tm = TestingUtil.getTransactionManager(cache); withTx(tm, () -> { assertNull(cache.put("exist", "value")); assertEquals(2, cache.size()); assertEquals("value", cache.remove("exist")); assertEquals(1, cache.size()); tm.setRollbackOnly(); return null; }); }