[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/options/cachemodelocal ...
Manik Surtani
msurtani at jboss.com
Thu Sep 7 11:42:16 EDT 2006
User: msurtani
Date: 06/09/07 11:42:16
Modified: tests/functional/org/jboss/cache/options/cachemodelocal
CacheModeLocalTestBase.java
Log:
Updated options API usage
Revision Changes Path
1.7 +61 -29 JBossCache/tests/functional/org/jboss/cache/options/cachemodelocal/CacheModeLocalTestBase.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheModeLocalTestBase.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/options/cachemodelocal/CacheModeLocalTestBase.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- CacheModeLocalTestBase.java 6 Sep 2006 15:30:59 -0000 1.6
+++ CacheModeLocalTestBase.java 7 Sep 2006 15:42:16 -0000 1.7
@@ -11,8 +11,8 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.TreeCache;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.Option;
+import javax.transaction.SystemException;
import javax.transaction.TransactionManager;
import java.util.HashMap;
import java.util.Map;
@@ -37,8 +37,6 @@
private TreeCache cache1;
private TreeCache cache2;
- private Option localOverride, defaultCacheMode;
-
private Fqn fqn = Fqn.fromString("/a");
private String key = "key";
@@ -62,12 +60,6 @@
cache2.getConfiguration().setNodeLockingScheme(nodeLockingScheme);
cache2.getConfiguration().setCacheMode(cacheMode);
cache2.start();
-
- localOverride = new Option();
- defaultCacheMode = new Option();
-
- localOverride.setCacheModeLocal(true);
- defaultCacheMode.setCacheModeLocal(false);
}
protected void tearDown()
@@ -75,19 +67,40 @@
if (cache1 != null)
{
cache1.stop();
+ flushTxs(cache1.getTransactionManager());
cache1 = null;
}
if (cache2 != null)
{
cache2.stop();
+ flushTxs(cache2.getTransactionManager());
cache2 = null;
}
}
+ private void flushTxs(TransactionManager mgr)
+ {
+ if (mgr != null)
+ {
+ try
+ {
+ if (mgr.getTransaction() != null)
+ {
+ mgr.rollback();
+ }
+ }
+ catch (SystemException e)
+ {
+ // do nothing
+ }
+ }
+ }
+
public void testPutKeyValue() throws Exception
{
- cache1.put(fqn, key, "value", localOverride);
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache1.put(fqn, key, "value");
delay();
// cache1 should still have this
Assert.assertEquals("value", cache1.get(fqn, key));
@@ -96,7 +109,8 @@
Assert.assertNull("Should be null", cache2.get(fqn, key));
// now try again with passing the default options
- cache1.put(fqn, key, "value", defaultCacheMode);
+ cache1.getInvocationContext().getOptionOverrides().reset();
+ cache1.put(fqn, key, "value");
delay();
// cache1 should still have this
Assert.assertEquals("value", cache1.get(fqn, key));
@@ -108,12 +122,14 @@
Assert.assertNull("should be invalidated", cache2.get(fqn, key));
// now cache2
- cache2.put(fqn, key, "value2", localOverride);
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache2.put(fqn, key, "value2");
delay();
Assert.assertEquals("value2", cache2.get(fqn, key));
Assert.assertEquals("value", cache1.get(fqn, key));
- cache2.put(fqn, key, "value2", defaultCacheMode);
+ cache2.getInvocationContext().getOptionOverrides().reset();
+ cache2.put(fqn, key, "value2");
delay();
Assert.assertEquals("value2", cache2.get(fqn, key));
if (!isInvalidation)
@@ -127,7 +143,8 @@
Map map = new HashMap();
map.put(key, "value");
- cache1.put(fqn, map, localOverride);
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache1.put(fqn, map);
delay();
// cache1 should still have this
Assert.assertEquals("value", cache1.get(fqn, key));
@@ -135,7 +152,8 @@
Assert.assertNull("Should be null", cache2.get(fqn, key));
// now try again with passing the default options
- cache1.put(fqn, map, defaultCacheMode);
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
+ cache1.put(fqn, map);
delay();
// cache1 should still have this
Assert.assertEquals("value", cache1.get(fqn, key));
@@ -147,12 +165,14 @@
// now cache2
map.put(key, "value2");
- cache2.put(fqn, map, localOverride);
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache2.put(fqn, map);
delay();
Assert.assertEquals("value2", cache2.get(fqn, key));
Assert.assertEquals("value", cache1.get(fqn, key));
- cache2.put(fqn, key, "value2", defaultCacheMode);
+ cache2.getInvocationContext().getOptionOverrides().reset();
+ cache2.put(fqn, key, "value2");
delay();
Assert.assertEquals("value2", cache2.get(fqn, key));
if (!isInvalidation)
@@ -174,7 +194,8 @@
else
Assert.assertEquals("value", cache2.get(fqn, key));
- cache1.remove(fqn, localOverride);
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache1.remove(fqn);
delay();
// should be removed in cache1
@@ -195,7 +216,8 @@
Assert.assertEquals("value", cache2.get(fqn, key));
// now try again with passing the default options
- cache1.remove(fqn, defaultCacheMode);
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
+ cache1.remove(fqn);
delay();
// both should be null
@@ -215,7 +237,8 @@
else
Assert.assertEquals("value", cache2.get(fqn, key));
- cache1.remove(fqn, key, localOverride);
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache1.remove(fqn, key);
delay();
// should be removed in cache1
@@ -236,7 +259,8 @@
Assert.assertEquals("value", cache2.get(fqn, key));
// now try again with passing the default options
- cache1.remove(fqn, key, defaultCacheMode);
+ cache1.getInvocationContext().getOptionOverrides().reset();
+ cache1.remove(fqn, key);
delay();
// both should be null
@@ -248,8 +272,10 @@
{
TransactionManager mgr = cache1.getTransactionManager();
mgr.begin();
- cache1.put(fqn, key, "value1", defaultCacheMode);
- cache1.put(fqn, key, "value2", localOverride);
+ cache1.getInvocationContext().getOptionOverrides().reset();
+ cache1.put(fqn, key, "value1");
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache1.put(fqn, key, "value2");
mgr.commit();
delay();
// cache1 should still have this
@@ -262,8 +288,10 @@
// now try again with passing the default options
mgr.begin();
- cache1.put(fqn, key, "value3", localOverride);
- cache1.put(fqn, key, "value", defaultCacheMode);
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache1.put(fqn, key, "value3");
+ cache1.getInvocationContext().getOptionOverrides().reset();
+ cache1.put(fqn, key, "value");
mgr.commit();
delay();
// cache1 should still have this
@@ -278,8 +306,10 @@
// now cache2
mgr = cache2.getTransactionManager();
mgr.begin();
- cache2.put(fqn, key, "value3", defaultCacheMode);
- cache2.put(fqn, key, "value2", localOverride);
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
+ cache2.put(fqn, key, "value3");
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache2.put(fqn, key, "value2");
mgr.commit();
delay();
@@ -291,8 +321,10 @@
assertNull(cache1.get(fqn, key));
mgr.begin();
- cache2.put(fqn, key, "value2", localOverride);
- cache2.put(fqn, key, "value2", defaultCacheMode);
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache2.put(fqn, key, "value2");
+ cache2.getInvocationContext().getOptionOverrides().reset();
+ cache2.put(fqn, key, "value2");
mgr.commit();
delay();
Assert.assertEquals("value2", cache2.get(fqn, key));
More information about the jboss-cvs-commits
mailing list