Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ISPN-2139 Extend ping_on_startup to getCache to check if cache defined

  • Loading branch information...
commit dadfda1cc2921f5cb5857063f9d026f1724aab39 1 parent c636b91
@galderz galderz authored Mircea Markus committed
View
18 client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java
@@ -515,15 +515,17 @@ private void loadFromStream(InputStream stream) {
RemoteCacheImpl<K, V> result = new RemoteCacheImpl<K, V>(this, cacheName);
RemoteCacheHolder rcc = new RemoteCacheHolder(result, forceReturnValueOverride == null ? forceReturnValueDefault : forceReturnValueOverride);
startRemoteCache(rcc);
- // If ping not successful assume that the cache does not exist
- // Default cache is always started, so don't do for it
- if (!cacheName.equals(BasicCacheContainer.DEFAULT_CACHE_NAME) &&
- ping(result) == PingResult.CACHE_DOES_NOT_EXIST) {
- return null;
- } else {
- cacheName2RemoteCache.put(cacheName, rcc);
- return result;
+ if (config.getPingOnStartup()) {
+ // If ping not successful assume that the cache does not exist
+ // Default cache is always started, so don't do for it
+ if (!cacheName.equals(BasicCacheContainer.DEFAULT_CACHE_NAME) &&
+ ping(result) == PingResult.CACHE_DOES_NOT_EXIST) {
+ return null;
+ }
}
+ // If ping on startup is disabled, or cache is defined in server
+ cacheName2RemoteCache.put(cacheName, rcc);
+ return result;
} else {
return (RemoteCache<K, V>) cacheName2RemoteCache.get(cacheName).remoteCache;
}
View
5 client/hotrod-client/src/test/java/org/infinispan/client/hotrod/CSAIntegrationTest.java
@@ -122,7 +122,7 @@ protected void createCacheManagers() throws Throwable {
//Important: this only connects to one of the two servers!
Properties props = new Properties();
props.put("infinispan.client.hotrod.server_list", "localhost:" + hotRodServer2.getPort() + ";localhost:" + hotRodServer2.getPort());
- props.put("infinispan.client.hotrod.ping_on_startup", "false");
+ props.put("infinispan.client.hotrod.ping_on_startup", "true");
setHotRodProtocolVersion(props);
remoteCacheManager = new RemoteCacheManager(props);
remoteCache = remoteCacheManager.getCache();
@@ -143,7 +143,7 @@ protected void destroy() {
}
public void testHashInfoRetrieved() throws InterruptedException {
- assert tcpConnectionFactory.getServers().size() == 3;
+ assertEquals(3, tcpConnectionFactory.getServers().size());
for (int i = 0; i < 10; i++) {
remoteCache.put("k", "v");
if (tcpConnectionFactory.getServers().size() == 3) break;
@@ -159,7 +159,6 @@ public void testCorrectSetup() {
assert remoteCache.get("k").equals("v");
}
-
@Test(dependsOnMethods = "testCorrectSetup")
public void testHashFunctionReturnsSameValues() {
for (int i = 0; i < 1000; i++) {
View
30 client/hotrod-client/src/test/java/org/infinispan/client/hotrod/PingOnStartupTest.java
@@ -33,6 +33,7 @@
import java.util.Properties;
import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
/**
* @author Mircea.Markus@jboss.com
@@ -50,12 +51,14 @@ protected void createCacheManagers() throws Throwable {
public void testTopologyFetched() throws Exception {
Properties props = new Properties();
HotRodServer hotRodServer2 = server(1);
- props.put("infinispan.client.hotrod.server_list", "localhost:" + hotRodServer2.getPort() + ";localhost:" + hotRodServer2.getPort());
+ props.put("infinispan.client.hotrod.server_list",
+ "localhost:" + hotRodServer2.getPort() + ";localhost:" + hotRodServer2.getPort());
props.put("infinispan.client.hotrod.ping_on_startup", "true");
props.put("timeBetweenEvictionRunsMillis", "500");
RemoteCacheManager remoteCacheManager = new RemoteCacheManager(props);
- TcpTransportFactory tcpConnectionFactory = (TcpTransportFactory) TestingUtil.extractField(remoteCacheManager, "transportFactory");
+ TcpTransportFactory tcpConnectionFactory = (TcpTransportFactory)
+ TestingUtil.extractField(remoteCacheManager, "transportFactory");
for (int i = 0; i < 10; i++) {
try {
if (tcpConnectionFactory.getServers().size() == 1) {
@@ -73,15 +76,34 @@ public void testTopologyFetched() throws Exception {
public void testTopologyNotFetched() {
Properties props = new Properties();
HotRodServer hotRodServer2 = server(1);
- props.put("infinispan.client.hotrod.server_list", "localhost:" + hotRodServer2.getPort() + ";localhost:" + hotRodServer2.getPort());
+ props.put("infinispan.client.hotrod.server_list",
+ "localhost:" + hotRodServer2.getPort() + ";localhost:" + hotRodServer2.getPort());
props.put("infinispan.client.hotrod.ping_on_startup", "false");
RemoteCacheManager remoteCacheManager = new RemoteCacheManager(props);
- TcpTransportFactory tcpConnectionFactory = (TcpTransportFactory) TestingUtil.extractField(remoteCacheManager, "transportFactory");
+ TcpTransportFactory tcpConnectionFactory = (TcpTransportFactory)
+ TestingUtil.extractField(remoteCacheManager, "transportFactory");
try {
assertEquals(1, tcpConnectionFactory.getServers().size());
} finally {
remoteCacheManager.stop();
}
}
+
+ public void testGetCacheWithPingOnStartupDisabled() {
+ Properties props = new Properties();
+ HotRodServer hotRodServer2 = server(1);
+ props.put("infinispan.client.hotrod.server_list",
+ "boomoo:12345;localhost:" + hotRodServer2.getPort() + ";localhost:" + hotRodServer2.getPort());
+ props.put("infinispan.client.hotrod.ping_on_startup", "false");
+ RemoteCacheManager remoteCacheManager = new RemoteCacheManager(props);
+
+ try {
+ RemoteCache<Object, Object> cache = remoteCacheManager.getCache();
+ assertFalse(cache.containsKey("k"));
+ } finally {
+ remoteCacheManager.stop();
+ }
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.