public void testVisibilityOfCommittedDataPut() throws Exception { Cache<String, String> c = lockTestData.cache; c.put("k", "v"); assertEquals("v", c.get("k")); // start a tx and read K lockTestData.tm.begin(); assertEquals("v", c.get("k")); assertEquals("v", c.get("k")); Transaction reader = lockTestData.tm.suspend(); lockTestData.tm.begin(); c.put("k", "v2"); Transaction writer = lockTestData.tm.suspend(); lockTestData.tm.resume(reader); assertEquals("Should not read uncommitted data", "v", c.get("k")); reader = lockTestData.tm.suspend(); lockTestData.tm.resume(writer); lockTestData.tm.commit(); lockTestData.tm.resume(reader); assertEquals("Should read committed data", "v2", c.get("k")); lockTestData.tm.commit(); }
public void testVisibilityOfCommittedDataReplace() throws Exception { Cache<String, String> c = lockTestData.cache; c.put("k", "v"); assertEquals("v", c.get("k")); // start a tx and read K lockTestData.tm.begin(); assertEquals("v", c.get("k")); assertEquals("v", c.get("k")); Transaction reader = lockTestData.tm.suspend(); lockTestData.tm.begin(); c.replace("k", "v2"); Transaction writer = lockTestData.tm.suspend(); lockTestData.tm.resume(reader); assertEquals("Should not read uncommitted data", "v", c.get("k")); reader = lockTestData.tm.suspend(); lockTestData.tm.resume(writer); lockTestData.tm.commit(); lockTestData.tm.resume(reader); assertEquals("Should read committed data", "v2", c.get("k")); lockTestData.tm.commit(); }
private void testLockMigrationAfterPrepare(Object key) throws Exception { final EmbeddedTransactionManager tm = embeddedTm(ORIGINATOR_INDEX); tm.begin(); originatorCache.put(key, "value"); EmbeddedTransaction tx = tm.getTransaction(); boolean prepareSuccess = tx.runPrepare(); assert prepareSuccess; tm.suspend(); log.trace("Lock transfer happens here"); killCache(); checkNewTransactionFails(key); log.trace("About to commit existing transaction."); tm.resume(tx); tx.runCommit(false); // read the data from the container, just to make sure all replicas are correctly set checkValue(key, "value"); }
public void testConcurrentWriters() throws Exception { LockTestData tl = lockTestData; Cache<String, String> cache = tl.cache; EmbeddedTransactionManager tm = tl.tm; tm.begin(); cache.put("k", "v"); final EmbeddedTransaction transaction = tm.getTransaction(); assertTrue(transaction.runPrepare()); tm.suspend(); tm.begin(); cache.put("k", "v"); assert !tm.getTransaction().runPrepare(); tm.rollback(); tm.resume(transaction); transaction.runCommit(false); assertNoLocks(); }
tm.resume(tx); tx.runCommit(false);
public void testSplitBeforeCommit() throws Exception { //the transaction is successfully prepare and then the split happens before the commit phase starts. waitForClusterToForm(OPTIMISTIC_TX_CACHE_NAME); final KeyInfo keyInfo = createKeys(OPTIMISTIC_TX_CACHE_NAME); final Cache<Object, String> originator = cache(0, OPTIMISTIC_TX_CACHE_NAME); final EmbeddedTransactionManager transactionManager = (EmbeddedTransactionManager) originator.getAdvancedCache().getTransactionManager(); transactionManager.begin(); final EmbeddedTransaction transaction = transactionManager.getTransaction(); keyInfo.putFinalValue(originator); AssertJUnit.assertTrue(transaction.runPrepare()); transactionManager.suspend(); SplitMode.BOTH_DEGRADED.split(this); transactionManager.resume(transaction); transaction.runCommit(false); assertLocked(cache(1, OPTIMISTIC_TX_CACHE_NAME), keyInfo.getKey1()); assertLocked(cache(2, OPTIMISTIC_TX_CACHE_NAME), keyInfo.getKey2()); mergeCluster(OPTIMISTIC_TX_CACHE_NAME); finalAsserts(OPTIMISTIC_TX_CACHE_NAME, keyInfo, FINAL_VALUE); }
public void testSplitBeforeRollback() throws Exception { //the transaction is successfully prepare and then the split happens before the commit phase starts. waitForClusterToForm(OPTIMISTIC_TX_CACHE_NAME); final KeyInfo keyInfo = createKeys(OPTIMISTIC_TX_CACHE_NAME); final Cache<Object, String> originator = cache(0, OPTIMISTIC_TX_CACHE_NAME); final EmbeddedTransactionManager transactionManager = (EmbeddedTransactionManager) originator.getAdvancedCache().getTransactionManager(); transactionManager.begin(); final EmbeddedTransaction transaction = transactionManager.getTransaction(); keyInfo.putFinalValue(originator); AssertJUnit.assertTrue(transaction.runPrepare()); transactionManager.suspend(); SplitMode.BOTH_DEGRADED.split(this); transactionManager.resume(transaction); transaction.runCommit(true); assertEventuallyNotLocked(cache(1, OPTIMISTIC_TX_CACHE_NAME), keyInfo.getKey1()); assertLocked(cache(2, OPTIMISTIC_TX_CACHE_NAME), keyInfo.getKey2()); mergeCluster(OPTIMISTIC_TX_CACHE_NAME); finalAsserts(OPTIMISTIC_TX_CACHE_NAME, keyInfo, INITIAL_VALUE); }