[infinispan-commits] Infinispan SVN: r2388 - in trunk/core/src: main/java/org/infinispan/interceptors and 2 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Wed Sep 15 18:14:40 EDT 2010
Author: mircea.markus
Date: 2010-09-15 18:14:39 -0400 (Wed, 15 Sep 2010)
New Revision: 2388
Added:
trunk/core/src/test/java/org/infinispan/tx/exception/ExceptionInCommandTest.java
Modified:
trunk/core/src/main/java/org/infinispan/commands/tx/RollbackCommand.java
trunk/core/src/main/java/org/infinispan/interceptors/InvocationContextInterceptor.java
trunk/core/src/test/java/org/infinispan/test/MultipleCacheManagersTest.java
trunk/core/src/test/java/org/infinispan/test/SingleCacheManagerTest.java
Log:
migrated 2387 to trunk
Modified: trunk/core/src/main/java/org/infinispan/commands/tx/RollbackCommand.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/commands/tx/RollbackCommand.java 2010-09-15 22:07:42 UTC (rev 2387)
+++ trunk/core/src/main/java/org/infinispan/commands/tx/RollbackCommand.java 2010-09-15 22:14:39 UTC (rev 2388)
@@ -53,4 +53,9 @@
public byte getCommandId() {
return COMMAND_ID;
}
+
+ @Override
+ public String toString() {
+ return "RollbackCommand{ " + super.toString();
+ }
}
Modified: trunk/core/src/main/java/org/infinispan/interceptors/InvocationContextInterceptor.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/interceptors/InvocationContextInterceptor.java 2010-09-15 22:07:42 UTC (rev 2387)
+++ trunk/core/src/main/java/org/infinispan/interceptors/InvocationContextInterceptor.java 2010-09-15 22:14:39 UTC (rev 2388)
@@ -69,12 +69,12 @@
log.trace("Exception while executing code, failing silently...", th);
return null;
} else {
+ log.error("Execution error: ", th);
if (ctx.isInTxScope() && ctx.isOriginLocal()) {
if (trace) log.trace("Transaction marked for rollback as exception was received.");
markTxForRollbackAndRethrow(ctx, th);
throw new IllegalStateException("This should not be reached");
}
- log.error("Execution error: ", th);
throw th;
}
} finally {
Modified: trunk/core/src/test/java/org/infinispan/test/MultipleCacheManagersTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/test/MultipleCacheManagersTest.java 2010-09-15 22:07:42 UTC (rev 2387)
+++ trunk/core/src/test/java/org/infinispan/test/MultipleCacheManagersTest.java 2010-09-15 22:14:39 UTC (rev 2388)
@@ -2,7 +2,9 @@
import org.infinispan.Cache;
import org.infinispan.config.Configuration;
+import org.infinispan.distribution.BaseDistFunctionalTest;
import org.infinispan.manager.CacheContainer;
+import org.infinispan.manager.CacheManager;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.remoting.transport.Address;
import org.infinispan.test.fwk.TestCacheManagerFactory;
@@ -12,6 +14,9 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
import java.util.ArrayList;
import java.util.IdentityHashMap;
import java.util.List;
@@ -142,12 +147,64 @@
return cm;
}
+ /**
+ * Creates a new cache manager, starts it, and adds it to the list of known cache managers on the current thread.
+ */
+ protected EmbeddedCacheManager addClusterEnabledCacheManager(Configuration.CacheMode mode, boolean transactional) {
+ Configuration configuration = getDefaultClusteredConfig(mode, transactional);
+ configuration.setCacheMode(mode);
+ return addClusterEnabledCacheManager(configuration);
+ }
+
+ protected void addClusterEnabledCacheManagers(Configuration.CacheMode mode, boolean transactional, int count) {
+ for (int i = 0; i < count; i++) addClusterEnabledCacheManager(mode, transactional);
+ }
+
+ protected void addClusterEnabledCacheManagers(Configuration.CacheMode mode, int count) {
+ for (int i = 0; i < count; i++) addClusterEnabledCacheManager(mode, true);
+ }
+
protected void defineConfigurationOnAllManagers(String cacheName, Configuration c) {
for (EmbeddedCacheManager cm : cacheManagers) {
cm.defineConfiguration(cacheName, c);
}
}
+ protected void waitForClusterToForm(String cacheName) {
+ List<Cache> caches;
+ caches = getCaches(cacheName);
+ Cache<Object, Object> cache = caches.get(0);
+ TestingUtil.blockUntilViewsReceived(10000, caches);
+ if (cache.getConfiguration().getCacheMode().isDistributed()) {
+ BaseDistFunctionalTest.RehashWaiter.waitForInitRehashToComplete(caches);
+ }
+ }
+
+ private List<Cache> getCaches(String cacheName) {
+ List<Cache> caches;
+ caches = new ArrayList<Cache>();
+ for (EmbeddedCacheManager cm : cacheManagers) {
+ caches.add(cacheName == null ? cm.getCache() : cm.getCache(cacheName));
+ }
+ return caches;
+ }
+
+ protected void waitForClusterToForm() {
+ waitForClusterToForm(null);
+ }
+
+ protected TransactionManager tm(int i) {
+ return cache(i).getAdvancedCache().getTransactionManager();
+ }
+
+ protected Transaction tx(int i) {
+ try {
+ return cache(i).getAdvancedCache().getTransactionManager().getTransaction();
+ } catch (SystemException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
protected <K, V> List<Cache<K, V>> createClusteredCaches(int numMembersInCluster, String cacheName, Configuration c) {
List<Cache<K, V>> caches = new ArrayList<Cache<K, V>>(numMembersInCluster);
for (int i = 0; i < numMembersInCluster; i++) {
Modified: trunk/core/src/test/java/org/infinispan/test/SingleCacheManagerTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/test/SingleCacheManagerTest.java 2010-09-15 22:07:42 UTC (rev 2387)
+++ trunk/core/src/test/java/org/infinispan/test/SingleCacheManagerTest.java 2010-09-15 22:14:39 UTC (rev 2388)
@@ -10,6 +10,10 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
/**
* Base class for tests that operate on a single (most likely local) cache instance. This operates similar to {@link
* org.infinispan.test.MultipleCacheManagersTest}, but on only once CacheManager.
@@ -77,5 +81,18 @@
return TestCacheManagerFactory.getDefaultConfiguration(transactional);
}
+ protected TransactionManager tm() {
+ return cache.getAdvancedCache().getTransactionManager();
+ }
+
+ protected Transaction tx() {
+ try {
+ return cache.getAdvancedCache().getTransactionManager().getTransaction();
+ } catch (SystemException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+
protected abstract EmbeddedCacheManager createCacheManager() throws Exception;
}
Copied: trunk/core/src/test/java/org/infinispan/tx/exception/ExceptionInCommandTest.java (from rev 2387, branches/4.2.x/core/src/test/java/org/infinispan/tx/exception/ExceptionInCommandTest.java)
===================================================================
--- trunk/core/src/test/java/org/infinispan/tx/exception/ExceptionInCommandTest.java (rev 0)
+++ trunk/core/src/test/java/org/infinispan/tx/exception/ExceptionInCommandTest.java 2010-09-15 22:14:39 UTC (rev 2388)
@@ -0,0 +1,74 @@
+package org.infinispan.tx.exception;
+
+import org.infinispan.atomic.AtomicHashMap;
+import org.infinispan.atomic.Delta;
+import org.infinispan.atomic.DeltaAware;
+import org.infinispan.config.Configuration;
+import org.infinispan.test.MultipleCacheManagersTest;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
+import org.testng.annotations.Test;
+
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import java.io.Serializable;
+
+/**
+ * @author Mircea.Markus at jboss.com
+ * @since 4.2
+ */
+ at Test(groups = "functional", testName = "tx.exception.ExceptionInCommandTest")
+public class ExceptionInCommandTest extends MultipleCacheManagersTest {
+
+ @Override
+ protected void createCacheManagers() throws Throwable {
+ addClusterEnabledCacheManagers(Configuration.CacheMode.REPL_SYNC, 2);
+ waitForClusterToForm();
+ }
+
+ public void testPutThrowsLocalException() throws Exception {
+ tm(0).begin();
+
+ Delta d = new Delta() {
+ public DeltaAware merge(DeltaAware d) {
+ throw new RuntimeException("Induced!");
+ }
+ };
+
+ try {
+ cache(0).put("k", d);
+ assert false;
+ } catch (RuntimeException e) {
+ assert tx(0).getStatus() == Status.STATUS_MARKED_ROLLBACK;
+ }
+ }
+
+ @Test (expectedExceptions = RollbackException.class)
+ public void testPutThrowsRemoteException() throws Exception {
+ tm(0).begin();
+
+ MyDelta d = new MyDelta();
+ d.setCreator();
+
+ cache(0).put("k", d);
+
+ tm(0).commit();
+
+ }
+
+ private static Log log = LogFactory.getLog(ExceptionInCommandTest.class);
+
+ private static class MyDelta implements Delta , Serializable {
+ transient Thread creator;
+
+ public void setCreator() {creator = Thread.currentThread();}
+
+ public DeltaAware merge(DeltaAware d) {
+ log.trace("Creator == " );
+
+ if (creator != Thread.currentThread())
+ throw new RuntimeException("Induced!");
+ return new AtomicHashMap();
+ }
+ }
+}
More information about the infinispan-commits
mailing list