[jboss-cvs] JBossAS SVN: r110339 - in branches/JBPAPP_5_1_datagrid/testsuite: src/main/org/jboss/test/cluster/datagrid/hotrod and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jan 12 16:11:51 EST 2011
Author: rachmatowicz at jboss.com
Date: 2011-01-12 16:11:50 -0500 (Wed, 12 Jan 2011)
New Revision: 110339
Added:
branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/hotrod/HotRodTestExecutorFactory.java
branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/hotrod/HotRodTestMarshaller.java
branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/hotrod/HotRodTestRequestBalancingStrategy.java
branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/hotrod/HotRodTestTransportFactory.java
branches/JBPAPP_5_1_datagrid/testsuite/src/resources/cluster/datagrid/
branches/JBPAPP_5_1_datagrid/testsuite/src/resources/cluster/datagrid/hotrod-client.properties
Modified:
branches/JBPAPP_5_1_datagrid/testsuite/imports/sections/cluster.xml
branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/HotRodClientRemoteCacheManagerTestCase.java
Log:
Update HotRodClintRemoteCacheManagerTestCase
Modified: branches/JBPAPP_5_1_datagrid/testsuite/imports/sections/cluster.xml
===================================================================
--- branches/JBPAPP_5_1_datagrid/testsuite/imports/sections/cluster.xml 2011-01-12 17:43:19 UTC (rev 110338)
+++ branches/JBPAPP_5_1_datagrid/testsuite/imports/sections/cluster.xml 2011-01-12 21:11:50 UTC (rev 110339)
@@ -851,7 +851,21 @@
<include name="META-INF/application.xml"/>
</fileset>
</jar>
-
+
+ <!-- properties files for datagrid HotRodClientCacheManagerTestCase tests -->
+ <!-- create a copy in cluster/datagrid resources -->
+ <copy todir="${build.resources}/cluster/datagrid" filtering="yes" overwrite="true">
+ <fileset dir="${source.resources}/cluster/datagrid">
+ <include name="hotrod-client.properties"/>
+ </fileset>
+ <filterset>
+ <filter token="jbosstest.server.module.host0" value="${node0}"/>
+ <filter token="jbosstest.server.module.host1" value="${node1}"/>
+ </filterset>
+ </copy>
+ <!-- add a copy to the classpath -->
+ <copy file="${build.resources}/cluster/datagrid/hotrod-client.properties" tofile="${build.resources}/hotrod-client.properties" overwrite="true"/>
+
</target>
Added: branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/hotrod/HotRodTestExecutorFactory.java
===================================================================
--- branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/hotrod/HotRodTestExecutorFactory.java (rev 0)
+++ branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/hotrod/HotRodTestExecutorFactory.java 2011-01-12 21:11:50 UTC (rev 110339)
@@ -0,0 +1,7 @@
+package org.jboss.test.cluster.datagrid.hotrod;
+
+import org.infinispan.client.hotrod.impl.async.DefaultAsyncExecutorFactory ;
+
+public class HotRodTestExecutorFactory extends DefaultAsyncExecutorFactory {
+
+}
\ No newline at end of file
Added: branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/hotrod/HotRodTestMarshaller.java
===================================================================
--- branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/hotrod/HotRodTestMarshaller.java (rev 0)
+++ branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/hotrod/HotRodTestMarshaller.java 2011-01-12 21:11:50 UTC (rev 110339)
@@ -0,0 +1,7 @@
+package org.jboss.test.cluster.datagrid.hotrod;
+
+import org.infinispan.marshall.jboss.GenericJBossMarshaller;
+
+public class HotRodTestMarshaller extends GenericJBossMarshaller {
+ // all methods provided by
+}
\ No newline at end of file
Added: branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/hotrod/HotRodTestRequestBalancingStrategy.java
===================================================================
--- branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/hotrod/HotRodTestRequestBalancingStrategy.java (rev 0)
+++ branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/hotrod/HotRodTestRequestBalancingStrategy.java 2011-01-12 21:11:50 UTC (rev 110339)
@@ -0,0 +1,7 @@
+package org.jboss.test.cluster.datagrid.hotrod;
+
+import org.infinispan.client.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy;
+
+public class HotRodTestRequestBalancingStrategy extends RoundRobinBalancingStrategy {
+
+}
\ No newline at end of file
Added: branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/hotrod/HotRodTestTransportFactory.java
===================================================================
--- branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/hotrod/HotRodTestTransportFactory.java (rev 0)
+++ branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/hotrod/HotRodTestTransportFactory.java 2011-01-12 21:11:50 UTC (rev 110339)
@@ -0,0 +1,7 @@
+package org.jboss.test.cluster.datagrid.hotrod;
+
+import org.infinispan.client.hotrod.impl.transport.tcp.TcpTransportFactory;
+
+public class HotRodTestTransportFactory extends TcpTransportFactory {
+
+}
\ No newline at end of file
Modified: branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/HotRodClientRemoteCacheManagerTestCase.java
===================================================================
--- branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/HotRodClientRemoteCacheManagerTestCase.java 2011-01-12 17:43:19 UTC (rev 110338)
+++ branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/HotRodClientRemoteCacheManagerTestCase.java 2011-01-12 21:11:50 UTC (rev 110339)
@@ -22,39 +22,46 @@
package org.jboss.test.cluster.datagrid.test;
import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.URL;
import java.util.Arrays;
import java.util.Properties;
+import java.util.Enumeration;
import java.util.concurrent.TimeUnit;
+import java.util.Collection;
+import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
-import java.util.Set;
-import java.util.Collection;
-import java.util.concurrent.Future;
+import java.util.concurrent.ExecutorService;
-import org.infinispan.client.hotrod.*;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.NoSuchFieldException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.IllegalAccessException;
+
import org.infinispan.Cache;
-import org.infinispan.config.Configuration;
-import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.executors.ExecutorFactory;
import org.infinispan.marshall.Marshaller;
-import org.infinispan.marshall.jboss.JBossMarshaller;
-//import org.infinispan.server.core.CacheValue;
-import org.infinispan.util.ByteArrayKey;
+import org.infinispan.marshall.jboss.JBossMarshaller;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
-import org.infinispan.util.concurrent.NotifyingFuture;
-import org.infinispan.notifications.Listener;
-// import org.infinispan.notifications.cachemanagerlistener.event.Event;
-import org.infinispan.notifications.cachemanagerlistener.annotation.ViewChanged;
-import org.infinispan.notifications.cachelistener.event.Event;
-import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified;
-import org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated;
-import org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved;
-import org.infinispan.notifications.cachelistener.annotation.CacheEntryVisited;
-import org.infinispan.notifications.cachelistener.annotation.CacheEntryLoaded;
-import org.infinispan.notifications.cachelistener.annotation.CacheEntryEvicted;
-import org.infinispan.notifications.cachelistener.annotation.CacheEntryActivated;
-import org.infinispan.notifications.cachelistener.annotation.CacheEntryPassivated;
+import org.infinispan.client.hotrod.RemoteCache;
+import org.infinispan.client.hotrod.RemoteCacheManager;
+import org.infinispan.client.hotrod.impl.ConfigurationProperties;
+import org.infinispan.client.hotrod.impl.RemoteCacheImpl;
+import org.infinispan.client.hotrod.impl.consistenthash.ConsistentHash;
+import org.infinispan.client.hotrod.impl.transport.TransportFactory;
+import org.infinispan.client.hotrod.impl.transport.tcp.TcpTransportFactory;
+import org.infinispan.client.hotrod.impl.transport.tcp.RequestBalancingStrategy;
+import org.infinispan.client.hotrod.impl.operations.OperationsFactory;
+
+import org.jboss.test.cluster.datagrid.hotrod.HotRodTestMarshaller;
+import org.jboss.test.cluster.datagrid.hotrod.HotRodTestTransportFactory;
+import org.jboss.test.cluster.datagrid.hotrod.HotRodTestExecutorFactory;
+import org.jboss.test.cluster.datagrid.hotrod.HotRodTestRequestBalancingStrategy;
+
import org.jboss.test.JBossClusteredTestCase;
import org.jboss.test.JBossTestSetup;
import org.jboss.test.JBossTestClusteredSetup;
@@ -64,30 +71,28 @@
import junit.framework.TestSuite;
/**
- * Tests for the HotRod client RemoteCachemanager class
+ * Tests for the HotRod client RemoteCacheManager class
*
* In addition to testing each constructor and the start()/stop()/isStarted() methods
* of the API, this class also tests the setting of the various property values, which are:
*
- * infinispan.client.hotrod.request_balancing_strategy
- * // list of HotRod servers available to connect to \
- * infinispan.client.hotrod.server_list
- * infinispan.client.hotrod.force_return_values
- * // TCP stuff \
- * infinispan.client.hotrod.tcp_no_delay
- * infinispan.client.hotrod.ping_on_startup
- * infinispan.client.hotrod.transport_factory
- * // marshalling \
- * infinispan.client.hotrod.marshaller
- * // executors \
- * infinispan.client.hotrod.async_executor_factory
- * infinispan.client.hotrod.default_executor_factory.pool_size
- * infinispan.client.hotrod.default_executor_factory.queue_size
- * // hashing \
- * infinispan.client.hotrod.hash_function_impl.1
- * infinispan.client.hotrod.key_size_estimate"
- * infinispan.client.hotrod.value_size_estimate
+ * infinispan.client.hotrod.request_balancing_strategy, org.infinispan.client.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy \
+ * infinispan.client.hotrod.server_list, 127.0.0.1:11311
+ * infinispan.client.hotrod.force_return_values false \
+ * infinispan.client.hotrod.tcp_no_delay true
+ * infinispan.client.hotrod.ping_on_startup true
+ * infinispan.client.hotrod.transport_factory org.infinispan.client.hotrod.impl.transport.tcp.TcpTransportFactory \
+ * infinispan.client.hotrod.marshaller org.infinispan.marshall.jboss.GenericJBossMarshaller \
+ * infinispan.client.hotrod.async_executor_factory org.infinispan.client.hotrod.impl.async.DefaultAsyncExecutorFactory
+ * infinispan.client.hotrod.default_executor_factory.pool_size 10
+ * infinispan.client.hotrod.default_executor_factory.queue_size 100000 \
+ * infinispan.client.hotrod.hash_function_impl.1 org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashV1
+ * infinispan.client.hotrod.key_size_estimate 64
+ * infinispan.client.hotrod.value_size_estimate 512
*
+ * Property values are not processed in any one location and so this test uses reflection to gather the property values from the components
+ * that eventually use them:
+ *
* @author <a href="mailto:richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
* @version $Revision: $
*/
@@ -95,17 +100,50 @@
extends JBossClusteredTestCase
{
private static final Log log = LogFactory.getLog(HotRodClientRemoteCacheManagerTestCase.class);
- private static final String REPL_CACHE_NAME = "sampleReplicatedCache";
- private static final String PERSIST_CACHE_NAME = "samplePersistentCache";
-
+
+ private final Properties defaultProperties = new Properties() ;
+ private final Properties testProperties = new Properties() ;
+
+ private final String REPL_CACHE_NAME = "sampleReplicatedCache";
+ private final String PERSIST_CACHE_NAME = "samplePersistentCache";
+
private RemoteCache remoteCache;
private RemoteCacheManager remoteCacheManager;
- private String[] servers = null ;
private String hotRodServerList = null ;
public HotRodClientRemoteCacheManagerTestCase(String name) {
super(name) ;
+
+ // setup the default properties
+ defaultProperties.put("infinispan.client.hotrod.request_balancing_strategy", "org.infinispan.client.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy") ;
+ defaultProperties.put("infinispan.client.hotrod.server_list", "127.0.0.1:11311");
+ defaultProperties.put("infinispan.client.hotrod.force_return_values", "false");
+ defaultProperties.put("infinispan.client.hotrod.tcp_no_delay", "true");
+ defaultProperties.put("infinispan.client.hotrod.ping_on_startup", "true");
+ defaultProperties.put("infinispan.client.hotrod.transport_factory", "org.infinispan.client.hotrod.impl.transport.tcp.TcpTransportFactory");
+ defaultProperties.put("infinispan.client.hotrod.marshaller", "org.infinispan.marshall.jboss.GenericJBossMarshaller");
+ defaultProperties.put("infinispan.client.hotrod.async_executor_factory","org.infinispan.client.hotrod.impl.async.DefaultAsyncExecutorFactory");
+ defaultProperties.put("infinispan.client.hotrod.default_executor_factory.pool_size","10");
+ defaultProperties.put("infinispan.client.hotrod.default_executor_factory.queue_size","100000");
+ defaultProperties.put("infinispan.client.hotrod.hash_function_impl.1","org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashV1");
+ defaultProperties.put("infinispan.client.hotrod.key_size_estimate","64");
+ defaultProperties.put("infinispan.client.hotrod.value_size_estimate","512");
+
+ // set up the test properties (booleans reversed, int values multiplied by 2)
+ testProperties.put("infinispan.client.hotrod.request_balancing_strategy", "org.jboss.test.cluster.datagrid.hotrod.HotRodTestRequestBalancingStrategy") ;
+ testProperties.put("infinispan.client.hotrod.server_list", "127.0.0.1:12345");
+ testProperties.put("infinispan.client.hotrod.force_return_values", "true");
+ testProperties.put("infinispan.client.hotrod.tcp_no_delay", "false");
+ testProperties.put("infinispan.client.hotrod.ping_on_startup", "false");
+ testProperties.put("infinispan.client.hotrod.transport_factory", "org.jboss.test.cluster.datagrid.hotrod.HotRodTestTransportFactory");
+ testProperties.put("infinispan.client.hotrod.marshaller", "org.jboss.test.cluster.datagrid.hotrod.HotRodTestMarshaller");
+ testProperties.put("infinispan.client.hotrod.async_executor_factory","org.jboss.test.cluster.datagrid.hotrod.HotRodTestExecutorFactory");
+ testProperties.put("infinispan.client.hotrod.default_executor_factory.pool_size","20");
+ testProperties.put("infinispan.client.hotrod.default_executor_factory.queue_size","200000");
+ testProperties.put("infinispan.client.hotrod.hash_function_impl.1","org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashV1");
+ testProperties.put("infinispan.client.hotrod.key_size_estimate","128");
+ testProperties.put("infinispan.client.hotrod.value_size_estimate","1024");
}
/*
@@ -113,88 +151,152 @@
*/
public void setUp() throws Exception {
super.setUp() ;
-
- // per-test setup
- System.out.println("per test set up") ;
- servers = getServers() ;
+
+ String[] servers = getServers() ;
// in case we need it
- hotRodServerList = servers[0] + ":" + "11222" + ";" + servers[1] + ":" + "11222";
+ hotRodServerList = servers[0] + ":" + "11222" + ";" + servers[1] + ":" + "11222";
}
/*
* Per-test case tear down
*/
public void tearDown() throws Exception {
- System.out.println("per test tearing down") ;
-
super.tearDown();
}
-
+
/*
* Tests the constructor RemoteCacheManager()
- * - properties file hotrod-client.properties from classpath used
+ * - the properties file hotrod-client.properties from classpath is used to define properties
+ * - confirm that the file hotrod-client.properties is picked up
*/
- public void testDefaultConstructor() {
+ public void testDefaultConstructor() throws Exception {
+
+ // use the properties file hotrod-client.properties on classpath
+ // this properties file contains the test properties with server_list set to ${node0}:11222;${node1}:11222
+ RemoteCacheManager rcm = new RemoteCacheManager() ;
+ RemoteCache rc = rcm.getCache() ;
- RemoteCacheManager rcm = new RemoteCacheManager() ;
- Properties props = rcm.getProperties() ;
- System.out.println("defaultProperties = + + props") ;
+ // check that actual props == test props and that marshaller was set correctly
+ Properties overrideProps = new Properties() ;
+ overrideProps.put("infinispan.client.hotrod.server_list", hotRodServerList) ;
+ Properties actualProps = getActualProperties(rc) ;
+ comparePropertiesMaps(testProperties, actualProps, overrideProps) ;
}
/*
* Tests the constructor RemoteCacheManager(Properties props)
- * - specified properties file used
+ * - check that specified properties file is used and can be retrieved
*/
- public void testPropertiesConstructor() {
+ public void testPropertiesConstructor() throws Exception {
- Properties props = getRemoteCacheManagerProperties(hotRodServerList);
- RemoteCacheManager rcm = new RemoteCacheManager(props, false);
+ // create a copy of test properties
+ Properties testProps = new Properties() ;
+ testProps.putAll(testProperties) ;
+ testProps.put("infinispan.client.hotrod.server_list", hotRodServerList) ;
+
+ RemoteCacheManager rcm = new RemoteCacheManager(testProps) ;
+ RemoteCache rc = rcm.getCache() ;
- // check started status
- assert rcm.isStarted() == false;
- rcm.start();
- assert rcm.isStarted() == true ;
+ Properties overrideProps = new Properties() ;
+ overrideProps.put("infinispan.client.hotrod.server_list", hotRodServerList) ;
+ Properties actualProps = getActualProperties(rc) ;
+ comparePropertiesMaps(testProperties, actualProps, overrideProps) ;
}
/*
* Tests the constructor RemoteCacheManager(Marshaller marshaller, Properties props)
* - specified marshaller and properties file used
*/
- public void testMarshallerPropertiesConstructor() {
+ public void testMarshallerPropertiesConstructor() throws Exception {
+ // create a set of test properties
+ Properties testProps = new Properties() ;
+ testProps.putAll(defaultProperties) ;
+ testProps.put("infinispan.client.hotrod.server_list", hotRodServerList) ;
+
+ // get a remote cache, specifying a specific marshaller
+ Marshaller testMarshaller = new HotRodTestMarshaller() ;
+ RemoteCacheManager rcm = new RemoteCacheManager(testMarshaller, testProps) ;
+ RemoteCache rc = rcm.getCache() ;
+
+ // check that actual props == test props and that marshaller was set correctly
+ Properties overrideProps = new Properties() ;
+ overrideProps.put("infinispan.client.hotrod.marshaller", "org.jboss.test.cluster.datagrid.hotrod.HotRodTestMarshaller") ;
+ Properties actualProps = getActualProperties(rc) ;
+ comparePropertiesMaps(testProps, actualProps, overrideProps) ;
}
/*
* Tests the constructor RemoteCacheManager(String servers)
* - specified server string used
- * - which properties file?
*/
- public void testServerStringConstructor() {
+ public void testServerStringConstructor() throws Exception {
+ InetSocketAddress addr1 = new InetSocketAddress("192.168.0.100", 1234) ;
+ InetSocketAddress addr2 = new InetSocketAddress("192.168.0.101", 5678) ;
+
+ RemoteCacheManager rcm = new RemoteCacheManager("192.168.0.100:1234;192.168.0.101:5678") ;
+ // use reflection to get the ConfigurationProperties instance
+ ConfigurationProperties config = getConfigurationPropertiesField(rcm) ;
+
+ Collection<InetSocketAddress> servers = config.getServerList();
+ assertTrue("server list size should be 2", servers.size() == 2) ;
+ assertTrue("server list does not contain required address", servers.contains(addr1)) ;
+ assertTrue("server list does not contain required address", servers.contains(addr2)) ;
}
/*
* Tests the constructor RemoteCacheManager(String host, int port)
* - specified host and port used to build single element server string
- * - which properties file used?
*/
- public void testHosttPortConstructor() {
+ public void testHostPortConstructor() throws Exception {
+ InetSocketAddress addr = new InetSocketAddress("192.168.0.100", 1234) ;
+
+ RemoteCacheManager rcm = new RemoteCacheManager("192.168.0.100", 1234) ;
+ // use reflection to get the ConfigurationProperties instance
+ ConfigurationProperties config = getConfigurationPropertiesField(rcm) ;
+
+ Collection<InetSocketAddress> servers = config.getServerList();
+ assertTrue("server list size should be 1", servers.size() == 1) ;
+ assertTrue("server list does not contain required address", servers.contains(addr)) ;
}
/*
* Tests the constructor RemoteCacheManager(URL props)
* - URL specifies properties file
+ * - place it in the resources/datagrid directory
+ *
*/
- public void testURLConstructor() {
+ public void testURLConstructor() throws Exception {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader() ;
+ URL url = loader.getResource("cluster/datagrid/hotrod-client.properties") ;
+
+ RemoteCacheManager rcm = new RemoteCacheManager(url) ;
+ RemoteCache rc = rcm.getCache();
+
+ // check that actual props == test props and that marshaller was set correctly
+ Properties overrideProps = new Properties() ;
+ overrideProps.put("infinispan.client.hotrod.server_list", hotRodServerList) ;
+ Properties actualProps = getActualProperties(rc) ;
+ comparePropertiesMaps(testProperties, actualProps, overrideProps) ;
}
/*
* Tests start(), stop() and isStarted() methods
*/
public void testStartStop() {
-
+
+ RemoteCacheManager rcm = new RemoteCacheManager(hotRodServerList, false);
+ // check initial status
+ assertTrue("RemoteCacheManager should not be started initially", rcm.isStarted() == false);
+ // check start status
+ rcm.start();
+ assertTrue("RemoteCacheManager should be started after calling start()", rcm.isStarted() == true) ;
+ // check stopped status
+ rcm.stop();
+ assertTrue("RemoteCacheManager should be stopped after calling stop()", rcm.isStarted() == false);
}
/*
@@ -202,6 +304,12 @@
*/
public void testGetCache() {
+ RemoteCacheManager rcm = new RemoteCacheManager() ;
+ RemoteCache rc1 = rcm.getCache() ;
+ RemoteCache rc2 = rcm.getCache("sampleReplicatedCache");
+
+ assertNotNull(rc1) ;
+ assertNotNull(rc2) ;
}
/*
@@ -210,29 +318,26 @@
public void testConnectionPooling() {
}
-
+
/*
- * Tests the setting of the Marshaller class
+ * Tests the setting of ConfigurationProperties instance
*/
- public void testSetingMarshaller() {
+ public void testConfigurationProperties() throws Exception {
- }
+ // use the existing EDG instances
+ RemoteCacheManager rcm = new RemoteCacheManager(hotRodServerList) ;
+ RemoteCache rc = rcm.getCache();
+
+ ConfigurationProperties cProps = getConfigurationPropertiesField(rcm) ;
+ System.out.println("Content of ConfigurationProperties instance:") ;
+ System.out.println(cProps.getProperties()) ;
+
+ Properties props = getActualProperties(rc) ;
+ System.out.println("Content of actual properties:") ;
+ System.out.println(props) ;
+ }
+
- /*
- * Tests the cache clear operation
- */
- public void XtestClear() {
- remoteCache.put("aKey", "aValue");
- remoteCache.put("aKey2", "aValue");
- remoteCache.clear();
- assert !remoteCache.containsKey("aKey");
- assert !remoteCache.containsKey("aKey2");
- }
-
- private void assertNull(Object obj, String msg) {
- assert obj == null : msg ;
- }
-
private void sleepForSecs(long numSecs) {
// give the elements time to be evicted
try {
@@ -246,42 +351,503 @@
Map<String,String> cacheElements = c.getBulk();
System.out.println(description + " : " + cacheElements);
}
-
- private Properties getRemoteCacheManagerProperties(String hotRodServerList) {
+
+ /*
+ * Returns a map of all properties, obtained by reflection from a RemoteCache instance
+ * - this is the most accurate view of properties being used by a RemoteCache
+ */
+ private Properties getActualProperties(RemoteCache rc) throws Exception {
Properties props = new Properties();
- // load balancing \
+
+ String request_balancing_strategy = getRequestBalancingStrategyProperty(rc) ;
+ props.put("infinispan.client.hotrod.request_balancing_strategy", request_balancing_strategy) ;
+
+ String server_list = getServerListProperty(rc) ;
+ props.put("infinispan.client.hotrod.server_list", server_list) ;
+
+ String force_return_values = getForceReturnValueProperty(rc) ;
+ props.put("infinispan.client.hotrod.force_return_values", force_return_values) ;
+
+ String tcp_no_delay = getTcpNoDelayProperty(rc) ;
+ props.put("infinispan.client.hotrod.tcp_no_delay", tcp_no_delay) ;
+
+ String ping_on_startup = getPingOnStartupProperty(rc) ;
+ props.put("infinispan.client.hotrod.ping_on_startup", ping_on_startup) ;
+
+ String transport_factory = getTransportFactoryProperty(rc) ;
+ props.put("infinispan.client.hotrod.transport_factory", transport_factory) ;
+
+ String marshaller = getMarshallerProperty(rc) ;
+ props.put("infinispan.client.hotrod.marshaller", marshaller) ;
- props.put("infinispan.client.hotrod.request_balancing_strategy",
- // "org.infinispan.client.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy");
- "org.jboss.test.cluster.datagrid.hotrod.Node0OnlyBalancingStrategy");
- // list of HotRod servers available to connect to \
+ String async_executor_factory = getAsyncExecutorFactoryProperty(rc) ;
+ props.put("infinispan.client.hotrod.async_executor_factory", async_executor_factory) ;
+
+ if ("org.infinispan.client.hotrod.impl.async.DefaultAsyncExecutorFactory".equals(async_executor_factory)) {
+ // get missing properties:
+ // infinispan.client.hotrod.async_executor_factory.pool_size
+ // infinispan.client.hotrod.async_executor_factory.queue_size
+ }
- props.put("infinispan.client.hotrod.server_list", hotRodServerList);
- props.put("infinispan.client.hotrod.force_return_values", "false");
- // TCP stuff \
+ // need ping_on_startup
+ rc.stats() ;
+ String hash_function_impl = getHashFunctionImplProperty(rc) ;
+ // need to find out version too
+ props.put("infinispan.client.hotrod.hash_function_impl.1", hash_function_impl) ;
+
+ String key_size_estimate = getKeySizeEstimateProperty(rc) ;
+ props.put("infinispan.client.hotrod.key_size_estimate", key_size_estimate) ;
- 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 \
+ String value_size_estimate = getValueSizeEstimateProperty(rc) ;
+ props.put("infinispan.client.hotrod.value_size_estimate", value_size_estimate) ;
+
+ return props ;
+ }
+
+ /*
+ * Compare maps expected and actual which should be:
+ * (i) equal in key sets
+ * (ii) equal in value sets, except for some entries, provided by overrides
+ */
+ private void comparePropertiesMaps(Properties expected, Properties actual, Properties overrides) {
+
+ // check that all non-overridden and overridden default values are present
+ for (Enumeration e = expected.keys(); e.hasMoreElements();) {
+ String key = (String) e.nextElement() ;
+
+ // don't check executor factory pool and queue for now
+ if ("infinispan.client.hotrod.default_executor_factory.pool_size".equals(key) || "infinispan.client.hotrod.default_executor_factory.queue_size".equals(key))
+ continue ;
+
+ if (!overrides.containsKey(key)) {
+ String expectedValue = (String) expected.get(key) ;
+ String actualValue = (String) actual.get(key) ;
+ System.out.println("Checking property: " + key + " expectedValue = " + expectedValue + " actualValue = " + actualValue) ;
+ assertTrue("Compare failed for key " + key + ": expected value = " + expectedValue + " actualValue = " + actualValue, expectedValue.equals(actualValue)) ;
+ }
+ else {
+ String overrideValue = (String) overrides.get(key) ;
+ String actualValue = (String) actual.get(key) ;
+ System.out.println("Checking property override: " + key + " expectedValue = " + overrideValue + " actualValue = " + actualValue) ;
+ assertTrue("Compare failed for key " + key + ": override value = " + overrideValue + " actualValue = " + actualValue, overrideValue.equals(actualValue)) ;
+ }
+ }
+ }
+
+ /*
+ * Helper methods for obtaining specific properties
+ */
+
+ /*
+ * request_balancing_strategy
+ * - this gets used directly by the TcpTransportfactory when processing HotRodOperations
+ */
+ private String getRequestBalancingStrategyProperty(RemoteCache rc) throws Exception {
+
+ RemoteCacheImpl rci = (RemoteCacheImpl) rc ;
+ OperationsFactory of = getOperationsFactoryField(rci) ;
+ TcpTransportFactory ttf = (TcpTransportFactory) getTransportFactoryField(of) ;
+ RequestBalancingStrategy rbs = ttf.getBalancer() ;
+ return rbs.getClass().getName() ;
+ }
+
+ /*
+ * server_list
+ * - this gets used directly by the TcpTransportfactory when processing HotRodOperations
+ */
+ private String getServerListProperty(RemoteCache rc) throws Exception {
+
+ RemoteCacheImpl rci = (RemoteCacheImpl) rc ;
+ OperationsFactory of = getOperationsFactoryField(rci) ;
+ TcpTransportFactory ttf = (TcpTransportFactory) getTransportFactoryField(of) ;
+ Collection<InetSocketAddress> servers = ttf.getServers() ;
+ // create a list of IP address:port to return
+ StringBuffer serverList = new StringBuffer() ;
+ int listSize = servers.size() ;
+ int i = 0 ;
+ for (Iterator iter = servers.iterator(); iter.hasNext(); i++) {
+ InetSocketAddress addr = (InetSocketAddress) iter.next() ;
+ // take care to remove prepended backslash
+ String serverAddress = addr.getAddress().toString() ;
+ if (serverAddress.startsWith("/"))
+ serverAddress = serverAddress.substring(1) ;
+ serverList.append(serverAddress);
+ serverList.append(":");
+ serverList.append(addr.getPort()) ;
+ if (i < listSize-1)
+ serverList.append(";") ;
+ }
+ return serverList.toString() ;
+ }
+
+ /*
+ * force_return_values
+ * - this gets used directly by the TcpTransportfactory when processing HotRodOperations
+ */
+ private String getForceReturnValueProperty(RemoteCache rc) throws Exception {
+
+ RemoteCacheImpl rci = (RemoteCacheImpl) rc ;
+ OperationsFactory of = getOperationsFactoryField(rci) ;
+ boolean forceReturn = getForceReturnValueField(of);
+ return Boolean.toString(forceReturn) ;
+ }
- props.put("infinispan.client.hotrod.marshaller", "org.infinispan.marshall.jboss.GenericJBossMarshaller");
- // executors \
+ /*
+ * tcp_no_delay
+ * - this gets used directly by the TcpTransportfactory when processing HotRodOperations
+ */
+ private String getTcpNoDelayProperty(RemoteCache rc) throws Exception {
+
+ RemoteCacheImpl rci = (RemoteCacheImpl) rc ;
+ OperationsFactory of = getOperationsFactoryField(rci) ;
+ TcpTransportFactory ttf = (TcpTransportFactory) getTransportFactoryField(of) ;
+ boolean tcpNoDelay = ttf.isTcpNoDelay();
+ return Boolean.toString(tcpNoDelay) ;
+ }
+
+ /*
+ * ping_on_startup
+ * - used by TransportObjectfactory (which adds TcpTransport objects to the pool) to
+ * know if we should get the topolgy on startup
+ * - to get the real value used, we need to trace through a list of components:
+ * RemoteCacheManager, TcpTransportFactory, PropsKeyedObjectPoolFactory, TransportObjectFactory
+ * - use the value set in RemoteCachemanager ConfigurationProperties as an estimate
+ */
+ private String getPingOnStartupProperty(RemoteCache rc) throws Exception {
+
+ RemoteCacheImpl rci = (RemoteCacheImpl) rc ;
+ RemoteCacheManager rcm = rci.getRemoteCacheManager();
+ ConfigurationProperties cp = (ConfigurationProperties) getConfigurationPropertiesField(rcm) ;
+ boolean pingOnStartup = cp.getPingOnStartup() ;
+ return Boolean.toString(pingOnStartup);
+ }
+ /*
+ * transport_factory
+ * - used by OperationsFactory to provide each HotRod operation with its own transport
+ */
+ private String getTransportFactoryProperty(RemoteCache rc) throws Exception {
+
+ RemoteCacheImpl rci = (RemoteCacheImpl) rc ;
+ OperationsFactory of = getOperationsFactoryField(rci) ;
+ TransportFactory tf = (TransportFactory) getTransportFactoryField(of) ;
+ // need to check instance type
+ return tf.getClass().getName() ;
+ }
+
+ /*
+ * marshaller
+ * - used by RemoteCacheImpl to marshal parameters for HotRod operations before
+ * sending over the TcpTransport
+ */
+ private String getMarshallerProperty(RemoteCache rc) throws Exception {
+
+ RemoteCacheImpl rci = (RemoteCacheImpl) rc ;
+ Marshaller m = getMarshallerField(rci) ;
+ // need to check instance
+ return m.getClass().getName() ;
+ }
- 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 \
+
+ /*
+ * async_executor_factory
+ * - used by RemoteCacheManager to init RemoteCacheImpl ExecutorService
+ */
+ private String getAsyncExecutorFactoryProperty(RemoteCache rc) throws Exception {
+
+ RemoteCacheImpl rci = (RemoteCacheImpl) rc ;
+ RemoteCacheManager rcm = rci.getRemoteCacheManager();
+ ConfigurationProperties cp = (ConfigurationProperties) getConfigurationPropertiesField(rcm) ;
+ return cp.getAsyncExecutorFactory() ;
+ }
+
+ /*
+ * executor_service
+ * - used by RemoteCacheImpl to schedule HotRod operations for async execution
+ */
+ private String getExecutorServiceProperty(RemoteCache rc) throws Exception {
+
+ RemoteCacheImpl rci = (RemoteCacheImpl) rc ;
+ ExecutorService es = getExecutorServiceField(rci) ;
+ // need to check instance
+ return es.getClass().getName() ;
+ }
+
+ /*
+ * hash_function_impl
+ * - used by TcpTransport to define a ConsistentHash, used in identifying a server to send a request to
+ * - NOTE: only initialised during HotRod operation execution, so need to fire off a ping to get it set
+ */
+ private String getHashFunctionImplProperty(RemoteCache rc) throws Exception {
+
+ RemoteCacheImpl rci = (RemoteCacheImpl) rc ;
+ OperationsFactory of = getOperationsFactoryField(rci) ;
+ TcpTransportFactory ttf = (TcpTransportFactory) getTransportFactoryField(of) ;
+ ConsistentHash ch = (ConsistentHash) getConsistentHashField(ttf);
+ return ch.getClass().getName() ;
+ }
+
+ /*
+ * key_size_estimate
+ * - used by RemoteCacheImpl when marshalling keys for HotRod operations
+ */
+ private String getKeySizeEstimateProperty(RemoteCache rc) throws Exception {
+
+ RemoteCacheImpl rci = (RemoteCacheImpl) rc ;
+ int keySize = getEstimateKeySizeField(rci) ;
+ return Integer.toString(keySize) ;
+ }
- 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");
+ /*
+ * value_size_estimate
+ * - used by RemoteCacheImpl when marshalling values for HotRod operations
+ */
+ private String getValueSizeEstimateProperty(RemoteCache rc) throws Exception {
+
+ RemoteCacheImpl rci = (RemoteCacheImpl) rc ;
+ int valueSize = getEstimateValueSizeField(rci) ;
+ return Integer.toString(valueSize) ;
+ }
+
+
+ /*
+ * Reflection helper methods
+ *
+ * When RemoteCacheManager and RemoteCache are initialised, properties are set in a variety of classes
+ * These methods use reflection to obtain the value of each property where it has effect.
+ */
+
+ /*
+ * RemoteCacheManager.getConfigurationPropertiesField
+ */
+ private ConfigurationProperties getConfigurationPropertiesField(RemoteCacheManager rcm) throws Exception {
+
+ Field field = null ;
+ try {
+ field = RemoteCacheManager.class.getDeclaredField("config") ;
+ }
+ catch(NoSuchFieldException e) {
+ throw new Exception("Could not access ConfigurationProperties field", e) ;
+ }
+ field.setAccessible(true) ;
+ ConfigurationProperties fieldValue = null ;
+ try {
+ fieldValue = (ConfigurationProperties) field.get(rcm) ;
+ }
+ catch(IllegalAccessException e) {
+ throw new Exception("Could not access ConfigurationProperties field", e) ;
+ }
+ return fieldValue ;
+ }
+
+ /*
+ * RemoteCacheImpl.getOperationsFactoryField
+ */
+ private OperationsFactory getOperationsFactoryField(RemoteCacheImpl rci) throws Exception {
+
+ Field field = null ;
+ try {
+ field = RemoteCacheImpl.class.getDeclaredField("operationsFactory") ;
+ }
+ catch(NoSuchFieldException e) {
+ throw new Exception("Could not access operationsFactory field", e) ;
+ }
+ field.setAccessible(true) ;
+ OperationsFactory fieldValue = null ;
+ try {
+ fieldValue = (OperationsFactory) field.get(rci) ;
+ }
+ catch(IllegalAccessException e) {
+ throw new Exception("Could not access OperationsFactory field", e) ;
+ }
+ return fieldValue ;
+ }
- return props ;
+ /*
+ * RemotecacheImpl.getEstimateKeySizeField
+ */
+ private int getEstimateKeySizeField(RemoteCacheImpl rci) throws Exception {
+
+ Field field = null ;
+ try {
+ field = RemoteCacheImpl.class.getDeclaredField("estimateKeySize") ;
+ }
+ catch(NoSuchFieldException e) {
+ throw new Exception("Could not access estimateKeySize field", e) ;
+ }
+ field.setAccessible(true) ;
+ int fieldValue = 0 ;
+ try {
+ fieldValue = field.getInt(rci) ;
+ }
+ catch(IllegalAccessException e) {
+ throw new Exception("Could not access estimateKeySize field", e) ;
+ }
+ return fieldValue ;
}
+
+ /*
+ * RemoteCacheImpl.getEstimateKeySizeField
+ */
+ private int getEstimateValueSizeField(RemoteCacheImpl rci) throws Exception {
+
+ Field field = null ;
+ try {
+ field = RemoteCacheImpl.class.getDeclaredField("estimateValueSize") ;
+ }
+ catch(NoSuchFieldException e) {
+ throw new Exception("Could not access estimateValueSize field", e) ;
+ }
+ field.setAccessible(true) ;
+ int fieldValue = 0 ;
+ try {
+ fieldValue = field.getInt(rci) ;
+ }
+ catch(IllegalAccessException e) {
+ throw new Exception("Could not access estimateValueSize field", e) ;
+ }
+ return fieldValue ;
+ }
+
+
+ /*
+ * RemoteCacheImpl.getMarshallerField
+ */
+ private Marshaller getMarshallerField(RemoteCacheImpl rci) throws Exception {
+
+ Field field = null ;
+ try {
+ field = RemoteCacheImpl.class.getDeclaredField("marshaller") ;
+ }
+ catch(NoSuchFieldException e) {
+ throw new Exception("Could not access marshaller field", e) ;
+ }
+ field.setAccessible(true) ;
+ Marshaller fieldValue = null ;
+ try {
+ fieldValue = (Marshaller) field.get(rci) ;
+ }
+ catch(IllegalAccessException e) {
+ throw new Exception("Could not access marshaller field", e) ;
+ }
+ return fieldValue ;
+ }
+
+ /*
+ * RemoteCacheImpl.getExecutorService
+ */
+ private ExecutorService getExecutorServiceField(RemoteCacheImpl rci) throws Exception {
+
+ Field field = null ;
+ try {
+ field = RemoteCacheImpl.class.getDeclaredField("executorService") ;
+ }
+ catch(NoSuchFieldException e) {
+ throw new Exception("Could not access executorService field", e) ;
+ }
+ field.setAccessible(true) ;
+ ExecutorService fieldValue = null ;
+ try {
+ fieldValue = (ExecutorService) field.get(rci) ;
+ }
+ catch(IllegalAccessException e) {
+ throw new Exception("Could not access executorService field", e) ;
+ }
+ return fieldValue ;
+ }
+
+
+ /*
+ * OperationsFactory.getForceReturnValueField
+ */
+ private boolean getForceReturnValueField(OperationsFactory of) throws Exception {
+
+ Field field = null ;
+ try {
+ field = OperationsFactory.class.getDeclaredField("forceReturnValue") ;
+ }
+ catch(NoSuchFieldException e) {
+ throw new Exception("Could not access forceReturnValue field", e) ;
+ }
+ field.setAccessible(true) ;
+ boolean fieldValue = false ;
+ try {
+ fieldValue = field.getBoolean(of) ;
+ }
+ catch(IllegalAccessException e) {
+ throw new Exception("Could not access forceReturnValue field", e) ;
+ }
+ return fieldValue ;
+ }
+
+ /*
+ * OperationsFactory.getTransportFactoryField
+ */
+ private TransportFactory getTransportFactoryField(OperationsFactory of) throws Exception {
+
+ Field field = null ;
+ try {
+ field = OperationsFactory.class.getDeclaredField("transportFactory") ;
+ }
+ catch(NoSuchFieldException e) {
+ throw new Exception("Could not access transportFactory field", e) ;
+ }
+ field.setAccessible(true) ;
+ TransportFactory fieldValue = null ;
+ try {
+ fieldValue = (TransportFactory) field.get(of) ;
+ }
+ catch(IllegalAccessException e) {
+ throw new Exception("Could not access transportFactory field", e) ;
+ }
+ return fieldValue ;
+ }
+
+ /*
+ * TcpTransportFactory.getRequestBalancingStrategyField
+ */
+ private RequestBalancingStrategy getRequestBalancingStrategyField(TcpTransportFactory ttf) throws Exception {
+
+ Field field = null ;
+ try {
+ field = TcpTransportFactory.class.getDeclaredField("balancer") ;
+ }
+ catch(NoSuchFieldException e) {
+ throw new Exception("Could not access balancer field", e) ;
+ }
+ field.setAccessible(true) ;
+ RequestBalancingStrategy fieldValue = null ;
+ try {
+ fieldValue = (RequestBalancingStrategy) field.get(ttf) ;
+ }
+ catch(IllegalAccessException e) {
+ throw new Exception("Could not access balancer field", e) ;
+ }
+ return fieldValue ;
+ }
+
+ /*
+ * TcpTransportFactory.getConsistentHashField
+ */
+ private ConsistentHash getConsistentHashField(TcpTransportFactory ttf) throws Exception {
+
+ Field field = null ;
+ try {
+ field = TcpTransportFactory.class.getDeclaredField("consistentHash") ;
+ }
+ catch(NoSuchFieldException e) {
+ throw new Exception("Could not access consistentHash field", e) ;
+ }
+ field.setAccessible(true) ;
+ ConsistentHash fieldValue = null ;
+ try {
+ fieldValue = (ConsistentHash) field.get(ttf) ;
+ }
+ catch(IllegalAccessException e) {
+ throw new Exception("Could not access consistentHash field", e) ;
+ }
+ return fieldValue ;
+ }
+
}
Added: branches/JBPAPP_5_1_datagrid/testsuite/src/resources/cluster/datagrid/hotrod-client.properties
===================================================================
--- branches/JBPAPP_5_1_datagrid/testsuite/src/resources/cluster/datagrid/hotrod-client.properties (rev 0)
+++ branches/JBPAPP_5_1_datagrid/testsuite/src/resources/cluster/datagrid/hotrod-client.properties 2011-01-12 21:11:50 UTC (rev 110339)
@@ -0,0 +1,13 @@
+infinispan.client.hotrod.request_balancing_strategy=org.jboss.test.cluster.datagrid.hotrod.HotRodTestRequestBalancingStrategy
+infinispan.client.hotrod.server_list=@jbosstest.server.module.host0@:11222;@jbosstest.server.module.host1@:11222
+infinispan.client.hotrod.force_return_values=true
+infinispan.client.hotrod.tcp_no_delay=false
+infinispan.client.hotrod.ping_on_startup=false
+infinispan.client.hotrod.transport_factory=org.jboss.test.cluster.datagrid.hotrod.HotRodTestTransportFactory
+infinispan.client.hotrod.marshaller=org.jboss.test.cluster.datagrid.hotrod.HotRodTestMarshaller
+infinispan.client.hotrod.async_executor_factory=org.jboss.test.cluster.datagrid.hotrod.HotRodTestExecutorFactory
+infinispan.client.hotrod.default_executor_factory.pool_size=20
+infinispan.client.hotrod.default_executor_factory.queue_size=200000
+infinispan.client.hotrod.hash_function_impl.1=org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashV1
+infinispan.client.hotrod.key_size_estimate=128
+infinispan.client.hotrod.value_size_estimate=1024
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list