[jboss-cvs] JBossAS SVN: r109438 - branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Nov 23 18:17:11 EST 2010
Author: rachmatowicz at jboss.com
Date: 2010-11-23 18:17:10 -0500 (Tue, 23 Nov 2010)
New Revision: 109438
Modified:
branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/HotRodClientTestCase.java
Log:
Update HotRodClientTestCase
Modified: branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/HotRodClientTestCase.java
===================================================================
--- branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/HotRodClientTestCase.java 2010-11-23 20:55:12 UTC (rev 109437)
+++ branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/HotRodClientTestCase.java 2010-11-23 23:17:10 UTC (rev 109438)
@@ -24,6 +24,7 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.Properties;
+import java.util.concurrent.TimeUnit;
import org.infinispan.client.hotrod.*;
import org.infinispan.Cache;
@@ -69,11 +70,15 @@
super(name) ;
}
+ /*
+ * Setup: some questions
+ * - does every test assume a clear cache
+ * -
+ */
public void setUp() throws Exception {
super.setUp();
System.out.println("per test set up") ;
-
servers = getServers() ;
hotRodServerList = servers[0] + ":" + "11222" + ";" + servers[1] + ":" + "11222";
System.out.println("datagrid host0 = " + servers[0]) ;
@@ -88,11 +93,17 @@
defaultRemote = remoteCacheManager.getCache();
// get a named cache
remoteCache = remoteCacheManager.getCache(REPL_CACHE_NAME);
+
+ printCacheContents(defaultRemote, "map of defaultCache elements at tearDown") ;
+ printCacheContents(remoteCache, "map of remoteCache elements at tearDown") ;
}
public void tearDown() throws Exception {
System.out.println("per test tearing down") ;
+ printCacheContents(defaultRemote, "map of defaultCache elements at tearDown") ;
+ printCacheContents(remoteCache, "map of remoteCache elements at tearDown") ;
+
remoteCacheManager.stop() ;
super.tearDown();
@@ -132,19 +143,132 @@
return new RemoteCacheManager(config, false);
}
+ /*
+ * The following operations should return an UnsupportedOperationException when invoked:
+ * void compact()
+ * AdvancedCache<K,V> getAdvancedCache()
+ * Configuration getConfiguration()
+ * void putForExternalRead(K key, V value)
+ * boolean remove(Object k, Object v)
+ * NotifyingFuture<Boolean> removeAsync(Object k, Object v)
+ * boolean replace(K k, V oldValue, V newValue)
+ * boolean replace(K k, V oldValue, V newValue, long lifespan, TimeUnit unit)
+ * boolean replace(K k, V oldValue, V newValue, long lifespan, TimeUnit unit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
+ * NotifyingFuture<Boolean> replaceAsync(K k, V oldValue, V newValue)
+ * NotifyingFuture<Boolean> replaceAsync(K k, V oldValue, V newValue, long lifespan, TimeUnit unit)
+ * NotifyingFuture<Boolean> replaceAsync(K k, V oldValue, V newValue, long lifespan, TimeUnit unit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
+ */
+ public void testUnsupportedOperations() {
+
+ try {
+ remoteCache.compact();
+ fail("call to compact() did not raise UnsupportedOperationException ") ;
+ }
+ catch(UnsupportedOperationException uoe) {
+ // Unsupported operation exception correctly thrown
+ }
+ try {
+ remoteCache.getAdvancedCache();
+ fail("call to getAdvancedCache() did not raise UnsupportedOperationException ") ;
+ }
+ catch(UnsupportedOperationException uoe) {
+ // Unsupported operation exception correctly thrown
+ }
+ try {
+ remoteCache.getConfiguration();
+ fail("call to getConfiguration() did not raise UnsupportedOperationException ") ;
+ }
+ catch(UnsupportedOperationException uoe) {
+ // Unsupported operation exception correctly thrown
+ }
+ try {
+ remoteCache.putForExternalRead("aKey", "aValue");
+ fail("call to getAdvancedCache() did not raise UnsupportedOperationException ") ;
+ }
+ catch(UnsupportedOperationException uoe) {
+ // Unsupported operation exception correctly thrown
+ }
+ try {
+ remoteCache.remove("aKey", "aValue");
+ fail("call to remove() did not raise UnsupportedOperationException ") ;
+ }
+ catch(UnsupportedOperationException uoe) {
+ // Unsupported operation exception correctly thrown
+ }
+ try {
+ remoteCache.removeAsync("aKey", "aValue");
+ fail("call to removeAsync() did not raise UnsupportedOperationException ") ;
+ }
+ catch(UnsupportedOperationException uoe) {
+ // Unsupported operation exception correctly thrown
+ }
+ try {
+ remoteCache.replace("aKey", "oldValue", "newValue");
+ fail("call to replace() did not raise UnsupportedOperationException ") ;
+ }
+ catch(UnsupportedOperationException uoe) {
+ // Unsupported operation exception correctly thrown
+ }
+ try {
+ remoteCache.replace("aKey", "oldValue", "newValue", -1, TimeUnit.SECONDS);
+ fail("call to replace() did not raise UnsupportedOperationException ") ;
+ }
+ catch(UnsupportedOperationException uoe) {
+ // Unsupported operation exception correctly thrown
+ }
+ try {
+ remoteCache.replace("aKey", "oldValue", "newValue", -1, TimeUnit.SECONDS, -1, TimeUnit.SECONDS);
+ fail("call to replace() did not raise UnsupportedOperationException ") ;
+ }
+ catch(UnsupportedOperationException uoe) {
+ // Unsupported operation exception correctly thrown
+ }
+ try {
+ remoteCache.replaceAsync("aKey", "oldValue", "newValue");
+ fail("call to replaceAsync() did not raise UnsupportedOperationException ") ;
+ }
+ catch(UnsupportedOperationException uoe) {
+ // Unsupported operation exception correctly thrown
+ }
+ try {
+ remoteCache.replaceAsync("aKey", "oldValue", "newValue", -1, TimeUnit.SECONDS);
+ fail("call to replaceAsync() did not raise UnsupportedOperationException ") ;
+ }
+ catch(UnsupportedOperationException uoe) {
+ // Unsupported operation exception correctly thrown
+ }
+ try {
+ remoteCache.replaceAsync("aKey", "oldValue", "newValue", -1, TimeUnit.SECONDS, -1, TimeUnit.SECONDS);
+ fail("call to replaceAsync() did not raise UnsupportedOperationException ") ;
+ }
+ catch(UnsupportedOperationException uoe) {
+ // Unsupported operation exception correctly thrown
+ }
+ }
+
+ /*
+ * Test the put operation
+ * - put key/value, confirm presence of key, confirm presence of value
+ * - test for default and named cache instances
+ */
public void testPut() throws IOException {
+
assert null == remoteCache.put("aKey", "aValue");
+ assert remoteCache.containsKey("aKey");
+ assert remoteCache.get("aKey").equals("aValue");
+
assert null == defaultRemote.put("otherKey", "otherValue");
- assert remoteCache.containsKey("aKey");
assert defaultRemote.containsKey("otherKey");
- assert remoteCache.get("aKey").equals("aValue");
assert defaultRemote.get("otherKey").equals("otherValue");
}
+ /*
+ * Test the remove operation
+ * - put key/value, verify put value, remove key, verify key removed
+ */
public void testRemove() throws IOException {
assert null == remoteCache.put("aKey", "aValue");
-
assert remoteCache.get("aKey").equals("aValue");
assert null == remoteCache.remove("aKey");
@@ -190,10 +314,12 @@
assert remoteCache.get("aKey").equals("anotherValue");
}
+ /*
+ * Tests replaceIfUnmodified operation
+ */
public void testReplaceIfUnmodified() {
assert null == remoteCache.replace("aKey", "aValue");
-
remoteCache.put("aKey", "aValue");
VersionedValue valueBinary = remoteCache.getVersioned("aKey");
assert remoteCache.replaceWithVersion("aKey", "aNewValue", valueBinary.getVersion());
@@ -254,38 +380,87 @@
}
}
*/
-
+
private void assertNull(Object obj, String msg) {
assert obj == null : msg ;
}
+
+ private void printCacheContents(RemoteCache c, String description) {
+ Map<String,String> cacheElements = c.getBulk();
+ System.out.println(description + cacheElements)
+ }
+
+
+ public static Test suite() throws Exception {
+ return HotRodClientTestSetup.getDeploySetup(HotRodClientTestCase.class,"") ;
+ }
+}
-// public static Test suite() throws Exception {
-//
-// TestSuite suite= new TestSuite();
-// suite.addTest(new TestSuite(HotRodClientTestCase.class));
-//
-// // Create an initializer for the test suite
-// Test wrapper = new HotRodClientTestSetup(suite) ;
-// return wrapper ;
-// }
-//
-// public static void main(String args[]) throws Exception {
-// junit.textui.TestRunner.run(suite());
-// }
-
-// class HotRodClientTestSetup extends JBossTestClusteredSetup {
-//
-// public void setUp() throws Exception {
-// super.setUp();
-// // one time setup here
-// System.out.println("one time setup") ;
-// }
-//
-// public void tearDown() throws Exception {
-// // one time tear down here
-// System.out.println("one time teardown") ;
-// super.tearDown();
-// }
-//
-// }
-}
\ No newline at end of file
+
+/*
+ * This class can be used to perform a one-time setup and teardown
+ */
+class HotRodClientTestSetup extends JBossTestClusteredSetup {
+
+ private final HotRodClientSetupDelegate delegate;
+
+ public HotRodClientTestSetup(Test test, String jarNames) throws Exception
+ {
+ super(test, jarNames);
+ this.delegate = new HotRodClientSetupDelegate();
+ }
+
+ public static Test getDeploySetup(final Test test, String jarNames)
+ throws Exception
+ {
+ return new HotRodClientTestSetup(test, jarNames);
+ }
+
+ public static Test getDeploySetup(final Class<?> clazz, String jarNames)
+ throws Exception
+ {
+ TestSuite suite = new TestSuite() ;
+ suite.addTest(new TestSuite(clazz)) ;
+ return getDeploySetup(suite, jarNames) ;
+ }
+
+ public void setUp() throws Exception {
+ delegate.setUp();
+
+ super.setUp();
+ }
+
+ public void tearDown() throws Exception {
+
+ try
+ {
+ super.tearDown();
+ }
+ finally
+ {
+ delegate.tearDown();
+ }
+ }
+}
+
+class HotRodClientSetupDelegate {
+
+ public HotRodClientSetupDelegate()
+ {
+ }
+
+ public void setUp() throws Exception {
+ // one time setup here
+ System.out.println("delegate one time setup") ;
+ }
+
+ public void tearDown() throws Exception {
+ // one time tear down here
+ System.out.println("delegate one time teardown") ;
+ }
+}
+
+
+
+
+
More information about the jboss-cvs-commits
mailing list