[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/loader ...
Manik Surtani
msurtani at jboss.com
Wed Sep 6 11:30:58 EDT 2006
User: msurtani
Date: 06/09/06 11:30:58
Modified: tests/functional/org/jboss/cache/loader
BdbjeTest.java
CacheLoaderMethodCallCounterTest.java
CacheLoaderPurgingTest.java
CacheLoaderTestsBase.java
CacheLoaderWithReplicationTest.java
ChainingCacheLoaderFullTest.java
ClusteredCacheLoaderTest.java
DataSourceIntegrationTest.java
InterceptorSynchronizationTest.java
JDBCCacheLoaderDerbyDSTest.java
LocalDelegatingCacheLoaderTest.java
RpcDelegatingCacheLoaderTests.java
SharedCacheLoaderTest.java TxCacheLoaderTest.java
Log:
Removed TreeCache dependency on ServiceMBeanSupport
Revision Changes Path
1.8 +351 -207 JBossCache/tests/functional/org/jboss/cache/loader/BdbjeTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: BdbjeTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/BdbjeTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- BdbjeTest.java 31 Aug 2006 14:56:46 -0000 1.7
+++ BdbjeTest.java 6 Sep 2006 15:30:57 -0000 1.8
@@ -1,6 +1,10 @@
package org.jboss.cache.loader;
-import com.sleepycat.je.*;
+import com.sleepycat.je.Database;
+import com.sleepycat.je.DatabaseConfig;
+import com.sleepycat.je.DatabaseException;
+import com.sleepycat.je.DeadlockException;
+import com.sleepycat.je.Environment;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -16,20 +20,27 @@
import java.io.File;
import java.io.FileFilter;
import java.io.Serializable;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
/**
* Tests BdbjeCacheLoader directly via the CacheLoader interface.
- *
+ * <p/>
* <p>Run this test case with the current directory set to the JE environment
* directory. Any scratch directory will do, but beware that all files in
* the directory will be deleted by setUp().</p>
*
- * @version $Revision: 1.7 $
+ * @version $Revision: 1.8 $
*/
-public class BdbjeTest extends TestCase {
+public class BdbjeTest extends TestCase
+{
- private static final int STREAM_HEADER_LENGTH=4;
+ private static final int STREAM_HEADER_LENGTH = 4;
private static final String envHome = ".";
private static final Fqn FQN = new Fqn("key");
@@ -39,31 +50,39 @@
/**
* Creates a test case.
*/
- public BdbjeTest(String name) {
+ public BdbjeTest(String name)
+ {
super(name);
}
/**
* Deletes all files in the environment directory.
*/
- public void setUp() throws Exception {
+ public void setUp() throws Exception
+ {
super.setUp();
File dir = new File(envHome);
- class MyFilter implements FileFilter {
- public boolean accept(File file) {
+ class MyFilter implements FileFilter
+ {
+ public boolean accept(File file)
+ {
return file.getName().endsWith(".jdb");
}
}
- File[] files=dir.listFiles(new MyFilter());
+ File[] files = dir.listFiles(new MyFilter());
- if (files != null) {
- for (int i = 0; i < files.length; i += 1) {
+ if (files != null)
+ {
+ for (int i = 0; i < files.length; i += 1)
+ {
File file = files[i];
- if (file.isFile()) {
- if (!file.delete()) {
+ if (file.isFile())
+ {
+ if (!file.delete())
+ {
System.err.println("Unable to delete: " + file);
}
}
@@ -75,31 +94,40 @@
* Release all resources and ignore exceptions, to shutdown gracefully
* when an assertion fires.
*/
- public void tearDown() throws Exception {
+ public void tearDown() throws Exception
+ {
super.tearDown();
- if (loader != null) {
- try {
+ if (loader != null)
+ {
+ try
+ {
loader.stop();
- } catch (Exception ignored) {}
+ }
+ catch (Exception ignored) {}
loader = null;
}
- if (treeCache != null) {
- try {
- treeCache.stopService();
- } catch (Exception ignored) {}
+ if (treeCache != null)
+ {
+ try
+ {
+ treeCache.stop();
+ }
+ catch (Exception ignored) {}
treeCache = null;
}
}
/**
* Creates and starts a loader.
+ *
* @param transactional whether to set the TransactionManagerLookupClass
* property.
* @param dbName a database name, or null to default to the cluster name.
*/
private void startLoader(boolean transactional, String dbName)
- throws Exception {
+ throws Exception
+ {
/*
* Create a dummy TreeCache object. This is used for setting the cluster
@@ -108,17 +136,21 @@
*/
treeCache = new TreeCache();
treeCache.getConfiguration().setClusterName("myCluster");
- if (transactional) {
+ if (transactional)
+ {
treeCache.getConfiguration().setTransactionManagerLookupClass(
"org.jboss.cache.DummyTransactionManagerLookup");
}
- treeCache.startService();
+ treeCache.start();
/* Derive the config string. */
String configStr;
- if (dbName != null) {
+ if (dbName != null)
+ {
configStr = envHome + '#' + dbName;
- } else {
+ }
+ else
+ {
configStr = envHome;
dbName = "myCluster";
}
@@ -127,7 +159,7 @@
/* Initialize and start the loader. */
loader.setCache(treeCache.getCacheSPI());
- Properties props=new Properties();
+ Properties props = new Properties();
props.setProperty("location", configStr);
loader.setConfig(props);
loader.create();
@@ -146,7 +178,8 @@
* Creates the loader instance.
*/
private void instantiateLoader()
- throws Exception {
+ throws Exception
+ {
/* Create the cache loader as TreeCache would. */
Class cls =
@@ -158,7 +191,8 @@
* Stops and destroys the loader.
*/
private void stopLoader()
- throws Exception {
+ throws Exception
+ {
loader.stop();
loader.destroy();
@@ -168,7 +202,8 @@
* Tests basic operations without a transaction.
*/
public void testBasicOperations()
- throws Exception {
+ throws Exception
+ {
doTestBasicOperations(false);
}
@@ -177,7 +212,8 @@
* Tests basic operations with a transaction.
*/
public void testBasicOperationsTransactional()
- throws Exception {
+ throws Exception
+ {
doTestBasicOperations(true);
}
@@ -186,7 +222,8 @@
* Tests basic operations.
*/
private void doTestBasicOperations(boolean transactional)
- throws Exception {
+ throws Exception
+ {
startLoader(transactional, null);
@@ -229,7 +266,8 @@
* Do basic put tests for a given FQN.
*/
private void doPutTests(Fqn fqn)
- throws Exception {
+ throws Exception
+ {
assertTrue(!loader.exists(fqn));
@@ -268,7 +306,8 @@
* Do basic remove tests for a given FQN.
*/
private void doRemoveTests(Fqn fqn)
- throws Exception {
+ throws Exception
+ {
/* remove(Fqn,Object) */
Object oldVal;
@@ -297,7 +336,8 @@
* and tests removing subtrees.
*/
public void testMultiLevelTree()
- throws Exception {
+ throws Exception
+ {
startLoader(false, null);
@@ -445,7 +485,8 @@
* Tests the getChildrenNames() method.
*/
public void testGetChildrenNames()
- throws Exception {
+ throws Exception
+ {
startLoader(false, null);
@@ -453,14 +494,14 @@
checkChildren(Fqn.fromString("/key0"), null);
loader.put(Fqn.fromString("/key0"), null);
- checkChildren(new Fqn(), new String[] { "key0" });
+ checkChildren(new Fqn(), new String[]{"key0"});
loader.put(Fqn.fromString("/key1/x"), null);
- checkChildren(new Fqn(), new String[] { "key0", "key1" });
- checkChildren(Fqn.fromString("/key1"), new String[] { "x" });
+ checkChildren(new Fqn(), new String[]{"key0", "key1"});
+ checkChildren(Fqn.fromString("/key1"), new String[]{"x"});
loader.remove(Fqn.fromString("/key1/x"));
- checkChildren(new Fqn(), new String[] { "key0", "key1" });
+ checkChildren(new Fqn(), new String[]{"key0", "key1"});
checkChildren(Fqn.fromString("/key0"), null);
checkChildren(Fqn.fromString("/key1"), null);
@@ -468,41 +509,41 @@
loader.put(Fqn.fromString("/key0/ab"), null);
loader.put(Fqn.fromString("/key0/abc"), null);
checkChildren(Fqn.fromString("/key0"),
- new String[] { "a", "ab", "abc" });
+ new String[]{"a", "ab", "abc"});
loader.put(Fqn.fromString("/key0/xxx"), null);
loader.put(Fqn.fromString("/key0/xx"), null);
loader.put(Fqn.fromString("/key0/x"), null);
checkChildren(Fqn.fromString("/key0"),
- new String[] { "a", "ab", "abc", "x", "xx", "xxx" });
+ new String[]{"a", "ab", "abc", "x", "xx", "xxx"});
loader.put(Fqn.fromString("/key0/a/1"), null);
loader.put(Fqn.fromString("/key0/a/2"), null);
loader.put(Fqn.fromString("/key0/a/2/1"), null);
- checkChildren(Fqn.fromString("/key0/a/2"), new String[] { "1" });
- checkChildren(Fqn.fromString("/key0/a"), new String[] { "1", "2" });
+ checkChildren(Fqn.fromString("/key0/a/2"), new String[]{"1"});
+ checkChildren(Fqn.fromString("/key0/a"), new String[]{"1", "2"});
checkChildren(Fqn.fromString("/key0"),
- new String[] { "a", "ab", "abc", "x", "xx", "xxx" });
+ new String[]{"a", "ab", "abc", "x", "xx", "xxx"});
loader.put(Fqn.fromString("/key0/\u0000"), null);
loader.put(Fqn.fromString("/key0/\u0001"), null);
checkChildren(Fqn.fromString("/key0"),
- new String[] { "a", "ab", "abc", "x", "xx", "xxx",
+ new String[]{"a", "ab", "abc", "x", "xx", "xxx",
"\u0000", "\u0001"});
loader.put(Fqn.fromString("/\u0001"), null);
- checkChildren(new Fqn(), new String[] { "key0", "key1", "\u0001" });
+ checkChildren(new Fqn(), new String[]{"key0", "key1", "\u0001"});
loader.put(Fqn.fromString("/\u0001/\u0001"), null);
- checkChildren(Fqn.fromString("/\u0001"), new String[] { "\u0001" });
+ checkChildren(Fqn.fromString("/\u0001"), new String[]{"\u0001"});
loader.put(Fqn.fromString("/\u0001/\uFFFF"), null);
checkChildren(Fqn.fromString("/\u0001"),
- new String[] { "\u0001", "\uFFFF" });
+ new String[]{"\u0001", "\uFFFF"});
loader.put(Fqn.fromString("/\u0001/\uFFFF/\u0001"), null);
checkChildren(Fqn.fromString("/\u0001/\uFFFF"),
- new String[] { "\u0001" });
+ new String[]{"\u0001"});
stopLoader();
}
@@ -511,15 +552,20 @@
* Checks that the given list of children part names is returned.
*/
private void checkChildren(Fqn fqn, String[] names)
- throws Exception {
+ throws Exception
+ {
Set set = loader.getChildrenNames(fqn);
- if (names != null) {
+ if (names != null)
+ {
assertEquals(names.length, set.size());
- for (int i = 0; i < names.length; i += 1) {
+ for (int i = 0; i < names.length; i += 1)
+ {
assertTrue(set.contains(names[i]));
}
- } else {
+ }
+ else
+ {
assertNull(set);
}
}
@@ -528,7 +574,8 @@
* Tests basic operations without a transaction.
*/
public void testModifications()
- throws Exception {
+ throws Exception
+ {
doTestModifications(false);
}
@@ -537,7 +584,8 @@
* Tests basic operations with a transaction.
*/
public void testModificationsTransactional()
- throws Exception {
+ throws Exception
+ {
doTestModifications(true);
}
@@ -546,7 +594,8 @@
* Tests modifications.
*/
private void doTestModifications(boolean transactional)
- throws Exception {
+ throws Exception
+ {
startLoader(transactional, null);
@@ -594,7 +643,8 @@
* Tests a one-phase transaction.
*/
public void testOnePhaseTransaction()
- throws Exception {
+ throws Exception
+ {
startLoader(true, null);
@@ -609,17 +659,20 @@
* Tests a two-phase transaction.
*/
public void testTwoPhaseTransaction()
- throws Exception {
+ throws Exception
+ {
startLoader(true, null);
Object txnKey = new Object();
List mods = createUpdates();
loader.prepare(txnKey, mods, false);
- try {
+ try
+ {
checkModifications(mods);
fail("Expected lock timeout");
- } catch (DeadlockException expected) {}
+ }
+ catch (DeadlockException expected) {}
loader.commit(txnKey);
checkModifications(mods);
@@ -630,7 +683,8 @@
* Tests rollback of a two-phase transaction.
*/
public void testTransactionRollback()
- throws Exception {
+ throws Exception
+ {
startLoader(true, null);
@@ -650,7 +704,8 @@
/**
* Creates a set of update (PUT_KEY_VALUE, PUT_DATA) modifications.
*/
- private List createUpdates() {
+ private List createUpdates()
+ {
List list = new ArrayList();
@@ -684,18 +739,22 @@
* Checks that a list of modifications was applied.
*/
private void checkModifications(List list)
- throws Exception {
+ throws Exception
+ {
- for (int i = 0; i < list.size(); i += 1) {
+ for (int i = 0; i < list.size(); i += 1)
+ {
Modification mod = (Modification) list.get(i);
Fqn fqn = mod.getFqn();
- switch (mod.getType()) {
+ switch (mod.getType())
+ {
case Modification.PUT_KEY_VALUE:
assertEquals(mod.getValue(), loader.get(fqn).get(mod.getKey()));
break;
case Modification.PUT_DATA:
Map map = mod.getData();
- for (Iterator iter = map.keySet().iterator(); iter.hasNext();) {
+ for (Iterator iter = map.keySet().iterator(); iter.hasNext();)
+ {
Object key = iter.next();
assertEquals(map.get(key), loader.get(fqn).get(key));
}
@@ -749,96 +808,127 @@
* Check exception cases that occur before create().
*/
private void checkPreCreateExceptions()
- throws Exception {
+ throws Exception
+ {
loader.setCache(new TreeCache().getCacheSPI());
loader.setConfig(null);
- try {
+ try
+ {
loader.start();
// fail();
- } catch (IllegalStateException expected) {}
+ }
+ catch (IllegalStateException expected) {}
// loader.setCache(null);
- Properties props=new Properties();
+ Properties props = new Properties();
props.setProperty("location", "xyz");
loader.setConfig(props);
- try {
+ try
+ {
loader.start();
fail();
- } catch (IllegalStateException expected) {}
+ }
+ catch (IllegalStateException expected) {}
loader.setCache(new TreeCache().getCacheSPI());
- props=new Properties();
+ props = new Properties();
props.setProperty("location", "directory_that_does_not_exist");
loader.setConfig(props);
- try {
+ try
+ {
loader.start();
fail();
- } catch (DatabaseException expected) {}
+ }
+ catch (DatabaseException expected) {}
- try {
+ try
+ {
loader.put(FQN, "one", "two");
fail();
- } catch (IllegalStateException expected) {}
+ }
+ catch (IllegalStateException expected) {}
- try {
+ try
+ {
loader.put(FQN, new HashMap());
fail();
- } catch (IllegalStateException expected) {}
+ }
+ catch (IllegalStateException expected) {}
- try {
+ try
+ {
loader.put(new ArrayList());
fail();
- } catch (IllegalStateException expected) {}
+ }
+ catch (IllegalStateException expected) {}
- try {
+ try
+ {
loader.get(FQN).get("one");
fail();
- } catch (IllegalStateException expected) {}
+ }
+ catch (IllegalStateException expected) {}
- try {
+ try
+ {
loader.get(FQN);
fail();
- } catch (IllegalStateException expected) {}
+ }
+ catch (IllegalStateException expected) {}
- try {
+ try
+ {
loader.remove(FQN);
fail();
- } catch (IllegalStateException expected) {}
+ }
+ catch (IllegalStateException expected) {}
- try {
+ try
+ {
loader.remove(FQN, "one");
fail();
- } catch (IllegalStateException expected) {}
+ }
+ catch (IllegalStateException expected) {}
- try {
+ try
+ {
loader.prepare(new Object(), new ArrayList(), false);
fail();
- } catch (IllegalStateException expected) {}
+ }
+ catch (IllegalStateException expected) {}
- try {
+ try
+ {
loader.commit(new Object());
fail();
- } catch (IllegalStateException expected) {}
+ }
+ catch (IllegalStateException expected) {}
- try {
+ try
+ {
loader.rollback(new Object());
fail();
- } catch (IllegalStateException expected) {}
+ }
+ catch (IllegalStateException expected) {}
- try {
+ try
+ {
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
loader.loadEntireState(os);
fail();
- } catch (IllegalStateException expected) {}
+ }
+ catch (IllegalStateException expected) {}
- try {
+ try
+ {
ByteArrayInputStream baos = new ByteArrayInputStream(new byte[0]);
MarshalledValueInputStream is = new MarshalledValueInputStream(baos);
loader.storeEntireState(is);
fail();
- } catch (IllegalStateException expected) {}
+ }
+ catch (IllegalStateException expected) {}
/* Redundant stop and destroy are allowed. */
loader.stop();
@@ -849,100 +939,134 @@
* Check exception cases that occur after create().
*/
private void checkPostCreateExceptions()
- throws Exception {
+ throws Exception
+ {
- try {
+ try
+ {
loader.create();
fail();
- } catch (IllegalStateException expected) {}
+ }
+ catch (IllegalStateException expected) {}
- try {
+ try
+ {
loader.start();
fail();
- } catch (IllegalStateException expected) {}
+ }
+ catch (IllegalStateException expected) {}
- try {
+ try
+ {
loader.put(null, "one", "two");
fail();
- } catch (NullPointerException expected) {}
+ }
+ catch (NullPointerException expected) {}
- try {
+ try
+ {
loader.put(null, new HashMap());
fail();
- } catch (NullPointerException expected) {}
+ }
+ catch (NullPointerException expected) {}
- try {
+ try
+ {
loader.put(null);
fail();
- } catch (NullPointerException expected) {}
+ }
+ catch (NullPointerException expected) {}
- try {
+ try
+ {
loader.get(null).get("one");
fail();
- } catch (NullPointerException expected) {}
+ }
+ catch (NullPointerException expected) {}
- try {
+ try
+ {
loader.get(null);
fail();
- } catch (NullPointerException expected) {}
+ }
+ catch (NullPointerException expected) {}
- try {
+ try
+ {
loader.remove(null);
fail();
- } catch (NullPointerException expected) {}
+ }
+ catch (NullPointerException expected) {}
- try {
+ try
+ {
loader.remove(null, "one");
fail();
- } catch (NullPointerException expected) {}
+ }
+ catch (NullPointerException expected) {}
- try {
+ try
+ {
loader.prepare(null, new ArrayList(), false);
fail();
- } catch (NullPointerException expected) {}
- try {
+ }
+ catch (NullPointerException expected) {}
+ try
+ {
loader.prepare(new Object(), null, false);
fail();
- } catch (NullPointerException expected) {}
+ }
+ catch (NullPointerException expected) {}
- try {
+ try
+ {
loader.commit(null);
fail();
- } catch (NullPointerException expected) {}
+ }
+ catch (NullPointerException expected) {}
- try {
+ try
+ {
loader.rollback(null);
fail();
- } catch (NullPointerException expected) {}
+ }
+ catch (NullPointerException expected) {}
}
/**
* Tests a non-transactional prepare.
*/
public void testTransactionExceptions()
- throws Exception {
+ throws Exception
+ {
List mods = createUpdates();
/* A non-transactional cache loader should not allow prepare(). */
startLoader(false, null);
- try {
+ try
+ {
loader.prepare(new Object(), mods, false);
fail();
- } catch (UnsupportedOperationException expected) {}
+ }
+ catch (UnsupportedOperationException expected) {}
stopLoader();
startLoader(true, null);
/* Commit and rollback a non-prepared transaction. */
- try {
+ try
+ {
loader.commit(new Object());
fail();
- } catch (IllegalArgumentException expected) {}
- try {
+ }
+ catch (IllegalArgumentException expected) {}
+ try
+ {
loader.rollback(new Object());
fail();
- } catch (IllegalArgumentException expected) {}
+ }
+ catch (IllegalArgumentException expected) {}
/* Commit and rollback after commit. */
@@ -958,14 +1082,18 @@
Object txnKey = new Object();
loader.prepare(txnKey, mods, false);
loader.commit(txnKey);
- try {
+ try
+ {
loader.commit(txnKey);
fail();
- } catch (IllegalArgumentException expected) {}
- try {
+ }
+ catch (IllegalArgumentException expected) {}
+ try
+ {
loader.rollback(txnKey);
fail();
- } catch (IllegalArgumentException expected) {}
+ }
+ catch (IllegalArgumentException expected) {}
/* Commit and rollback after rollback. */
bais = new ByteArrayInputStream(baos.toByteArray());
@@ -975,14 +1103,18 @@
txnKey = new Object();
loader.prepare(txnKey, mods, false);
loader.rollback(txnKey);
- try {
+ try
+ {
loader.rollback(txnKey);
fail();
- } catch (IllegalArgumentException expected) {}
- try {
+ }
+ catch (IllegalArgumentException expected) {}
+ try
+ {
loader.rollback(txnKey);
fail();
- } catch (IllegalArgumentException expected) {}
+ }
+ catch (IllegalArgumentException expected) {}
stopLoader();
}
@@ -991,7 +1123,8 @@
* Tests that null keys and values work as for a standard Java Map.
*/
public void testNullKeysAndValues()
- throws Exception {
+ throws Exception
+ {
startLoader(false, null);
@@ -1040,7 +1173,8 @@
* Test non-default database name.
*/
public void testDatabaseName()
- throws Exception {
+ throws Exception
+ {
startLoader(false, "nonDefaultDbName");
loader.put(FQN, "one", "two");
@@ -1052,7 +1186,8 @@
* Test load/store state.
*/
public void testLoadAndStore()
- throws Exception {
+ throws Exception
+ {
startLoader(false, null);
byte [] nullState = null;
@@ -1104,7 +1239,7 @@
os = new MarshalledValueOutputStream(baos);
loader.loadEntireState(os);
os.writeObject(StateTransferManager.STREAMING_DELIMETER_NODE);
- assertTrue(baos.size()>STREAM_HEADER_LENGTH);
+ assertTrue(baos.size() > STREAM_HEADER_LENGTH);
os.close();
byte [] savedState = baos.toByteArray();
@@ -1133,13 +1268,15 @@
}
public static Test suite()
- throws Exception {
+ throws Exception
+ {
return new TestSuite(BdbjeTest.class);
}
public static void main(String[] args)
- throws Exception {
+ throws Exception
+ {
junit.textui.TestRunner.run(suite());
}
@@ -1147,24 +1284,31 @@
/**
* Complex object whose class description is stored in the class catalog.
*/
- private static class Complex implements Serializable {
+ private static class Complex implements Serializable
+ {
Complex nested;
- Complex() {
+ Complex()
+ {
this(null);
}
- Complex(Complex nested) {
+ Complex(Complex nested)
+ {
this.nested = nested;
}
- public boolean equals(Object o) {
- try {
+ public boolean equals(Object o)
+ {
+ try
+ {
Complex x = (Complex) o;
return (nested != null) ? nested.equals(x.nested)
: (x.nested == null);
- } catch (ClassCastException e) {
+ }
+ catch (ClassCastException e)
+ {
return false;
}
}
1.10 +76 -76 JBossCache/tests/functional/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheLoaderMethodCallCounterTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- CacheLoaderMethodCallCounterTest.java 20 Jul 2006 10:54:00 -0000 1.9
+++ CacheLoaderMethodCallCounterTest.java 6 Sep 2006 15:30:57 -0000 1.10
@@ -29,15 +29,15 @@
if (cache != null) tearDown();
cache = new TreeCache();
cache.getConfiguration().setCacheLoaderConfiguration(getSingleCacheLoaderConfig("", DummyCacheLoader.class.getName(), "", false, false, false));
- cache.startService();
+ cache.start();
dummyLoader = (DummyCacheLoader) cache.getCacheLoader();
}
protected void tearDown()
{
if (cache != null)
- cache.stopService();
- cache.destroyService();
+ cache.stop();
+ cache.destroy();
cache = null;
}
@@ -45,19 +45,19 @@
public void testPut() throws Exception
{
cache.put("/node", "key", "value");
- printReport( "putKeyValue", dummyLoader );
+ printReport("putKeyValue", dummyLoader);
}
public void testGet() throws Exception
{
cache.get("/node", "key");
- printReport( "getKey", dummyLoader );
+ printReport("getKey", dummyLoader);
}
public void testRemove() throws Exception
{
cache.remove("/node", "key");
- printReport( "removeKey", dummyLoader );
+ printReport("removeKey", dummyLoader);
}
private void printReport(String test, DummyCacheLoader d)
@@ -83,7 +83,7 @@
// the cloader interceptor does a get as well when doing the put ... ?
assertEquals(0, dummyLoader.getGetCount());
- for (int i=0;i<2000; i++)
+ for (int i = 0; i < 2000; i++)
{
cache.get("/test");
}
1.4 +10 -10 JBossCache/tests/functional/org/jboss/cache/loader/CacheLoaderPurgingTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheLoaderPurgingTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/CacheLoaderPurgingTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- CacheLoaderPurgingTest.java 30 Aug 2006 19:09:56 -0000 1.3
+++ CacheLoaderPurgingTest.java 6 Sep 2006 15:30:57 -0000 1.4
@@ -26,7 +26,7 @@
if (cache != null)
{
cache.remove(Fqn.ROOT);
- cache.stopService();
+ cache.stop();
cache = null;
}
}
@@ -37,7 +37,7 @@
Configuration c = new Configuration();
cache.setConfiguration(c);
c.setCacheLoaderConfiguration(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.FileCacheLoader", "location=" + System.getProperty("java.io.tmpdir", "/tmp") + "/" + "CacheLoaderPurgingTest", false, false, false));
- cache.startService();
+ cache.start();
cache.put(fqn, key, value);
@@ -47,10 +47,10 @@
assertEquals(value, loader.get(fqn).get(key));
cache.evict(fqn);
- cache.stopService();
+ cache.stop();
assertEquals(value, loader.get(fqn).get(key));
- cache.startService();
+ cache.start();
assertEquals(value, cache.get(fqn, key));
assertEquals(value, loader.get(fqn).get(key));
}
@@ -61,7 +61,7 @@
Configuration c = new Configuration();
cache.setConfiguration(c);
c.setCacheLoaderConfiguration(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.FileCacheLoader", "location=" + System.getProperty("java.io.tmpdir", "/tmp") + "/" + "CacheLoaderPurgingTest", false, false, false, true));
- cache.startService();
+ cache.start();
cache.put(fqn, key, value);
@@ -71,10 +71,10 @@
assertEquals(value, loader.get(fqn).get(key));
cache.evict(fqn);
- cache.stopService();
+ cache.stop();
assertEquals(value, loader.get(fqn).get(key));
- cache.startService();
+ cache.start();
assertNull(cache.get(fqn));
assertNull(loader.get(fqn));
}
@@ -109,7 +109,7 @@
Configuration c = new Configuration();
cache.setConfiguration(c);
c.setCacheLoaderConfiguration(XmlHelper.stringToElement(xml));
- cache.startService();
+ cache.start();
cache.put(fqn, key, value);
@@ -120,11 +120,11 @@
assertEquals(value, loader[1].get(fqn).get(key));
cache.evict(fqn);
- cache.stopService();
+ cache.stop();
assertEquals(value, loader[0].get(fqn).get(key));
assertEquals(value, loader[1].get(fqn).get(key));
- cache.startService();
+ cache.start();
assertTrue(!cache.exists(fqn));
assertNull(loader[0].get(fqn));
assertNotNull(loader[1].get(fqn));
1.29 +495 -376 JBossCache/tests/functional/org/jboss/cache/loader/CacheLoaderTestsBase.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheLoaderTestsBase.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/CacheLoaderTestsBase.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -b -r1.28 -r1.29
--- CacheLoaderTestsBase.java 31 Aug 2006 14:56:46 -0000 1.28
+++ CacheLoaderTestsBase.java 6 Sep 2006 15:30:58 -0000 1.29
@@ -1,75 +1,91 @@
package org.jboss.cache.loader;
-import org.jboss.cache.*;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.DataNode;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Modification;
+import org.jboss.cache.TreeCache;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.statetransfer.StateTransferManager;
import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.invocation.MarshalledValueInputStream;
import org.jboss.invocation.MarshalledValueOutputStream;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import javax.transaction.NotSupportedException;
import javax.transaction.Transaction;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.Serializable;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* Commons tests for all CacheLoaders
+ *
* @author Bela Ban
- * @version $Id: CacheLoaderTestsBase.java,v 1.28 2006/08/31 14:56:46 vblagojevic Exp $
+ * @version $Id: CacheLoaderTestsBase.java,v 1.29 2006/09/06 15:30:58 msurtani Exp $
*/
-abstract public class CacheLoaderTestsBase extends AbstractCacheLoaderTestBase {
+abstract public class CacheLoaderTestsBase extends AbstractCacheLoaderTestBase
+{
private static final Log log = LogFactory.getLog(CacheLoaderTestsBase.class);
TreeCache cache;
- CacheLoader loader=null;
- Transaction tx=null;
+ CacheLoader loader = null;
+ Transaction tx = null;
static final Fqn FQN = new Fqn("key");
- public CacheLoaderTestsBase(String name) {
+ public CacheLoaderTestsBase(String name)
+ {
super(name);
}
- public CacheLoaderTestsBase() {
+ public CacheLoaderTestsBase()
+ {
super();
}
- protected void setUp() throws Exception {
+ protected void setUp() throws Exception
+ {
super.setUp();
log.debug("\nTest " + getName() + "\n");
- cache=new TreeCache();
+ cache = new TreeCache();
Configuration c = new Configuration();
cache.setConfiguration(c);
c.setCacheMode(Configuration.CacheMode.LOCAL);
c.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
configureCache();
- cache.startService();
- loader=cache.getCacheLoader();
+ cache.start();
+ loader = cache.getCacheLoader();
}
abstract protected void configureCache() throws Exception;
- protected void tearDown() throws Exception {
+ protected void tearDown() throws Exception
+ {
super.tearDown();
- if(tx != null) {
- try {
+ if (tx != null)
+ {
+ try
+ {
tx.commit();
}
- catch(Throwable e) {
+ catch (Throwable e)
+ {
e.printStackTrace();
}
}
cache.remove("/");
loader.remove(Fqn.fromString("/"));
- cache.stopService();
- cache.destroyService();
+ cache.stop();
+ cache.destroy();
}
protected void addDelay()
@@ -97,59 +113,63 @@
}
- public void testPrint() throws CacheException {
- final Fqn NODE=Fqn.fromString("/test");
- final String KEY="key";
+ public void testPrint() throws CacheException
+ {
+ final Fqn NODE = Fqn.fromString("/test");
+ final String KEY = "key";
cache.put(NODE, KEY, new Integer(10));
cache.evict(NODE);
addDelay();
- String ret=cache.print(NODE);
+ String ret = cache.print(NODE);
assertNotNull(ret);
}
- public void testPut() throws CacheException {
- final String NODE="/test";
- final String KEY="key";
- Object retval=null;
+ public void testPut() throws CacheException
+ {
+ final String NODE = "/test";
+ final String KEY = "key";
+ Object retval = null;
cache.remove(NODE);
addDelay();
- retval=cache.put(NODE, KEY, new Integer(10));
+ retval = cache.put(NODE, KEY, new Integer(10));
assertEquals(null, retval);
- retval=cache.put(NODE, KEY, new Integer(20));
+ retval = cache.put(NODE, KEY, new Integer(20));
addDelay();
assertEquals(new Integer(10), retval);
cache.evict(Fqn.fromString(NODE)); // evicts from memory, but *not* from store
addDelay();
log.debug("put 30, expect 20 back");
- retval=cache.put(NODE, KEY, new Integer(30));
+ retval = cache.put(NODE, KEY, new Integer(30));
assertEquals(new Integer(20), retval);
}
- public void testPut2() throws CacheException {
- final String NODE="/a/b/c";
- final String KEY="key";
- Object retval=null;
+ public void testPut2() throws CacheException
+ {
+ final String NODE = "/a/b/c";
+ final String KEY = "key";
+ Object retval = null;
cache.remove(NODE);
addDelay();
- retval=cache.put(NODE, KEY, new Integer(10));
+ retval = cache.put(NODE, KEY, new Integer(10));
assertNull(retval);
addDelay();
- retval=cache.put(NODE, KEY, new Integer(20));
+ retval = cache.put(NODE, KEY, new Integer(20));
assertEquals(new Integer(10), retval);
cache.evict(Fqn.fromString(NODE)); // evicts from memory, but *not* from store
cache.evict(Fqn.fromString("/a/b"));
cache.evict(Fqn.fromString("/a"));
addDelay();
log.debug("replace KEY with 30, expect 20");
- retval=cache.put(NODE, KEY, new Integer(30));
+ retval = cache.put(NODE, KEY, new Integer(30));
assertEquals(new Integer(20), retval);
}
/**
* Tests various Map puts.
*/
- public void testPut3() throws CacheException {
- final Fqn NODE=Fqn.fromString("/a/b/c");
+ public void testPut3() throws CacheException
+ {
+ final Fqn NODE = Fqn.fromString("/a/b/c");
cache.remove(NODE);
addDelay();
@@ -179,8 +199,9 @@
/**
* Tests various put combos which should exercise the CacheLoaderInterceptor.
*/
- public void testPutRemoveCombos() throws Exception {
- final String NODE="/a/b/c";
+ public void testPutRemoveCombos() throws Exception
+ {
+ final String NODE = "/a/b/c";
cache.remove(NODE);
Fqn fqn = Fqn.fromString(NODE);
addDelay();
@@ -203,35 +224,36 @@
assertEquals(2, cache.get(NODE).getData().size());
}
- public void testGet() throws CacheException {
- final String NODE="/a/b/c";
- Object retval=null;
+ public void testGet() throws CacheException
+ {
+ final String NODE = "/a/b/c";
+ Object retval = null;
cache.remove(NODE);
addDelay();
- retval=cache.put(NODE, "1", new Integer(10));
+ retval = cache.put(NODE, "1", new Integer(10));
assertNull(retval);
addDelay();
- retval=cache.put(NODE, "2", new Integer(20));
+ retval = cache.put(NODE, "2", new Integer(20));
cache.evict(Fqn.fromString("/a/b/c"));
assertTrue("DataNode should not exisit ", !cache.exists("/a/b/c"));
addDelay();
- retval=cache.get(NODE, "1");
+ retval = cache.get(NODE, "1");
assertEquals(new Integer(10), retval);
- retval=cache.get(NODE, "2");
+ retval = cache.get(NODE, "2");
assertEquals(new Integer(20), retval);
}
public void testGetNode() throws CacheException
{
- final String NODE="/a/b/c";
- Object retval=null;
+ final String NODE = "/a/b/c";
+ Object retval = null;
cache.remove(NODE);
addDelay();
cache.put(NODE, "1", new Integer(10));
cache.evict(Fqn.fromString(NODE));
assertTrue("DataNode should not exisit ", !cache.exists("/a/b/c"));
addDelay();
- retval=cache.get(NODE);
+ retval = cache.get(NODE);
assertNotNull("Should not be null", retval);
assertTrue("Expecting instance of data node", retval instanceof DataNode);
@@ -241,8 +263,9 @@
}
- public void testSerialization() throws CacheException {
- SamplePojo pojo=new SamplePojo(39, "Bela");
+ public void testSerialization() throws CacheException
+ {
+ SamplePojo pojo = new SamplePojo(39, "Bela");
pojo.getHobbies().add("Running");
pojo.getHobbies().add("Beerathlon");
pojo.getHobbies().add("Triathlon");
@@ -251,18 +274,22 @@
assertNotNull(cache.get("/mypojo", new Integer(322649)));
cache.evict(Fqn.fromString("/mypojo"));
assertFalse(cache.exists("/mypojo"));
- SamplePojo pojo2=(SamplePojo)cache.get("/mypojo", new Integer(322649)); // should fetch from CacheLoader
+ SamplePojo pojo2 = (SamplePojo) cache.get("/mypojo", new Integer(322649)); // should fetch from CacheLoader
assertNotNull(pojo2);
assertEquals(39, pojo2.getAge());
assertEquals("Bela", pojo2.getName());
assertEquals(3, pojo2.getHobbies().size());
}
- /** Just adds some data that wil be later retrieved. This test has to be run first */
- public void testPopulate() {
- try {
- Map m=new HashMap();
- for(int i=0; i < 10; i++)
+ /**
+ * Just adds some data that wil be later retrieved. This test has to be run first
+ */
+ public void testPopulate()
+ {
+ try
+ {
+ Map m = new HashMap();
+ for (int i = 0; i < 10; i++)
m.put("key" + i, "val" + i);
cache.put("/a/b/c", m);
cache.load("/1/2/3/4/5");
@@ -282,13 +309,15 @@
assertTrue(cache.exists("/a/b/c"));
assertFalse(cache.exists("/a/b/c/d"));
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testPreloading() throws CacheException {
+ public void testPreloading() throws CacheException
+ {
cache.remove("/");
cache.put("1/2/3/4/5/d", "key", "val");
cache.evict(Fqn.fromString("1/2/3/4/5/d"));
@@ -301,29 +330,34 @@
}
-
- public void testCacheLoading2() throws CacheException {
- Set keys=null;
+ public void testCacheLoading2() throws CacheException
+ {
+ Set keys = null;
cache.put("/a/b/c", "key", "val");
- try {
- keys=cache.getKeys("/a/b/c");
+ try
+ {
+ keys = cache.getKeys("/a/b/c");
assertNotNull(keys);
assertEquals(1, keys.size());
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
- try {
+ try
+ {
keys.add("myKey");
}
- catch(UnsupportedOperationException ex) {
+ catch (UnsupportedOperationException ex)
+ {
fail("unsupported operation: " + ex);
}
}
- public void testExists() throws Exception {
+ public void testExists() throws Exception
+ {
cache.put("/eins/zwei/drei", "key1", "val1");
assertTrue(cache.exists("/eins/zwei/drei"));
assertTrue(cache.exists("/eins/zwei/drei", "key1"));
@@ -332,25 +366,29 @@
assertFalse(cache.exists("/une/due/tre", "key1"));
}
- public void testGetChildren() {
- try {
+ public void testGetChildren()
+ {
+ try
+ {
cache.put("/1/2/3/4/5/d/one", null);
cache.put("/1/2/3/4/5/d/two", null);
cache.put("/1/2/3/4/5/d/three", null);
- Set children=cache.getChildrenNames("/1/2/3/4/5/d");
+ Set children = cache.getChildrenNames("/1/2/3/4/5/d");
assertNotNull(children);
assertEquals(3, children.size());
assertTrue(children.contains("one"));
assertTrue(children.contains("two"));
assertTrue(children.contains("three"));
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testGetChildrenWithEviction() throws CacheException {
+ public void testGetChildrenWithEviction() throws CacheException
+ {
cache.put("/a/b/c/1", null);
cache.put("/a/b/c/2", null);
cache.put("/a/b/c/3", null);
@@ -362,7 +400,7 @@
cache.evict(Fqn.fromString("/a"));
cache.evict(Fqn.fromString("/"));
addDelay();
- Set children=cache.getChildrenNames("/a/b/c");
+ Set children = cache.getChildrenNames("/a/b/c");
assertNotNull(children);
assertEquals(3, children.size());
assertTrue(children.contains("1"));
@@ -370,71 +408,85 @@
assertTrue(children.contains("3"));
}
- public void testGetChildren2() {
- try {
+ public void testGetChildren2()
+ {
+ try
+ {
cache.put("/1", null);
cache.put("a", null);
- Set children=cache.getChildrenNames("/");
+ Set children = cache.getChildrenNames("/");
assertNotNull(children);
assertEquals(2, children.size());
assertTrue(children.contains("1"));
assertTrue(children.contains("a"));
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testGetChildren3() {
- try {
+ public void testGetChildren3()
+ {
+ try
+ {
cache.put("/1", null);
cache.put("a", null);
- Set children=cache.getChildrenNames("");
+ Set children = cache.getChildrenNames("");
assertNotNull(children);
assertEquals(2, children.size());
assertTrue(children.contains("1"));
assertTrue(children.contains("a"));
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testGetChildren4() {
- try {
- if(!cache.exists("/a/b/c"))
+ public void testGetChildren4()
+ {
+ try
+ {
+ if (!cache.exists("/a/b/c"))
cache.put("/a/b/c", null);
- Set children=cache.getChildrenNames((Fqn)null);
+ Set children = cache.getChildrenNames((Fqn) null);
assertNull(children);
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testGetChildren5() {
- try {
+ public void testGetChildren5()
+ {
+ try
+ {
cache.put("/a/1", null);
cache.put("/a/2", null);
cache.put("/a/3", null);
System.out.println("cache is " + cache.printLockInfo());
- DataNode n=cache.get("/a");
+ DataNode n = cache.get("/a");
assertNotNull(n);
- Set children=cache.getChildrenNames("/a");
+ Set children = cache.getChildrenNames("/a");
assertNotNull(children);
assertEquals(3, children.size());
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testGetChildren6() {
- try {
+ public void testGetChildren6()
+ {
+ try
+ {
cache.put("/a/1", null);
cache.put("/a/2", null);
cache.put("/a/3", null);
@@ -447,18 +499,21 @@
addDelay();
assertNotNull(cache.get("/a"));
- Set children=cache.getChildrenNames("/a");
+ Set children = cache.getChildrenNames("/a");
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testGetChildren7() {
- try {
+ public void testGetChildren7()
+ {
+ try
+ {
cache.put("/a/1", null);
cache.put("/a/2", null);
cache.put("/a/3", null);
@@ -470,15 +525,16 @@
cache.evict(Fqn.fromString("/a"));
System.out.println("cache is " + cache.printLockInfo());
addDelay();
- Object val=cache.get("/a", "test");
+ Object val = cache.get("/a", "test");
assertEquals("attributes weren't loaded", "test", val);
- Set children=cache.getChildrenNames("/a");
+ Set children = cache.getChildrenNames("/a");
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
@@ -498,14 +554,16 @@
assertNull(cache.get("/a", "test"));
cache.get("/a/1");
- Set children=cache.getChildrenNames("/a");
+ Set children = cache.getChildrenNames("/a");
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
}
- public void testGetChildren9() {
- try {
+ public void testGetChildren9()
+ {
+ try
+ {
cache.put("/a/1", null);
cache.put("/a/2", null);
cache.put("/a/3", null);
@@ -519,7 +577,7 @@
assertNull(cache.get("/a", "test"));
cache.get("/a/1");
- Set children=cache.getChildrenNames("/a");
+ Set children = cache.getChildrenNames("/a");
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
@@ -533,19 +591,22 @@
assertNull(cache.get("/a", "test"));
cache.get("/a/1");
- children=cache.getChildrenNames("/a");
+ children = cache.getChildrenNames("/a");
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testGetChildren10() {
- try {
+ public void testGetChildren10()
+ {
+ try
+ {
cache.put("/a/1", null);
cache.put("/a/2", null);
cache.put("/a/3", null);
@@ -559,25 +620,28 @@
assertNull(cache.get("/a", "test"));
cache.get("/a/1");
- Set children=cache.getChildrenNames("/a");
+ Set children = cache.getChildrenNames("/a");
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
- children=cache.getChildrenNames("/a");
+ children = cache.getChildrenNames("/a");
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testGetChildren11() {
+ public void testGetChildren11()
+ {
Set children;
- try {
+ try
+ {
cache.put("/a/b", "key", "val");
cache.put("/a/b/1", "key", "val");
cache.put("/a/b/2", "key", "val");
@@ -593,7 +657,7 @@
cache.evict(Fqn.fromString("/a/b/3"));
// now load the children - this set childrenLoaded in /a/b to true
- children=cache.getChildrenNames("/a/b");
+ children = cache.getChildrenNames("/a/b");
assertEquals(3, children.size());
cache.evict(Fqn.fromString("/a/b"));
@@ -605,23 +669,26 @@
cache.evict(Fqn.fromString(("/a/b/3")));
cache.evict(Fqn.fromString("/a"));
- children=cache.getChildrenNames("/a/b");
+ children = cache.getChildrenNames("/a/b");
assertEquals(3, children.size());
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testGetChildren12() {
+ public void testGetChildren12()
+ {
Set children;
- try {
+ try
+ {
cache.put("/a/b", "key", "val");
cache.put("/a/b/1", "key", "val");
cache.put("/a/b/2", "key", "val");
cache.put("/a/b/3", "key", "val");
- children=cache.getChildrenNames("/a/b");
+ children = cache.getChildrenNames("/a/b");
assertEquals(3, children.size());
cache.evict(Fqn.fromString("/a/b/3"));
@@ -632,7 +699,7 @@
// now load the children - this set childrenLoaded in /a/b to true
cache.getChildrenNames("/a/b");
- children=cache.getChildrenNames("/a/b");
+ children = cache.getChildrenNames("/a/b");
assertEquals(3, children.size());
cache.evict(Fqn.fromString("/a/b/3"));
@@ -640,63 +707,68 @@
// cache.evict(Fqn.fromString("/a/b/1"));
cache.evict(Fqn.fromString("/a/b"));
cache.evict(Fqn.fromString("/a"));
- children=cache.getChildrenNames("/a/b");
+ children = cache.getChildrenNames("/a/b");
assertEquals(3, children.size());
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testRemoveData() throws Exception {
- String key="/x/y/z/";
+ public void testRemoveData() throws Exception
+ {
+ String key = "/x/y/z/";
cache.put(key, "keyA", "valA");
cache.put(key, "keyB", "valB");
cache.put(key, "keyC", "valC");
assertEquals(3, cache.getKeys(key).size());
cache.removeData(key);
- Set keys=cache.getKeys(key);
+ Set keys = cache.getKeys(key);
assertEquals(0, keys.size());
cache.remove("/x");
- Object val=cache.get(key, "keyA");
+ Object val = cache.get(key, "keyA");
assertNull(val);
}
- public void testRemoveData2() throws Exception {
+ public void testRemoveData2() throws Exception
+ {
Set keys;
- Fqn key=Fqn.fromString("/x/y/z/");
+ Fqn key = Fqn.fromString("/x/y/z/");
cache.put(key, "keyA", "valA");
cache.put(key, "keyB", "valB");
cache.put(key, "keyC", "valC");
addDelay();
- keys=cache.getKeys(key);
+ keys = cache.getKeys(key);
assertEquals(3, keys.size());
cache.removeData(key);
cache.evict(key);
addDelay();
- keys=cache.getKeys(key);
+ keys = cache.getKeys(key);
assertNotNull(keys);
assertEquals(0, keys.size());
}
- public void testRemoveData3() throws Exception {
+ public void testRemoveData3() throws Exception
+ {
Set keys;
- Fqn key=Fqn.fromString("/x/y/z/");
+ Fqn key = Fqn.fromString("/x/y/z/");
cache.put(key, "keyA", "valA");
cache.put(key, "keyB", "valB");
cache.put(key, "keyC", "valC");
- keys=cache.getKeys(key);
+ keys = cache.getKeys(key);
assertEquals(3, keys.size());
cache.evict(key);
cache.removeData(key);
- keys=cache.getKeys(key);
+ keys = cache.getKeys(key);
assertEquals("no more keys", 0, keys.size());
}
- public void testRemoveKey() throws Exception {
- String key="/x/y/z/";
+ public void testRemoveKey() throws Exception
+ {
+ String key = "/x/y/z/";
cache.put(key, "keyA", "valA");
cache.put(key, "keyB", "valB");
cache.put(key, "keyC", "valC");
@@ -706,56 +778,60 @@
}
- public void testRemoveKey2() throws CacheException {
- final String NODE="/test";
- final String KEY="key";
- Object retval=null;
+ public void testRemoveKey2() throws CacheException
+ {
+ final String NODE = "/test";
+ final String KEY = "key";
+ Object retval = null;
cache.remove(NODE);
- retval=cache.put(NODE, KEY, new Integer(10));
+ retval = cache.put(NODE, KEY, new Integer(10));
assertNull(retval);
addDelay();
- retval=cache.remove(NODE, KEY);
+ retval = cache.remove(NODE, KEY);
assertEquals(new Integer(10), retval);
addDelay();
- retval=cache.remove(NODE, KEY);
+ retval = cache.remove(NODE, KEY);
assertNull(retval);
}
- public void testRemoveKey3() throws CacheException {
- final String NODE="/test";
- final String KEY="key";
- Object retval=null;
+ public void testRemoveKey3() throws CacheException
+ {
+ final String NODE = "/test";
+ final String KEY = "key";
+ Object retval = null;
cache.remove(NODE);
- retval=cache.put(NODE, KEY, new Integer(10));
+ retval = cache.put(NODE, KEY, new Integer(10));
assertNull(retval);
cache.evict(Fqn.fromString(NODE)); // evicts from memory, but *not* from store
addDelay();
- retval=cache.remove(NODE, KEY);
+ retval = cache.remove(NODE, KEY);
assertEquals(new Integer(10), retval);
cache.evict(Fqn.fromString(NODE)); // evicts from memory, but *not* from store
addDelay();
- retval=cache.remove(NODE, KEY);
+ retval = cache.remove(NODE, KEY);
assertNull(retval);
}
- public void testRemove() throws Exception {
- String key="/x/y/z/";
+ public void testRemove() throws Exception
+ {
+ String key = "/x/y/z/";
cache.put(key, "keyA", "valA");
cache.put(key, "keyB", "valB");
cache.put(key, "keyC", "valC");
cache.remove("/x");
assertNull(cache.get(key, "keyA"));
addDelay();
- Set keys=cache.getKeys(key);
+ Set keys = cache.getKeys(key);
assertNull("got keys " + keys, keys);
cache.remove("/x");
}
- public void testRemoveRoot() throws Exception {
+ public void testRemoveRoot() throws Exception
+ {
assertEquals(0, cache.getKeys("/").size());
cache.put("/1/2/3/4/5", null);
cache.put("uno/due/tre", null);
@@ -767,7 +843,8 @@
}
- public void testEvictionWithCacheLoader() throws Exception {
+ public void testEvictionWithCacheLoader() throws Exception
+ {
cache.put("/first/second", "key1", "val1"); // stored in cache loader
cache.put("/first/second/third", "key2", "val2"); // stored in cache loader
cache.evict(Fqn.fromString("/first/second")); // doesn't remove node, just data !
@@ -775,7 +852,7 @@
assertTrue(cache.exists("/first/second/third"));
assertTrue(cache.exists("/first/second"));
assertTrue(cache.exists("/first"));
- String val=(String)cache.get("/first/second", "key1"); // should be loaded from cache loader
+ String val = (String) cache.get("/first/second", "key1"); // should be loaded from cache loader
assertEquals("val1", val);
assertTrue(cache.exists("/first/second/third"));
assertTrue(cache.exists("/first/second"));
@@ -783,14 +860,15 @@
}
- public void testEvictionWithCacheLoader2() throws Exception {
+ public void testEvictionWithCacheLoader2() throws Exception
+ {
cache.put("/first/second/third", "key1", "val1"); // stored in cache loader
cache.evict(Fqn.fromString("/first/second/third")); // removes node, because there are no children
addDelay();
assertFalse(cache.exists("/first/second/third"));
assertTrue(cache.exists("/first/second"));
assertTrue(cache.exists("/first"));
- String val=(String)cache.get("/first/second/third", "key1"); // should be loaded from cache loader
+ String val = (String) cache.get("/first/second/third", "key1"); // should be loaded from cache loader
assertEquals("val1", val);
assertTrue(cache.exists("/first/second/third"));
assertTrue(cache.exists("/first/second"));
@@ -798,8 +876,8 @@
}
-
- public void testEvictionWithGetChildrenNames() throws Exception {
+ public void testEvictionWithGetChildrenNames() throws Exception
+ {
cache.put("/a/1", null);
cache.put("/a/2", null);
cache.put("/a/3", null);
@@ -810,11 +888,11 @@
cache.evict(Fqn.fromString("/a"));
addDelay();
- DummyTransactionManager mgr=DummyTransactionManager.getInstance();
+ DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
- tx=mgr.getTransaction();
- Set children=cache.getChildrenNames("/a");
+ tx = mgr.getTransaction();
+ Set children = cache.getChildrenNames("/a");
System.out.println("**** " + cache.getTransactionManager());
@@ -831,30 +909,32 @@
}
- public void testTxPutCommit() throws Exception, NotSupportedException {
- DummyTransactionManager mgr=DummyTransactionManager.getInstance();
+ public void testTxPutCommit() throws Exception, NotSupportedException
+ {
+ DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
- tx=mgr.getTransaction();
+ tx = mgr.getTransaction();
cache.put("/one/two/three", "key1", "val1");
cache.put("/one/two/three/four", "key2", "val2");
tx.commit();
assertNotNull("Cache has node /one/two/three", cache.getKeys("/one/two/three"));
assertNotNull("Loader has node /one/two/three", loader.get(Fqn.fromString("/one/two/three")));
- Set children=cache.getChildrenNames("/one");
+ Set children = cache.getChildrenNames("/one");
assertEquals("Cache has correct number of children", 1, children.size());
children = loader.getChildrenNames(Fqn.fromString("/one"));
assertEquals("Loader has correct number of children", 1, children.size());
cache.remove("/");
}
- public void testTxPutRollback() throws Exception, NotSupportedException {
- DummyTransactionManager mgr=DummyTransactionManager.getInstance();
+ public void testTxPutRollback() throws Exception, NotSupportedException
+ {
+ DummyTransactionManager mgr = DummyTransactionManager.getInstance();
cache.remove("/one");
addDelay();
mgr.begin();
- tx=mgr.getTransaction();
+ tx = mgr.getTransaction();
cache.put("/one/two/three", "key1", "val1");
cache.put("/one/two/three/four", "key2", "val2");
@@ -866,7 +946,7 @@
addDelay();
assertNull("Loader does not have node /one/two/three", loader.get(Fqn.fromString("/one/two/three")));
assertEquals("Cache does not have node /one/two/three", null, cache.getKeys("/one/two/three"));
- Set children=cache.getChildrenNames("/one");
+ Set children = cache.getChildrenNames("/one");
assertEquals("Cache has no children under /one", null, children);
children = loader.getChildrenNames(Fqn.fromString("/one"));
assertEquals("Loader has no children under /one", null, children);
@@ -877,7 +957,8 @@
* Tests basic operations without a transaction.
*/
public void testBasicOperations()
- throws Exception {
+ throws Exception
+ {
doTestBasicOperations();
}
@@ -886,11 +967,12 @@
* Tests basic operations with a transaction.
*/
public void testBasicOperationsTransactional()
- throws Exception {
+ throws Exception
+ {
- DummyTransactionManager mgr=DummyTransactionManager.getInstance();
+ DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
- tx=mgr.getTransaction();
+ tx = mgr.getTransaction();
doTestBasicOperations();
tx.commit();
}
@@ -898,7 +980,8 @@
/**
* Tests basic operations.
*/
- private void doTestBasicOperations() throws Exception {
+ private void doTestBasicOperations() throws Exception
+ {
/* One FQN only. */
doPutTests(new Fqn("key"));
@@ -927,7 +1010,8 @@
* Do basic put tests for a given FQN.
*/
private void doPutTests(Fqn fqn)
- throws Exception {
+ throws Exception
+ {
assertTrue(!loader.exists(fqn));
@@ -972,7 +1056,8 @@
* Do basic remove tests for a given FQN.
*/
private void doRemoveTests(Fqn fqn)
- throws Exception {
+ throws Exception
+ {
/* remove(Fqn,Object) */
Object oldVal;
@@ -1005,7 +1090,8 @@
* and tests removing subtrees.
*/
public void testMultiLevelTree()
- throws Exception {
+ throws Exception
+ {
/* Create top level node implicitly. */
assertTrue(!loader.exists(new Fqn("key0")));
@@ -1167,23 +1253,24 @@
* Tests the getChildrenNames() method.
*/
public void testGetChildrenNames()
- throws Exception {
+ throws Exception
+ {
checkChildren(new Fqn(), null);
checkChildren(Fqn.fromString("/key0"), null);
loader.put(Fqn.fromString("/key0"), null);
addDelay();
- checkChildren(new Fqn(), new String[] { "key0" });
+ checkChildren(new Fqn(), new String[]{"key0"});
loader.put(Fqn.fromString("/key1/x"), null);
addDelay();
- checkChildren(new Fqn(), new String[] { "key0", "key1" });
- checkChildren(Fqn.fromString("/key1"), new String[] { "x" });
+ checkChildren(new Fqn(), new String[]{"key0", "key1"});
+ checkChildren(Fqn.fromString("/key1"), new String[]{"x"});
loader.remove(Fqn.fromString("/key1/x"));
addDelay();
- checkChildren(new Fqn(), new String[] { "key0", "key1" });
+ checkChildren(new Fqn(), new String[]{"key0", "key1"});
checkChildren(Fqn.fromString("/key0"), null);
checkChildren(Fqn.fromString("/key1"), null);
@@ -1192,23 +1279,23 @@
loader.put(Fqn.fromString("/key0/abc"), null);
addDelay();
checkChildren(Fqn.fromString("/key0"),
- new String[] { "a", "ab", "abc" });
+ new String[]{"a", "ab", "abc"});
loader.put(Fqn.fromString("/key0/xxx"), null);
loader.put(Fqn.fromString("/key0/xx"), null);
loader.put(Fqn.fromString("/key0/x"), null);
addDelay();
checkChildren(Fqn.fromString("/key0"),
- new String[] { "a", "ab", "abc", "x", "xx", "xxx" });
+ new String[]{"a", "ab", "abc", "x", "xx", "xxx"});
loader.put(Fqn.fromString("/key0/a/1"), null);
loader.put(Fqn.fromString("/key0/a/2"), null);
loader.put(Fqn.fromString("/key0/a/2/1"), null);
addDelay();
- checkChildren(Fqn.fromString("/key0/a/2"), new String[] { "1" });
- checkChildren(Fqn.fromString("/key0/a"), new String[] { "1", "2" });
+ checkChildren(Fqn.fromString("/key0/a/2"), new String[]{"1"});
+ checkChildren(Fqn.fromString("/key0/a"), new String[]{"1", "2"});
checkChildren(Fqn.fromString("/key0"),
- new String[] { "a", "ab", "abc", "x", "xx", "xxx" });
+ new String[]{"a", "ab", "abc", "x", "xx", "xxx"});
//
// loader.put(Fqn.fromString("/key0/\u0000"), null);
// loader.put(Fqn.fromString("/key0/\u0001"), null);
@@ -1235,15 +1322,20 @@
* Checks that the given list of children part names is returned.
*/
private void checkChildren(Fqn fqn, String[] names)
- throws Exception {
+ throws Exception
+ {
Set set = loader.getChildrenNames(fqn);
- if (names != null) {
+ if (names != null)
+ {
assertEquals(names.length, set.size());
- for (int i = 0; i < names.length; i += 1) {
+ for (int i = 0; i < names.length; i += 1)
+ {
assertTrue(set.contains(names[i]));
}
- } else {
+ }
+ else
+ {
assertNull(set);
}
}
@@ -1252,7 +1344,8 @@
* Tests basic operations without a transaction.
*/
public void testModifications()
- throws Exception {
+ throws Exception
+ {
doTestModifications();
}
@@ -1261,11 +1354,12 @@
* Tests basic operations with a transaction.
*/
public void testModificationsTransactional()
- throws Exception {
+ throws Exception
+ {
- DummyTransactionManager mgr=DummyTransactionManager.getInstance();
+ DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
- tx=mgr.getTransaction();
+ tx = mgr.getTransaction();
doTestModifications();
tx.commit();
}
@@ -1274,7 +1368,8 @@
* Tests modifications.
*/
private void doTestModifications()
- throws Exception {
+ throws Exception
+ {
/* PUT_KEY_VALUE, PUT_DATA */
List list = createUpdates();
@@ -1320,7 +1415,8 @@
* Tests a one-phase transaction.
*/
public void testOnePhaseTransaction()
- throws Exception {
+ throws Exception
+ {
List mods = createUpdates();
loader.prepare(null, mods, true);
checkModifications(mods);
@@ -1330,7 +1426,8 @@
* Tests a two-phase transaction.
*/
public void testTwoPhaseTransaction()
- throws Exception {
+ throws Exception
+ {
Object txnKey = new Object();
List mods = createUpdates();
@@ -1343,16 +1440,19 @@
/**
* Tests rollback of a two-phase transaction.
*/
- public void testTransactionRollback() throws Exception {
+ public void testTransactionRollback() throws Exception
+ {
loader.remove(Fqn.fromString("/"));
- int num=0;
- try {
+ int num = 0;
+ try
+ {
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
loader.loadEntireState(os);
num = baos.size();
}
- catch(UnsupportedOperationException ex) {
+ catch (UnsupportedOperationException ex)
+ {
System.out.println("caught unsupported operation exception that's okay: " + ex);
return;
}
@@ -1370,16 +1470,19 @@
/**
* Tests rollback of a two-phase transaction that is mediated by the cache.
*/
- public void testIntegratedTransactionRollback() throws Exception {
+ public void testIntegratedTransactionRollback() throws Exception
+ {
loader.remove(Fqn.fromString("/"));
- int num=0;
- try {
+ int num = 0;
+ try
+ {
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
loader.loadEntireState(os);
num = baos.size();
}
- catch(UnsupportedOperationException ex) {
+ catch (UnsupportedOperationException ex)
+ {
System.out.println("caught unsupported operation exception that's okay: " + ex);
return;
}
@@ -1397,7 +1500,8 @@
/**
* Creates a set of update (PUT_KEY_VALUE, PUT_DATA) modifications.
*/
- private List createUpdates() {
+ private List createUpdates()
+ {
List list = new ArrayList();
@@ -1431,18 +1535,22 @@
* Checks that a list of modifications was applied.
*/
private void checkModifications(List list)
- throws Exception {
+ throws Exception
+ {
- for (int i = 0; i < list.size(); i += 1) {
+ for (int i = 0; i < list.size(); i += 1)
+ {
Modification mod = (Modification) list.get(i);
Fqn fqn = mod.getFqn();
- switch (mod.getType()) {
+ switch (mod.getType())
+ {
case Modification.PUT_KEY_VALUE:
assertEquals(mod.getValue(), loader.get(fqn).get(mod.getKey()));
break;
case Modification.PUT_DATA:
Map map = mod.getData();
- for (Iterator iter = map.keySet().iterator(); iter.hasNext();) {
+ for (Iterator iter = map.keySet().iterator(); iter.hasNext();)
+ {
Object key = iter.next();
assertEquals(map.get(key), loader.get(fqn).get(key));
}
@@ -1469,7 +1577,8 @@
* Tests that null keys and values work as for a standard Java Map.
*/
public void testNullKeysAndValues()
- throws Exception {
+ throws Exception
+ {
loader.put(FQN, null, "x");
addDelay();
@@ -1522,7 +1631,8 @@
* Test non-default database name.
*/
public void testDatabaseName()
- throws Exception {
+ throws Exception
+ {
loader.put(FQN, "one", "two");
addDelay();
@@ -1533,7 +1643,8 @@
* Test load/store state.
*/
public void testLoadAndStore()
- throws Exception {
+ throws Exception
+ {
// Empty state
loader.remove(Fqn.fromString("/"));
@@ -1551,29 +1662,32 @@
assertEquals(2, loader.get(FQN).size());
// Save state
- byte[] state=null;
- try {
+ byte[] state = null;
+ try
+ {
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
loader.loadEntireState(os);
os.writeObject(StateTransferManager.STREAMING_DELIMETER_NODE);
os.close();
- assertTrue(baos.size()>0);
+ assertTrue(baos.size() > 0);
state = baos.toByteArray();
}
- catch(UnsupportedOperationException ex) {
+ catch (UnsupportedOperationException ex)
+ {
System.out.println("caught unsupported operation exception (this is expected): " + ex);
}
-
/* Restore state. */
- try {
+ try
+ {
ByteArrayInputStream bais = new ByteArrayInputStream(state);
MarshalledValueInputStream is = new MarshalledValueInputStream(bais);
loader.storeEntireState(is);
is.close();
}
- catch(UnsupportedOperationException ex) {
+ catch (UnsupportedOperationException ex)
+ {
System.out.println("caught unsupported operation exception (this is expected): " + ex);
}
@@ -1586,19 +1700,23 @@
/**
* Complex object whose class description is stored in the class catalog.
*/
- public static class Complex implements Serializable {
+ public static class Complex implements Serializable
+ {
Complex nested;
- Complex() {
+ Complex()
+ {
this(null);
}
- Complex(Complex nested) {
+ Complex(Complex nested)
+ {
this.nested = nested;
}
- public boolean equals(Object o) {
+ public boolean equals(Object o)
+ {
if (!(o instanceof Complex))
return false;
Complex x = (Complex) o;
@@ -1606,8 +1724,9 @@
: (x.nested == null);
}
- public int hashCode() {
- if(nested == null)
+ public int hashCode()
+ {
+ if (nested == null)
return super.hashCode();
else
return 13 + nested.hashCode();
@@ -1663,7 +1782,9 @@
}
- /** See http://jira.jboss.com/jira/browse/JBCACHE-352 */
+ /**
+ * See http://jira.jboss.com/jira/browse/JBCACHE-352
+ */
public void testRemoveAndGetInTransaction() throws Exception
{
Fqn fqn = new Fqn("/a/b");
@@ -1687,6 +1808,4 @@
}
-
-
}
1.22 +286 -286 JBossCache/tests/functional/org/jboss/cache/loader/CacheLoaderWithReplicationTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheLoaderWithReplicationTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/CacheLoaderWithReplicationTest.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- CacheLoaderWithReplicationTest.java 20 Jul 2006 09:03:53 -0000 1.21
+++ CacheLoaderWithReplicationTest.java 6 Sep 2006 15:30:58 -0000 1.22
@@ -9,12 +9,12 @@
import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.TreeCache;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.misc.TestingUtil;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import javax.transaction.TransactionManager;
import java.io.File;
@@ -66,7 +66,7 @@
{
cache1.remove(fqn);
cache1.getCacheLoader().remove(fqn);
- cache1.stopService();
+ cache1.stop();
}
finally
{
@@ -80,7 +80,7 @@
{
cache2.remove(fqn);
cache2.getCacheLoader().remove(fqn);
- cache2.stopService();
+ cache2.stop();
}
finally
{
@@ -95,8 +95,8 @@
cache1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
cache2.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
- cache1.startService();
- cache2.startService();
+ cache1.start();
+ cache2.start();
Assert.assertNull(cache1.get(fqn, key));
Assert.assertNull(cache2.get(fqn, key));
@@ -144,8 +144,8 @@
cache1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
cache2.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
- cache1.startService();
- cache2.startService();
+ cache1.start();
+ cache2.start();
CacheLoader loader1 = cache1.getCacheLoader();
CacheLoader loader2 = cache2.getCacheLoader();
@@ -204,8 +204,8 @@
cache1.getConfiguration().setNodeLockingScheme("OPTIMISTIC");
cache2.getConfiguration().setNodeLockingScheme("OPTIMISTIC");
- cache1.startService();
- cache2.startService();
+ cache1.start();
+ cache2.start();
CacheLoader loader1 = cache1.getCacheLoader();
CacheLoader loader2 = cache2.getCacheLoader();
@@ -258,8 +258,8 @@
cache1.getConfiguration().setNodeLockingScheme("OPTIMISTIC");
cache2.getConfiguration().setNodeLockingScheme("OPTIMISTIC");
- cache1.startService();
- cache2.startService();
+ cache1.start();
+ cache2.start();
CacheLoader loader1 = cache1.getCacheLoader();
CacheLoader loader2 = cache2.getCacheLoader();
1.7 +251 -252 JBossCache/tests/functional/org/jboss/cache/loader/ChainingCacheLoaderFullTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ChainingCacheLoaderFullTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/ChainingCacheLoaderFullTest.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- ChainingCacheLoaderFullTest.java 20 Jul 2006 09:03:53 -0000 1.6
+++ ChainingCacheLoaderFullTest.java 6 Sep 2006 15:30:58 -0000 1.7
@@ -51,7 +51,7 @@
cache.getConfiguration().setCacheLoaderConfiguration(getCacheLoaderConfig(loc1, loc2, ignoreMods1, ignoreMods2));
cache.getConfiguration().setCacheMode("local");
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
- cache.startService();
+ cache.start();
chainingCacheLoader = (ChainingCacheLoader) cache.getCacheLoader();
loader1 = (CacheLoader) chainingCacheLoader.getCacheLoaders().get(0);
@@ -61,7 +61,7 @@
protected void cleanup() throws Exception
{
cache.remove("/");
- cache.stopService();
+ cache.stop();
cache = null;
}
@@ -77,7 +77,7 @@
"</properties>\n" +
"<async>false</async>\n" +
"<fetchPersistentState>true</fetchPersistentState>\n" +
- "<ignoreModifications>"+ignoreMods1+"</ignoreModifications>\n" +
+ "<ignoreModifications>" + ignoreMods1 + "</ignoreModifications>\n" +
"</cacheloader>\n" +
"<cacheloader>\n" +
"<class>org.jboss.cache.loader.FileCacheLoader</class>\n" +
@@ -247,7 +247,6 @@
Assert.assertNull(loader2.get(fqn));
Assert.assertNull(chainingCacheLoader.get(fqn));
-
// put something in the cache.
mgr.begin();
cache.put(fqn, key, value);
1.9 +160 -160 JBossCache/tests/functional/org/jboss/cache/loader/ClusteredCacheLoaderTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ClusteredCacheLoaderTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/ClusteredCacheLoaderTest.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- ClusteredCacheLoaderTest.java 20 Jul 2006 10:59:14 -0000 1.8
+++ ClusteredCacheLoaderTest.java 6 Sep 2006 15:30:58 -0000 1.9
@@ -7,11 +7,11 @@
package org.jboss.cache.loader;
import junit.framework.Assert;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.TreeCache;
import org.jboss.cache.config.Configuration;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import java.util.Map;
import java.util.Set;
@@ -42,11 +42,11 @@
cache1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
cache2.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
- cache1.getConfiguration().setCacheLoaderConfiguration( getSingleCacheLoaderConfig("", "org.jboss.cache.loader.ClusteredCacheLoader", "timeout=500", false, false, false) );
+ cache1.getConfiguration().setCacheLoaderConfiguration(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.ClusteredCacheLoader", "timeout=500", false, false, false));
cache2.getConfiguration().setCacheLoaderConfiguration(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.ClusteredCacheLoader", "timeout=500", false, false, false));
- cache1.startService();
- cache2.startService();
+ cache1.start();
+ cache2.start();
loader1 = cache1.getCacheLoader();
loader2 = cache2.getCacheLoader();
@@ -56,14 +56,14 @@
{
if (cache1 != null)
{
- cache1.stopService();
+ cache1.stop();
cache1 = null;
loader1 = null;
}
if (cache2 != null)
{
- cache2.stopService();
+ cache2.stop();
cache2 = null;
loader2 = null;
}
@@ -116,7 +116,7 @@
Assert.assertNull("Expecting null", loader2.get(fqn));
map = loader2.get(fqn);
- Assert.assertNull( "Should be null", map );
+ Assert.assertNull("Should be null", map);
// calling a get on cache1 should cause the loader to retrieve the node from cache2
Assert.assertEquals("value", cache1.get(fqn, key));
1.8 +29 -20 JBossCache/tests/functional/org/jboss/cache/loader/DataSourceIntegrationTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: DataSourceIntegrationTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/DataSourceIntegrationTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- DataSourceIntegrationTest.java 20 Jul 2006 09:03:53 -0000 1.7
+++ DataSourceIntegrationTest.java 6 Sep 2006 15:30:58 -0000 1.8
@@ -25,7 +25,8 @@
private final String JNDI_NAME = "java:/MockDS";
private TreeCache cache;
- protected void setUp() throws Exception {
+ protected void setUp() throws Exception
+ {
super.setUp();
old_factory = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, FACTORY);
@@ -37,12 +38,12 @@
protected Element getCacheLoaderConfig(String jndi) throws Exception
{
String props = "cache.jdbc.datasource=" + jndi + "\ncache.jdbc.table.create=false\ncache.jdbc.table.drop=false";
- return getSingleCacheLoaderConfig("", "org.jboss.cache.loader.JDBCCacheLoader", props, false, false,false);
+ return getSingleCacheLoaderConfig("", "org.jboss.cache.loader.JDBCCacheLoader", props, false, false, false);
}
/**
* Tests fix for JBCACHE-303, ensuring that JDBCCacheLoader works if
- * its DataSource is not in JNDI until startService is called.
+ * its DataSource is not in JNDI until start is called.
*
* @throws Exception
*/
@@ -54,19 +55,20 @@
Object obj = context.lookup(JNDI_NAME);
assertNull(JNDI_NAME + " not bound", obj);
}
- catch (NameNotFoundException n) {
+ catch (NameNotFoundException n)
+ {
// expected
}
- cache=new TreeCache();
+ cache = new TreeCache();
cache.getConfiguration().setCacheMode("local");
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
cache.getConfiguration().setCacheLoaderConfiguration(getCacheLoaderConfig(JNDI_NAME));
- cache.createService();
+ cache.create();
context.bind(JNDI_NAME, new MockDataSource());
assertNotNull(JNDI_NAME + " bound", context.lookup(JNDI_NAME));
- cache.startService();
+ cache.start();
assertNotNull("Cache has a cache loader", cache.getCacheLoader());
}
@@ -77,17 +79,20 @@
Context ctx = new InitialContext();
ctx.unbind(JNDI_NAME);
- if (old_factory != null) {
+ if (old_factory != null)
+ {
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, old_factory);
}
- else {
+ else
+ {
System.getProperties().remove(Context.INITIAL_CONTEXT_FACTORY);
}
- if (cache != null) {
- cache.stopService();
- cache.destroyService();
+ if (cache != null)
+ {
+ cache.stop();
+ cache.destroy();
}
}
@@ -114,9 +119,13 @@
return null;
}
- public void setLoginTimeout(int seconds) throws SQLException {}
+ public void setLoginTimeout(int seconds) throws SQLException
+ {
+ }
- public void setLogWriter(PrintWriter printWriter) throws SQLException {}
+ public void setLogWriter(PrintWriter printWriter) throws SQLException
+ {
+ }
}
}
1.4 +217 -182 JBossCache/tests/functional/org/jboss/cache/loader/InterceptorSynchronizationTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: InterceptorSynchronizationTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/InterceptorSynchronizationTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- InterceptorSynchronizationTest.java 31 Aug 2006 14:56:46 -0000 1.3
+++ InterceptorSynchronizationTest.java 6 Sep 2006 15:30:58 -0000 1.4
@@ -3,12 +3,19 @@
import junit.framework.TestCase;
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
-import org.jboss.cache.TreeCache;
import org.jboss.cache.Modification;
+import org.jboss.cache.TreeCache;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
/**
* Test case that proves that the TreeCache is serialized inside the CacheLoaderInterceptor
@@ -17,19 +24,20 @@
* that wants a node out of the cache will wait for the first one to finish before it can even _start_ loading.
*
* @author paulsmith
- *
*/
-public class InterceptorSynchronizationTest extends TestCase {
+public class InterceptorSynchronizationTest extends TestCase
+{
final int CACHELOADER_WAITTIME = 2000; // lets say loading a node takes 2 seconds
final int numThreadsPerTopLevelNode = 5; // we'll have 5 requests for nodes within a branch
- public void testBlockingProblem() throws Exception {
+ public void testBlockingProblem() throws Exception
+ {
TreeCache cache = new TreeCache();
cache.setCacheLoader(new TestSlowCacheLoader());
- cache.startService();
+ cache.start();
long begin = System.currentTimeMillis();
Collection threads = new ArrayList();
@@ -38,24 +46,27 @@
* Create lots of threads all trying to load DIFFERENT fqn's, as well as a set with different top level nodes.
*/
- for(int i=0; i< numThreadsPerTopLevelNode; i++) {
- Thread thread = new Thread(new Retriever(cache,"/Moo/"+i));
+ for (int i = 0; i < numThreadsPerTopLevelNode; i++)
+ {
+ Thread thread = new Thread(new Retriever(cache, "/Moo/" + i));
threads.add(thread);
- Thread thread2 = new Thread(new Retriever(cache,"/Meow/"+i));
+ Thread thread2 = new Thread(new Retriever(cache, "/Meow/" + i));
threads.add(thread2);
}
- for (Iterator iter = threads.iterator(); iter.hasNext();) {
+ for (Iterator iter = threads.iterator(); iter.hasNext();)
+ {
Thread thread = (Thread) iter.next();
thread.start();
}
- for (Iterator iter = threads.iterator(); iter.hasNext();) {
+ for (Iterator iter = threads.iterator(); iter.hasNext();)
+ {
Thread thread = (Thread) iter.next();
thread.join();
}
long end = System.currentTimeMillis();
- long timeTaken = (end-begin);
+ long timeTaken = (end - begin);
/*
* My expectation is that if there are 2 top level nodes they should be loaded in parallel at the very least,
@@ -63,43 +74,50 @@
*
* In this test, NONE of the threads operate in parallel once entered into CacheLoaderInterceptor.
*/
- int totalTimeExpectedToWaitIfNotSerialized = 3*CACHELOADER_WAITTIME; // i'm being very generous here. 3 times the wait time for each node is more than enough if it was in parallel.
- assertTrue("If it was parallel, it should have finished quicker than this:" +timeTaken, timeTaken<totalTimeExpectedToWaitIfNotSerialized);
+ int totalTimeExpectedToWaitIfNotSerialized = 3 * CACHELOADER_WAITTIME; // i'm being very generous here. 3 times the wait time for each node is more than enough if it was in parallel.
+ assertTrue("If it was parallel, it should have finished quicker than this:" + timeTaken, timeTaken < totalTimeExpectedToWaitIfNotSerialized);
}
/**
* Dummy cache loader that emulates a slow loading of any node from a virtual backing store.
*
* @author paulsmith
- *
*/
public class TestSlowCacheLoader extends AbstractCacheLoader
{
- public void setConfig(Properties arg0) {
+ public void setConfig(Properties arg0)
+ {
}
- public Set getChildrenNames(Fqn arg0) throws Exception {
+
+ public Set getChildrenNames(Fqn arg0) throws Exception
+ {
return null;
}
- public Object get(Fqn arg0, Object arg1) throws Exception {
+ public Object get(Fqn arg0, Object arg1) throws Exception
+ {
return null;
}
- public Map get(Fqn arg0) throws Exception {
+ public Map get(Fqn arg0) throws Exception
+ {
Thread.sleep(CACHELOADER_WAITTIME);
return Collections.singletonMap("foo", "bar");
}
- public boolean exists(Fqn arg0) throws Exception {
+ public boolean exists(Fqn arg0) throws Exception
+ {
return true;
}
- public Object put(Fqn arg0, Object arg1, Object arg2) throws Exception {
+ public Object put(Fqn arg0, Object arg1, Object arg2) throws Exception
+ {
return null;
}
- public void put(Fqn arg0, Map arg1) throws Exception {
+ public void put(Fqn arg0, Map arg1) throws Exception
+ {
}
@@ -107,15 +125,18 @@
{
}
- public Object remove(Fqn arg0, Object arg1) throws Exception {
+ public Object remove(Fqn arg0, Object arg1) throws Exception
+ {
return null;
}
- public void remove(Fqn arg0) throws Exception {
+ public void remove(Fqn arg0) throws Exception
+ {
}
- public void removeData(Fqn arg0) throws Exception {
+ public void removeData(Fqn arg0) throws Exception
+ {
}
@@ -123,11 +144,13 @@
{
}
- public void commit(Object arg0) throws Exception {
+ public void commit(Object arg0) throws Exception
+ {
}
- public void rollback(Object arg0) {
+ public void rollback(Object arg0)
+ {
}
/*public byte[] loadEntireState() throws Exception {
@@ -156,6 +179,7 @@
{
// nothing to do here
}
+
public void storeEntireState(ObjectInputStream is) throws Exception
{
// nothing to do here
@@ -166,38 +190,49 @@
// nothing to do here
}
- public void create() throws Exception {
+ public void create() throws Exception
+ {
}
- public void start() throws Exception {
+ public void start() throws Exception
+ {
}
- public void stop() {
+ public void stop()
+ {
}
- public void destroy() {
+ public void destroy()
+ {
}
}
-
- private static class Retriever implements Runnable{
+ private static class Retriever implements Runnable
+ {
private final String fqn;
private TreeCache cache;
- private Retriever(TreeCache cache, String fqn) {
+
+ private Retriever(TreeCache cache, String fqn)
+ {
this.fqn = fqn;
this.cache = cache;
}
- public void run() {
- try {
+
+ public void run()
+ {
+ try
+ {
cache.get(fqn, "foo");
- } catch (CacheException e) {
- throw new RuntimeException("Unexpected",e);
+ }
+ catch (CacheException e)
+ {
+ throw new RuntimeException("Unexpected", e);
}
}
1.3 +66 -52 JBossCache/tests/functional/org/jboss/cache/loader/JDBCCacheLoaderDerbyDSTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: JDBCCacheLoaderDerbyDSTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/JDBCCacheLoaderDerbyDSTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- JDBCCacheLoaderDerbyDSTest.java 20 Jul 2006 10:31:30 -0000 1.2
+++ JDBCCacheLoaderDerbyDSTest.java 6 Sep 2006 15:30:58 -0000 1.3
@@ -16,17 +16,18 @@
import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
import java.util.Properties;
+
/**
* This test runs cache loader tests using Database as the cache loader store.
* The default test is configured using MySQL.
* The server and database configuration is read from a properties file located at
* /etc/cache-jdbc.properties.
- *
+ * <p/>
* The appropriate JDBC driver (i.e mysql-connector-java-3.0.10-stable-bin.jar)
* must be in the lib directory for this test to run successfuly
*
* @author <a href="hmesha at novell.com">Hany Mesha</a>
- * @version <tt>$Revision: 1.2 $</tt>
+ * @version <tt>$Revision: 1.3 $</tt>
*/
public class JDBCCacheLoaderDerbyDSTest
extends CacheLoaderTestsBase
@@ -47,14 +48,18 @@
Object obj = context.lookup(JNDI_NAME);
assertNull(JNDI_NAME + " not bound", obj);
}
- catch (NameNotFoundException n) {
+ catch (NameNotFoundException n)
+ {
// expected
}
Properties prop = new Properties();
- try{
+ try
+ {
prop.load(this.getClass().getClassLoader().getResourceAsStream("cache-jdbc.properties"));
- }catch(Exception e){
+ }
+ catch (Exception e)
+ {
System.out.println("Error loading jdbc properties ");
}
@@ -62,7 +67,8 @@
EmbeddedXADataSource ds = new EmbeddedXADataSource();
ds.setDatabaseName("jbossdb");
ds.setCreateDatabase("create");
- ds.setUser(prop.getProperty("cache.jdbc.user"));;
+ ds.setUser(prop.getProperty("cache.jdbc.user"));
+ ;
ds.setPassword(prop.getProperty("cache.jdbc.password"));
@@ -70,8 +76,8 @@
"cache.jdbc.node.type=" + prop.getProperty("cache.jdbc.node.type");
- cache.getConfiguration().setCacheLoaderConfiguration( getSingleCacheLoaderConfig("", "org.jboss.cache.loader.JDBCCacheLoader", props, false, true, false) );
- cache.createService();
+ cache.getConfiguration().setCacheLoaderConfiguration(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.JDBCCacheLoader", props, false, true, false));
+ cache.create();
context.bind(JNDI_NAME, ds);
@@ -80,11 +86,13 @@
public void testLargeObject()
{
- try {
+ try
+ {
String key = "LargeObj";
// create an object with size bigger than 4k (k=1024 bytes)
StringBuffer text = new StringBuffer("LargeObject");
- while (text.toString().getBytes().length < (1024*100)) {
+ while (text.toString().getBytes().length < (1024 * 100))
+ {
text.append(text);
}
String initialValue = text.toString();
@@ -101,16 +109,20 @@
retVal = loader.put(FQN, key, updatedValue);
assertEquals(initialValue, (String) retVal);
assertEquals(updatedValue, (String) loader.get(FQN).get(key));
- } catch(Exception e) {
+ }
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testTransactionRollback() throws Exception {
+ public void testTransactionRollback() throws Exception
+ {
// no-op
}
- public void testIntegratedTransactionRollback() throws Exception {
+ public void testIntegratedTransactionRollback() throws Exception
+ {
// no-op
}
@@ -130,10 +142,12 @@
Context ctx = new InitialContext();
ctx.unbind(JNDI_NAME);
- if (old_factory != null) {
+ if (old_factory != null)
+ {
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, old_factory);
}
- else {
+ else
+ {
System.getProperties().remove(Context.INITIAL_CONTEXT_FACTORY);
}
}
1.11 +17 -12 JBossCache/tests/functional/org/jboss/cache/loader/LocalDelegatingCacheLoaderTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LocalDelegatingCacheLoaderTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/LocalDelegatingCacheLoaderTest.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- LocalDelegatingCacheLoaderTest.java 20 Jul 2006 09:03:53 -0000 1.10
+++ LocalDelegatingCacheLoaderTest.java 6 Sep 2006 15:30:58 -0000 1.11
@@ -11,36 +11,41 @@
* Date: Jun 9, 2004
* Time: 9:05:19 AM
*/
-public class LocalDelegatingCacheLoaderTest extends CacheLoaderTestsBase {
+public class LocalDelegatingCacheLoaderTest extends CacheLoaderTestsBase
+{
TreeCache delegating_cache;
- protected void configureCache() throws Exception {
- delegating_cache=new TreeCache();
+ protected void configureCache() throws Exception
+ {
+ delegating_cache = new TreeCache();
delegating_cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
- delegating_cache.createService();
- delegating_cache.startService();
+ delegating_cache.create();
+ delegating_cache.start();
// configure first ...
cache.getConfiguration().setCacheLoaderConfiguration(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.LocalDelegatingCacheLoader", "", false, false, false));
// force our own cache loader instance
- LocalDelegatingCacheLoader cacheLoader = new LocalDelegatingCacheLoader( delegating_cache );
- cache.setCacheLoader( cacheLoader );
+ LocalDelegatingCacheLoader cacheLoader = new LocalDelegatingCacheLoader(delegating_cache);
+ cache.setCacheLoader(cacheLoader);
}
- protected void tearDown() throws Exception {
+ protected void tearDown() throws Exception
+ {
super.tearDown();
- delegating_cache.stopService();
- delegating_cache.destroyService();
+ delegating_cache.stop();
+ delegating_cache.destroy();
}
- public static Test suite() {
+ public static Test suite()
+ {
return new TestSuite(LocalDelegatingCacheLoaderTest.class);
}
- public static void main(String[] args) {
+ public static void main(String[] args)
+ {
junit.textui.TestRunner.run(suite());
}
1.7 +49 -38 JBossCache/tests/functional/org/jboss/cache/loader/RpcDelegatingCacheLoaderTests.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: RpcDelegatingCacheLoaderTests.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/RpcDelegatingCacheLoaderTests.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- RpcDelegatingCacheLoaderTests.java 20 Jul 2006 10:31:30 -0000 1.6
+++ RpcDelegatingCacheLoaderTests.java 6 Sep 2006 15:30:58 -0000 1.7
@@ -9,52 +9,62 @@
/**
* @author Bela Ban
- * @version $Id: RpcDelegatingCacheLoaderTests.java,v 1.6 2006/07/20 10:31:30 msurtani Exp $
+ * @version $Id: RpcDelegatingCacheLoaderTests.java,v 1.7 2006/09/06 15:30:58 msurtani Exp $
*/
-public class RpcDelegatingCacheLoaderTests {
+public class RpcDelegatingCacheLoaderTests
+{
TreeCache cache;
- public static void main(String[] args) {
- boolean client=false;
+ public static void main(String[] args)
+ {
+ boolean client = false;
- for(int i=0; i < args.length; i++) {
- String arg=args[i];
- if(arg.equals("client")) {
- client=true;
+ for (int i = 0; i < args.length; i++)
+ {
+ String arg = args[i];
+ if (arg.equals("client"))
+ {
+ client = true;
continue;
}
- if(arg.equals("server")) {
- client=false;
+ if (arg.equals("server"))
+ {
+ client = false;
continue;
}
help();
return;
}
- try {
+ try
+ {
new RpcDelegatingCacheLoaderTests().start(client);
}
- catch(Exception e) {
+ catch (Exception e)
+ {
e.printStackTrace();
}
}
- private static void help() {
+ private static void help()
+ {
System.out.println("RpcDelegatingCacheLoadeTest [client / server]");
}
- private void start(boolean client) throws Exception {
- cache=new TreeCache();
+ private void start(boolean client) throws Exception
+ {
+ cache = new TreeCache();
cache.getConfiguration().setClusterName("test-cluster");
cache.getConfiguration().setInitialStateRetrievalTimeout(3000);
cache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
cache.getConfiguration().setFetchInMemoryState(true);
cache.getConfiguration().setCacheLoaderConfiguration(getCacheLoaderConfig());
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
- cache.startService();
+ cache.start();
- if(client == false) {
+ if (client == false)
+ {
System.out.println("started as SERVER");
System.out.println("populating the cache");
cache.getTransactionManager().begin();
@@ -63,7 +73,8 @@
cache.getTransactionManager().commit();
System.out.println("the cache is " + cache.toString() + ", locks: " + cache.printLockInfo());
- while(true){
+ while (true)
+ {
TestingUtil.sleepThread(2000);
cache.getTransactionManager().begin();
cache.put("/x/y/z", "d", "d");
@@ -94,10 +105,10 @@
System.out.println("cache contents after eviction: " + cache.printLockInfo());
System.out.println("accessing /a and /1. this will trigger a fetch from the remote SERVER");
- Object val=cache.get("/a/b/c", "bela");
+ Object val = cache.get("/a/b/c", "bela");
System.out.println("value is " + val);
- val=cache.get("/1/2/3", "ben");
+ val = cache.get("/1/2/3", "ben");
System.out.println("value is " + val);
System.out.println("the cache is " + cache.toString() + ", locks: " + cache.printLockInfo());
1.6 +63 -63 JBossCache/tests/functional/org/jboss/cache/loader/SharedCacheLoaderTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SharedCacheLoaderTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/SharedCacheLoaderTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- SharedCacheLoaderTest.java 17 Aug 2006 21:57:59 -0000 1.5
+++ SharedCacheLoaderTest.java 6 Sep 2006 15:30:58 -0000 1.6
@@ -36,8 +36,8 @@
cache1.getConfiguration().setCacheLoaderConfiguration(getSingleCacheLoaderConfig("", DummyCacheLoader.class.getName(), "", false, false, true));
cache2.getConfiguration().setCacheLoaderConfiguration(getSingleCacheLoaderConfig("", DummyCacheLoader.class.getName(), "", false, false, true));
- cache1.startService();
- cache2.startService();
+ cache1.start();
+ cache2.start();
// force setting up the same cache loader class
dummyCacheLoader = new DummyCacheLoader();
@@ -66,8 +66,8 @@
protected void tearDown()
{
- if (cache1 != null) cache1.stopService();
- if (cache2 != null) cache2.stopService();
+ if (cache1 != null) cache1.stop();
+ if (cache2 != null) cache2.stop();
cache1 = null;
cache2 = null;
}
1.6 +75 -61 JBossCache/tests/functional/org/jboss/cache/loader/TxCacheLoaderTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TxCacheLoaderTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/TxCacheLoaderTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- TxCacheLoaderTest.java 20 Jul 2006 09:03:53 -0000 1.5
+++ TxCacheLoaderTest.java 6 Sep 2006 15:30:58 -0000 1.6
@@ -16,59 +16,60 @@
/**
* @author Bela Ban
- * @version $Id: TxCacheLoaderTest.java,v 1.5 2006/07/20 09:03:53 msurtani Exp $
+ * @version $Id: TxCacheLoaderTest.java,v 1.6 2006/09/06 15:30:58 msurtani Exp $
*/
-public class TxCacheLoaderTest extends AbstractCacheLoaderTestBase {
+public class TxCacheLoaderTest extends AbstractCacheLoaderTestBase
+{
TreeCache cache1, cache2;
private Fqn fqn = Fqn.fromString("/one/two/three");
- protected void setUp() throws Exception {
+ protected void setUp() throws Exception
+ {
super.setUp();
String tmpLoc = System.getProperty("java.io.tmpdir", "/tmp");
String location = tmpLoc + File.separator + "TxCacheLoaderTest1";
- cache1=new TreeCache();
+ cache1 = new TreeCache();
cache1.getConfiguration().setCacheMode("repl_sync");
cache1.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
cache1.getConfiguration().setCacheLoaderConfiguration(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.FileCacheLoader", "location=" + location, false, false, false));
// cache1.setReplQueueInterval(3000);
- cache1.createService();
- cache1.startService();
+ cache1.create();
+ cache1.start();
location = tmpLoc + File.separator + "TxCacheLoaderTest2";
- cache2=new TreeCache();
+ cache2 = new TreeCache();
cache2.getConfiguration().setCacheMode("repl_sync");
cache2.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
cache2.getConfiguration().setCacheLoaderConfiguration(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.FileCacheLoader", "location=" + location, false, false, false));
cache2.getConfiguration().setLockAcquisitionTimeout(2000);
// cache2.setReplQueueInterval(3000);
- cache2.createService();
- cache2.startService();
+ cache2.create();
+ cache2.start();
}
- protected void tearDown() throws Exception {
+ protected void tearDown() throws Exception
+ {
super.tearDown();
// clean up cache loaders!!
cache1.remove(Fqn.ROOT);
- cache1.stopService();
- cache1.destroyService();
- cache2.stopService();
- cache2.destroyService();
+ cache1.stop();
+ cache1.destroy();
+ cache2.stop();
+ cache2.destroy();
}
-
-
-
- public void testTxPutCommit() throws Exception, NotSupportedException {
- DummyTransactionManager mgr=DummyTransactionManager.getInstance();
+ public void testTxPutCommit() throws Exception, NotSupportedException
+ {
+ DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
- Transaction tx=mgr.getTransaction();
+ Transaction tx = mgr.getTransaction();
cache1.put(fqn, "key1", "val1");
@@ -77,7 +78,7 @@
assertNull(cache2.get("/one/two/three/four", "key2"));
tx.commit();
assertNotNull(cache1.getKeys(fqn));
- Set children=cache1.getChildrenNames("/one");
+ Set children = cache1.getChildrenNames("/one");
assertEquals(1, children.size());
TestingUtil.sleepThread(2000);
assertEquals("val1", cache2.get(fqn, "key1"));
@@ -85,34 +86,43 @@
}
-
- public void testTxPrepareAndRollback() throws Exception, NotSupportedException {
- final DummyTransactionManager mgr=DummyTransactionManager.getInstance();
+ public void testTxPrepareAndRollback() throws Exception, NotSupportedException
+ {
+ final DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
- Transaction tx1=mgr.getTransaction();
+ Transaction tx1 = mgr.getTransaction();
cache1.getConfiguration().setLockAcquisitionTimeout(1500);
cache2.getConfiguration().setLockAcquisitionTimeout(1500);
- Thread locker=new Thread() {
- Transaction tx2=null;
- public void run() {
- try {
+ Thread locker = new Thread()
+ {
+ Transaction tx2 = null;
+
+ public void run()
+ {
+ try
+ {
mgr.begin();
- tx2=mgr.getTransaction();
+ tx2 = mgr.getTransaction();
cache2.put(fqn, "block-key1", "block-val1"); // acquires a lock on cache2./one/two/three
TestingUtil.sleepThread(5000);
}
- catch(Exception e) {
+ catch (Exception e)
+ {
e.printStackTrace();
}
- finally {
- if(tx2 != null) {
- try {
+ finally
+ {
+ if (tx2 != null)
+ {
+ try
+ {
tx2.rollback();
}
- catch(SystemException e) {
+ catch (SystemException e)
+ {
e.printStackTrace();
}
}
@@ -126,11 +136,13 @@
cache1.put(fqn, "key1", "val1");
cache1.put("/one/two/three/four", "key2", "val2");
- try {
+ try
+ {
tx1.commit(); // prepare() on cache2 will fail due to lock held by locker thread
fail("commit() should fail because we cannot acquire the lock on cache2");
}
- catch(RollbackException rollback) {
+ catch (RollbackException rollback)
+ {
System.out.println("--- TX was rolled back (as expected)");
assertTrue(true);
}
@@ -143,9 +155,9 @@
public void testPutAfterTxCommit() throws Exception, NotSupportedException
{
- DummyTransactionManager mgr=DummyTransactionManager.getInstance();
+ DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
- Transaction tx=mgr.getTransaction();
+ Transaction tx = mgr.getTransaction();
cache1.put(fqn, "key1", "val1");
assertTrue(cache1.exists(fqn));
@@ -157,9 +169,9 @@
public void testPutAfterTxRollback() throws Exception, NotSupportedException
{
- DummyTransactionManager mgr=DummyTransactionManager.getInstance();
+ DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
- Transaction tx=mgr.getTransaction();
+ Transaction tx = mgr.getTransaction();
cache1.put(fqn, "key1", "val1");
assertTrue(cache1.exists(fqn));
@@ -170,11 +182,13 @@
assertTrue(cache1.exists("/a/b/c"));
}
- public static Test suite() {
+ public static Test suite()
+ {
return new TestSuite(TxCacheLoaderTest.class);
}
- public static void main(String[] args) {
+ public static void main(String[] args)
+ {
junit.textui.TestRunner.run(suite());
}
More information about the jboss-cvs-commits
mailing list