[infinispan-commits] Infinispan SVN: r1901 - in branches/4.1.x/client/hotrod-client/src: main/java/org/infinispan/client/hotrod/impl/transport/tcp and 1 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Fri Jun 11 03:46:08 EDT 2010
Author: mircea.markus
Date: 2010-06-11 03:46:07 -0400 (Fri, 11 Jun 2010)
New Revision: 1901
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/transport/tcp/PropsKeyedObjectPoolFactory.java
branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/CSAIntegrationTest.java
Log:
updated test
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-06-10 16:02:41 UTC (rev 1900)
+++ branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java 2010-06-11 07:46:07 UTC (rev 1901)
@@ -187,7 +187,8 @@
/**
* Same as {@link #RemoteCacheManager(java.util.Properties)}, but it will try to lookup the config properties in the
- * classpath, in a file named <tt>hotrod-client.properties</tt>.
+ * classpath, in a file named <tt>hotrod-client.properties</tt>. If no properties can be found in the classpath, the
+ * server tries to connect to "127.0.0.1:11311" in start.
*
* @param start weather or not to start the RemoteCacheManager
* @throws HotRodClientException if such a file cannot be found in the classpath
Modified: branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/PropsKeyedObjectPoolFactory.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/PropsKeyedObjectPoolFactory.java 2010-06-10 16:02:41 UTC (rev 1900)
+++ branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/PropsKeyedObjectPoolFactory.java 2010-06-11 07:46:07 UTC (rev 1901)
@@ -65,3 +65,4 @@
}
}
}
+
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-06-10 16:02:41 UTC (rev 1900)
+++ branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/CSAIntegrationTest.java 2010-06-11 07:46:07 UTC (rev 1901)
@@ -1,9 +1,11 @@
package org.infinispan.client.hotrod;
import org.infinispan.Cache;
+import org.infinispan.client.hotrod.impl.transport.Transport;
import org.infinispan.client.hotrod.impl.transport.tcp.TcpTransport;
import org.infinispan.client.hotrod.impl.transport.tcp.TcpTransportFactory;
import org.infinispan.config.Configuration;
+import org.infinispan.container.DataContainer;
import org.infinispan.distribution.DistributionManager;
import org.infinispan.interceptors.CacheMgmtInterceptor;
import org.infinispan.interceptors.base.CommandInterceptor;
@@ -13,11 +15,15 @@
import org.infinispan.server.hotrod.HotRodServer;
import org.infinispan.test.MultipleCacheManagersTest;
import org.infinispan.test.TestingUtil;
+import org.infinispan.util.ByteArrayKey;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.HashMap;
@@ -43,6 +49,7 @@
private RemoteCache<Object, Object> remoteCache;
private TcpTransportFactory tcpConnectionFactory;
private static final String CACHE_NAME = "distributedCache";
+ Map<InetSocketAddress, CacheManager> hrServ2CacheManager = new HashMap<InetSocketAddress, CacheManager>();
private static Log log = LogFactory.getLog(CSAIntegrationTest.class);
@@ -54,6 +61,7 @@
@Override
protected void createCacheManagers() throws Throwable {
Configuration config = getDefaultClusteredConfig(Configuration.CacheMode.DIST_SYNC);
+ config.setNumOwners(1);
config.setUnsafeUnreliableReturnValues(true);
EmbeddedCacheManager cm1 = addClusterEnabledCacheManager();
EmbeddedCacheManager cm2 = addClusterEnabledCacheManager();
@@ -63,8 +71,11 @@
cm3.defineConfiguration(CACHE_NAME, config);
hotRodServer1 = TestHelper.startHotRodServer(manager(0));
- hotRodServer2 = TestHelper.startHotRodServer(manager(1));
+ hrServ2CacheManager.put(new InetSocketAddress(hotRodServer1.getHost(), hotRodServer1.getPort()), manager(0));
+ hotRodServer2 = TestHelper.startHotRodServer(manager(1));
+ hrServ2CacheManager.put(new InetSocketAddress(hotRodServer2.getHost(), hotRodServer2.getPort()), manager(1));
hotRodServer3 = TestHelper.startHotRodServer(manager(2));
+ hrServ2CacheManager.put(new InetSocketAddress(hotRodServer3.getHost(), hotRodServer3.getPort()), manager(2));
assert manager(0).getCache(CACHE_NAME) != null;
assert manager(1).getCache(CACHE_NAME) != null;
@@ -85,7 +96,6 @@
//Important: this only connects to one of the two servers!
Properties props = new Properties();
props.put("hotrod-servers", "localhost:" + hotRodServer2.getPort() + ";localhost:" + hotRodServer2.getPort());
-// props.put("marshaller", ByteMarshaller.class.getName());
remoteCacheManager = new RemoteCacheManager(props);
remoteCache = remoteCacheManager.getCache(CACHE_NAME);
@@ -130,7 +140,7 @@
}
@Test(dependsOnMethods = "testHashFunctionReturnsSameValues")
- public void testRequestsGoToExpectedServer() {
+ public void testRequestsGoToExpectedServer() throws Exception {
addCacheMgmtInterceptor(manager(0).getCache(CACHE_NAME));
addCacheMgmtInterceptor(manager(1).getCache(CACHE_NAME));
@@ -140,7 +150,12 @@
for (int i = 0; i < 500; i++) {
byte[] key = generateKey(i);
keys.add(key);
- remoteCache.put(new String(key), "value");
+ String keyStr = new String(key);
+ remoteCache.put(keyStr, "value");
+ byte[] keyBytes = toBytes(keyStr);
+ TcpTransport transport = (TcpTransport) tcpConnectionFactory.getTransport(keyBytes);
+ assertCacheContainsKey(transport.getServerAddress(), keyBytes);
+ tcpConnectionFactory.releaseTransport(transport);
}
assertMisses(false);
@@ -148,7 +163,13 @@
log.info("Right before first get.");
for (byte[] key : keys) {
- assert remoteCache.get(new String(key)).equals("value");
+ resetStats();
+ String keyStr = new String(key);
+ assert remoteCache.get(keyStr).equals("value");
+ byte[] keyBytes = toBytes(keyStr);
+ TcpTransport transport = (TcpTransport) tcpConnectionFactory.getTransport(keyBytes);
+ assertOnlyServerHit(transport.getServerAddress());
+ tcpConnectionFactory.releaseTransport(transport);
assertMisses(false);
}
assertMisses(false);
@@ -157,6 +178,39 @@
assertMisses(true);
}
+ private void assertOnlyServerHit(InetSocketAddress serverAddress) {
+ CacheManager cacheManager = hrServ2CacheManager.get(serverAddress);
+ CacheMgmtInterceptor interceptor = getCacheMgmtInterceptor(cacheManager.getCache(CACHE_NAME));
+ assert interceptor.getHits() == 1;
+ for (CacheManager cm : hrServ2CacheManager.values()) {
+ if (cm != cacheManager) {
+ interceptor = getCacheMgmtInterceptor(cm.getCache(CACHE_NAME));
+ assert interceptor.getHits() == 0;
+ }
+ }
+ }
+
+ private void resetStats() {
+ for (int i = 0; i< 3; i++) {
+ CacheMgmtInterceptor cmi = getCacheMgmtInterceptor(manager(i).getCache(CACHE_NAME));
+ cmi.resetStatistics();
+ }
+ }
+
+ private void assertCacheContainsKey(InetSocketAddress serverAddress, byte[] keyBytes) {
+ CacheManager cacheManager = hrServ2CacheManager.get(serverAddress);
+ Cache<Object, Object> cache = cacheManager.getCache(CACHE_NAME);
+ DataContainer dataContainer = cache.getAdvancedCache().getDataContainer();
+ assert dataContainer.keySet().contains(new ByteArrayKey(keyBytes));
+ }
+
+ private byte[] toBytes(String keyStr) throws IOException {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(byteArrayOutputStream);
+ oos.writeObject(keyStr);
+ return byteArrayOutputStream.toByteArray();
+ }
+
private void addCacheMgmtInterceptor(Cache<Object, Object> cache) {
CacheMgmtInterceptor interceptor = new CacheMgmtInterceptor();
cache.getAdvancedCache().addInterceptor(interceptor, 1);
@@ -175,14 +229,19 @@
}
private int getMissCount(Cache<Object, Object> cache) {
+ CacheMgmtInterceptor cacheMgmtInterceptor = getCacheMgmtInterceptor(cache);
+ return (int) cacheMgmtInterceptor.getMisses();
+ }
+
+ private CacheMgmtInterceptor getCacheMgmtInterceptor(Cache<Object, Object> cache) {
+ CacheMgmtInterceptor cacheMgmtInterceptor = null;
List<CommandInterceptor> interceptorChain = cache.getAdvancedCache().getInterceptorChain();
for (CommandInterceptor interceptor : interceptorChain) {
if (interceptor instanceof CacheMgmtInterceptor) {
- CacheMgmtInterceptor cacheMgmtInterceptor = (CacheMgmtInterceptor) interceptor;
- return (int) cacheMgmtInterceptor.getMisses();
+ cacheMgmtInterceptor = (CacheMgmtInterceptor) interceptor;
}
}
- throw new IllegalStateException();
+ return cacheMgmtInterceptor;
}
private byte[] generateKey(int i) {
More information about the infinispan-commits
mailing list