[jboss-cvs] JBossAS SVN: r109479 - 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
Thu Nov 25 16:50:10 EST 2010
Author: rachmatowicz at jboss.com
Date: 2010-11-25 16:50:10 -0500 (Thu, 25 Nov 2010)
New Revision: 109479
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-25 18:10:20 UTC (rev 109478)
+++ branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/HotRodClientTestCase.java 2010-11-25 21:50:10 UTC (rev 109479)
@@ -28,6 +28,7 @@
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
+import java.util.Collection;
import java.util.concurrent.Future;
import org.infinispan.client.hotrod.*;
@@ -76,7 +77,6 @@
private static final String REPL_CACHE_NAME = "sampleReplicatedCache";
private static final String PERSIST_CACHE_NAME = "samplePersistentCache";
- private RemoteCache defaultRemote;
private RemoteCache remoteCache;
private RemoteCacheManager remoteCacheManager;
@@ -88,78 +88,31 @@
}
/*
- * Setup: some questions
- * - does every test assume a clear cache
- * -
+ * Per-test case setup
*/
public void setUp() throws Exception {
super.setUp();
-
- System.out.println("per test set up") ;
- servers = getServers() ;
- hotRodServerList = servers[0] + ":" + "11222" + ";" + servers[1] + ":" + "11222";
-
- // get the Remote Cache Manager proxy from the server
- remoteCacheManager = getRemoteCacheManager();
- remoteCacheManager.start() ;
- // get the default cache and the named cache
- defaultRemote = remoteCacheManager.getCache();
- remoteCache = remoteCacheManager.getCache(REPL_CACHE_NAME);
-
- defaultRemote.clear();
+ remoteCacheManager = HotRodClientTestSetup.getRemoteCacheManager() ;
+ remoteCache = HotRodClientTestSetup.getRemoteCache() ;
+
remoteCache.clear();
-
- printCacheContents(defaultRemote, "map of defaultCache elements (setUp)") ;
- printCacheContents(remoteCache, "map of remoteCache elements (setUp)") ;
+
+ // printCacheContents(remoteCache, "map of remoteCache elements") ;
}
+ /*
+ * Per-test case tear down
+ */
public void tearDown() throws Exception {
System.out.println("per test tearing down") ;
-
- // clean up the server side copies - they persist as long is the servers are up
- defaultRemote.clear();
+
+ // clean up the server side copies - they persist as long is the servers are up
remoteCache.clear() ;
-
- remoteCacheManager.stop() ;
-
+
super.tearDown();
}
-
- protected void createCacheManager() throws Exception {
- }
-
- // this should be in a one time setup
- protected RemoteCacheManager getRemoteCacheManager() {
- Properties config = new Properties();
- // load balancing
- config.put("infinispan.client.hotrod.request_balancing_strategy",
- "org.infinispan.client.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy");
- // list of HotRod servers available to connect to
- config.put("infinispan.client.hotrod.server_list", hotRodServerList);
- config.put("infinispan.client.hotrod.force_return_values", "false");
- // TCP stuff
- config.put("infinispan.client.hotrod.tcp_no_delay", "true");
- config.put("infinispan.client.hotrod.ping_on_startup", "true");
- config.put("infinispan.client.hotrod.transport_factory",
- "org.infinispan.client.hotrod.impl.transport.tcp.TcpTransportFactory");
- // marshalling
- config.put("infinispan.client.hotrod.marshaller", "org.infinispan.marshall.jboss.GenericJBossMarshaller");
- // executors
- config.put("infinispan.client.hotrod.async_executor_factory",
- "org.infinispan.client.hotrod.impl.async.DefaultAsyncExecutorFactory");
- config.put("infinispan.client.hotrod.default_executor_factory.pool_size", "10");
- config.put("infinispan.client.hotrod.default_executor_factory.queue_size", "100000");
- // hashing
- config.put("infinispan.client.hotrod.hash_function_impl.1",
- "org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashV1");
- config.put("infinispan.client.hotrod.key_size_estimate", "64");
- config.put("infinispan.client.hotrod.value_size_estimate", "512");
-
- return new RemoteCacheManager(config, false);
- }
-
/*
* The following operations should return an UnsupportedOperationException when invoked:
* void compact()
@@ -174,6 +127,11 @@
* 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)
+ *
+ * void evict()
+ * void addListener(Object listener)
+ * Set<Object> getListeners()
+ * void removeListener(Object listener)
*/
public void testUnsupportedOperations() {
@@ -261,7 +219,48 @@
catch(UnsupportedOperationException uoe) {
// Unsupported operation exception correctly thrown
}
-
+ try {
+ remoteCache.evict("aKey");
+ fail("call to evict() did not raise UnsupportedOperationException ") ;
+ }
+ catch(UnsupportedOperationException uoe) {
+ // Unsupported operation exception correctly thrown
+ }
+ try {
+ remoteCache.addListener(new SingleEventListener());
+ fail("call to addListener() did not raise UnsupportedOperationException ") ;
+ }
+ catch(UnsupportedOperationException uoe) {
+ // Unsupported operation exception correctly thrown
+ }
+ try {
+ remoteCache.removeListener(new SingleEventListener());
+ fail("call to removeListener() did not raise UnsupportedOperationException ") ;
+ }
+ catch(UnsupportedOperationException uoe) {
+ // Unsupported operation exception correctly thrown
+ }
+ try {
+ remoteCache.getListeners();
+ fail("call to getListeners() did not raise UnsupportedOperationException ") ;
+ }
+ catch(UnsupportedOperationException uoe) {
+ // Unsupported operation exception correctly thrown
+ }
+ try {
+ remoteCache.startBatch();
+ fail("call to startBatch() did not raise UnsupportedOperationException ") ;
+ }
+ catch(UnsupportedOperationException uoe) {
+ // Unsupported operation exception correctly thrown
+ }
+ try {
+ remoteCache.endBatch(true);
+ fail("call to endBatch() did not raise UnsupportedOperationException ") ;
+ }
+ catch(UnsupportedOperationException uoe) {
+ // Unsupported operation exception correctly thrown
+ }
}
/*
@@ -274,12 +273,8 @@
assert null == remoteCache.put("aKey", "aValue");
assert remoteCache.containsKey("aKey");
assert remoteCache.get("aKey").equals("aValue");
-
- assert null == defaultRemote.put("otherKey", "otherValue");
- assert defaultRemote.containsKey("otherKey");
- assert defaultRemote.get("otherKey").equals("otherValue");
- }
-
+ }
+
/*
* Test the size operation
*/
@@ -334,10 +329,30 @@
}
/*
+ * Test the withFlags operation
+ *
+ * Flags available:
+ * FORCE_RETURN_VALUE
+ */
+ public void testWithFlags() throws IOException {
+
+ assert null == remoteCache.put("aKey", "aValue");
+ assert remoteCache.containsKey("aKey");
+ assertEquals("aValue", remoteCache.get("aKey"));
+
+ // should not return return old value
+ assert null == remoteCache.put("aKey", "anotherValue") ;
+ assertEquals("anotherValue", remoteCache.get("aKey"));
+
+ // now should return old value
+ assertEquals("anotherValue", remoteCache.withFlags(Flag.FORCE_RETURN_VALUE).put("aKey","yetAnotherValue"));
+ }
+
+ /*
* Test eviction of cache elements
* - here, we assume there is no cache store available to persist the element if evicted
*/
- public void testEviction() {
+ public void XtestEviction() {
remoteCache.put("aKey", "aValue");
assert remoteCache.containsKey("aKey");
remoteCache.evict("aKey");
@@ -434,6 +449,62 @@
/*
+ * Test operations on cache entry sets
+ * - RemoteCache.entrySet()
+ * - RemoteCache.keySet()
+ * - RemoteCache.values()
+ */
+ public void testEntrySets() {
+
+ Map<String,String> mapOut = new HashMap<String,String>() ;
+ mapOut.put("aKey", "aValue");
+ mapOut.put("bKey", "bValue");
+ mapOut.put("cKey", "cValue");
+
+ Set<Map.Entry<String,String>> mapEntrySet = mapOut.entrySet() ;
+ Set<String> mapKeySet = mapOut.keySet();
+ Collection<String> mapValues = mapOut.values() ;
+
+ remoteCache.putAll(mapOut) ;
+
+ assert mapEntrySet.equals(remoteCache.entrySet()) ;
+ assert mapKeySet.equals(remoteCache.keySet()) ;
+ assert mapValues.equals(remoteCache.values());
+ }
+
+
+ /*
+ * Test bulk put and get with lifespan for eviction in async mode
+ */
+ public void XtestBatch() {
+
+ // check commit operation
+ remoteCache.startBatch() ;
+ remoteCache.put("aKey", "aValue") ;
+ remoteCache.endBatch(true) ;
+
+ assertEquals(remoteCache.get("aKey"),"aValue") ;
+
+ // check abort operation
+ remoteCache.startBatch() ;
+ remoteCache.put("anotherKey", "anotherValue") ;
+ remoteCache.endBatch(false) ;
+
+ assert null == remoteCache.get("aKey") ;
+
+ // check no intermediate results committed
+
+// remoteCache.startBatch() ;
+// remoteCache.put("yetAnotherKey", "yetAnotherValue") ;
+// assert null == remoteCache.get("yetAnotherKey") ;
+// remoteCache.endBatch(true) ;
+//
+// assertEquals(remoteCache.get("yetAnotherKey"),"yetAnotherValue") ;
+
+ }
+
+
+ /*
* Test the versioned cache entries
* - check that versions differ even if the key value pairs are the same
* - check that versions differ when key value pairs are different
@@ -540,8 +611,11 @@
assert !remoteCache.containsKey("aKey");
}
-
- public void testRemoveIfUnmodified() {
+ /*
+ * Test removeWithVersion operation (which is basically removeIfUnmodified)
+ */
+ public void testRemoveWithVersion() {
+
assert !remoteCache.removeWithVersion("aKey", 12321212l);
remoteCache.put("aKey", "aValue");
@@ -556,7 +630,33 @@
assert !remoteCache.removeWithVersion("aKey", valueBinary.getVersion());
}
+
+ /*
+ * Test removeWithVersion operation (which is basically removeIfUnmodified)
+ * in async mode
+ */
+ public void testRemoveWithVersionAsync() throws Exception {
+ NotifyingFuture<Boolean> future = null ;
+
+ future = remoteCache.removeWithVersionAsync("aKey", 12321212l);
+ assert !future.get();
+ remoteCache.put("aKey", "aValue");
+ VersionedValue valueBinary = remoteCache.getVersioned("aKey");
+ future = remoteCache.removeWithVersionAsync("aKey", valueBinary.getVersion());
+ assert future.get();
+
+ remoteCache.put("aKey", "aNewValue");
+
+ VersionedValue entry2 = remoteCache.getVersioned("aKey");
+ assert entry2.getVersion() != valueBinary.getVersion();
+ assertEquals(entry2.getValue(), "aNewValue");
+
+ future = remoteCache.removeWithVersionAsync("aKey", valueBinary.getVersion());
+ assert !future.get();
+ }
+
+
/*
* Test putIfAbsent operatiion, which only puts if the key is not already associated
* with a value
@@ -590,19 +690,12 @@
RemoteCacheManager manager = null ;
- manager = defaultRemote.getRemoteCacheManager() ;
- assert manager == this.remoteCacheManager : "getRemoteCachemanager() returned incorrect value" ;
-
manager = remoteCache.getRemoteCacheManager() ;
assert manager == this.remoteCacheManager : "getRemoteCachemanager() returned incorrect value" ;
}
public void testStats() {
- ServerStatistics defaultStats = defaultRemote.stats();
- assert null != defaultStats ;
- System.out.println("default stats = " + defaultStats.getStatsMap()) ;
-
ServerStatistics remoteStats = remoteCache.stats();
assert null != remoteStats ;
System.out.println("named stats = " + remoteStats.getStatsMap()) ;
@@ -676,74 +769,10 @@
}
public static Test suite() throws Exception {
- return HotRodClientTestSetup.getDeploySetup(HotRodClientTestCase.class,"") ;
+ return HotRodClientTestSetup.getCacheManagerSetup(HotRodClientTestCase.class,"repl") ;
}
}
-
-/*
- * 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") ;
- }
-}
-
@Listener
class SingleEventListener {
@@ -784,6 +813,125 @@
}
+/*
+ * This class can be used to perform a one-time setup and teardown of the RemoteCache
+ */
+class HotRodClientTestSetup extends JBossTestClusteredSetup {
+ private final String cacheConfig ;
+ private static RemoteCacheManager remoteCacheManager ;
+ private static RemoteCache remoteCache ;
+ public HotRodClientTestSetup(Test test, String cacheConfig) throws Exception
+ {
+ // workaround for a bug in JBossTestClusteredSetup
+ // the JBossTestClusteredSetup(Test) constructor needs to pass base test class
+ super(test, "");
+ this.cacheConfig = cacheConfig ;
+ }
+ public static RemoteCacheManager getRemoteCacheManager() {
+ return remoteCacheManager;
+ }
+
+ public static RemoteCache getRemoteCache() {
+ return remoteCache;
+ }
+
+ public static Test getCacheManagerSetup(final Test test, String cacheConfig)
+ throws Exception
+ {
+ return new HotRodClientTestSetup(test, cacheConfig);
+ }
+
+ public static Test getCacheManagerSetup(final Class<?> clazz, String cacheConfig)
+ throws Exception
+ {
+ TestSuite suite = new TestSuite() ;
+ suite.addTest(new TestSuite(clazz)) ;
+ return getCacheManagerSetup(suite, cacheConfig) ;
+ }
+
+ public void setUp() throws Exception {
+
+ // run this before any tests
+ System.out.println("one-time setup of RemoteCacheManager") ;
+ remoteCacheManager = getRemoteCacheManagerInstance() ;
+ remoteCacheManager.start() ;
+
+ if (cacheConfig.equals("default")) {
+ remoteCache = remoteCacheManager.getCache() ;
+ }
+ else if (cacheConfig.equals("repl")) {
+ remoteCache = remoteCacheManager.getCache("sampleReplicatedCache") ;
+ }
+ else if (cacheConfig.equals("dist")) {
+ throw new IllegalArgumentException("dist cache configuration is not supported") ;
+ }
+ else {
+ throw new IllegalArgumentException("no cache config specified") ;
+ }
+ // delegate.setUp();
+ super.setUp();
+ }
+
+ public void tearDown() throws Exception {
+ try {
+ super.tearDown();
+ }
+ finally {
+ // run this after any tests
+ System.out.println("one-time teardown of RemoteCachemanager") ;
+ remoteCacheManager.stop() ;
+ }
+ }
+
+ private Properties getRemoteCacheManagerProperties(String hotRodServerList) {
+ Properties props = new Properties();
+ // load balancing \
+
+ props.put("infinispan.client.hotrod.request_balancing_strategy",
+ "org.infinispan.client.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy");
+ // list of HotRod servers available to connect to \
+
+ props.put("infinispan.client.hotrod.server_list", hotRodServerList);
+ props.put("infinispan.client.hotrod.force_return_values", "false");
+ // TCP stuff \
+
+ props.put("infinispan.client.hotrod.tcp_no_delay", "true");
+ props.put("infinispan.client.hotrod.ping_on_startup", "true");
+ props.put("infinispan.client.hotrod.transport_factory",
+ "org.infinispan.client.hotrod.impl.transport.tcp.TcpTransportFactory");
+ // marshalling \
+
+ props.put("infinispan.client.hotrod.marshaller", "org.infinispan.marshall.jboss.GenericJBossMarshaller");
+ // executors \
+
+ props.put("infinispan.client.hotrod.async_executor_factory",
+ "org.infinispan.client.hotrod.impl.async.DefaultAsyncExecutorFactory");
+ props.put("infinispan.client.hotrod.default_executor_factory.pool_size", "10");
+ props.put("infinispan.client.hotrod.default_executor_factory.queue_size", "100000");
+ // hashing \
+
+ props.put("infinispan.client.hotrod.hash_function_impl.1",
+ "org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashV1");
+ props.put("infinispan.client.hotrod.key_size_estimate", "64");
+ props.put("infinispan.client.hotrod.value_size_estimate", "512");
+
+ return props ;
+ }
+
+ private RemoteCacheManager getRemoteCacheManagerInstance() {
+
+ String[] servers = new String[2];
+ servers[0] = System.getProperty("jbosstest.cluster.node0") ;
+ servers[1] = System.getProperty("jbosstest.cluster.node1") ;
+ String hotRodServerList = servers[0] + ":" + "11222" + ";" + servers[1] + ":" + "11222";
+
+ System.out.println("RemoteCacheManager: using server list: " + hotRodServerList) ;
+
+ Properties props = getRemoteCacheManagerProperties(hotRodServerList) ;
+
+ return new RemoteCacheManager(props, false);
+ }
+}
More information about the jboss-cvs-commits
mailing list