[jbosscache-commits] JBoss Cache SVN: r7319 - core/trunk/src/test/java/org/jboss/cache/invocationcontext.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Fri Dec 12 18:59:35 EST 2008
Author: mircea.markus
Date: 2008-12-12 18:59:35 -0500 (Fri, 12 Dec 2008)
New Revision: 7319
Added:
core/trunk/src/test/java/org/jboss/cache/invocationcontext/OnePcTransactionTest.java
core/trunk/src/test/java/org/jboss/cache/invocationcontext/TwoPcTransactionTest.java
Removed:
core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java
Log:
refacotred for performance
Copied: core/trunk/src/test/java/org/jboss/cache/invocationcontext/OnePcTransactionTest.java (from rev 7308, core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java)
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invocationcontext/OnePcTransactionTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/invocationcontext/OnePcTransactionTest.java 2008-12-12 23:59:35 UTC (rev 7319)
@@ -0,0 +1,93 @@
+package org.jboss.cache.invocationcontext;
+
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.UnitTestCacheFactory;
+import org.jboss.cache.AbstractSingleCacheTest;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.transaction.TransactionContext;
+import org.jboss.cache.transaction.TransactionTable;
+import org.jboss.cache.transaction.GenericTransactionManagerLookup;
+import org.jboss.cache.util.TestingUtil;
+import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.util.Map;
+
+/**
+ * A test to ensure the transactional context is properly set up in the IC
+ *
+ * @author <a href="mailto:manik AT jboss DOT org">Manik Surtani</a>
+ */
+ at Test(groups = {"functional", "transaction"}, testName = "invocationcontext.OnePcTransactionTest")
+public class OnePcTransactionTest extends AbstractSingleCacheTest
+{
+ private TransactionManager tm;
+
+ protected CacheSPI createCache()
+ {
+ Configuration config = new Configuration();
+ config.setTransactionManagerLookupClass(GenericTransactionManagerLookup.class.getName());
+ config.setCacheMode(CacheMode.REPL_ASYNC);
+ cache = (CacheSPI) new UnitTestCacheFactory().createCache(config, true, getClass());
+ tm = cache.getTransactionManager();
+ return cache;
+ }
+
+ public void testTxExistenceAfterWrite() throws Exception
+ {
+ // make sure we have a running transaction.
+ tm.begin();
+
+ assertNull("Tx should not have been set up yet", cache.getInvocationContext().getTransaction());
+ assertNull("Gtx should not have been set up yet", cache.getInvocationContext().getGlobalTransaction());
+
+ // now make a WRITE call into the cache (should start a tx)
+ cache.getRoot().put("k", "v");
+ Map data = cache.getRoot().getData();
+ assertEquals("Data map should not empty", 1, data.size());
+
+ // but now we should have a local tx registered in the invocation context
+ assertNotNull("Tx should have been set up by now", cache.getInvocationContext().getTransaction());
+ assertEquals("The same current transaction should be associated with this invocation ctx.", tm.getTransaction(), cache.getInvocationContext().getTransaction());
+ assertNotNull("Gtx should have been set up by now", cache.getInvocationContext().getGlobalTransaction());
+
+ tm.commit();
+ }
+
+ public void testTxExistenceAfterRead() throws Exception
+ {
+ // make sure we have a running transaction.
+ tm.begin();
+
+ assertNull("Tx should not have been set up yet", cache.getInvocationContext().getTransaction());
+ assertNull("Gtx should not have been set up yet", cache.getInvocationContext().getGlobalTransaction());
+
+ // now make a WRITE call into the cache (should start a tx)
+ Object value = cache.get(Fqn.ROOT, "k");
+ assertNull("Value should be null", value);
+
+ // but now we should have a local tx registered in the invocation context
+ assertNotNull("Tx should have been set up by now", cache.getInvocationContext().getTransaction());
+ assertEquals("The same current transaction should be associated with this invocation ctx.", tm.getTransaction(), cache.getInvocationContext().getTransaction());
+ assertNotNull("Gtx should have been set up by now", cache.getInvocationContext().getGlobalTransaction());
+
+ tm.commit();
+ }
+
+ public void testScrubbingAfterOnePhaseCommit() throws Exception
+ {
+ TwoPcTransactionTest.doScrubbingTest(cache, tm, true);
+ }
+
+ public void testScrubbingAfterOnePhaseRollback() throws Exception
+ {
+ TwoPcTransactionTest.doScrubbingTest(cache, tm, false);
+ }
+
+}
Property changes on: core/trunk/src/test/java/org/jboss/cache/invocationcontext/OnePcTransactionTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Deleted: core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java 2008-12-12 23:28:06 UTC (rev 7318)
+++ core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java 2008-12-12 23:59:35 UTC (rev 7319)
@@ -1,159 +0,0 @@
-package org.jboss.cache.invocationcontext;
-
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.UnitTestCacheFactory;
-import org.jboss.cache.config.Configuration.CacheMode;
-import org.jboss.cache.transaction.TransactionContext;
-import org.jboss.cache.transaction.TransactionTable;
-import org.jboss.cache.util.TestingUtil;
-import static org.testng.AssertJUnit.*;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-import java.util.Map;
-
-/**
- * A test to ensure the transactional context is properly set up in the IC
- *
- * @author <a href="mailto:manik AT jboss DOT org">Manik Surtani</a>
- */
- at Test(groups = {"functional", "transaction"}, testName = "invocationcontext.TransactionTest")
-public class TransactionTest
-{
- private CacheSPI<Object, Object> cache;
- private TransactionManager tm;
-
- @BeforeMethod(alwaysRun = true)
- public void setUp()
- {
- cache = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache("configs/local-tx.xml", getClass());
- tm = cache.getTransactionManager();
- }
-
- @AfterMethod(alwaysRun = true)
- public void tearDown()
- {
- TestingUtil.killCaches(cache);
- cache = null;
- }
-
- public void testTxExistenceAfterWrite() throws Exception
- {
- // make sure we have a running transaction.
- tm.begin();
-
- assertNull("Tx should not have been set up yet", cache.getInvocationContext().getTransaction());
- assertNull("Gtx should not have been set up yet", cache.getInvocationContext().getGlobalTransaction());
-
- // now make a WRITE call into the cache (should start a tx)
- cache.getRoot().put("k", "v");
- Map data = cache.getRoot().getData();
- assertEquals("Data map should not empty", 1, data.size());
-
- // but now we should have a local tx registered in the invocation context
- assertNotNull("Tx should have been set up by now", cache.getInvocationContext().getTransaction());
- assertEquals("The same current transaction should be associated with this invocation ctx.", tm.getTransaction(), cache.getInvocationContext().getTransaction());
- assertNotNull("Gtx should have been set up by now", cache.getInvocationContext().getGlobalTransaction());
-
- tm.commit();
- }
-
- public void testTxExistenceAfterRead() throws Exception
- {
- // make sure we have a running transaction.
- tm.begin();
-
- assertNull("Tx should not have been set up yet", cache.getInvocationContext().getTransaction());
- assertNull("Gtx should not have been set up yet", cache.getInvocationContext().getGlobalTransaction());
-
- // now make a WRITE call into the cache (should start a tx)
- Object value = cache.get(Fqn.ROOT, "k");
- assertNull("Value should be null", value);
-
- // but now we should have a local tx registered in the invocation context
- assertNotNull("Tx should have been set up by now", cache.getInvocationContext().getTransaction());
- assertEquals("The same current transaction should be associated with this invocation ctx.", tm.getTransaction(), cache.getInvocationContext().getTransaction());
- assertNotNull("Gtx should have been set up by now", cache.getInvocationContext().getGlobalTransaction());
-
- tm.commit();
- }
-
- public void testScrubbingAfterCommit() throws Exception
- {
- doScrubbingTest(true);
- }
-
- public void testScrubbingAfterOnePhaseCommit() throws Exception
- {
- setUpOnePhaseCache();
-
- doScrubbingTest(true);
- }
-
- public void testScrubbingAfterRollback() throws Exception
- {
- doScrubbingTest(false);
- }
-
- public void testScrubbingAfterOnePhaseRollback() throws Exception
- {
- setUpOnePhaseCache();
-
- doScrubbingTest(true);
- }
-
- @SuppressWarnings("deprecation")
- private void doScrubbingTest(boolean commit) throws Exception
- {
- // Start clean
- cache.getInvocationContext().reset();
-
- tm.begin();
- TransactionTable tt = cache.getTransactionTable();
- cache.getRoot().put("key", "value");
-
- assertNotNull("Tx should have been set up by now", cache.getInvocationContext().getTransaction());
- assertEquals("The same current transaction should be associated with this invocation ctx.", tm.getTransaction(), cache.getInvocationContext().getTransaction());
- assertNotNull("Gtx should have been set up by now", cache.getInvocationContext().getGlobalTransaction());
-
- Transaction tx = tm.getTransaction();
- TransactionContext transactionContext = tt.get(tt.get(tx));
-
- if (commit)
- {
- tm.commit();
- }
- else
- {
- tm.rollback();
- }
-
- assertNull("Tx should have been scrubbed", cache.getInvocationContext().getTransaction());
- assertNull("Gtx should have been scrubbed", cache.getInvocationContext().getGlobalTransaction());
- assertEquals("Method call should have been scrubbed", null, cache.getInvocationContext().getMethodCall());
- assertEquals("Cache command should have been scrubbed", null, cache.getInvocationContext().getCommand());
-
- // check that the transaction transactionContext hasn't leaked stuff.
- assert transactionContext.getModifications().isEmpty() : "Should have scrubbed modifications in transaction transactionContext";
- assert transactionContext.getLocks().isEmpty() : "Should have scrubbed modifications in transaction transactionContext";
- assert transactionContext.getOrderedSynchronizationHandler() == null : "Should have removed the ordered sync handler";
- }
-
- private void setUpOnePhaseCache()
- {
- if (cache != null)
- {
- cache.stop();
- cache = null;
- }
-
- cache = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache("configs/replSync.xml", false, getClass());
- cache.getConfiguration().setCacheMode(CacheMode.REPL_ASYNC);
- cache.start();
- tm = cache.getTransactionManager();
- }
-}
Added: core/trunk/src/test/java/org/jboss/cache/invocationcontext/TwoPcTransactionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invocationcontext/TwoPcTransactionTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/invocationcontext/TwoPcTransactionTest.java 2008-12-12 23:59:35 UTC (rev 7319)
@@ -0,0 +1,77 @@
+package org.jboss.cache.invocationcontext;
+
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.UnitTestCacheFactory;
+import org.jboss.cache.AbstractSingleCacheTest;
+import org.jboss.cache.transaction.TransactionTable;
+import org.jboss.cache.transaction.TransactionContext;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNull;
+
+import javax.transaction.TransactionManager;
+import javax.transaction.Transaction;
+
+/**
+ * @author Mircea.Markus at jboss.com
+ */
+public class TwoPcTransactionTest extends AbstractSingleCacheTest
+{
+ private TransactionManager tm;
+
+ protected CacheSPI createCache()
+ {
+ cache = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache("configs/local-tx.xml", getClass());
+ tm = cache.getTransactionManager();
+ return cache;
+ }
+
+ @SuppressWarnings("deprecation")
+ static void doScrubbingTest(CacheSPI cache, TransactionManager tm, boolean commit) throws Exception
+ {
+ // Start clean
+ cache.getInvocationContext().reset();
+
+ tm.begin();
+ TransactionTable tt = cache.getTransactionTable();
+ cache.getRoot().put("key", "value");
+
+ assertNotNull("Tx should have been set up by now", cache.getInvocationContext().getTransaction());
+ assertEquals("The same current transaction should be associated with this invocation ctx.", tm.getTransaction(), cache.getInvocationContext().getTransaction());
+ assertNotNull("Gtx should have been set up by now", cache.getInvocationContext().getGlobalTransaction());
+
+ Transaction tx = tm.getTransaction();
+ TransactionContext transactionContext = tt.get(tt.get(tx));
+
+ if (commit)
+ {
+ tm.commit();
+ } else
+ {
+ tm.rollback();
+ }
+
+ assertNull("Tx should have been scrubbed", cache.getInvocationContext().getTransaction());
+ assertNull("Gtx should have been scrubbed", cache.getInvocationContext().getGlobalTransaction());
+ assertEquals("Method call should have been scrubbed", null, cache.getInvocationContext().getMethodCall());
+ assertEquals("Cache command should have been scrubbed", null, cache.getInvocationContext().getCommand());
+
+ // check that the transaction transactionContext hasn't leaked stuff.
+ assert transactionContext.getModifications().isEmpty() : "Should have scrubbed modifications in transaction transactionContext";
+ assert transactionContext.getLocks().isEmpty() : "Should have scrubbed modifications in transaction transactionContext";
+ assert transactionContext.getOrderedSynchronizationHandler() == null : "Should have removed the ordered sync handler";
+ }
+
+ public void testScrubbingAfterCommit() throws Exception
+ {
+ doScrubbingTest(cache, tm, true);
+ }
+
+ public void testScrubbingAfterRollback() throws Exception
+ {
+ doScrubbingTest(cache, tm, false);
+ }
+
+
+
+}
More information about the jbosscache-commits
mailing list