[infinispan-commits] Infinispan SVN: r2014 - in branches/4.1.x/client/hotrod-client/src: main/java/org/infinispan/client/hotrod/impl/protocol and 4 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Mon Jul 12 06:39:50 EDT 2010
Author: mircea.markus
Date: 2010-07-12 06:39:49 -0400 (Mon, 12 Jul 2010)
New Revision: 2014
Modified:
branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java
branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/protocol/HotRodOperationsImpl.java
branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/TransportFactory.java
branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/NettyTransportFactory.java
branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TcpTransportFactory.java
branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TransportObjectFactory.java
branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/CSAIntegrationTest.java
branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/CacheManagerNotStartedTest.java
branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ClientConnectionPoolingTest.java
branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/DroppedConnectionsTest.java
branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValueTest.java
branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HeavyLoadConnectionPoolingTest.java
branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodServerStartStopTest.java
branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/PingOnStartupTest.java
branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RemoteAsyncAPITest.java
branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ReplTopologyChangeTest.java
branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/WorkerThread.java
Log:
ISPN-505-Hot Rod client to send a ping as part of connection to get topology
- various improvements
- tests cleanup resorces better now
Modified: branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java 2010-07-12 08:09:33 UTC (rev 2013)
+++ branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java 2010-07-12 10:39:49 UTC (rev 2014)
@@ -3,7 +3,6 @@
import org.infinispan.client.hotrod.exceptions.HotRodClientException;
import org.infinispan.client.hotrod.impl.async.DefaultAsyncExecutorFactory;
import org.infinispan.client.hotrod.impl.protocol.HotRodOperations;
-import org.infinispan.client.hotrod.impl.protocol.HotRodOperationsHelper;
import org.infinispan.client.hotrod.impl.protocol.HotRodOperationsImpl;
import org.infinispan.client.hotrod.impl.RemoteCacheImpl;
import org.infinispan.client.hotrod.impl.SerializationMarshaller;
@@ -329,20 +328,8 @@
}
}
started = true;
- ping();
}
- private void ping() {
- String pingOnStartup = props.getProperty("ping-on-startup");
- if (pingOnStartup != null && !Boolean.valueOf(pingOnStartup)) {
- if (log.isTraceEnabled()) {
- log.trace("Not pinging on startup as: 'ping-on-startup' = " + pingOnStartup);
- }
- } else {
- transportFactory.ping();
- }
- }
-
@Override
public void stop() {
transportFactory.destroy();
Modified: branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/protocol/HotRodOperationsImpl.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/protocol/HotRodOperationsImpl.java 2010-07-12 08:09:33 UTC (rev 2013)
+++ branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/protocol/HotRodOperationsImpl.java 2010-07-12 10:39:49 UTC (rev 2014)
@@ -34,9 +34,10 @@
}
public byte[] get(byte[] key, Flag[] flags) {
- for (int i = 0; i < transportFactory.getTransportCount(); i++) {
+ Transport transport = getTransport(key, true);
+ int retryCount = 0;
+ do {
try {
- Transport transport = getTransport(key, i == 0);
try {
short status = sendKeyOperation(key, transport, GET_REQUEST, flags, GET_RESPONSE);
if (status == KEY_DOES_NOT_EXIST_STATUS) {
@@ -49,15 +50,20 @@
releaseTransport(transport);
}
} catch (TransportException te) {
- logErrorAndThrowExceptionIfNeeded(i, te);
+ logErrorAndThrowExceptionIfNeeded(retryCount, te);
}
- }
+ if (shouldRetry(retryCount)) {
+ transport = getTransport(key, false);
+ }
+ retryCount++;
+ } while (shouldRetry(retryCount));
throw new IllegalStateException("We should not reach here!");
}
public byte[] remove(byte[] key, Flag[] flags) {
- for (int i = 0; i < transportFactory.getTransportCount(); i++) {
- Transport transport = getTransport(key, i == 0);
+ Transport transport = getTransport(key, true);
+ int retryCount = 0;
+ do {
try {
short status = sendKeyOperation(key, transport, REMOVE_REQUEST, flags, REMOVE_RESPONSE);
if (status == KEY_DOES_NOT_EXIST_STATUS) {
@@ -66,17 +72,22 @@
return returnPossiblePrevValue(transport, flags);
}
} catch (TransportException te) {
- logErrorAndThrowExceptionIfNeeded(i, te);
+ logErrorAndThrowExceptionIfNeeded(retryCount, te);
} finally {
releaseTransport(transport);
}
- }
+ if (shouldRetry(retryCount)) {
+ transport = getTransport(key, false);
+ }
+ retryCount++;
+ } while (shouldRetry(retryCount));
throw new IllegalStateException("We should not reach here!");
}
public boolean containsKey(byte[] key, Flag... flags) {
- for (int i = 0; i < transportFactory.getTransportCount(); i++) {
- Transport transport = getTransport(key, i == 0);
+ Transport transport = getTransport(key, true);
+ int retryCount = 0;
+ do {
try {
short status = sendKeyOperation(key, transport, CONTAINS_KEY_REQUEST, flags, CONTAINS_KEY_RESPONSE);
if (status == KEY_DOES_NOT_EXIST_STATUS) {
@@ -85,18 +96,24 @@
return true;
}
} catch (TransportException te) {
- logErrorAndThrowExceptionIfNeeded(i, te);
+ logErrorAndThrowExceptionIfNeeded(retryCount, te);
}
finally {
releaseTransport(transport);
}
- }
+ if (shouldRetry(retryCount)) {
+ transport = getTransport(key, false);
+ }
+ retryCount++;
+
+ } while (shouldRetry(retryCount));
throw new IllegalStateException("We should not reach here!");
}
public BinaryVersionedValue getWithVersion(byte[] key, Flag... flags) {
- for (int i = 0; i < transportFactory.getTransportCount(); i++) {
- Transport transport = getTransport(key, i == 0);
+ Transport transport = getTransport(key, true);
+ int retryCount = 0;
+ do {
try {
short status = sendKeyOperation(key, transport, GET_WITH_VERSION, flags, GET_WITH_VERSION_RESPONSE);
if (status == KEY_DOES_NOT_EXIST_STATUS) {
@@ -111,18 +128,23 @@
return new BinaryVersionedValue(version, value);
}
} catch (TransportException te) {
- logErrorAndThrowExceptionIfNeeded(i, te);
+ logErrorAndThrowExceptionIfNeeded(retryCount, te);
} finally {
releaseTransport(transport);
}
- }
+ if (shouldRetry(retryCount)) {
+ transport = getTransport(key, false);
+ }
+ retryCount++;
+ } while (shouldRetry(retryCount));
throw new IllegalStateException("We should not reach here!");
}
public byte[] put(byte[] key, byte[] value, int lifespan, int maxIdle, Flag... flags) {
- for (int i = 0; i < transportFactory.getTransportCount(); i++) {
- Transport transport = getTransport(key, i == 0);
+ Transport transport = getTransport(key, true);
+ int retryCount = 0;
+ do {
try {
short status = sendPutOperation(key, value, transport, PUT_REQUEST, PUT_RESPONSE, lifespan, maxIdle, flags);
if (status != NO_ERROR_STATUS) {
@@ -130,17 +152,22 @@
}
return returnPossiblePrevValue(transport, flags);
} catch (TransportException te) {
- logErrorAndThrowExceptionIfNeeded(i, te);
+ logErrorAndThrowExceptionIfNeeded(retryCount, te);
} finally {
releaseTransport(transport);
}
- }
- throw new IllegalStateException("This should not be reached!");
+ if (shouldRetry(retryCount)) {
+ transport = getTransport(key, false);
+ }
+ retryCount++;
+ } while (shouldRetry(retryCount));
+ throw new IllegalStateException("We should not reach here!");
}
public byte[] putIfAbsent(byte[] key, byte[] value, int lifespan, int maxIdle, Flag... flags) {
- for (int i = 0; i < transportFactory.getTransportCount(); i++) {
- Transport transport = getTransport(key, i == 0);
+ Transport transport = getTransport(key, true);
+ int retryCount = 0;
+ do {
try {
short status = sendPutOperation(key, value, transport, PUT_IF_ABSENT_REQUEST, PUT_IF_ABSENT_RESPONSE, lifespan, maxIdle, flags);
if (status == NO_ERROR_STATUS || status == NOT_PUT_REMOVED_REPLACED_STATUS) {
@@ -151,29 +178,38 @@
return bytes;
}
} catch (TransportException te) {
- logErrorAndThrowExceptionIfNeeded(i, te);
+ logErrorAndThrowExceptionIfNeeded(retryCount, te);
}
finally {
releaseTransport(transport);
}
- }
+ if (shouldRetry(retryCount)) {
+ transport = getTransport(key, false);
+ }
+ retryCount++;
+ } while (shouldRetry(retryCount));
throw new IllegalStateException("We should not reach here!");
}
public byte[] replace(byte[] key, byte[] value, int lifespan, int maxIdle, Flag... flags) {
- for (int i = 0; i < transportFactory.getTransportCount(); i++) {
- Transport transport = getTransport(key, i == 0);
+ Transport transport = getTransport(key, true);
+ int retryCount = 0;
+ do {
try {
short status = sendPutOperation(key, value, transport, REPLACE_REQUEST, REPLACE_RESPONSE, lifespan, maxIdle, flags);
if (status == NO_ERROR_STATUS || status == NOT_PUT_REMOVED_REPLACED_STATUS) {
return returnPossiblePrevValue(transport, flags);
}
} catch (TransportException te) {
- logErrorAndThrowExceptionIfNeeded(i, te);
+ logErrorAndThrowExceptionIfNeeded(retryCount, te);
} finally {
releaseTransport(transport);
}
- }
+ if (shouldRetry(retryCount)) {
+ transport = getTransport(key, false);
+ }
+ retryCount++;
+ } while (shouldRetry(retryCount));
throw new IllegalStateException(" should not reach here!");
}
@@ -184,8 +220,9 @@
* was sent, the response would be empty.
*/
public VersionedOperationResponse replaceIfUnmodified(byte[] key, byte[] value, int lifespan, int maxIdle, long version, Flag... flags) {
- for (int i = 0; i < transportFactory.getTransportCount(); i++) {
- Transport transport = getTransport(key, i == 0);
+ Transport transport = getTransport(key, true);
+ int retryCount = 0;
+ do {
try {
// 1) write header
long messageId = HotRodOperationsHelper.writeHeader(transport, REPLACE_IF_UNMODIFIED_REQUEST, cacheName, topologyId, flags);
@@ -198,12 +235,16 @@
transport.writeArray(value);
return returnVersionedOperationResponse(transport, messageId, REPLACE_IF_UNMODIFIED_RESPONSE, flags);
} catch (TransportException te) {
- logErrorAndThrowExceptionIfNeeded(i, te);
+ logErrorAndThrowExceptionIfNeeded(retryCount, te);
}
finally {
releaseTransport(transport);
}
- }
+ if (shouldRetry(retryCount)) {
+ transport = getTransport(key, false);
+ }
+ retryCount++;
+ } while (shouldRetry(retryCount));
throw new IllegalStateException(" should not reach here!");
}
@@ -211,8 +252,9 @@
* Request: [header][key length][key][entry_version]
*/
public VersionedOperationResponse removeIfUnmodified(byte[] key, long version, Flag... flags) {
- for (int i = 0; i < transportFactory.getTransportCount(); i++) {
- Transport transport = getTransport(key, i == 0);
+ Transport transport = getTransport(key, true);
+ int retryCount = 0;
+ do {
try {
// 1) write header
long messageId = HotRodOperationsHelper.writeHeader(transport, REMOVE_IF_UNMODIFIED_REQUEST, cacheName, topologyId, flags);
@@ -225,28 +267,38 @@
return returnVersionedOperationResponse(transport, messageId, REMOVE_IF_UNMODIFIED_RESPONSE, flags);
} catch (TransportException te) {
- logErrorAndThrowExceptionIfNeeded(i, te);
+ logErrorAndThrowExceptionIfNeeded(retryCount, te);
}
finally {
releaseTransport(transport);
}
- }
+ if (shouldRetry(retryCount)) {
+ transport = getTransport(key, false);
+ }
+ retryCount++;
+ } while (shouldRetry(retryCount));
throw new IllegalStateException("Should not reach this point!");
}
public void clear(Flag... flags) {
- for (int i = 0; i < transportFactory.getTransportCount(); i++) {
- Transport transport = transportFactory.getTransport();
+ Transport transport = transportFactory.getTransport();
+ int retryCount = 0;
+ do {
try {
// 1) write header
long messageId = HotRodOperationsHelper.writeHeader(transport, CLEAR_REQUEST, cacheName, topologyId, flags);
HotRodOperationsHelper.readHeaderAndValidate(transport, messageId, CLEAR_RESPONSE, topologyId);
} catch (TransportException te) {
- logErrorAndThrowExceptionIfNeeded(i, te);
+ logErrorAndThrowExceptionIfNeeded(retryCount, te);
} finally {
releaseTransport(transport);
}
- }
+ if (shouldRetry(retryCount)) {
+ transport = transportFactory.getTransport();
+ }
+ retryCount++;
+
+ } while (shouldRetry(retryCount));
}
public Map<String, String> stats() {
@@ -347,7 +399,7 @@
private void logErrorAndThrowExceptionIfNeeded(int i, TransportException te) {
String message = "Transport exception. Retry " + i + " out of " + transportFactory.getTransportCount();
- if (i == transportFactory.getTransportCount() - 1) {
+ if (i == transportFactory.getTransportCount() - 1 || transportFactory.getTransportCount() < 0) {
log.warn(message, te);
throw te;
} else {
@@ -362,4 +414,8 @@
return transportFactory.getTransport();
}
}
+
+ private boolean shouldRetry(int retryCount) {
+ return retryCount < transportFactory.getTransportCount();
+ }
}
Modified: branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/TransportFactory.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/TransportFactory.java 2010-07-12 08:09:33 UTC (rev 2013)
+++ branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/TransportFactory.java 2010-07-12 10:39:49 UTC (rev 2014)
@@ -34,6 +34,4 @@
boolean isTcpNoDelay();
int getTransportCount();
-
- void ping();
}
Modified: branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/NettyTransportFactory.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/NettyTransportFactory.java 2010-07-12 08:09:33 UTC (rev 2013)
+++ branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/NettyTransportFactory.java 2010-07-12 10:39:49 UTC (rev 2014)
@@ -72,8 +72,4 @@
return 1;
}
- @Override
- public void ping() {
- //ignoring
- }
}
Modified: branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TcpTransportFactory.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TcpTransportFactory.java 2010-07-12 08:09:33 UTC (rev 2013)
+++ branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TcpTransportFactory.java 2010-07-12 10:39:49 UTC (rev 2014)
@@ -5,8 +5,6 @@
import org.infinispan.client.hotrod.exceptions.TransportException;
import org.infinispan.client.hotrod.impl.consistenthash.ConsistentHash;
import org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashFactory;
-import org.infinispan.client.hotrod.impl.protocol.HotRodConstants;
-import org.infinispan.client.hotrod.impl.protocol.HotRodOperationsHelper;
import org.infinispan.client.hotrod.impl.transport.Transport;
import org.infinispan.client.hotrod.impl.transport.TransportFactory;
import org.infinispan.client.hotrod.impl.transport.VHelper;
@@ -40,22 +38,34 @@
private volatile ConsistentHash consistentHash;
private volatile boolean tcpNoDelay;
private final ConsistentHashFactory hashFactory = new ConsistentHashFactory();
- private volatile AtomicInteger topologyId;
@Override
public void start(Properties props, Collection<InetSocketAddress> staticConfiguredServers, AtomicInteger topologyId) {
- this.topologyId = topologyId;
hashFactory.init(props);
+ String pingOnStartup = props.getProperty("ping-on-startup");
servers = staticConfiguredServers;
String balancerClass = props.getProperty("request-balancing-strategy", RoundRobinBalancingStrategy.class.getName());
balancer = (RequestBalancingStrategy) VHelper.newInstance(balancerClass);
tcpNoDelay = Boolean.valueOf(props.getProperty("tcp-no-delay", "true"));
if (log.isDebugEnabled()) log.debug("TCP no delay flag value is: {0}", tcpNoDelay);
- PropsKeyedObjectPoolFactory poolFactory = new PropsKeyedObjectPoolFactory(new TransportObjectFactory(this, topologyId), props);
- connectionPool = (GenericKeyedObjectPool) poolFactory.createPool();
+ boolean skipPingOnStartup = pingOnStartup != null && !Boolean.valueOf(pingOnStartup);
+ log.trace("'ping-on-startup' set to " + !skipPingOnStartup);
+ PropsKeyedObjectPoolFactory poolFactory = new PropsKeyedObjectPoolFactory(new TransportObjectFactory(this, topologyId, !skipPingOnStartup), props);
+ createAndPreparePool(staticConfiguredServers, poolFactory);
balancer.setServers(servers);
}
+ /**
+ * This will makes sure that, when the evictor thread kicks in the minIdle is set. We don't want to do this is the caller's thread,
+ * as this is the user.
+ */
+ private void createAndPreparePool(Collection<InetSocketAddress> staticConfiguredServers, PropsKeyedObjectPoolFactory poolFactory) {
+ connectionPool = (GenericKeyedObjectPool) poolFactory.createPool();
+ for (InetSocketAddress addr: staticConfiguredServers) {
+ connectionPool.preparePool(addr, false);
+ }
+ }
+
@Override
public void destroy() {
connectionPool.clear();
@@ -209,16 +219,6 @@
}
}
- @Override
- public void ping() {
- Transport transport = getTransport();
- try {
- HotRodOperationsHelper.ping(transport, topologyId);
- } finally {
- releaseTransport(transport);
- }
- }
-
public RequestBalancingStrategy getBalancer() {
return balancer;
}
Modified: branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TransportObjectFactory.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TransportObjectFactory.java 2010-07-12 08:09:33 UTC (rev 2013)
+++ branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TransportObjectFactory.java 2010-07-12 10:39:49 UTC (rev 2014)
@@ -17,10 +17,13 @@
private static final Log log = LogFactory.getLog(TransportObjectFactory.class);
private final TcpTransportFactory tcpTransportFactory;
private final AtomicInteger topologyId;
+ private final boolean pingOnStartup;
+ private volatile boolean firstPingExecuted = false;
- public TransportObjectFactory(TcpTransportFactory tcpTransportFactory, AtomicInteger topologyId) {
+ public TransportObjectFactory(TcpTransportFactory tcpTransportFactory, AtomicInteger topologyId, boolean pingOnStartup) {
this.tcpTransportFactory = tcpTransportFactory;
this.topologyId = topologyId;
+ this.pingOnStartup = pingOnStartup;
}
@Override
@@ -30,6 +33,15 @@
if (log.isTraceEnabled()) {
log.trace("Created tcp transport: " + tcpTransport);
}
+ if (pingOnStartup && !firstPingExecuted) {
+ log.trace("Executing first ping!");
+ firstPingExecuted = true;
+ try {
+ HotRodOperationsHelper.ping(tcpTransport, topologyId);
+ } catch (Exception e) {
+ log.trace("Ignoring ping request failure during ping on startup: " + e.getMessage());
+ }
+ }
return tcpTransport;
}
Modified: branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/CSAIntegrationTest.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/CSAIntegrationTest.java 2010-07-12 08:09:33 UTC (rev 2013)
+++ branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/CSAIntegrationTest.java 2010-07-12 10:39:49 UTC (rev 2014)
@@ -13,6 +13,7 @@
import org.infinispan.util.ByteArrayKey;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
+import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -91,6 +92,13 @@
tcpConnectionFactory = (TcpTransportFactory) TestingUtil.extractField(remoteCacheManager, "transportFactory");
}
+ @AfterClass
+ @Override
+ protected void destroy() {
+ super.destroy();
+ remoteCacheManager.stop();
+ }
+
public void testHashInfoRetrieved() throws InterruptedException {
assert tcpConnectionFactory.getServers().size() == 1;
for (int i = 0; i < 10; i++) {
Modified: branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/CacheManagerNotStartedTest.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/CacheManagerNotStartedTest.java 2010-07-12 08:09:33 UTC (rev 2013)
+++ branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/CacheManagerNotStartedTest.java 2010-07-12 10:39:49 UTC (rev 2014)
@@ -6,6 +6,7 @@
import org.infinispan.server.hotrod.HotRodServer;
import org.infinispan.test.SingleCacheManagerTest;
import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;
@@ -36,9 +37,20 @@
@AfterTest(alwaysRun = true)
public void release() {
if (cacheManager != null) cacheManager.stop();
- if (hotrodServer != null) hotrodServer.stop();
+ if (hotrodServer != null) hotrodServer.stop();
}
+ @AfterClass
+ @Override
+ protected void destroyAfterClass() {
+ super.destroyAfterClass();
+ try {
+ remoteCacheManager.stop();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
public void testGetCacheOperations() {
assert remoteCacheManager.getCache() != null;
assert remoteCacheManager.getCache(CACHE_NAME) != null;
Modified: branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ClientConnectionPoolingTest.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ClientConnectionPoolingTest.java 2010-07-12 08:09:33 UTC (rev 2013)
+++ branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ClientConnectionPoolingTest.java 2010-07-12 10:39:49 UTC (rev 2014)
@@ -79,6 +79,7 @@
hotrodClientConf.put("testWhileIdle", "true");
hotrodClientConf.put("minIdle", "-5");
hotrodClientConf.put("lifo", "true");
+ hotrodClientConf.put("ping-on-startup", "false");
remoteCacheManager = new RemoteCacheManager(hotrodClientConf);
remoteCache = remoteCacheManager.getCache();
@@ -106,6 +107,7 @@
workerThread4.stopThread();
workerThread5.stopThread();
workerThread6.stopThread();
+ remoteCacheManager.stop();
}
public void testPropsCorrectlySet() {
Modified: branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/DroppedConnectionsTest.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/DroppedConnectionsTest.java 2010-07-12 08:09:33 UTC (rev 2013)
+++ branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/DroppedConnectionsTest.java 2010-07-12 10:39:49 UTC (rev 2014)
@@ -33,7 +33,7 @@
hotRodServer = TestHelper.startHotRodServer(cacheManager);
Properties hrClientConfig = new Properties();
hrClientConfig.put("testWhileIdle", "false");
- hrClientConfig.put("minIdle","2");
+ hrClientConfig.put("minIdle","1");
hrClientConfig.put("maxIdle","2");
hrClientConfig.put("maxActive","2");
hrClientConfig.put("hotrod-servers", "127.0.0.1:" + hotRodServer.getPort());
Modified: branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValueTest.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValueTest.java 2010-07-12 08:09:33 UTC (rev 2013)
+++ branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValueTest.java 2010-07-12 10:39:49 UTC (rev 2014)
@@ -32,7 +32,7 @@
}
- @AfterClass(enabled = true)
+ @AfterClass
public void testDestroyRemoteCacheFactory() {
remoteCacheManager.stop();
hotrodServer.stop();
Modified: branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HeavyLoadConnectionPoolingTest.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HeavyLoadConnectionPoolingTest.java 2010-07-12 08:09:33 UTC (rev 2013)
+++ branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HeavyLoadConnectionPoolingTest.java 2010-07-12 10:39:49 UTC (rev 2014)
@@ -7,6 +7,8 @@
import org.infinispan.test.SingleCacheManagerTest;
import org.infinispan.test.TestingUtil;
import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import java.util.ArrayList;
@@ -26,7 +28,12 @@
private RemoteCache<Object, Object> remoteCache;
private GenericKeyedObjectPool connectionPool;
+ @AfterMethod
@Override
+ protected void clearContent() {
+ }
+
+ @Override
protected EmbeddedCacheManager createCacheManager() throws Exception {
cacheManager = TestCacheManagerFactory.createLocalCacheManager();
cache = cacheManager.getCache();
@@ -37,6 +44,7 @@
hotrodClientConf.put("hotrod-servers", "localhost:"+hotRodServer.getPort());
hotrodClientConf.put("timeBetweenEvictionRunsMillis", "3000");
hotrodClientConf.put("minEvictableIdleTimeMillis", "1000");
+ hotrodClientConf.put("ping-on-startup", "1000");
remoteCacheManager = new RemoteCacheManager(hotrodClientConf);
remoteCache = remoteCacheManager.getCache();
@@ -46,6 +54,14 @@
return cacheManager;
}
+ @AfterClass
+ @Override
+ protected void destroyAfterClass() {
+ super.destroyAfterClass();
+ remoteCacheManager.stop();
+ hotRodServer.stop();
+ }
+
public void testHeavyLoad() throws InterruptedException {
List<WorkerThread> workers = new ArrayList<WorkerThread>();
@@ -65,7 +81,7 @@
}
//now wait for the idle thread to wake up and clean them
for (int i = 0; i < 50; i++) {
- System.out.println("connectionPool = " + connectionPool.getNumActive());
+// System.out.println("connectionPool = " + connectionPool.getNumActive());
if (connectionPool.getNumIdle() == 1) break;
Thread.sleep(1000);
}
Modified: branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodServerStartStopTest.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodServerStartStopTest.java 2010-07-12 08:09:33 UTC (rev 2013)
+++ branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodServerStartStopTest.java 2010-07-12 10:39:49 UTC (rev 2014)
@@ -5,6 +5,7 @@
import org.infinispan.server.hotrod.HotRodServer;
import org.infinispan.test.MultipleCacheManagersTest;
import org.infinispan.test.TestingUtil;
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import static org.testng.AssertJUnit.assertEquals;
@@ -18,7 +19,12 @@
private HotRodServer hotRodServer1;
private HotRodServer hotRodServer2;
+ @AfterMethod
@Override
+ protected void clearContent() throws Throwable {
+ }
+
+ @Override
protected void createCacheManagers() throws Throwable {
Configuration config = getDefaultClusteredConfig(Configuration.CacheMode.DIST_SYNC);
addClusterEnabledCacheManager(config);
Modified: branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/PingOnStartupTest.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/PingOnStartupTest.java 2010-07-12 08:09:33 UTC (rev 2013)
+++ branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/PingOnStartupTest.java 2010-07-12 10:39:49 UTC (rev 2014)
@@ -54,18 +54,26 @@
}
}
- public void testTopologyFetched() {
+ public void testTopologyFetched() throws Exception {
Properties props = new Properties();
props.put("hotrod-servers", "localhost:" + hotRodServer2.getPort() + ";localhost:" + hotRodServer2.getPort());
props.put("ping-on-startup", "true");
+ props.put("timeBetweenEvictionRunsMillis", "500");
RemoteCacheManager remoteCacheManager = new RemoteCacheManager(props);
TcpTransportFactory tcpConnectionFactory = (TcpTransportFactory) TestingUtil.extractField(remoteCacheManager, "transportFactory");
- try {
- assertEquals(2, tcpConnectionFactory.getServers().size());
- } finally {
- remoteCacheManager.stop();
+ for (int i = 0; i < 10; i++) {
+ try {
+ if (tcpConnectionFactory.getServers().size() == 1) {
+ Thread.sleep(1000);
+ } else {
+ break;
+ }
+ } finally {
+ remoteCacheManager.stop();
+ }
}
+ assertEquals(2, tcpConnectionFactory.getServers().size());
}
public void testTopologyNotFetched() {
Modified: branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RemoteAsyncAPITest.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RemoteAsyncAPITest.java 2010-07-12 08:09:33 UTC (rev 2013)
+++ branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RemoteAsyncAPITest.java 2010-07-12 10:39:49 UTC (rev 2014)
@@ -5,6 +5,7 @@
import org.infinispan.test.SingleCacheManagerTest;
import org.infinispan.test.fwk.TestCacheManagerFactory;
import org.infinispan.util.concurrent.NotifyingFuture;
+import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import java.util.Collections;
@@ -37,6 +38,14 @@
return cm;
}
+ @AfterClass
+ @Override
+ protected void destroyAfterClass() {
+ super.destroyAfterClass();
+ rcm.stop();
+ hotrodServer.stop();
+ }
+
public void testAsyncPut() throws Exception {
// put
Future<String> f = c.putAsync("k", "v");
Modified: branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ReplTopologyChangeTest.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ReplTopologyChangeTest.java 2010-07-12 08:09:33 UTC (rev 2013)
+++ branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ReplTopologyChangeTest.java 2010-07-12 10:39:49 UTC (rev 2014)
@@ -8,6 +8,7 @@
import org.infinispan.test.MultipleCacheManagersTest;
import org.infinispan.test.TestingUtil;
import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -40,7 +41,15 @@
protected void clearContent() throws Throwable {
}
+ @AfterClass
@Override
+ protected void destroy() {
+ hotRodServer1.stop();
+ hotRodServer2.stop();
+ super.destroy();
+ }
+
+ @Override
protected void createCacheManagers() throws Throwable {
config = getDefaultClusteredConfig(getCacheMode());
CacheContainer cm1 = TestCacheManagerFactory.createClusteredCacheManager(config);
@@ -127,7 +136,7 @@
}
protected void waitForClusterToForm(int memberCount) {
- TestingUtil.blockUntilViewReceived(manager(0).getCache(), memberCount, 10000);
+ TestingUtil.blockUntilViewReceived(manager(0).getCache(), memberCount, 30000);
for (int i = 0; i < memberCount; i++) {
TestingUtil.blockUntilCacheStatusAchieved(manager(i).getCache(), ComponentStatus.RUNNING, 10000);
}
Modified: branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/WorkerThread.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/WorkerThread.java 2010-07-12 08:09:33 UTC (rev 2013)
+++ branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/WorkerThread.java 2010-07-12 10:39:49 UTC (rev 2014)
@@ -72,7 +72,6 @@
Random rnd = new Random();
while (!isInterrupted()) {
remoteCache.put(rnd.nextLong(), rnd.nextLong());
- System.out.println(getName() + " Finished put.");
try {
Thread.sleep(50);
} catch (InterruptedException e) {
More information about the infinispan-commits
mailing list