[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/transaction ...
Manik Surtani
msurtani at jboss.com
Wed Jul 12 10:16:45 EDT 2006
User: msurtani
Date: 06/07/12 10:16:45
Modified: tests/functional/org/jboss/cache/transaction Tag:
Branch_JBossCache_1_3_0 AbortionTest.java
NotifyingTransactionManager.java
Log:
Added more UTs
Revision Changes Path
No revision
No revision
1.1.2.5 +76 -11 JBossCache/tests/functional/org/jboss/cache/transaction/AbortionTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AbortionTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/transaction/AbortionTest.java,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -b -r1.1.2.4 -r1.1.2.5
--- AbortionTest.java 5 Jul 2006 17:00:53 -0000 1.1.2.4
+++ AbortionTest.java 12 Jul 2006 14:16:45 -0000 1.1.2.5
@@ -23,7 +23,7 @@
*/
public class AbortionTest extends TestCase
{
- private TreeCache cache1, cache2, cache3;
+ private ChannelExposingCache cache1, cache2, cache3;
private boolean abortBeforeCompletion;
@@ -44,9 +44,9 @@
super.tearDown();
}
- private TreeCache initCache(boolean notifying) throws Exception
+ private ChannelExposingCache initCache(boolean notifying) throws Exception
{
- TreeCache c = new MyTC();
+ ChannelExposingCache c = new ChannelExposingCache();
c.setCacheMode("REPL_SYNC");
c.setSyncCommitPhase(true);
// c.setSyncRollbackPhase(true);
@@ -121,9 +121,9 @@
Transaction t = finalTx;
public void beforeCompletion()
{
- System.out.println("In abort.beforeCompletion. Cache3 is " + cache3 + " and myChannel is " + ((MyTC)cache3).myChannel);
+ System.out.println("In abort.beforeCompletion. Cache3 is " + cache3 + " and exposedChannel is " + cache3.exposedChannel);
if (abortBeforeCompletion) {
- ((MyTC) cache3).myChannel.close();
+ cache3.exposedChannel.close();
System.out.println("Returning from abort.beforeCompletion");
try
{
@@ -139,9 +139,9 @@
public void afterCompletion(int i)
{
- System.out.println("In abort.afterCompletion. Cache3 is " + cache3 + " and myChannel is " + ((MyTC)cache3).myChannel);
+ System.out.println("In abort.afterCompletion. Cache3 is " + cache3 + " and exposedChannel is " + cache3.exposedChannel);
if (!abortBeforeCompletion) {
- ((MyTC) cache3).myChannel.close();
+ cache3.exposedChannel.close();
System.out.println("Returning from abort.afterCompletion");
throw new RuntimeException("Dummy exception");
}
@@ -169,11 +169,76 @@
assertEquals("put in transaction should NOT have been rolled back", "value2", cache2.get("/test", "key"));
}
- public static class MyTC extends TreeCache
+ public void testRepeatedPutsWhileKillingNode() throws Exception
{
- JChannel myChannel;
+ int numThreads = 10;
+ int numLoops = 100;
+ Putter[] putters = new Putter[numThreads];
- public MyTC() throws Exception
+ for (int i=0; i<numThreads; i++)
+ {
+ putters[i] = new Putter("Putter-" + i, cache1, numLoops);
+ putters[i].start();
+ }
+
+
+ // sleep a bit
+ TestingUtil.sleepThread(500);
+ // now kill a cache
+ System.out.println("*** Killing cache3");
+ cache3.exposedChannel.close();
+
+
+ // join
+ for (int i=0; i<numThreads; i++) putters[i].join();
+
+ assertEquals(0, cache1.getNumberOfLocksHeld());
+ assertEquals(0, cache2.getNumberOfLocksHeld());
+ }
+
+ static class Putter extends Thread
+ {
+ TreeCache myCache;
+ int numLoops;
+
+ public Putter(String name, TreeCache myCache, int numLoops)
+ {
+ super(name);
+ this.myCache = myCache;
+ this.numLoops = numLoops;
+ }
+
+ public void run()
+ {
+ try
+ {
+ TransactionManager tm = myCache.getTransactionManager();
+ for (int i=0; i<numLoops; i++)
+ {
+ tm.begin();
+ Transaction tx = tm.getTransaction();
+ myCache.put("/test/" + getName(), "key" + i, "value");
+ System.out.println("Putting loop " + i + "; putter " + getName());
+ tx.commit();
+ }
+ }
+ catch (RollbackException re)
+ {
+ // we're ok with these...
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ static class ChannelExposingCache extends TreeCache
+ {
+ JChannel exposedChannel;
+
+ public ChannelExposingCache() throws Exception
{
super();
}
@@ -181,7 +246,7 @@
public void startService() throws Exception
{
super.startService();
- myChannel = channel;
+ exposedChannel = channel;
}
}
1.1.2.2 +1 -2 JBossCache/tests/functional/org/jboss/cache/transaction/NotifyingTransactionManager.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: NotifyingTransactionManager.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/transaction/NotifyingTransactionManager.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -b -r1.1.2.1 -r1.1.2.2
--- NotifyingTransactionManager.java 3 Jul 2006 13:36:15 -0000 1.1.2.1
+++ NotifyingTransactionManager.java 12 Jul 2006 14:16:45 -0000 1.1.2.2
@@ -33,8 +33,7 @@
super.begin();
try
{
- System.out.println("Calling notification.notify()");
- notification.notify(getTransaction());
+ if (notification != null) notification.notify(getTransaction());
}
catch (RollbackException e)
{
More information about the jboss-cvs-commits
mailing list