[jboss-cvs] JBossAS SVN: r110478 - in branches/JBPAPP_5_1_datagrid/testsuite: imports/config and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jan 27 17:13:39 EST 2011


Author: rachmatowicz at jboss.com
Date: 2011-01-27 17:13:38 -0500 (Thu, 27 Jan 2011)
New Revision: 110478

Added:
   branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/HotRodClientFailoverTestCase.java
Modified:
   branches/JBPAPP_5_1_datagrid/testsuite/imports/config/tests-clustering.xml
   branches/JBPAPP_5_1_datagrid/testsuite/imports/server-config.xml
   branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/DeploymentTestCase.java
   branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/HotRodClientRemoteCacheManagerTestCase.java
Log:
Add EDG HotRodClientFailoverTestCase; update DeploymentTestCase and HotRodClientRemoteCacheManagerTestCase 

Modified: branches/JBPAPP_5_1_datagrid/testsuite/imports/config/tests-clustering.xml
===================================================================
--- branches/JBPAPP_5_1_datagrid/testsuite/imports/config/tests-clustering.xml	2011-01-27 21:51:38 UTC (rev 110477)
+++ branches/JBPAPP_5_1_datagrid/testsuite/imports/config/tests-clustering.xml	2011-01-27 22:13:38 UTC (rev 110478)
@@ -986,18 +986,38 @@
 	
   <patternset id="cluster.datagrid.includes">
 	<include name="org/jboss/test/cluster/datagrid/**/*TestCase.class"/>
+	<exclude name="org/jboss/test/cluster/datagrid/**/DeploymentTestCase.class"/>
+	<exclude name="org/jboss/test/cluster/datagrid/**/HotRodClientFailoverTestCase.class"/>
   </patternset>
 
   <patternset id="cluster.datagrid.startup.includes">
 	<include name="org/jboss/test/cluster/datagrid/**/DeploymentTestCase.class"/>
   </patternset>	
+
+  <patternset id="cluster.datagrid.failover.includes">
+	<include name="org/jboss/test/cluster/datagrid/**/HotRodClientFailoverTestCase.class"/>
+  </patternset>	
 	
+	
   <!-- Depending on the value of Infinispan config ??? -->
   <target name="tests-clustering-datagrid" description="Execute datagrid tests requiring two nodes.">
 
+  	<!-- core tests -->
 	<antcall target="tests-clustering-datagrid-core-tests" inheritRefs="true">
 	  <param name="cluster.datagrid.includes" value="cluster.datagrid.includes"/>
 	</antcall>
+  	
+  	<!-- deployment tests -->
+	<antcall target="tests-clustering-datagrid-startup-tests" inheritRefs="true">
+	  <param name="cluster.datagrid.includes" value="cluster.datagrid.startup.includes"/>
+	</antcall>
+ 	
+  	<!-- failover tests -->
+	<antcall target="tests-clustering-datagrid-failover-tests" inheritRefs="true">
+	  <param name="cluster.datagrid.includes" value="cluster.datagrid.failover.includes"/>
+	</antcall>
+
+  	
   </target>
 	
 
@@ -1039,7 +1059,23 @@
   	
   </target>	
 
+  <target name="tests-clustering-datagrid-failover-tests" description="Starts server, runs failover test, stops server">
+
+	<antcall target="tests-clustering-datagrid-failover-configure" inheritRefs="true"/>	
+		  	
+	<server:start name="datagrid-failover-0"/>
+
+	<!-- after the servers have been started and stopped, run a test which checks the logs -->
+	<antcall target="tests-clustering-datagrid-execute">
+	  <param name="cluster.datagrid.includes.refid" value="cluster.datagrid.failover.includes"/>
+	  <param name="jboss-junit-configuration" value="datagrid"/>
+	</antcall>
+
+	<server:stop name="datagrid-failover-0"/>
+	 	
+  </target>	
 	
+	
   <target name="tests-clustering-datagrid-configure" description="Configures datagrid server nodes">
   	<property name="baseconf" value="datagrid"/>
 	 <create-cluster-node-from-baseconf conf="datagrid-0" baseconf="${baseconf}"/>
@@ -1054,6 +1090,12 @@
 	<!-- add in any other configuration steps here -->
   </target>	
 	
+  <target name="tests-clustering-datagrid-failover-configure" description="Configures datagrid server nodes">
+	<property name="baseconf" value="datagrid"/>
+	<create-cluster-node-from-baseconf conf="datagrid-failover-0" baseconf="${baseconf}"/>
+	<create-cluster-node-from-baseconf conf="datagrid-failover-1" baseconf="${baseconf}"/>
+	<!-- add in any other configuration steps here -->
+  </target>	
 	
   <!-- Executes a set of tests in a datagrid environment -->  
   <target name="tests-clustering-datagrid-execute" description="JUnit task to execute a batch of tests against the datagrid">
@@ -1073,6 +1115,7 @@
 
 	   <sysproperty key="java.net.preferIPv4Stack" value="true"/>
 	         
+	   <sysproperty key="jboss.dist" value="${jboss.dist}"/>
 	   <sysproperty key="jboss.internal-server.serverroot" value="${jboss.dist}/server"/>
 	   <sysproperty key="jbosstest.deploy.dir" file="${build.lib}"/>
 	   <sysproperty key="jbosstest.cluster.node0" value="${node0}"/>
@@ -1162,6 +1205,7 @@
 
 		   <sysproperty key="java.net.preferIPv4Stack" value="true"/>
 		         
+		   <sysproperty key="jboss.dist" value="${jboss.dist}"/>
 		   <sysproperty key="jboss.internal-server.serverroot" value="${jboss.dist}/server"/>
 		   <sysproperty key="jbosstest.deploy.dir" file="${build.lib}"/>
 		   <sysproperty key="jbosstest.cluster.node0" value="${node0}"/>

Modified: branches/JBPAPP_5_1_datagrid/testsuite/imports/server-config.xml
===================================================================
--- branches/JBPAPP_5_1_datagrid/testsuite/imports/server-config.xml	2011-01-27 21:51:38 UTC (rev 110477)
+++ branches/JBPAPP_5_1_datagrid/testsuite/imports/server-config.xml	2011-01-27 22:13:38 UTC (rev 110478)
@@ -1448,6 +1448,30 @@
        <sysproperty key="xb.builder.useUnorderedSequence" value="true" />
     </server>
    	
+    <server name="datagrid-failover-0" host="${node0}">
+       <jvmarg value="-Xms128m" />
+       <jvmarg value="-Xmx512m" />
+       <jvmarg value="-XX:MaxPermSize=512m" />
+       <jvmarg value="-XX:+HeapDumpOnOutOfMemoryError" />
+       <jvmarg value="-XX:-UseGCOverheadLimit" />
+       <sysproperty key="java.endorsed.dirs" value="${jboss.dist}/lib/endorsed" />
+       <sysproperty key="java.net.preferIPv4Stack" value="true" />
+       <sysproperty key="jgroups.udp.ip_ttl" value="${jbosstest.udp.ip_ttl}" />
+       <sysproperty key="xb.builder.useUnorderedSequence" value="true" />
+    </server>
+    <!-- <server name="datagrid-failover-1" host="${node1}"  hasWebServer="false" rmiPort="11222"> -->
+    <server name="datagrid-failover-1" host="${node1}">
+       <jvmarg value="-Xms128m" />
+       <jvmarg value="-Xmx512m" />
+       <jvmarg value="-XX:MaxPermSize=512m" />
+       <jvmarg value="-XX:+HeapDumpOnOutOfMemoryError" />
+       <jvmarg value="-XX:-UseGCOverheadLimit" />
+       <sysproperty key="java.endorsed.dirs" value="${jboss.dist}/lib/endorsed" />
+       <sysproperty key="java.net.preferIPv4Stack" value="true" />
+       <sysproperty key="jgroups.udp.ip_ttl" value="${jbosstest.udp.ip_ttl}" />
+       <sysproperty key="xb.builder.useUnorderedSequence" value="true" />
+    </server>
+
    	
    	<!-- datagrid configs based on SBM -->
    	<server name="datagrid-sbm-0" host="${node0}" httpPort="8180" rmiPort="1199">

Modified: branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/DeploymentTestCase.java
===================================================================
--- branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/DeploymentTestCase.java	2011-01-27 21:51:38 UTC (rev 110477)
+++ branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/DeploymentTestCase.java	2011-01-27 22:13:38 UTC (rev 110478)
@@ -48,14 +48,16 @@
  * @author Richard Achmatowicz
  * @version $Revision: $
  */
-public class DeploymentTestCase extends JBossClusteredTestCase
+public class DeploymentTestCase extends TestCase
 {
 
-	private String jbossDist = null ;
-	private String[] errorLogPath = null ;
-	private LogFileAssertionChecker[] errorLog = null ;
+    private String jbossServerRoot = null ;
+    private String[] logDirPath = null ;
+    private LogFileAssertionChecker[] bootLog = null ;	
+    private LogFileAssertionChecker[] errorLog = null ;	
+    private LogFileAssertionChecker[] outputLog = null ;	
+    private LogFileAssertionChecker[] systemLog = null ;	
 	
-	
    /**
     * Create a new DeploymentTestCase.
     * 
@@ -64,68 +66,55 @@
    public DeploymentTestCase(String name)
    {
       super(name);           
-      
-      errorLogPath = new String[2];
+      logDirPath = new String[2];
+      bootLog = new LogFileAssertionChecker[2];
+      errorLog = new LogFileAssertionChecker[2];
+      outputLog = new LogFileAssertionChecker[2];
+      systemLog = new LogFileAssertionChecker[2];
    }
    
    public void setUp() throws Exception 
    {
       super.setUp();
       
-      jbossDist = System.getProperty("jboss.dist") ;
-      if (jbossDist == null)
-    	  throw new Exception("jboss.dist property not defined") ;
+      jbossServerRoot = System.getProperty("jboss.internal-server.serverroot") ;
+      if (jbossServerRoot == null)
+    	  throw new Exception("jboss.internal-server.serverroot property not defined") ;
       
-      errorLogPath[0] = jbossDist + "/server/datagrid-0/log" ;
-      errorLogPath[1] = jbossDist + "/server/datagrid-1/log" ;
+      logDirPath[0] = jbossServerRoot + "/datagrid-startup-0/log" ;
+      logDirPath[1] = jbossServerRoot + "/datagrid-startup-1/log" ;
       
-      errorLog[0] = new LogFileAssertionChecker(errorLogPath[0]) ;
-      errorLog[1] = new LogFileAssertionChecker(errorLogPath[1]) ;
+      bootLog[0] = new LogFileAssertionChecker(logDirPath[0] + "/boot.log") ;
+      bootLog[1] = new LogFileAssertionChecker(logDirPath[1] + "/boot.log") ;
+      errorLog[0] = new LogFileAssertionChecker(logDirPath[0] + "/error.log") ;
+      errorLog[1] = new LogFileAssertionChecker(logDirPath[1] + "/error.log") ;
+      outputLog[0] = new LogFileAssertionChecker(logDirPath[0] + "/output.log") ;
+      outputLog[1] = new LogFileAssertionChecker(logDirPath[1] + "/output.log") ;
+      systemLog[0] = new LogFileAssertionChecker(logDirPath[0] + "/system.log") ;
+      systemLog[1] = new LogFileAssertionChecker(logDirPath[1] + "/system.log") ;
    }
-
    
-   
    /**
-    * Tests basic access to logs 
+    * Test logs for some basic correctness properties
+    * - each server should have started
+    * - each server should have no ERROR messages
     */
    public void testLogAccess() {
 
-	   if (errorLog[0].isStringInLog("Started", false, false)) {
-		   System.out.println("Started string found in error log 0") ;
-	   }
-	   else {
-		   System.out.println("Started string not found in error log 0") ;
-	   }
-	   
-	   if (errorLog[1].isStringInLog("Started", false, false)) {
-		   System.out.println("Started string found in error log 1") ;
-	   }
-	   else {
-		   System.out.println("Started string not found in error log 1") ;
-	   }
-	   
-   }
-      
-   
-   /* 
-    * one time setup mechamism
-    * only good for static stuff
-    *  
-   public static Test suite() throws Exception
-   {
-	   TestSuite suite = new TestSuite();
-	   suite.addTest(new TestSuite(TwiddleTestCase.class));
-	   
-	   JBossTestSetup setup = new JBossTestSetup(suite) {
-		   
-           protected void setUp() throws Exception {
-           }
-           
-           protected void tearDown() throws Exception {
-        	   
-           }
-	   } ;
-      return setup ;
-   }
-   */
+       // check for presence of started messages
+       assertTrue("\"Started in\" message does not appear in output log in datagrid-0", outputLog[0].isStringInLog("Started in",false,false)) ;
+       assertTrue("\"Started in\" message does not appear in output log in datagrid-1", outputLog[1].isStringInLog("Started in",false,false)) ;
+
+       // check for absence of ERROR messages
+       assertFalse("\"ERROR\" message appears in output log in datagrid-0", outputLog[0].isStringInLog("ERROR",false,false)) ;
+       assertFalse("\"ERROR\" message appears in output log in datagrid-1", outputLog[1].isStringInLog("ERROR",false,false)) ;
+
+       // check for message indicating complete view
+   }      
 }
+
+
+
+
+
+

Added: branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/HotRodClientFailoverTestCase.java
===================================================================
--- branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/HotRodClientFailoverTestCase.java	                        (rev 0)
+++ branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/HotRodClientFailoverTestCase.java	2011-01-27 22:13:38 UTC (rev 110478)
@@ -0,0 +1,335 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.cluster.datagrid.test;
+
+import java.io.File;
+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.Hashtable;
+import java.util.concurrent.ExecutorService;
+
+import javax.management.ObjectName ;
+import javax.management.MalformedObjectNameException;
+import javax.management.MBeanServerConnection;
+
+import javax.naming.InitialContext;
+
+import org.infinispan.Cache;
+import org.infinispan.executors.ExecutorFactory;
+import org.infinispan.marshall.Marshaller;
+import org.infinispan.marshall.jboss.JBossMarshaller;       
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
+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.Transport;
+import org.infinispan.client.hotrod.impl.transport.tcp.TcpTransportFactory;
+import org.infinispan.client.hotrod.impl.transport.tcp.TcpTransport;
+import org.infinispan.client.hotrod.impl.transport.tcp.RequestBalancingStrategy;
+import org.infinispan.client.hotrod.impl.operations.OperationsFactory;
+
+import org.jboss.test.JBossClusteredTestCase;
+import org.jboss.test.JBossTestSetup;
+import org.jboss.test.JBossTestClusteredSetup;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.jboss.test.scripts.test.ScriptsTestBase;
+
+/**
+ * Tests for the HotRod client failover
+ * 
+ * We start one server using server-manager, before the test case starts.
+ * 
+ * We start the second server using AsyncShellScriptExecutor so that we can interrogate and
+ * kill the server as we please from within the test case. Even restart it if necessary! 
+ * 
+ * This test is based on JBossTestCase, so we only have all info for one server.
+ * We need to pick up the details for the second server using jbosstest properties
+ * and this is done in the setUp().
+ * 
+ * @author <a href="mailto:richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
+ * @version $Revision: $
+ */
+public class HotRodClientFailoverTestCase extends ScriptsTestBase
+{
+	private static final Log log = LogFactory.getLog(HotRodClientFailoverTestCase.class); 
+
+	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 ObjectName SERVER_OBJ_NAME = null ;
+	private String[] servers = null ;
+
+	private String hotRodServerList = null ;
+
+	public HotRodClientFailoverTestCase(String name) {
+		super(name) ;
+
+		try {
+			SERVER_OBJ_NAME = new ObjectName("jboss.system:type=Server") ;
+		}
+		catch(MalformedObjectNameException mfe) {
+			System.out.println("Malformed Object 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");	
+	}
+
+	/*
+	 * Per-test case setup
+	 * 
+	 * 1. datagrid-failover-0 is running at the start of this test
+	 * 2. datagrid-failover-1 will be started during the test at IP address servers[1] 
+	 * 3. we can choose to start HotRod Cachemanager 
+	 * - at the start of the test, with server list servers[0]:11222
+	 * - after we have started the second host, with server list servers[0]:11222;servers[1]:11222
+	 *  
+	 */
+	public void setUp() throws Exception {
+		super.setUp() ;
+
+		// get set up for asynchronous start of our failing host
+		String failingHost = System.getProperty("jbosstest.cluster.node1") ;
+		if (failingHost == null)
+			throw new Exception("System property jbosstest.cluster.node1 not set") ;
+
+		// set the server configuration used by ScriptsTestBase
+		System.setProperty("jbosstest.server.config", "datagrid-failover-1") ;
+
+		// get the server host for the second server
+		servers = new String[2] ;
+		servers[0] = getServerHost() ;
+		servers[1] = failingHost ;
+
+		// in case we need it
+		hotRodServerList = servers[0] + ":" + "11222" + ";" + servers[1] + ":" + "11222";		
+	}
+
+	/*
+	 * Per-test case tear down
+	 */
+	public void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	/*
+	 * Tests the startup of the second server
+	 */
+	public void testFailoverWithCleanShutdown() throws Exception {
+
+		// start the AS instance datagrid-failover-0
+		startFailingHost() ;
+		
+		// get a CacheManager and a cache
+		Properties testProps = new Properties() ;
+		testProps.putAll(defaultProperties) ;
+		testProps.put("infinispan.client.hotrod.server_list", hotRodServerList) ;
+
+		RemoteCacheManager rcm = new RemoteCacheManager(testProps) ;
+		RemoteCache rc = rcm.getCache() ;
+
+		// now perform some data grid operations
+		System.out.println("Putting keys and values") ;
+		rc.put("key1", "value1") ;
+		rc.put("key2", "value2") ;
+		rc.put("key3", "value3") ;
+		
+		System.out.println("Getting keys and values before server shutdown") ;
+		assertTrue("key1 not accessible before server shutdown", rc.get("key1").equals("value1")) ;
+		assertTrue("key2 not accessible before server shutdown", rc.get("key2").equals("value2")) ;
+		assertTrue("key3 not accessible before server shutdown", rc.get("key3").equals("value3")) ;
+		
+		// now stop the server we started
+		stopFailingHostByCleanShutdown() ;
+		
+		System.out.println("Getting keys and values after server shutdown") ;
+		assertTrue("key1 not accessible after server shutdown", rc.get("key1").equals("value1")) ;
+		assertTrue("key2 not accessible after server shutdown", rc.get("key2").equals("value2")) ;
+		assertTrue("key3 not accessible after server shutdown", rc.get("key3").equals("value3")) ;
+	}
+
+	/*
+	 * Tests the startup of the second server
+	 */
+//	public void testFailoverWithCrash() throws Exception {
+//
+//		// start the AS instance datagrid-failover-0
+//		startFailingHost() ;
+//		
+//		// get a CacheManager and a cache
+//		Properties testProps = new Properties() ;
+//		testProps.put("infinispan.client.hotrod.server_list", hotRodServerList) ;
+//
+//		RemoteCacheManager rcm = new RemoteCacheManager(testProps) ;
+//		RemoteCache rc = rcm.getCache() ;
+//
+//		// now perform some data grid operations
+//		rc.put("key1", "value1") ;
+//		rc.put("key2", "value2") ;
+//		rc.put("key3", "value3") ;
+//		
+//		// now stop the server we started
+//		stopFailingHostByCrash() ;
+//		
+//		assertTrue("key1 not accessible after server shutdown", rc.get("key1").equals("value1")) ;
+//		assertTrue("key2 not accessible after server shutdown", rc.get("key2").equals("value2")) ;
+//		assertTrue("key3 not accessible after server shutdown", rc.get("key3").equals("value3")) ;
+//	}
+	
+	
+	/**
+	 * Start the failing host and check that it has started, failing the test if it has not
+	 */
+	private void startFailingHost() throws Exception {
+
+		final int STARTUP_TIMEOUT = 90 ;
+		
+		// build the shell command to execute
+		String command = "run" ;
+		String options = " -c " + getServerConfig() + " -b " + servers[1]   ;  
+		String args = null ;
+
+		String[] shellCommand = getShellCommand(command, options, args) ;
+		String[] envp = null ;
+		File workingDir = new File(getBinDir()) ;
+
+		// execute command
+		getAsyncShellScriptExecutor().startShellCommand(shellCommand, envp, workingDir) ; 
+
+		// waitForServerStart kills the process and throws an exception if server does not start 
+		try {
+			ScriptsTestBase.waitForServerStart(getAsyncShellScriptExecutor(), servers[1], STARTUP_TIMEOUT) ;
+			System.out.println("Server started successfully") ;
+		}
+		catch(IOException e) {
+			System.out.println("IOException: message = " + e.getMessage()) ;
+			writeLogsToTestCase() ;   
+			fail("Server failed to start") ;
+		}		
+	}
+
+	private void stopFailingHostByCleanShutdown() throws Exception {
+		
+		final int SHUTDOWN_TIMEOUT = 90 ;
+
+		// use the JMX operation shutdown to stop the server
+		MBeanServerConnection jmxServer = getMBeanServerConnection(servers[1], 1099) ;
+		jmxServer.invoke(SERVER_OBJ_NAME, "shutdown", new Object[0], new String[0]);
+		System.out.println("shutdown successfully invoked on MBean jboss.system:type=Server; waiting for shutdown") ;
+
+		// waitForServerStop kills the process and throws an exception if server does not stop 
+		try {
+			// kill the process by supplying a timeout of 0 ms
+			// getAsyncShellScriptExecutor().joinShellCommand(20);
+			ScriptsTestBase.waitForServerStop(getAsyncShellScriptExecutor(), SHUTDOWN_TIMEOUT);
+			System.out.println("Server killed successfully") ;
+		}
+		catch(Exception e) {
+			System.out.println("IOException: message = " + e.getMessage()) ;
+			writeLogsToTestCase() ;
+
+			fail("Server failed to die") ;
+		}
+		
+	}
+
+	private void stopFailingHostByCrash() {
+		
+		// use Process.destroy() to stop the server
+		// waitForServerStop kills the process and throws an exception if server does not stop 
+		try {
+			// kill the process by supplying a timeout of 0 ms
+			getAsyncShellScriptExecutor().joinShellCommand(0);
+			System.out.println("Server killed successfully") ;
+		}
+		catch(Exception e) {
+			System.out.println("IOException: message = " + e.getMessage()) ;
+			writeLogsToTestCase() ;
+
+			fail("Server failed to die") ;
+		}
+				
+	}
+	
+
+	/**
+	 * Get an MBeanServerConection to the AS instance at host:port
+	 */
+	private MBeanServerConnection getMBeanServerConnection(String host, int port) throws Exception {
+
+		Hashtable env = new Hashtable() ;
+		env.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+		env.put("java.naming.factory.url.pkgs", "org.jnp.interfaces");
+		env.put("java.naming.provider.url","jnp://" + host + ":" + port);
+
+		InitialContext ctx = new InitialContext(env) ;
+		MBeanServerConnection jmx = (MBeanServerConnection) ctx.lookup("jmx/invoker/RMIAdaptor");	
+
+		return jmx ;
+	}
+
+	private void writeLogsToTestCase() {
+
+		// write the logs to output for diagnosis
+		System.out.println("============================== system.out ==============================") ;
+		System.out.println(getAsyncShellScriptExecutor().getOutput()) ;
+		System.out.println("============================== system.err ==============================") ;
+		System.out.println(getAsyncShellScriptExecutor().getError()) ;
+		System.out.println("========================================================================") ;	   
+	}
+}
+

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-27 21:51:38 UTC (rev 110477)
+++ branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/HotRodClientRemoteCacheManagerTestCase.java	2011-01-27 22:13:38 UTC (rev 110478)
@@ -52,7 +52,9 @@
 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.Transport;
 import org.infinispan.client.hotrod.impl.transport.tcp.TcpTransportFactory;
+import org.infinispan.client.hotrod.impl.transport.tcp.TcpTransport;
 import org.infinispan.client.hotrod.impl.transport.tcp.RequestBalancingStrategy;
 import org.infinispan.client.hotrod.impl.operations.OperationsFactory;
 
@@ -110,6 +112,7 @@
 	private RemoteCache remoteCache;
 	private RemoteCacheManager remoteCacheManager;
 
+	private String[] servers = null ;
 	private String hotRodServerList = null ;
 
 	public HotRodClientRemoteCacheManagerTestCase(String name) {
@@ -152,7 +155,7 @@
 	public void setUp() throws Exception {
 		super.setUp() ;
 
-		String[] servers = getServers() ;
+		servers = getServers() ;
 		// in case we need it
 		hotRodServerList = servers[0] + ":" + "11222" + ";" + servers[1] + ":" + "11222";		
 	}
@@ -320,6 +323,96 @@
 	}
 		
 	/*
+	 * Tests the load balancing feature 
+	 * 
+	 * Checks that the default load balancing strategy, RoundRobin, will cycle 
+	 * through the server list as operations are executed. 
+	 * 
+	 * For each operation executed, we would need to obtain its Transport and 
+	 * call getServerAddress() to discover which address was used, but this is
+	 * difficult to arrange. So instead, we simulate by making repeated calls
+	 * to TransportFactory.getTransport() 
+	 * 
+	 */
+	public void testDefaultLoadBalancing() throws Exception {
+		
+		// the InetSocketAddress instances which this test should be using
+		InetSocketAddress hostport0 = new InetSocketAddress(servers[0], 11222) ;
+		InetSocketAddress hostport1 = new InetSocketAddress(servers[1], 11222) ;
+		
+		TcpTransport tt = null ;
+		InetSocketAddress sock_addr = null ;
+		
+		RemoteCacheManager rcm = new RemoteCacheManager() ;
+		RemoteCache rc = rcm.getCache() ;		
+		RemoteCacheImpl rci = (RemoteCacheImpl) rc ;
+		// the factory used to create all remote operations for this class 
+		OperationsFactory of = getOperationsFactoryField(rci) ;
+		TcpTransportFactory ttf = (TcpTransportFactory) getTransportFactoryField(of) ;
+
+		// perform first simulated operation
+		tt = (TcpTransport) ttf.getTransport() ;
+		sock_addr = tt.getServerAddress() ;
+		ttf.releaseTransport(tt) ;
+		assertTrue("load balancing first request: server address expected " + hostport0 + ", actual server address " + sock_addr, sock_addr.equals(hostport0)) ;
+		
+		tt = (TcpTransport) ttf.getTransport() ;
+		sock_addr = tt.getServerAddress() ;
+		ttf.releaseTransport(tt) ;
+		assertTrue("load balancing second request: server address expected " + hostport1 + ", actual server address" + sock_addr, sock_addr.equals(hostport1)) ;
+		
+		tt = (TcpTransport) ttf.getTransport() ;
+		sock_addr = tt.getServerAddress() ;
+		ttf.releaseTransport(tt) ;
+		assertTrue("load balancing third request: server address expected " + hostport0 + ", actual server address" + sock_addr, sock_addr.equals(hostport0)) ;
+	}
+	
+	/*
+	 * Tests the load balancing feature 
+	 * 
+	 * Checks that a custom load balancing strategy, Node0Only, will cycle 
+	 * through the server list as operations are executed. 
+	 * 
+	 * NOTE: the default properties have a server list of node0/node1.
+	 */
+	public void testCustomLoadBalancing() throws Exception {
+		
+		// the InetSocketAddress instances which this test should be using
+		InetSocketAddress hostport0 = new InetSocketAddress(servers[0], 11222) ;
+		InetSocketAddress hostport1 = new InetSocketAddress(servers[1], 11222) ;
+		
+		TcpTransport tt = null ;
+		InetSocketAddress sock_addr = null ;
+		
+		
+		// create a set of test properties to specify the custom balancer
+		Properties testProps = new Properties() ;
+		testProps.putAll(testProperties) ;
+		testProps.put("infinispan.client.hotrod.request_balancing_strategy", "org.jboss.test.cluster.datagrid.hotrod.Node0OnlyBalancingStrategy") ;
+		testProps.put("infinispan.client.hotrod.server_list", hotRodServerList) ;
+		
+		RemoteCacheManager rcm = new RemoteCacheManager(testProps) ;
+		RemoteCache rc = rcm.getCache() ;		
+		RemoteCacheImpl rci = (RemoteCacheImpl) rc ;
+		// the factory used to create all remote operations for this class 
+		OperationsFactory of = getOperationsFactoryField(rci) ;
+		TcpTransportFactory ttf = (TcpTransportFactory) getTransportFactoryField(of) ;
+
+		// perform first simulated operation
+		tt = (TcpTransport) ttf.getTransport() ;
+		sock_addr = tt.getServerAddress() ;
+		ttf.releaseTransport(tt) ;
+		assertTrue("load balancing first request: server address expected " + hostport0 + ", actual server address " + sock_addr, sock_addr.equals(hostport0)) ;
+		
+		tt = (TcpTransport) ttf.getTransport() ;
+		sock_addr = tt.getServerAddress() ;
+		ttf.releaseTransport(tt) ;
+		assertTrue("load balancing second request: server address expected " + hostport0 + ", actual server address" + sock_addr, sock_addr.equals(hostport0)) ;		
+	}
+	
+	
+	
+	/*
 	 * Tests the setting of ConfigurationProperties instance
 	 */
 	public void testConfigurationProperties() throws Exception {



More information about the jboss-cvs-commits mailing list