Permalink
Browse files

ISPN-2551 Make the HotRod client testsuite clean up all dangling threads

  • Loading branch information...
1 parent 91e927b commit 5336ca9ac037dd152b7e0a2d8fd35b1451f3b5cb @tristantarrant tristantarrant committed Nov 26, 2012
Showing with 62 additions and 28 deletions.
  1. +6 −6 cachestore/remote/src/test/java/org/infinispan/loaders/remote/RemoteCacheStoreRawValuesTest.java
  2. +1 −0 cachestore/remote/src/test/java/org/infinispan/loaders/remote/RemoteCacheStoreTest.java
  3. +10 −0 client/hotrod-client/src/test/java/org/infinispan/client/hotrod/BulkGetSimpleTest.java
  4. +2 −0 client/hotrod-client/src/test/java/org/infinispan/client/hotrod/CacheContainerTest.java
  5. +2 −1 client/hotrod-client/src/test/java/org/infinispan/client/hotrod/CacheManagerStoppedTest.java
  6. +0 −3 client/hotrod-client/src/test/java/org/infinispan/client/hotrod/DefaultExpirationTest.java
  7. +4 −3 client/hotrod-client/src/test/java/org/infinispan/client/hotrod/DroppedConnectionsTest.java
  8. +4 −2 client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HeavyLoadConnectionPoolingTest.java
  9. +3 −0 client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodServerStartStopTest.java
  10. +3 −2 client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodStatisticsTest.java
  11. +4 −2 client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RemoteAsyncAPITest.java
  12. +2 −1 client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RemoteCacheManagerTest.java
  13. +8 −6 .../hotrod-client/src/test/java/org/infinispan/client/hotrod/RoundRobinBalancingIntegrationTest.java
  14. +4 −2 client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ServerErrorTest.java
  15. +9 −0 client/hotrod-client/src/test/java/org/infinispan/client/hotrod/SocketTimeoutErrorTest.java
@@ -56,19 +56,19 @@
@Override
protected CacheStore createCacheStore() throws Exception {
- RemoteCacheStoreConfig remoteCacheStoreConfig = new RemoteCacheStoreConfig();
- remoteCacheStoreConfig.setPurgeSynchronously(true);
- remoteCacheStoreConfig.setUseDefaultRemoteCache(true);
- remoteCacheStoreConfig.setRawValues(true);
- assert remoteCacheStoreConfig.isUseDefaultRemoteCache();
-
ConfigurationBuilder cb = TestCacheManagerFactory.getDefaultCacheConfiguration(true);
cb.eviction().maxEntries(100).strategy(EvictionStrategy.UNORDERED)
.expiration().wakeUpInterval(10L);
localCacheManager = TestCacheManagerFactory.createCacheManager(cb);
hrServer = TestHelper.startHotRodServer(localCacheManager);
+ RemoteCacheStoreConfig remoteCacheStoreConfig = new RemoteCacheStoreConfig();
+ remoteCacheStoreConfig.setPurgeSynchronously(true);
+ remoteCacheStoreConfig.setUseDefaultRemoteCache(true);
+ remoteCacheStoreConfig.setRawValues(true);
+ assert remoteCacheStoreConfig.isUseDefaultRemoteCache();
+
Properties properties = new Properties();
properties.put("infinispan.client.hotrod.server_list", "localhost:" + hrServer.getPort());
remoteCacheStoreConfig.setHotRodClientProperties(properties);
@@ -62,6 +62,7 @@ protected CacheStore createCacheStore() throws Exception {
localCacheManager = TestCacheManagerFactory.createCacheManager(cb);
hrServer = TestHelper.startHotRodServer(localCacheManager);
+
Properties properties = new Properties();
properties.put("infinispan.client.hotrod.server_list", "localhost:" + hrServer.getPort());
remoteCacheStoreConfig.setHotRodClientProperties(properties);
@@ -22,17 +22,21 @@
*/
package org.infinispan.client.hotrod;
+import org.infinispan.client.hotrod.test.HotRodClientTestingUtil;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.server.hotrod.HotRodServer;
import org.infinispan.test.SingleCacheManagerTest;
import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
+import static org.infinispan.client.hotrod.test.HotRodClientTestingUtil.*;
+import static org.infinispan.test.TestingUtil.killCacheManagers;
import static org.testng.AssertJUnit.assertEquals;
/**
@@ -62,6 +66,12 @@ protected EmbeddedCacheManager createCacheManager() throws Exception {
return cacheManager;
}
+ @AfterTest(alwaysRun = true)
+ public void release() {
+ killRemoteCacheManager(remoteCacheManager);
+ killServers(hotRodServer);
+ }
+
private void populateCacheManager() {
for (int i = 0; i < 100; i++) {
remoteCache.put(i, i);
@@ -23,6 +23,7 @@
package org.infinispan.client.hotrod;
import org.infinispan.api.BasicCache;
+import org.infinispan.client.hotrod.test.HotRodClientTestingUtil;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.server.hotrod.HotRodServer;
@@ -59,6 +60,7 @@ protected EmbeddedCacheManager createCacheManager() throws Exception {
@AfterTest(alwaysRun = true)
public void release() {
killCacheManagers(cacheManager);
+ killRemoteCacheManager(remoteCacheManager);
killServers(hotrodServer);
}
@@ -60,6 +60,7 @@ protected EmbeddedCacheManager createCacheManager() throws Exception {
@AfterTest(alwaysRun = true)
public void release() {
+ killRemoteCacheManager(remoteCacheManager);
killCacheManagers(cacheManager);
killServers(hotrodServer);
}
@@ -68,7 +69,7 @@ public void testGetCacheOperations() {
assert remoteCacheManager.getCache() != null;
assert remoteCacheManager.getCache(CACHE_NAME) != null;
remoteCache().put("k", "v");
- assert remoteCache().get("k").equals("v");
+ assert remoteCache().get("k").equals("v");
}
@Test (dependsOnMethods = "testGetCacheOperations")
@@ -20,16 +20,13 @@
import org.testng.annotations.Test;
import org.testng.AssertJUnit;
-import java.io.IOException;
-import java.util.Arrays;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.infinispan.Cache;
import org.infinispan.client.hotrod.test.HotRodClientTestingUtil;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.container.entries.InternalCacheEntry;
-import org.infinispan.container.entries.MortalCacheEntry;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.marshall.Marshaller;
import org.infinispan.marshall.jboss.JBossMarshaller;
@@ -25,6 +25,7 @@
import org.apache.commons.pool.impl.GenericKeyedObjectPool;
import org.infinispan.client.hotrod.impl.transport.tcp.TcpTransport;
import org.infinispan.client.hotrod.impl.transport.tcp.TcpTransportFactory;
+import org.infinispan.client.hotrod.test.HotRodClientTestingUtil;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.server.hotrod.HotRodServer;
import org.infinispan.test.SingleCacheManagerTest;
@@ -69,8 +70,8 @@ protected EmbeddedCacheManager createCacheManager() throws Exception {
@Override
protected void teardown() {
super.teardown();
- remoteCacheManager.stop();
- hotRodServer.stop();
+ HotRodClientTestingUtil.killRemoteCacheManager(remoteCacheManager);
+ HotRodClientTestingUtil.killServers(hotRodServer);
}
public void testClosedConnection() throws Exception {
@@ -95,5 +96,5 @@ public void testClosedConnection() throws Exception {
assert tcpConnection2.getId() != tcpConnection.getId();
}
-
+
}
@@ -41,6 +41,8 @@
import java.util.Properties;
import java.util.concurrent.ExecutionException;
+import static org.infinispan.client.hotrod.test.HotRodClientTestingUtil.killRemoteCacheManager;
+import static org.infinispan.client.hotrod.test.HotRodClientTestingUtil.killServers;
import static org.testng.AssertJUnit.assertEquals;
/**
@@ -88,8 +90,8 @@ protected EmbeddedCacheManager createCacheManager() throws Exception {
@Override
protected void destroyAfterClass() {
super.destroyAfterClass();
- remoteCacheManager.stop();
- hotRodServer.stop();
+ killRemoteCacheManager(remoteCacheManager);
+ killServers(hotRodServer);
}
public void testHeavyLoad() throws InterruptedException, ExecutionException {
@@ -29,6 +29,8 @@
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
+import static org.infinispan.client.hotrod.test.HotRodClientTestingUtil.killRemoteCacheManager;
+import static org.infinispan.client.hotrod.test.HotRodClientTestingUtil.killServers;
import static org.testng.AssertJUnit.assertEquals;
/**
@@ -68,6 +70,7 @@ public void testTouchServer() {
RemoteCache<Object, Object> remoteCache = remoteCacheManager.getCache();
remoteCache.put("k", "v");
assertEquals("v", remoteCache.get("k"));
+ killRemoteCacheManager(remoteCacheManager);
}
@Test (dependsOnMethods = "testTouchServer")
@@ -33,6 +33,7 @@
import java.util.Map;
+import static org.infinispan.client.hotrod.test.HotRodClientTestingUtil.*;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
@@ -62,8 +63,8 @@ protected void setup() throws Exception {
@AfterMethod(alwaysRun = true)
void tearDown() {
TestingUtil.killCacheManagers(cacheContainer);
- rcm.stop();
- hotrodServer.stop();
+ killRemoteCacheManager(rcm);
+ killServers(hotrodServer);
}
public void testAllStatsArePresent() {
@@ -35,6 +35,8 @@
import java.util.concurrent.Future;
import static junit.framework.Assert.assertEquals;
+import static org.infinispan.client.hotrod.test.HotRodClientTestingUtil.killRemoteCacheManager;
+import static org.infinispan.client.hotrod.test.HotRodClientTestingUtil.killServers;
/**
* @author Mircea.Markus@jboss.com
@@ -64,8 +66,8 @@ protected EmbeddedCacheManager createCacheManager() throws Exception {
@Override
protected void destroyAfterClass() {
super.destroyAfterClass();
- rcm.stop();
- hotrodServer.stop();
+ killRemoteCacheManager(rcm);
+ killServers(hotrodServer);
}
public void testAsyncPut() throws Exception {
@@ -80,7 +80,7 @@ public void testBooleanConstructor() {
remoteCacheManager.start();
remoteCacheManager.stop();
}
-
+
public void testUrlAndBooleanConstructor() throws Exception {
URL resource = Thread.currentThread().getContextClassLoader().getResource("empty-config.properties");
assert resource != null;
@@ -126,6 +126,7 @@ public void testGetUndefinedCache() {
assert !remoteCacheManager.isStarted();
remoteCacheManager.start();
assert null == remoteCacheManager.getCache("Undefined1234");
+ remoteCacheManager.stop();
}
private void assertWorks(RemoteCacheManager remoteCacheManager) {
@@ -40,6 +40,8 @@
import java.util.ArrayList;
import java.util.List;
+import static org.infinispan.client.hotrod.test.HotRodClientTestingUtil.killRemoteCacheManager;
+import static org.infinispan.client.hotrod.test.HotRodClientTestingUtil.killServers;
import static org.testng.AssertJUnit.assertEquals;
/**
@@ -64,6 +66,8 @@
RemoteCache<String, String> remoteCache;
+ private RemoteCacheManager remoteCacheManager;
+
@Override
protected void assertSupportedConfig() {
return;
@@ -85,16 +89,14 @@ protected void createCacheManagers() throws Throwable {
log.trace("Server 3 port: " + hotRodServer3.getPort());
String servers = TestHelper.getServersString(hotRodServer1, hotRodServer2, hotRodServer3);
log.trace("Server list is: " + servers);
- RemoteCacheManager remoteCacheManager = new RemoteCacheManager(servers);
+ remoteCacheManager = new RemoteCacheManager(servers);
remoteCache = remoteCacheManager.getCache();
}
@AfterTest(alwaysRun = true)
public void tearDown() {
- hotRodServer1.stop();
- hotRodServer2.stop();
- hotRodServer3.stop();
- hotRodServer4.stop();
+ killRemoteCacheManager(remoteCacheManager);
+ killServers(hotRodServer1, hotRodServer2, hotRodServer3, hotRodServer4);
}
public void testRoundRobinLoadBalancing() {
@@ -125,7 +127,7 @@ public void testRoundRobinLoadBalancing() {
@Test(dependsOnMethods = "testRoundRobinLoadBalancing")
public void testAddNewHotrodServer() {
c4 = TestCacheManagerFactory.createLocalCacheManager(false).getCache();
- hotRodServer4 = TestHelper.startHotRodServer((EmbeddedCacheManager) c4.getCacheManager());
+ hotRodServer4 = TestHelper.startHotRodServer(c4.getCacheManager());
registerCacheManager(c4.getCacheManager());
List<SocketAddress> serverAddresses = new ArrayList<SocketAddress>();
@@ -41,6 +41,8 @@
import java.lang.reflect.Method;
import java.util.Properties;
+import static org.infinispan.client.hotrod.test.HotRodClientTestingUtil.killRemoteCacheManager;
+import static org.infinispan.client.hotrod.test.HotRodClientTestingUtil.killServers;
import static org.infinispan.test.TestingUtil.k;
import static org.infinispan.test.TestingUtil.v;
@@ -76,8 +78,8 @@ protected RemoteCacheManager getRemoteCacheManager() {
@AfterClass(alwaysRun = true)
public void shutDownHotrod() {
- remoteCacheManager.stop();
- hotrodServer.stop();
+ killRemoteCacheManager(remoteCacheManager);
+ killServers(hotrodServer);
}
public void testErrorWhileDoingPut(Method m) throws Exception {
@@ -23,6 +23,8 @@
package org.infinispan.client.hotrod;
+import static org.infinispan.client.hotrod.test.HotRodClientTestingUtil.killRemoteCacheManager;
+import static org.infinispan.client.hotrod.test.HotRodClientTestingUtil.killServers;
import static org.infinispan.test.TestingUtil.*;
import java.lang.reflect.Method;
@@ -79,6 +81,13 @@ protected void setup() throws Exception {
remoteCache = remoteCacheManager.getCache();
}
+ @Override
+ protected void teardown() {
+ killRemoteCacheManager(remoteCacheManager);
+ killServers(hotrodServer);
+ super.teardown();
+ }
+
protected Properties getClientProperties() {
Properties props = new Properties();
props.put("infinispan.client.hotrod.server_list", "127.0.0.1:" + hotrodServer.getPort());

0 comments on commit 5336ca9

Please sign in to comment.