[infinispan-commits] Infinispan SVN: r1688 - in trunk: client/hotrod-client/src/main/java/org/infinispan/client/hotrod and 6 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Wed Apr 14 09:43:44 EDT 2010
Author: mircea.markus
Date: 2010-04-14 09:43:43 -0400 (Wed, 14 Apr 2010)
New Revision: 1688
Added:
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/VersionedValue.java
trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodServerStarter.java
trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotrodClientConcurrencyTest.java
trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotrodStatisticsTest.java
Removed:
trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodListenerTest.java
trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/TestHotrodStatistics.java
Modified:
trunk/
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCache.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/ServerStatistics.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/AbstractTransport.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/HotrodOperations.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/HotrodOperationsImpl.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/RemoteCacheImpl.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/ServerStatisticsImpl.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/TransportFactory.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/VersionedValueImpl.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/AbstractTransportFactory.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/VHelper.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/NettyTransport.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/NettyTransportFactory.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TcpTransport.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TcpTransportFactory.java
trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValueTest.java
trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodIntegrationTest.java
trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/NettyHotRodIntegrationTest.java
trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RemoteCacheManagerTest.java
trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/VHelperTest.java
trunk/core/src/main/java/org/infinispan/io/UnsignedNumeric.java
Log:
ongoing work on hotrod client
Property changes on: trunk
___________________________________________________________________
Name: svn:ignore
- target
coretarget
Infinispan-BdbjeCacheStore
infinispan-config-4.0.xsd
.classpath
.project
.settings
+ Infinispan-BdbjeCacheStore
infinispan-config-4.0.xsd
.classpath
.project
target
.settings
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCache.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCache.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCache.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -67,7 +67,7 @@
* Lat call (remove) will make sure that the entry will only be removed if it hasn't been changed in between.
*
* @return true if the entry has been removed
- * @see org.infinispan.client.hotrod.RemoteCache.VersionedValue
+ * @see VersionedValue
* @see #getVersioned(Object)
*/
boolean remove(K key, long version);
@@ -83,7 +83,7 @@
*
* @return true if the method has been replaced
* @see #getVersioned(Object)
- * @see org.infinispan.client.hotrod.RemoteCache.VersionedValue
+ * @see VersionedValue
*/
boolean replace(K key, V newValue, long version);
@@ -114,7 +114,7 @@
/**
- * Returns the {@link org.infinispan.client.hotrod.RemoteCache.VersionedValue} associated to the supplied key param, or null if it doesn't exist.
+ * Returns the {@link VersionedValue} associated to the supplied key param, or null if it doesn't exist.
*/
VersionedValue getVersioned(K key);
@@ -345,13 +345,5 @@
public ServerStatistics stats();
- /**
- * Besides the key and value, also contains an version. To be used in versioned operations, e.g. {@link RemoteCache#remove(Object, long)}.
- */
- public static interface VersionedValue<V> {
- public long getVersion();
- public V getValue();
- }
-
RemoteCache<K,V> withFlags(Flag... flags);
}
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -80,6 +80,23 @@
}
/**
+ * Creates a remote cache manager aware of the hotrod server listening at host:port.
+ * @param start weather or not to start the RemoteCacheManager.
+ */
+ public RemoteCacheManager(String host, int port, boolean start) {
+ props = new Properties();
+ props.put(TransportFactory.CONF_HOTROD_SERVERS, host + ":" + port);
+ if (start) start();
+ }
+
+ /**
+ * Same as {@link #RemoteCacheManager(String, int)} with start=true.
+ */
+ public RemoteCacheManager(String host, int port) {
+ this(host, port, true);
+ }
+
+ /**
* Same as {@link #RemoteCacheManager(java.util.Properties)}, but it will try to lookup the config properties in
* supplied URL.
*
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/ServerStatistics.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/ServerStatistics.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/ServerStatistics.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -57,7 +57,9 @@
*/
public static final String REMOVE_MISSES = "removeMisses";
- public Map<String, Number> getStatsMap();
+ public Map<String, String> getStatsMap();
- public Number getStats(String statsName);
+ public String getStatistic(String statsName);
+
+ public Integer getIntStatistic(String statsName);
}
Added: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/VersionedValue.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/VersionedValue.java (rev 0)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/VersionedValue.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -0,0 +1,10 @@
+package org.infinispan.client.hotrod;
+
+/**
+ * Besides the key and value, also contains an version. To be used in versioned operations, e.g. {@link org.infinispan.client.hotrod.RemoteCache#remove(Object, long)}.
+ * @author Mircea.Markus at jboss.com
+ */
+public interface VersionedValue<V> {
+ public long getVersion();
+ public V getValue();
+}
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/AbstractTransport.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/AbstractTransport.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/AbstractTransport.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -1,5 +1,8 @@
package org.infinispan.client.hotrod.impl;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
+
/**
* // TODO: Document this
*
@@ -8,6 +11,8 @@
*/
public abstract class AbstractTransport implements Transport {
+ private static Log log = LogFactory.getLog(AbstractTransport.class);
+
public byte[] readArray() {
int responseLength = readVInt();
return readByteArray(responseLength);
@@ -16,7 +21,11 @@
@Override
public String readString() {
byte[] strContent = readArray();
- return new String(strContent);//todo take care of encoding here
+ String readString = new String(strContent);
+ if (log.isTraceEnabled()) {
+ log.trace("Read string is: " + readString);
+ }
+ return readString;//todo take care of encoding here
}
@Override
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/HotrodOperations.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/HotrodOperations.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/HotrodOperations.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -61,7 +61,7 @@
public void clear(Flag... flags);
- public Map<String, Number> stats();
+ public Map<String, String> stats();
public boolean ping();
}
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/HotrodOperationsImpl.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/HotrodOperationsImpl.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/HotrodOperationsImpl.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -197,17 +197,18 @@
}
}
- public Map<String, Number> stats() {
+ public Map<String, String> stats() {
Transport transport = getTransport();
try {
// 1) write header
long messageId = writeHeader(transport, STATS_REQUEST);
readHeaderAndValidate(transport, messageId, STATS_RESPONSE);
int nrOfStats = transport.readVInt();
- Map<String, Number> result = new HashMap<String, Number>();
+
+ Map<String, String> result = new HashMap<String, String>();
for (int i = 0; i < nrOfStats; i++) {
String statName = transport.readString();
- Long statValue = transport.readVLong();
+ String statValue = transport.readString();
result.put(statName, statValue);
}
return result;
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/RemoteCacheImpl.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/RemoteCacheImpl.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/RemoteCacheImpl.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -4,6 +4,7 @@
import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.ServerStatistics;
import org.infinispan.client.hotrod.Version;
+import org.infinispan.client.hotrod.VersionedValue;
import org.infinispan.util.concurrent.NotifyingFuture;
import java.util.Map;
@@ -71,9 +72,9 @@
@Override
public ServerStatistics stats() {
- Map<String, Number> statsMap = operations.stats();
+ Map<String, String> statsMap = operations.stats();
ServerStatisticsImpl stats = new ServerStatisticsImpl();
- for (Map.Entry<String, Number> entry : statsMap.entrySet()) {
+ for (Map.Entry<String, String> entry : statsMap.entrySet()) {
stats.addStats(entry.getKey(), entry.getValue());
}
return stats;
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/ServerStatisticsImpl.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/ServerStatisticsImpl.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/ServerStatisticsImpl.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -16,37 +16,25 @@
*/
public class ServerStatisticsImpl implements ServerStatistics {
- public static final Set<String> supportedStatNames;
+ private Map<String, String> stats = new HashMap<String, String>();
- private Map<String, Number> stats = new HashMap<String, Number>();
-
- static {
- Set<String> keys = new HashSet<String>();
- keys.add(CURRENT_NR_OF_ENTRIES);
- keys.add(HITS);
- keys.add(MISSES);
- keys.add(REMOVE_HITS);
- keys.add(REMOVE_MISSES);
- keys.add(RETRIEVALS);
- keys.add(TOTAL_NR_OF_ENTRIES);
- keys.add(TIME_SINCE_START);
- supportedStatNames = Collections.unmodifiableSet(keys);
- }
-
@Override
- public Map<String, Number> getStatsMap() {
+ public Map<String, String> getStatsMap() {
return Collections.unmodifiableMap(stats);
}
@Override
- public Number getStats(String statsName) {
+ public String getStatistic(String statsName) {
return stats.get(statsName);
}
- public void addStats(String name, Number value) {
- if (!supportedStatNames.contains(name)) {
- throw new IllegalArgumentException("Unknown stat: '" + name);
- }
+ public void addStats(String name, String value) {
stats.put(name, value);
}
+
+ @Override
+ public Integer getIntStatistic(String statsName) {
+ String value = stats.get(statsName);
+ return value == null ? null : Integer.parseInt(value);
+ }
}
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/TransportFactory.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/TransportFactory.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/TransportFactory.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -9,6 +9,11 @@
* @since 4.1
*/
public interface TransportFactory {
+
+ public static final String CONF_HOTROD_SERVERS = "hotrod-servers";
+
+ public static final String OVERRIDE_HOTROD_SERVERS = "infinispan.hotrod-client.servers-default";
+
public Transport getTransport();
void init(Properties props);
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/VersionedValueImpl.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/VersionedValueImpl.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/VersionedValueImpl.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -1,6 +1,6 @@
package org.infinispan.client.hotrod.impl;
-import org.infinispan.client.hotrod.RemoteCache;
+import org.infinispan.client.hotrod.VersionedValue;
/**
* // TODO: Document this
@@ -8,7 +8,7 @@
* @author Mircea.Markus at jboss.com
* @since 4.1
*/
-public class VersionedValueImpl<V> implements RemoteCache.VersionedValue<V> {
+public class VersionedValueImpl<V> implements VersionedValue<V> {
private long version;
@@ -28,4 +28,12 @@
public V getValue() {
return value;
}
+
+ @Override
+ public String toString() {
+ return "VersionedValueImpl{" +
+ "version=" + version +
+ ", value=" + value +
+ '}';
+ }
}
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/AbstractTransportFactory.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/AbstractTransportFactory.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/AbstractTransportFactory.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -21,12 +21,17 @@
protected int serverPort;
public void init(Properties props) {
- String servers = props.getProperty("hotrod-servers");
+ String servers = props.getProperty(CONF_HOTROD_SERVERS);
if (servers == null) {
- servers = "127.0.0.1:11311";
- log.info("'hotrod-servers' property not found, defaulting to " + servers);
+ servers = System.getProperty(OVERRIDE_HOTROD_SERVERS);
+ if (servers != null) {
+ log.info("Overwriting default server properties (-D" + OVERRIDE_HOTROD_SERVERS + ") with " + servers);
+ } else {
+ servers = "127.0.0.1:11311";
+ }
+ log.info("'hotrod-servers' property not specified in config, using " + servers);
}
- StringTokenizer tokenizer = new StringTokenizer(servers,";");
+ StringTokenizer tokenizer = new StringTokenizer(servers, ";");
String server = tokenizer.nextToken();
String[] serverDef = tokenizeServer(server);
serverHost = serverDef[0];
@@ -35,6 +40,6 @@
private String[] tokenizeServer(String server) {
StringTokenizer t = new StringTokenizer(server, ":");
- return new String[] {t.nextToken(), t.nextToken()};
+ return new String[]{t.nextToken(), t.nextToken()};
}
}
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/VHelper.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/VHelper.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/VHelper.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -1,5 +1,7 @@
package org.infinispan.client.hotrod.impl.transport;
+import org.infinispan.io.UnsignedNumeric;
+
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -11,92 +13,36 @@
* @since 4.1
*/
public class VHelper {
- private static final int MAX_VINT_BYTES = 5;
- private static final int MAX_VLONG_BYTES = 9;
-
public static int readVInt(InputStream is) {
- int result = 0;
- for (int i = 0; i < MAX_VINT_BYTES; i++) {
- int aByte = nextByte(is);
- boolean hasMore = (aByte & 128) > 0;
- aByte &= 127; //remove leading byte
- result = result | (aByte << (i*7));
- if (!hasMore) break;
+ try {
+ return UnsignedNumeric.readUnsignedInt(is);
+ } catch (IOException e) {
+ throw new TransportException(e);
}
- if (result < 0)
- throw new TransportException("negative number read: " + result);
- return result;
}
public static void writeVInt(int toWrite, OutputStream os) {
- boolean hasMore;
- do {
- int currentByte = toWrite & 0x0000007F;
- toWrite = toWrite >> 7;
- hasMore = toWrite > 0;
- if (hasMore) {
- currentByte |= 128;
- }
- writeByte(os, currentByte);
- } while (hasMore);
- }
-
- private static void writeByte(OutputStream os, int currentByte) {
try {
- os.write(currentByte);
+ UnsignedNumeric.writeUnsignedInt(os, toWrite);
} catch (IOException e) {
throw new TransportException(e);
}
}
- private static int nextByte(InputStream is) {
+ public static long readVLong(InputStream is) {
try {
- int result = is.read();
- if (result < 0) {
- throw new TransportException("Unexpected end of stream " + result);
- }
- return result;
+ return UnsignedNumeric.readUnsignedLong(is);
} catch (IOException e) {
throw new TransportException(e);
}
}
- public static long readVLong(InputStream is) {
- long result = 0;
- for (int i = 0; i < MAX_VLONG_BYTES; i++) {
- long aByte = nextByte(is);
- boolean hasMore = (aByte & 128) > 0;
- aByte &= 127; //remove leading byte
- result = result | (aByte << (i*7));
- if (!hasMore) break;
- }
- if (result < 0)
- throw new TransportException("negative number read: " + result);
- return result;
- }
-
public static void writeVLong(long toWrite, OutputStream os) {
- boolean hasMore;
- do {
- long currentByte = toWrite & 0x000000000000007F;
- toWrite = toWrite >> 7;
- hasMore = toWrite > 0;
- if (hasMore) {
- currentByte |= 128;
- }
- writeByte(os, (int)currentByte);
- } while (hasMore);
+ try {
+ UnsignedNumeric.writeUnsignedLong(os, toWrite);
+ } catch (IOException e) {
+ throw new TransportException(e);
+ }
}
-
- public static void main(String[] args) {
- long zero = 0;
- long aByte = 1;
- long shift = 35;
- System.out.println((zero | (aByte << 35)));
- long a = 1l<<18;
- long b = 1l<<17;
- long ab = a * b;
- System.out.println(ab);
- }
}
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/NettyTransport.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/NettyTransport.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/NettyTransport.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -2,6 +2,8 @@
import org.infinispan.client.hotrod.impl.AbstractTransport;
import org.infinispan.client.hotrod.impl.transport.TransportException;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
import org.jboss.netty.bootstrap.ClientBootstrap;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFuture;
@@ -18,6 +20,8 @@
*/
public class NettyTransport extends AbstractTransport {
+ private static Log log = LogFactory.getLog(NettyTransport.class);
+
private InetSocketAddress serverAddress;
private Channel channel;
private ChannelFuture lastWrite;
@@ -44,7 +48,7 @@
channel = future.awaitUninterruptibly().getChannel();
if (!future.isSuccess()) {
bootstrap.releaseExternalResources();
- throw new TransportException("Coukd not create netty transport", future.getCause());
+ throw new TransportException("Could not create netty transport", future.getCause());
}
}
@@ -95,7 +99,8 @@
@Override
public void release() {
- // TODO: Customise this generated block
+ log.trace("About to close the channel: " + channel);
+ channel.close();
}
@Override
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/NettyTransportFactory.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/NettyTransportFactory.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/NettyTransportFactory.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -2,6 +2,8 @@
import org.infinispan.client.hotrod.impl.Transport;
import org.infinispan.client.hotrod.impl.transport.AbstractTransportFactory;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
import java.net.InetSocketAddress;
import java.util.Properties;
@@ -13,6 +15,9 @@
* @since 4.1
*/
public class NettyTransportFactory extends AbstractTransportFactory {
+
+ private static Log log = LogFactory.getLog(NettyTransportFactory.class);
+
private InetSocketAddress serverAddr;
@Override
@@ -23,6 +28,7 @@
@Override
public Transport getTransport() {
+ log.info("Connecting to server on: " + serverAddr);
return new NettyTransport(serverAddr);
}
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TcpTransport.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TcpTransport.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TcpTransport.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -3,10 +3,14 @@
import org.infinispan.client.hotrod.impl.AbstractTransport;
import org.infinispan.client.hotrod.impl.transport.TransportException;
import org.infinispan.client.hotrod.impl.transport.VHelper;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
import java.io.IOException;
+import java.net.InetSocketAddress;
import java.net.Socket;
-import java.util.logging.Logger;
+import java.net.SocketAddress;
+import java.nio.channels.SocketChannel;
/**
* // TODO: Document this
@@ -16,7 +20,7 @@
*/
public class TcpTransport extends AbstractTransport {
- public static final Logger log = Logger.getLogger(TcpTransport.class.getName());
+ private static Log log = LogFactory.getLog(TcpTransport.class);
private String host;
private int port;
@@ -61,7 +65,8 @@
public void connect() {
try {
- socket = new Socket(host, port);
+ SocketChannel socketChannel = SocketChannel.open(new InetSocketAddress(host, port));
+ socket = socketChannel.socket();
} catch (IOException e) {
throw new TransportException("Problems establishing initial connection", e);
}
@@ -109,23 +114,35 @@
try {
socket.close();
} catch (IOException e) {
- log.warning("Issues closing socket:" + e.getMessage());
+ log.warn("Issues closing socket:" + e.getMessage());
}
}
- public byte[] readByteArray(int size) {
- byte[] bytes = new byte[size];
- try {
- size = socket.getInputStream().read(bytes);
- } catch (IOException e) {
- throw new TransportException(e);
- }
- if (size == -1) {
- throw new RuntimeException("End of stream reached!");
- }
- if (size != bytes.length) {
- throw new TransportException("Expected " + bytes.length + " bytes but only could read " + size + " bytes!");
- }
- return bytes;
+ public byte[] readByteArray(final int size) {
+ byte[] result = new byte[size];
+ boolean done = false;
+ int offset = 0;
+ do {
+ int read;
+ try {
+ int len = size - offset;
+ if (log.isTraceEnabled()) {
+ log.trace("Offset: " + offset + ", len=" + len + ", size=" + size);
+ }
+ read = socket.getInputStream().read(result, offset, len);
+ } catch (IOException e) {
+ throw new TransportException(e);
+ }
+ if (read == -1) {
+ throw new RuntimeException("End of stream reached!");
+ }
+ if (read + offset == size) {
+ done = true;
+ } else {
+ offset += read;
+ if (offset > result.length) throw new IllegalStateException("Assertion!");
+ }
+ } while (!done);
+ return result;
}
}
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TcpTransportFactory.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TcpTransportFactory.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TcpTransportFactory.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -3,6 +3,8 @@
import org.infinispan.client.hotrod.impl.Transport;
import org.infinispan.client.hotrod.impl.TransportFactory;
import org.infinispan.client.hotrod.impl.transport.AbstractTransportFactory;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
import java.util.Properties;
import java.util.StringTokenizer;
@@ -15,6 +17,8 @@
*/
public class TcpTransportFactory extends AbstractTransportFactory {
+ private static Log log = LogFactory.getLog(TcpTransportFactory.class);
+
@Override
public void destroy() {
// TODO: Customise this generated block
@@ -22,6 +26,7 @@
@Override
public Transport getTransport() {
+ log.info("Connecting to server on: " + serverHost + ":" + serverPort);
TcpTransport transport = new TcpTransport(serverHost, serverPort);
transport.connect();
return transport;
Modified: trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValueTest.java
===================================================================
--- trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValueTest.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValueTest.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -39,7 +39,7 @@
protected CacheManager createCacheManager() throws Exception {
cacheManager = TestCacheManagerFactory.createLocalCacheManager();
cache = cacheManager.getCache();
- hotrodServer = HotRodTestingUtil.startHotRodServer(cacheManager);
+ hotrodServer = HotRodServerStarter.startHotRodServer(cacheManager);
remoteCacheManager = getRemoteCacheManager();
remoteCache = remoteCacheManager.getCache();
Modified: trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodIntegrationTest.java
===================================================================
--- trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodIntegrationTest.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodIntegrationTest.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -16,8 +16,11 @@
import org.testng.annotations.Test;
import java.util.Arrays;
+import java.util.Properties;
import static junit.framework.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.AssertJUnit.assertTrue;
/**
@@ -26,9 +29,11 @@
* @author mmarkus
* @since 4.1
*/
- at Test (testName = "client.hotrod.HotRodClientIntegrationTest", groups = "functional", enabled = false, description = "TODO To be re-enabled when we have a multithreaded HotRod server impl")
+ at Test (testName = "client.hotrod.HotRodClientIntegrationTest", groups = "functional" )
public class HotRodIntegrationTest extends SingleCacheManagerTest {
+ private static Log log = LogFactory.getLog(HotRodIntegrationTest.class);
+
private static final String CACHE_NAME = "replSync";
private Cache cache;
private Cache defaultCache;
@@ -37,7 +42,7 @@
RemoteCache remoteCache;
private RemoteCacheManager remoteCacheManager;
- private HotRodServer hotrodServer;
+ protected HotRodServer hotrodServer;
@Override
protected CacheManager createCacheManager() throws Exception {
@@ -49,7 +54,8 @@
//pass the config file to the cache
- hotrodServer = HotRodTestingUtil.startHotRodServer(cacheManager);
+ hotrodServer = HotRodServerStarter.startHotRodServer(cacheManager);
+ log.info("Started server on port: " + hotrodServer.getPort());
remoteCacheManager = getRemoteCacheManager();
defaultRemote = remoteCacheManager.getCache();
@@ -58,7 +64,9 @@
}
protected RemoteCacheManager getRemoteCacheManager() {
- return new RemoteCacheManager();
+ Properties config = new Properties();
+ config.put("hotrod-servers", "127.0.0.1:" + hotrodServer.getPort());
+ return new RemoteCacheManager(config);
}
@@ -129,20 +137,19 @@
assert remoteCache.containsKey("aKey");
}
- private static Log log = LogFactory.getLog(HotRodIntegrationTest.class);
-
public void testGetVersionedCacheEntry() {
- assert null == remoteCache.getVersioned("aKey");
+ VersionedValue value = remoteCache.getVersioned("aKey");
+ assertNull(remoteCache.getVersioned("aKey"), "expected null but received: " + value);
remoteCache.put("aKey", "aValue");
assert remoteCache.get("aKey").equals("aValue");
- RemoteCache.VersionedValue valueBinary = remoteCache.getVersioned("aKey");
+ VersionedValue valueBinary = remoteCache.getVersioned("aKey");
assert valueBinary != null;
assertEquals(valueBinary.getValue(), "aValue");
log.info("Version is: " + valueBinary.getVersion());
//now put the same value
remoteCache.put("aKey", "aValue");
- RemoteCache.VersionedValue entry2 = remoteCache.getVersioned("aKey");
+ VersionedValue entry2 = remoteCache.getVersioned("aKey");
assertEquals(entry2.getValue(), "aValue");
assert entry2.getVersion() != valueBinary.getVersion();
@@ -150,7 +157,7 @@
//now put a different value
remoteCache.put("aKey", "anotherValue");
- RemoteCache.VersionedValue entry3 = remoteCache.getVersioned("aKey");
+ VersionedValue entry3 = remoteCache.getVersioned("aKey");
assertEquals(entry3.getValue(), "anotherValue");
assert entry3.getVersion() != entry2.getVersion();
assert !entry3.equals(entry2);
@@ -168,10 +175,10 @@
remoteCache.put("aKey", "aValue");
- RemoteCache.VersionedValue valueBinary = remoteCache.getVersioned("aKey");
+ VersionedValue valueBinary = remoteCache.getVersioned("aKey");
assert remoteCache.replace("aKey", "aNewValue", valueBinary.getVersion());
- RemoteCache.VersionedValue entry2 = remoteCache.getVersioned("aKey");
+ VersionedValue entry2 = remoteCache.getVersioned("aKey");
assert entry2.getVersion() != valueBinary.getVersion();
assertEquals(entry2.getValue(), "aNewValue");
@@ -182,13 +189,13 @@
assert !remoteCache.remove("aKey", 12321212l);
remoteCache.put("aKey", "aValue");
- RemoteCache.VersionedValue valueBinary = remoteCache.getVersioned("aKey");
+ VersionedValue valueBinary = remoteCache.getVersioned("aKey");
assert remoteCache.remove("aKey", valueBinary.getVersion());
assert !cache.containsKey("aKey");
remoteCache.put("aKey", "aNewValue");
- RemoteCache.VersionedValue entry2 = remoteCache.getVersioned("aKey");
+ VersionedValue entry2 = remoteCache.getVersioned("aKey");
assert entry2.getVersion() != valueBinary.getVersion();
assertEquals(entry2.getValue(), "aNewValue");
@@ -198,9 +205,9 @@
public void testPutIfAbsent() {
remoteCache.put("aKey", "aValue");
assert null == remoteCache.putIfAbsent("aKey", "anotherValue");
- assert remoteCache.get("aKey").equals("aValue");
+ assertEquals(remoteCache.get("aKey"),"aValue");
- assert remoteCache.get("aKey").equals("aValue");
+ assertEquals(remoteCache.get("aKey"),"aValue");
assert remoteCache.containsKey("aKey");
assert true : remoteCache.replace("aKey", "anotherValue");
Deleted: trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodListenerTest.java
===================================================================
--- trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodListenerTest.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodListenerTest.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -1,13 +0,0 @@
-package org.infinispan.client.hotrod;
-
-import org.testng.annotations.Test;
-
-/**
- * // TODO: Document this
- *
- * @author mmarkus
- * @since 4.1
- */
- at Test (testName = "client.hotrod.HotRodListenerTest", groups = "functional", enabled = false, description = "TODO To be re-enabled when we have a multithreaded HotRod server impl")
-public class HotRodListenerTest {
-}
Added: trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodServerStarter.java
===================================================================
--- trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodServerStarter.java (rev 0)
+++ trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodServerStarter.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -0,0 +1,32 @@
+package org.infinispan.client.hotrod;
+
+import org.infinispan.manager.CacheManager;
+import org.infinispan.server.hotrod.HotRodServer;
+import org.infinispan.server.hotrod.test.HotRodTestingUtil;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * // TODO: Document this
+ *
+ * @author Mircea.Markus at jboss.com
+ * @since 4.1
+ */
+public class HotRodServerStarter {
+ private static ThreadLocal<Integer> ports = new ThreadLocal<Integer>() {
+
+ /**
+ * This needs to be different than the one used in the server tests in order to make sure that there's no clash.
+ */
+ private AtomicInteger uniquePort = new AtomicInteger(11312);
+
+ @Override
+ protected Integer initialValue() {
+ return uniquePort.addAndGet(100);
+ }
+ };
+
+ public static HotRodServer startHotRodServer(CacheManager cacheManager) {
+ return HotRodTestingUtil.startHotRodServer(cacheManager, ports.get());
+ }
+}
Added: trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotrodClientConcurrencyTest.java
===================================================================
--- trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotrodClientConcurrencyTest.java (rev 0)
+++ trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotrodClientConcurrencyTest.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -0,0 +1,10 @@
+package org.infinispan.client.hotrod;
+
+/**
+ * // TODO: Document this
+ *
+ * @author Mircea.Markus at jboss.com
+ * @since 4.1
+ */
+public class HotrodClientConcurrencyTest {
+}
Copied: trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotrodStatisticsTest.java (from rev 1685, trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/TestHotrodStatistics.java)
===================================================================
--- trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotrodStatisticsTest.java (rev 0)
+++ trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotrodStatisticsTest.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -0,0 +1,115 @@
+package org.infinispan.client.hotrod;
+
+import org.infinispan.manager.CacheManager;
+import org.infinispan.server.hotrod.HotRodServer;
+import org.infinispan.test.TestingUtil;
+import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.Map;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
+
+/**
+ * // TODO: Document this
+ *
+ * @author Mircea.Markus at jboss.com
+ * @since 4.1
+ */
+ at Test(groups = "functional", testName = "client.hotrod.HotrodStatisticsTest")
+public class HotrodStatisticsTest {
+
+ private HotRodServer hotrodServer;
+ private CacheManager cacheManager;
+ private RemoteCacheManager rcm;
+ private RemoteCache remoteCache;
+ long startTime;
+
+ @BeforeMethod
+ protected void setup() throws Exception {
+ cacheManager = TestCacheManagerFactory.createCacheManagerEnforceJmxDomain(getClass().getSimpleName());
+
+ hotrodServer = HotRodServerStarter.startHotRodServer(cacheManager);
+ startTime = System.currentTimeMillis();
+ rcm = new RemoteCacheManager("localhost", hotrodServer.getPort());
+ remoteCache = rcm.getCache();
+ }
+
+ @AfterMethod
+ void tearDown() {
+ TestingUtil.killCacheManagers(cacheManager);
+ hotrodServer.stop();
+ rcm.stop();
+ }
+
+ public void testAllStatsArePresent() {
+ ServerStatistics serverStatistics = remoteCache.stats();
+ Map<String, String> statsMap = serverStatistics.getStatsMap();
+ assertEquals(statsMap.get(ServerStatistics.STORES), "0");
+ assertEquals(statsMap.get(ServerStatistics.CURRENT_NR_OF_ENTRIES), "0");
+ assertEquals(statsMap.get(ServerStatistics.HITS),"0");
+ assertEquals(statsMap.get(ServerStatistics.MISSES),"0");
+ assertEquals(statsMap.get(ServerStatistics.REMOVE_HITS),"0");
+ assertEquals(statsMap.get(ServerStatistics.REMOVE_MISSES),"0");
+ assertEquals(statsMap.get(ServerStatistics.RETRIEVALS),"0");
+ assertEquals(statsMap.get(ServerStatistics.TOTAL_NR_OF_ENTRIES),"0");
+
+ Integer number = serverStatistics.getIntStatistic(ServerStatistics.TIME_SINCE_START);
+ assertTrue(number >= 0);
+ assertTrue(number <= (System.currentTimeMillis() - startTime) / 1000);
+ }
+
+ public void testStoresAndEntries() {
+ remoteCache.put("a","v");
+ assertEquals((Integer)1, remoteCache.stats().getIntStatistic(ServerStatistics.STORES));
+ assertEquals((Integer)1, remoteCache.stats().getIntStatistic(ServerStatistics.CURRENT_NR_OF_ENTRIES));
+ assertEquals((Integer)1, remoteCache.stats().getIntStatistic(ServerStatistics.TOTAL_NR_OF_ENTRIES));
+ remoteCache.put("a2","v2");
+ assertEquals((Integer)2, remoteCache.stats().getIntStatistic(ServerStatistics.STORES));
+ assertEquals((Integer)2, remoteCache.stats().getIntStatistic(ServerStatistics.CURRENT_NR_OF_ENTRIES));
+ assertEquals((Integer)2, remoteCache.stats().getIntStatistic(ServerStatistics.TOTAL_NR_OF_ENTRIES));
+ remoteCache.put("a2","v3");
+ assertEquals((Integer)3, remoteCache.stats().getIntStatistic(ServerStatistics.STORES));
+ assertEquals((Integer)2, remoteCache.stats().getIntStatistic(ServerStatistics.CURRENT_NR_OF_ENTRIES));
+ assertEquals((Integer)3, remoteCache.stats().getIntStatistic(ServerStatistics.TOTAL_NR_OF_ENTRIES));
+ }
+
+ public void testHitsAndMisses() {
+ remoteCache.get("a");
+ assertEquals((Integer)0, remoteCache.stats().getIntStatistic(ServerStatistics.HITS));
+ assertEquals((Integer)1, remoteCache.stats().getIntStatistic(ServerStatistics.MISSES));
+ remoteCache.put("a","v");
+ assertEquals((Integer)0, remoteCache.stats().getIntStatistic(ServerStatistics.HITS));
+ assertEquals((Integer)1, remoteCache.stats().getIntStatistic(ServerStatistics.MISSES));
+ remoteCache.get("a");
+ assertEquals((Integer)1, remoteCache.stats().getIntStatistic(ServerStatistics.HITS));
+ assertEquals((Integer)1, remoteCache.stats().getIntStatistic(ServerStatistics.MISSES));
+ remoteCache.get("a");
+ remoteCache.get("a");
+ remoteCache.get("a");
+ assertEquals((Integer)4, remoteCache.stats().getIntStatistic(ServerStatistics.HITS));
+ assertEquals((Integer)1, remoteCache.stats().getIntStatistic(ServerStatistics.MISSES));
+ }
+
+ public void testRemoveHitsAndMisses() {
+ remoteCache.remove("a");
+ assertEquals((Integer)0, remoteCache.stats().getIntStatistic(ServerStatistics.REMOVE_HITS));
+ assertEquals((Integer)1, remoteCache.stats().getIntStatistic(ServerStatistics.REMOVE_MISSES));
+ remoteCache.put("a","v");
+ remoteCache.remove("a");
+ assertEquals((Integer)1, remoteCache.stats().getIntStatistic(ServerStatistics.REMOVE_HITS));
+ assertEquals((Integer)1, remoteCache.stats().getIntStatistic(ServerStatistics.REMOVE_MISSES));
+ remoteCache.put("a","v");
+ remoteCache.put("b","v");
+ remoteCache.put("c","v");
+
+ remoteCache.remove("a");
+ remoteCache.remove("b");
+ remoteCache.remove("c");
+ assertEquals((Integer)4, remoteCache.stats().getIntStatistic(ServerStatistics.REMOVE_HITS));
+ assertEquals((Integer)1, remoteCache.stats().getIntStatistic(ServerStatistics.REMOVE_MISSES));
+ }
+}
Modified: trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/NettyHotRodIntegrationTest.java
===================================================================
--- trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/NettyHotRodIntegrationTest.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/NettyHotRodIntegrationTest.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -1,6 +1,8 @@
package org.infinispan.client.hotrod;
import org.infinispan.client.hotrod.impl.transport.netty.NettyTransportFactory;
+import org.infinispan.config.Configuration;
+import org.infinispan.test.fwk.TestCacheManagerFactory;
import org.testng.annotations.Test;
import java.util.Properties;
@@ -8,22 +10,17 @@
/**
* // TODO: Document this
*
- * @author Mircea.Marku127.0.0.1:11311;127.0.0.2:11411s at jboss.com
+ * @author Mircea.Markus at jboss.com
* @since 4.1
*/
- at Test(testName = "hotrod.NettyHotRodIntegrationTest", groups = "functional", enabled = false, description = "TODO To be re-enabled when we have a multithreaded HotRod server impl")
+ at Test(testName = "hotrod.NettyHotRodIntegrationTest", groups = "functional")
public class NettyHotRodIntegrationTest extends HotRodIntegrationTest {
@Override
protected RemoteCacheManager getRemoteCacheManager() {
Properties props = new Properties();
props.put("transport-factory", NettyTransportFactory.class.getName());
- props.put("hotrod-servers", "127.0.0.1:11311;127.0.0.2:11411");
+ props.put("hotrod-servers", "127.0.0.1:" + hotrodServer.getPort());
return new RemoteCacheManager(props, true);
}
-
- @Override
- public void testPut() {
- super.testPut(); // TODO: Customise this generated block
- }
}
Modified: trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RemoteCacheManagerTest.java
===================================================================
--- trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RemoteCacheManagerTest.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RemoteCacheManagerTest.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -1,5 +1,6 @@
package org.infinispan.client.hotrod;
+import org.infinispan.client.hotrod.impl.transport.AbstractTransportFactory;
import org.infinispan.manager.CacheManager;
import org.infinispan.server.hotrod.HotRodServer;
import org.infinispan.test.SingleCacheManagerTest;
@@ -16,18 +17,18 @@
* @author Mircea.Markus at jboss.com
* @since 4.1
*/
- at Test(testName = "client.hotrod.RemoteCacheManagerTest", groups = "functional", enabled = false, description = "TODO To be re-enabled when we have a multithreaded HotRod server impl")
+ at Test(testName = "client.hotrod.RemoteCacheManagerTest", groups = "functional" )
public class RemoteCacheManagerTest extends SingleCacheManagerTest {
CacheManager cacheManager = null;
HotRodServer hotrodServer = null;
+ private String prevValue;
-
@Override
protected CacheManager createCacheManager() throws Exception {
cacheManager = TestCacheManagerFactory.createLocalCacheManager();
- hotrodServer = new HotRodServer();
- hotrodServer.start("127.0.0.1", 11311, cacheManager, 0, 0);
+ hotrodServer = HotRodServerStarter.startHotRodServer(cacheManager);
+ prevValue = System.setProperty(AbstractTransportFactory.OVERRIDE_HOTROD_SERVERS, "localhost:" + hotrodServer.getPort());
return cacheManager;
}
@@ -35,12 +36,16 @@
public void release() {
if (hotrodServer != null) hotrodServer.stop();
if (cacheManager != null) cacheManager.stop();
+ if (prevValue != null) {
+ System.setProperty(AbstractTransportFactory.OVERRIDE_HOTROD_SERVERS, prevValue);
+ } else {
+ System.getProperties().remove(AbstractTransportFactory.OVERRIDE_HOTROD_SERVERS);
+ }
}
public void testNoArgConstructor() {
RemoteCacheManager remoteCacheManager = new RemoteCacheManager();
assert remoteCacheManager.isStarted();
- assertWorks(remoteCacheManager);
remoteCacheManager.stop();
}
@@ -48,7 +53,6 @@
RemoteCacheManager remoteCacheManager = new RemoteCacheManager(false);
assert !remoteCacheManager.isStarted();
remoteCacheManager.start();
- assertWorks(remoteCacheManager);
remoteCacheManager.stop();
}
Deleted: trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/TestHotrodStatistics.java
===================================================================
--- trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/TestHotrodStatistics.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/TestHotrodStatistics.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -1,11 +0,0 @@
-package org.infinispan.client.hotrod;
-
-/**
- * // TODO: Document this
- *
- * @author Mircea.Markus at jboss.com
- * @since 4.1
- * todo - add test
- */
-public class TestHotrodStatistics {
-}
Modified: trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/VHelperTest.java
===================================================================
--- trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/VHelperTest.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/VHelperTest.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -14,7 +14,7 @@
* @author mmarkus
* @since 4.1
*/
- at Test(testName = "client.hotrod.VHelperTest", groups = "unit, functional", enabled = false, description = "TODO To be re-enabled when we have a multithreaded HotRod server impl")
+ at Test(testName = "client.hotrod.VHelperTest", groups = "unit, functional")
public class VHelperTest {
public void testString2Byte() {
Modified: trunk/core/src/main/java/org/infinispan/io/UnsignedNumeric.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/io/UnsignedNumeric.java 2010-04-14 13:29:34 UTC (rev 1687)
+++ trunk/core/src/main/java/org/infinispan/io/UnsignedNumeric.java 2010-04-14 13:43:43 UTC (rev 1688)
@@ -1,8 +1,10 @@
package org.infinispan.io;
import java.io.IOException;
+import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectOutput;
+import java.io.OutputStream;
/**
* Helper to read and write unsigned numerics
@@ -24,6 +26,16 @@
}
return i;
}
+
+ public static int readUnsignedInt(InputStream in) throws IOException {
+ int b = in.read();
+ int i = b & 0x7F;
+ for (int shift = 7; (b & 0x80) != 0; shift += 7) {
+ b = in.read();
+ i |= (b & 0x7FL) << shift;
+ }
+ return i;
+ }
/**
* Writes an int in a variable-length format. Writes between one and five bytes. Smaller values take fewer bytes.
@@ -39,7 +51,15 @@
out.writeByte((byte) i);
}
+ public static void writeUnsignedInt(OutputStream out, int i) throws IOException {
+ while ((i & ~0x7F) != 0) {
+ out.write((byte) ((i & 0x7f) | 0x80));
+ i >>>= 7;
+ }
+ out.write((byte) i);
+ }
+
/**
* Reads an int stored in variable-length format. Reads between one and nine bytes. Smaller values take fewer
* bytes. Negative numbers are not supported.
@@ -54,6 +74,16 @@
return i;
}
+ public static long readUnsignedLong(InputStream in) throws IOException {
+ int b = in.read();
+ long i = b & 0x7F;
+ for (int shift = 7; (b & 0x80) != 0; shift += 7) {
+ b = in.read();
+ i |= (b & 0x7FL) << shift;
+ }
+ return i;
+ }
+
/**
* Writes an int in a variable-length format. Writes between one and nine bytes. Smaller values take fewer bytes.
* Negative numbers are not supported.
@@ -68,6 +98,14 @@
out.writeByte((byte) i);
}
+ public static void writeUnsignedLong(OutputStream out, long i) throws IOException {
+ while ((i & ~0x7F) != 0) {
+ out.write((byte) ((i & 0x7f) | 0x80));
+ i >>>= 7;
+ }
+ out.write((byte) i);
+ }
+
/**
* Reads an int stored in variable-length format. Reads between one and five bytes. Smaller values take fewer
* bytes. Negative numbers are not supported.
More information about the infinispan-commits
mailing list