JBoss Cache SVN: r7592 - core/branches/flat/src/main/java/org/horizon/factories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-01-23 08:55:58 -0500 (Fri, 23 Jan 2009)
New Revision: 7592
Modified:
core/branches/flat/src/main/java/org/horizon/factories/ComponentRegistry.java
Log:
Logging
Modified: core/branches/flat/src/main/java/org/horizon/factories/ComponentRegistry.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/ComponentRegistry.java 2009-01-23 13:53:15 UTC (rev 7591)
+++ core/branches/flat/src/main/java/org/horizon/factories/ComponentRegistry.java 2009-01-23 13:55:58 UTC (rev 7592)
@@ -21,7 +21,7 @@
GlobalComponentRegistry globalComponents;
String cacheName;
- Log log;
+ Log log = LogFactory.getLog(ComponentRegistry.class);
/**
* Creates an instance of the component registry. The configuration passed in is automatically registered.
@@ -35,8 +35,6 @@
try {
this.cacheName = cacheName;
if (cacheName == null) throw new ConfigurationException("Cache name cannot be null!");
- StringBuilder sb = new StringBuilder(ComponentRegistry.class.getName()).append(cacheName);
- this.log = LogFactory.getLog(sb.toString());
if (globalComponents == null) throw new NullPointerException("GlobalComponentRegistry cannot be null!");
this.globalComponents = globalComponents;
15 years, 11 months
JBoss Cache SVN: r7591 - in core/branches/flat/src: test/java/org/horizon/tx and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-01-23 08:53:15 -0500 (Fri, 23 Jan 2009)
New Revision: 7591
Modified:
core/branches/flat/src/main/java/org/horizon/transaction/DummyTransaction.java
core/branches/flat/src/main/java/org/horizon/transaction/TransactionTable.java
core/branches/flat/src/test/java/org/horizon/tx/MarkAsRollbackTest.java
Log:
JBCACHE-1468: JBoss Cache ignores transactions with STATUS_MARKED_ROLLBACK and auto commits data changes
Modified: core/branches/flat/src/main/java/org/horizon/transaction/DummyTransaction.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/transaction/DummyTransaction.java 2009-01-23 13:50:07 UTC (rev 7590)
+++ core/branches/flat/src/main/java/org/horizon/transaction/DummyTransaction.java 2009-01-23 13:53:15 UTC (rev 7591)
@@ -37,8 +37,6 @@
/**
* @author bela
- * <p/>
- * Date: May 15, 2003 Time: 4:20:17 PM
* @since 1.0
*/
public class DummyTransaction implements Transaction {
@@ -189,7 +187,6 @@
throw new IllegalArgumentException("null synchronization " + this);
switch (status) {
- case Status.STATUS_MARKED_ROLLBACK: // we should allow synchronizations to be registered even if the status is MARKED_ROLLBACK
case Status.STATUS_ACTIVE:
case Status.STATUS_PREPARING:
break;
@@ -199,6 +196,8 @@
throw new IllegalStateException("already started committing. " + this);
case Status.STATUS_COMMITTED:
throw new IllegalStateException("already committed. " + this);
+ case Status.STATUS_MARKED_ROLLBACK:
+ throw new RollbackException("already marked for rollback " + this);
case Status.STATUS_ROLLING_BACK:
throw new RollbackException("already started rolling back. " + this);
case Status.STATUS_ROLLEDBACK:
Modified: core/branches/flat/src/main/java/org/horizon/transaction/TransactionTable.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/transaction/TransactionTable.java 2009-01-23 13:50:07 UTC (rev 7590)
+++ core/branches/flat/src/main/java/org/horizon/transaction/TransactionTable.java 2009-01-23 13:53:15 UTC (rev 7591)
@@ -250,29 +250,13 @@
}
/**
- * Returns true if transaction is STATUS_MARKED_ROLLBACK, false otherwise
- */
- public static boolean isMarkedAsRollback(Transaction tx) {
- if (tx == null) return false;
- int status;
- try {
- status = tx.getStatus();
- return status == Status.STATUS_MARKED_ROLLBACK;
- }
- catch (SystemException e) {
- return false;
- }
- }
-
-
- /**
- * Return s true of tx's status is ACTIVE or PREPARING or MARKED_ROLLBACK
+ * Return s true of tx's status is ACTIVE or PREPARING
*
* @param tx
* @return true if the tx is active or preparing
*/
public static boolean isValid(Transaction tx) {
- return isActive(tx) || isPreparing(tx) || isMarkedAsRollback(tx);
+ return isActive(tx) || isPreparing(tx);
}
/**
Modified: core/branches/flat/src/test/java/org/horizon/tx/MarkAsRollbackTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/tx/MarkAsRollbackTest.java 2009-01-23 13:50:07 UTC (rev 7590)
+++ core/branches/flat/src/test/java/org/horizon/tx/MarkAsRollbackTest.java 2009-01-23 13:53:15 UTC (rev 7591)
@@ -52,9 +52,13 @@
assert tm != null;
tm.begin();
tm.setRollbackOnly();
- cache.put("k", "v");
- assert cache.get("k").equals("v");
try {
+ cache.put("k", "v");
+ assert false : "Should have throw an illegal state exception";
+ } catch (IllegalStateException expected) {
+
+ }
+ try {
tm.commit();
assert false : "Should have rolled back";
}
15 years, 11 months
JBoss Cache SVN: r7590 - in core/trunk/src: test/java/org/jboss/cache/transaction and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-01-23 08:50:07 -0500 (Fri, 23 Jan 2009)
New Revision: 7590
Modified:
core/trunk/src/main/java/org/jboss/cache/transaction/DummyTransaction.java
core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java
core/trunk/src/test/java/org/jboss/cache/transaction/MarkAsRollbackTest.java
Log:
JBCACHE-1468: JBoss Cache ignores transactions with STATUS_MARKED_ROLLBACK and auto commits data changes
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/DummyTransaction.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/DummyTransaction.java 2009-01-23 13:43:02 UTC (rev 7589)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/DummyTransaction.java 2009-01-23 13:50:07 UTC (rev 7590)
@@ -235,7 +235,6 @@
switch (status)
{
- case Status.STATUS_MARKED_ROLLBACK:
case Status.STATUS_ACTIVE:
case Status.STATUS_PREPARING:
break;
@@ -245,6 +244,8 @@
throw new IllegalStateException("already started committing. " + this);
case Status.STATUS_COMMITTED:
throw new IllegalStateException("already committed. " + this);
+ case Status.STATUS_MARKED_ROLLBACK:
+ throw new RollbackException("already marked for rollback " + this);
case Status.STATUS_ROLLING_BACK:
throw new RollbackException("already started rolling back. " + this);
case Status.STATUS_ROLLEDBACK:
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java 2009-01-23 13:43:02 UTC (rev 7589)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java 2009-01-23 13:50:07 UTC (rev 7590)
@@ -359,33 +359,14 @@
}
/**
- * Returns true if transaction is STATUS_MARKED_ROLLBACK, false otherwise
- */
- public static boolean isMarkedAsRollback(Transaction tx)
- {
- if (tx == null) return false;
- int status;
- try
- {
- status = tx.getStatus();
- return status == Status.STATUS_MARKED_ROLLBACK;
- }
- catch (SystemException e)
- {
- return false;
- }
- }
-
-
- /**
- * Returns true of tx's status is ACTIVE or PREPARING or MARKED_ROLLBACK
+ * Returns true of tx's status is ACTIVE or PREPARING
*
* @param tx
* @return true if the tx is active or preparing
*/
public static boolean isValid(Transaction tx)
{
- return isActive(tx) || isPreparing(tx) || isMarkedAsRollback(tx);
+ return isActive(tx) || isPreparing(tx);
}
/**
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/MarkAsRollbackTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/MarkAsRollbackTest.java 2009-01-23 13:43:02 UTC (rev 7589)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/MarkAsRollbackTest.java 2009-01-23 13:50:07 UTC (rev 7590)
@@ -63,11 +63,17 @@
assert tm != null;
tm.begin();
tm.setRollbackOnly();
- cache.put(fqn, "k", "v");
- assert cache.get(fqn, "k").equals("v");
- assert cache.getRoot().getChildren().size() == 1;
try
{
+ cache.put(fqn, "k", "v");
+ assert false : "Should have failed";
+ }
+ catch (IllegalStateException expected)
+ {
+
+ }
+ try
+ {
tm.commit();
assert false : "Should have rolled back";
}
15 years, 11 months
JBoss Cache SVN: r7589 - core/branches/1.4.X/docs.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-01-23 08:43:02 -0500 (Fri, 23 Jan 2009)
New Revision: 7589
Modified:
core/branches/1.4.X/docs/Changelog.txt
Log:
Modified: core/branches/1.4.X/docs/Changelog.txt
===================================================================
--- core/branches/1.4.X/docs/Changelog.txt 2009-01-23 13:42:32 UTC (rev 7588)
+++ core/branches/1.4.X/docs/Changelog.txt 2009-01-23 13:43:02 UTC (rev 7589)
@@ -1,5 +1,12 @@
$Id$
+Release 1.4.1.SP12 (January 23, 2009)
+=====================================
+Patch release on 1.4.1.GA
+
+** Bug
+ * [ JBCACHE-1304 ] OrderedSynchronizationHandler not thread safe
+
Release 1.4.1.SP11 (January 5, 2009)
====================================
Patch release on 1.4.1.GA
15 years, 11 months
JBoss Cache SVN: r7588 - core/tags/1.4.1.SP12/docs.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-01-23 08:42:32 -0500 (Fri, 23 Jan 2009)
New Revision: 7588
Modified:
core/tags/1.4.1.SP12/docs/Changelog.txt
Log:
Modified: core/tags/1.4.1.SP12/docs/Changelog.txt
===================================================================
--- core/tags/1.4.1.SP12/docs/Changelog.txt 2009-01-23 12:51:14 UTC (rev 7587)
+++ core/tags/1.4.1.SP12/docs/Changelog.txt 2009-01-23 13:42:32 UTC (rev 7588)
@@ -1,5 +1,12 @@
$Id$
+Release 1.4.1.SP12 (January 23, 2009)
+=====================================
+Patch release on 1.4.1.GA
+
+** Bug
+ * [ JBCACHE-1304 ] OrderedSynchronizationHandler not thread safe
+
Release 1.4.1.SP11 (January 5, 2009)
====================================
Patch release on 1.4.1.GA
15 years, 11 months
JBoss Cache SVN: r7587 - core/trunk.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2009-01-23 07:51:14 -0500 (Fri, 23 Jan 2009)
New Revision: 7587
Modified:
core/trunk/README-Maven.txt
Log:
updated doc
Modified: core/trunk/README-Maven.txt
===================================================================
--- core/trunk/README-Maven.txt 2009-01-23 12:50:05 UTC (rev 7586)
+++ core/trunk/README-Maven.txt 2009-01-23 12:51:14 UTC (rev 7587)
@@ -19,7 +19,7 @@
* mvn compile: Compiles java source code.
* mvn test: Runs the TestNG unit test suite on the compiled code. Will also compile the tests. See the testing section
- below for more information on running different test groups. The default test group run is the "unit" group.
+ below for more information on running different test groups. The default test groups run are the "unit" and "functional".
* mvn package: Packages the module as a JAR file, the resulting JAR file will be in target/
15 years, 11 months
JBoss Cache SVN: r7586 - core/trunk.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2009-01-23 07:50:05 -0500 (Fri, 23 Jan 2009)
New Revision: 7586
Modified:
core/trunk/pom.xml
Log:
test-hudson profile is active by default
Modified: core/trunk/pom.xml
===================================================================
--- core/trunk/pom.xml 2009-01-23 12:17:27 UTC (rev 7585)
+++ core/trunk/pom.xml 2009-01-23 12:50:05 UTC (rev 7586)
@@ -32,7 +32,7 @@
<!--
For the JTA 1.1 API; consuming projects can safely
- exclude this and replace with any valid source of this API, such as a Java EE app server.
+ exclude this and replace with any valid source of this API, such as a Java EE app server.
-->
<dependency>
<groupId>javax.transaction</groupId>
@@ -404,6 +404,9 @@
<profile>
<id>test-hudson</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
<properties>
<defaultTestGroup>functional,unit</defaultTestGroup>
<protocol.stack>tcp</protocol.stack>
15 years, 11 months
JBoss Cache SVN: r7585 - in core/branches/flat/src: main/java/org/horizon/transaction and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-01-23 07:17:27 -0500 (Fri, 23 Jan 2009)
New Revision: 7585
Added:
core/branches/flat/src/test/java/org/horizon/tx/MarkAsRollbackTest.java
Modified:
core/branches/flat/src/main/java/org/horizon/interceptors/TxInterceptor.java
core/branches/flat/src/main/java/org/horizon/transaction/TransactionTable.java
Log:
JBCACHE-1468: JBoss Cache ignores transactions with STATUS_MARKED_ROLLBACK and auto commits data changes
Modified: core/branches/flat/src/main/java/org/horizon/interceptors/TxInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/interceptors/TxInterceptor.java 2009-01-23 12:17:02 UTC (rev 7584)
+++ core/branches/flat/src/main/java/org/horizon/interceptors/TxInterceptor.java 2009-01-23 12:17:27 UTC (rev 7585)
@@ -479,7 +479,7 @@
try {
// JBCACHE-457
VisitableCommand rollbackCommand = commandsFactory.buildRollbackCommand(gtx);
- if (trace) log.trace(" running rollback for " + gtx);
+ if (trace) log.trace(" running rollback for {0}", gtx);
//JBCACHE-359 Store a lookup for the globalTransaction so a listener
// callback can find it
@@ -547,9 +547,15 @@
* Creates a gtx (if one doesnt exist), a sync handler, and registers the tx.
*/
private GlobalTransaction registerTransaction(Transaction tx, InvocationContext ctx) throws Exception {
+ // we have ascertained that the current thread *is* associated with a transaction. We need to make sure the
+ // transaction is in a valid state before moving on, and throwing an exception if not.
+ boolean txValid = TransactionTable.isValid(tx);
+ if (!txValid)
+ throw new IllegalStateException("Transaction " + tx + " is not in a valid state to be invoking cache operations on.");
+
GlobalTransaction gtx;
- if (TransactionTable.isValid(tx) && transactions.add(tx)) {
+ if (transactions.add(tx)) {
gtx = txTable.getCurrentTransaction(tx, true);
TransactionContext transactionContext;
if (ctx.getGlobalTransaction() == null) {
@@ -563,16 +569,16 @@
// should be no need to register a handler since this a remotely initiated globalTransaction
if (trace) log.trace("is a remotely initiated gtx so no need to register a tx for it");
} else {
- if (trace) log.trace("Registering sync handler for tx " + tx + ", gtx " + gtx);
+ if (trace) log.trace("Registering sync handler for tx {0} and gtx {1}", tx, gtx);
// see the comment in the LocalSyncHandler for the last isOriginLocal param.
LocalSynchronizationHandler myHandler = new LocalSynchronizationHandler(gtx, tx, transactionContext, !ctx.isOriginLocal());
registerHandler(tx, myHandler, ctx);
}
} else if ((gtx = rollbackTransactions.get(tx)) != null) {
- if (trace) log.trace("Transaction " + tx + " is already registered and is rolling back.");
+ if (trace) log.trace("Transaction {0} is already registered and is rolling back.", tx);
} else {
- if (trace) log.trace("Transaction " + tx + " is already registered.");
+ if (trace) log.trace("Transaction {0} is already registered.", tx);
}
return gtx;
}
Modified: core/branches/flat/src/main/java/org/horizon/transaction/TransactionTable.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/transaction/TransactionTable.java 2009-01-23 12:17:02 UTC (rev 7584)
+++ core/branches/flat/src/main/java/org/horizon/transaction/TransactionTable.java 2009-01-23 12:17:27 UTC (rev 7585)
@@ -250,13 +250,29 @@
}
/**
- * Return s true of tx's status is ACTIVE or PREPARING
+ * Returns true if transaction is STATUS_MARKED_ROLLBACK, false otherwise
+ */
+ public static boolean isMarkedAsRollback(Transaction tx) {
+ if (tx == null) return false;
+ int status;
+ try {
+ status = tx.getStatus();
+ return status == Status.STATUS_MARKED_ROLLBACK;
+ }
+ catch (SystemException e) {
+ return false;
+ }
+ }
+
+
+ /**
+ * Return s true of tx's status is ACTIVE or PREPARING or MARKED_ROLLBACK
*
* @param tx
* @return true if the tx is active or preparing
*/
public static boolean isValid(Transaction tx) {
- return isActive(tx) || isPreparing(tx);
+ return isActive(tx) || isPreparing(tx) || isMarkedAsRollback(tx);
}
/**
Added: core/branches/flat/src/test/java/org/horizon/tx/MarkAsRollbackTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/tx/MarkAsRollbackTest.java (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/tx/MarkAsRollbackTest.java 2009-01-23 12:17:27 UTC (rev 7585)
@@ -0,0 +1,73 @@
+package org.horizon.tx;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.horizon.CacheSPI;
+import org.horizon.UnitTestCacheFactory;
+import org.horizon.config.Configuration;
+import org.horizon.transaction.DummyTransactionManagerLookup;
+import org.horizon.util.TestingUtil;
+import org.testng.annotations.Test;
+
+import javax.transaction.RollbackException;
+import javax.transaction.TransactionManager;
+
+@Test(groups = "functional")
+public class MarkAsRollbackTest {
+ private static final Log log = LogFactory.getLog(MarkAsRollbackTest.class);
+
+ public void testMarkAsRollbackAfterMods() throws Exception {
+ Configuration c = new Configuration();
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ CacheSPI<String, String> cache = (CacheSPI<String, String>) new UnitTestCacheFactory<String, String>().createCache(c);
+ try {
+ TransactionManager tm = cache.getTransactionManager();
+ assert tm != null;
+ tm.begin();
+ cache.put("k", "v");
+ assert cache.get("k").equals("v");
+ tm.setRollbackOnly();
+ try {
+ tm.commit();
+ assert false : "Should have rolled back";
+ }
+ catch (RollbackException expected) {
+ }
+
+ 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");
+ }
+ finally {
+ log.warn("Cleaning up");
+ TestingUtil.killCaches(cache);
+ }
+ }
+
+ public void testMarkAsRollbackBeforeMods() throws Exception {
+ Configuration c = new Configuration();
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ CacheSPI<String, String> cache = (CacheSPI<String, String>) new UnitTestCacheFactory<String, String>().createCache(c);
+ try {
+ TransactionManager tm = cache.getTransactionManager();
+ assert tm != null;
+ tm.begin();
+ tm.setRollbackOnly();
+ cache.put("k", "v");
+ assert cache.get("k").equals("v");
+ try {
+ tm.commit();
+ assert false : "Should have rolled back";
+ }
+ catch (RollbackException expected) {
+
+ }
+
+ 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");
+ }
+ finally {
+ log.warn("Cleaning up");
+ TestingUtil.killCaches(cache);
+ }
+ }
+}
15 years, 11 months
JBoss Cache SVN: r7584 - in core/trunk/src: main/java/org/jboss/cache/transaction and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-01-23 07:17:02 -0500 (Fri, 23 Jan 2009)
New Revision: 7584
Added:
core/trunk/src/test/java/org/jboss/cache/transaction/MarkAsRollbackTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java
Log:
JBCACHE-1468: JBoss Cache ignores transactions with STATUS_MARKED_ROLLBACK and auto commits data changes
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2009-01-23 12:12:31 UTC (rev 7583)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2009-01-23 12:17:02 UTC (rev 7584)
@@ -323,13 +323,17 @@
if (trace) log.trace("Created new tx for gtx " + gtx);
if (trace)
+ {
log.trace("Started new local tx as result of remote prepare: local tx=" + ltx + " (status=" + ltx.getStatus() + "), gtx=" + gtx);
+ }
}
else
{
//this should be valid
if (!TransactionTable.isValid(ltx))
+ {
throw new CacheException("Transaction " + ltx + " not in correct state to be prepared");
+ }
//associate this thread with the local transaction associated with the global transaction, IF the localTx is NOT the current tx.
if (currentTx == null || !ltx.equals(currentTx))
@@ -372,7 +376,9 @@
if (command.isOnePhaseCommit())
{
if (trace)
+ {
log.trace("Using one-phase prepare. Not propagating the prepare call up the stack until called to do so by the sync handler.");
+ }
}
else
{
@@ -562,9 +568,13 @@
throw new RuntimeException(e2);
}
if (e instanceof RuntimeException)
+ {
throw (RuntimeException) e;
+ }
else
+ {
throw new RuntimeException("Commit failed.", e);
+ }
}
}
@@ -675,9 +685,17 @@
*/
private GlobalTransaction registerTransaction(Transaction tx, InvocationContext ctx) throws Exception
{
+ // we have ascertained that the current thread *is* associated with a transaction. We need to make sure the
+ // transaction is in a valid state before moving on, and throwing an exception if not.
+ boolean txValid = TransactionTable.isValid(tx);
+ if (!txValid)
+ {
+ throw new IllegalStateException("Transaction " + tx + " is not in a valid state to be invoking cache operations on.");
+ }
+
GlobalTransaction gtx;
- if (TransactionTable.isValid(tx) && transactions.add(tx))
+ if (transactions.add(tx))
{
gtx = txTable.getCurrentTransaction(tx, true);
TransactionContext transactionContext;
@@ -711,17 +729,7 @@
}
else
{
- if (trace)
- {
- if (TransactionTable.isValid(tx))
- {
- log.trace("Transaction " + tx + " is already registered.");
- }
- else
- {
- log.trace("Transaction " + tx + " is not valid! Status: " + tx.getStatus());
- }
- }
+ if (trace) log.trace("Transaction " + tx + " is already registered.");
}
return gtx;
}
@@ -867,7 +875,9 @@
setTransactionalContext(tx, gtx, transactionContext, ctx);
if (ctx.isOptionsUninitialised() && transactionContext.getOption() != null)
+ {
ctx.setOptionOverrides(transactionContext.getOption());
+ }
assertCanContinue();
@@ -954,7 +964,9 @@
private void assertCanContinue()
{
if (!componentRegistry.invocationsAllowed(true) && (ctx.getOptionOverrides() == null || !ctx.getOptionOverrides().isSkipCacheStatusCheck()))
+ {
throw new IllegalStateException("Cache not in STARTED state!");
+ }
}
/**
@@ -981,7 +993,9 @@
{
// JBCACHE-1114 -- don't call toString() on tx or it can lead to stack overflow
if (tx == null)
+ {
return null;
+ }
return tx.getClass().getName() + "@" + System.identityHashCode(tx);
}
@@ -1053,7 +1067,9 @@
if (result instanceof Throwable)
{
if (log.isDebugEnabled())
+ {
log.debug("Transaction needs to be rolled back - the cache returned an instance of Throwable for this prepare call (tx=" + tx + " and gtx=" + gtx + ")", (Throwable) result);
+ }
tx.setRollbackOnly();
throw (Throwable) result;
}
@@ -1074,9 +1090,13 @@
throw new RuntimeException("setting tx rollback failed ", se);
}
if (t instanceof RuntimeException)
+ {
throw (RuntimeException) t;
+ }
else
+ {
throw new RuntimeException("", t);
+ }
}
finally
{
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java 2009-01-23 12:12:31 UTC (rev 7583)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java 2009-01-23 12:17:02 UTC (rev 7584)
@@ -103,7 +103,9 @@
public GlobalTransaction get(Transaction tx)
{
if (tx == null)
+ {
return null;
+ }
return tx2gtxMap.get(tx);
}
@@ -194,7 +196,9 @@
public GlobalTransaction remove(Transaction tx)
{
if (tx == null)
+ {
return null;
+ }
return tx2gtxMap.remove(tx);
}
@@ -223,7 +227,9 @@
public String toString(boolean printDetails)
{
if (!printDetails)
+ {
return toString();
+ }
StringBuilder sb = new StringBuilder();
sb.append("LocalTransactions: ").append(tx2gtxMap.size()).append("\n");
sb.append("GlobalTransactions: ").append(gtx2ContextMap.size()).append("\n");
@@ -353,14 +359,33 @@
}
/**
- * Return s true of tx's status is ACTIVE or PREPARING
+ * Returns true if transaction is STATUS_MARKED_ROLLBACK, false otherwise
+ */
+ public static boolean isMarkedAsRollback(Transaction tx)
+ {
+ if (tx == null) return false;
+ int status;
+ try
+ {
+ status = tx.getStatus();
+ return status == Status.STATUS_MARKED_ROLLBACK;
+ }
+ catch (SystemException e)
+ {
+ return false;
+ }
+ }
+
+
+ /**
+ * Returns true of tx's status is ACTIVE or PREPARING or MARKED_ROLLBACK
*
* @param tx
* @return true if the tx is active or preparing
*/
public static boolean isValid(Transaction tx)
{
- return isActive(tx) || isPreparing(tx);
+ return isActive(tx) || isPreparing(tx) || isMarkedAsRollback(tx);
}
/**
@@ -369,14 +394,17 @@
public static void assertTransactionValid(InvocationContext ctx)
{
Transaction tx = ctx.getTransaction();
- if (!isValid(tx)) try
+ if (!isValid(tx))
{
- throw new CacheException("Invalid transaction " + tx + ", status = " + (tx == null ? null : tx.getStatus()));
+ try
+ {
+ throw new CacheException("Invalid transaction " + tx + ", status = " + (tx == null ? null : tx.getStatus()));
+ }
+ catch (SystemException e)
+ {
+ throw new CacheException("Exception trying to analyse status of transaction " + tx, e);
+ }
}
- catch (SystemException e)
- {
- throw new CacheException("Exception trying to analyse status of transaction " + tx, e);
- }
}
@@ -425,13 +453,13 @@
return gtx;
}
- @ManagedAttribute(name="numberOfRegisteredTransactions", description = "Number of registered transactions")
+ @ManagedAttribute(name = "numberOfRegisteredTransactions", description = "Number of registered transactions")
public int getNumberOfRegisteredTransactions()
{
return tx2gtxMap.size();
}
- @ManagedAttribute(name="transactionMap", description = "A String representation of the transaction map")
+ @ManagedAttribute(name = "transactionMap", description = "A String representation of the transaction map")
public String getTransactionMap()
{
return tx2gtxMap.toString();
Added: core/trunk/src/test/java/org/jboss/cache/transaction/MarkAsRollbackTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/MarkAsRollbackTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/MarkAsRollbackTest.java 2009-01-23 12:17:02 UTC (rev 7584)
@@ -0,0 +1,89 @@
+package org.jboss.cache.transaction;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.UnitTestCacheFactory;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.util.TestingUtil;
+import org.testng.annotations.Test;
+
+import javax.transaction.RollbackException;
+import javax.transaction.TransactionManager;
+
+@Test(groups = "functional")
+public class MarkAsRollbackTest
+{
+ private static final Fqn fqn = Fqn.fromString("/a/b/c");
+ private static final Log log = LogFactory.getLog(MarkAsRollbackTest.class);
+
+ public void testMarkAsRollbackAfterMods() throws Exception
+ {
+ Configuration c = new Configuration();
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ CacheSPI<String, String> cache = (CacheSPI<String, String>) new UnitTestCacheFactory<String, String>().createCache(c, MarkAsRollbackTest.class);
+ try
+ {
+ TransactionManager tm = cache.getTransactionManager();
+ assert tm != null;
+ tm.begin();
+ cache.put(fqn, "k", "v");
+ assert cache.get(fqn, "k").equals("v");
+ assert cache.getRoot().getChildren().size() == 1;
+ tm.setRollbackOnly();
+ try
+ {
+ tm.commit();
+ assert false : "Should have rolled back";
+ }
+ catch (RollbackException expected)
+ {
+ }
+
+ assert tm.getTransaction() == null : "There should be no transaction in scope anymore!";
+ assert cache.get(fqn, "k") == null : "Expected a null but was " + cache.get(fqn, "k");
+ assert cache.getRoot().getChildren().size() == 0;
+ }
+ finally
+ {
+ log.warn("Cleaning up");
+ TestingUtil.killCaches(cache);
+ }
+ }
+
+ public void testMarkAsRollbackBeforeMods() throws Exception
+ {
+ Configuration c = new Configuration();
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ CacheSPI<String, String> cache = (CacheSPI<String, String>) new UnitTestCacheFactory<String, String>().createCache(c, MarkAsRollbackTest.class);
+ try
+ {
+ TransactionManager tm = cache.getTransactionManager();
+ assert tm != null;
+ tm.begin();
+ tm.setRollbackOnly();
+ cache.put(fqn, "k", "v");
+ assert cache.get(fqn, "k").equals("v");
+ assert cache.getRoot().getChildren().size() == 1;
+ try
+ {
+ tm.commit();
+ assert false : "Should have rolled back";
+ }
+ catch (RollbackException expected)
+ {
+
+ }
+
+ assert tm.getTransaction() == null : "There should be no transaction in scope anymore!";
+ assert cache.get(fqn, "k") == null : "Expected a null but was " + cache.get(fqn, "k");
+ assert cache.getRoot().getChildren().size() == 0;
+ }
+ finally
+ {
+ log.warn("Cleaning up");
+ TestingUtil.killCaches(cache);
+ }
+ }
+}
15 years, 11 months