[infinispan-commits] Infinispan SVN: r1894 - in trunk: core/src/main/java/org/infinispan/marshall and 5 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Thu Jun 10 08:39:03 EDT 2010
Author: galder.zamarreno at jboss.com
Date: 2010-06-10 08:39:02 -0400 (Thu, 10 Jun 2010)
New Revision: 1894
Added:
trunk/core/src/main/java/org/infinispan/util/ByteArrayKey.java
Modified:
trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodIntegrationTest.java
trunk/core/src/main/java/org/infinispan/marshall/Ids.java
trunk/core/src/main/java/org/infinispan/marshall/jboss/ConstantObjectTable.java
trunk/core/src/main/java/org/infinispan/util/hash/MurmurHash2.java
trunk/server/hotrod/src/main/scala/org/infinispan/server/hotrod/AbstractVersionedDecoder.scala
trunk/server/hotrod/src/main/scala/org/infinispan/server/hotrod/CacheKey.scala
trunk/server/hotrod/src/main/scala/org/infinispan/server/hotrod/Decoder10.scala
trunk/server/hotrod/src/main/scala/org/infinispan/server/hotrod/HotRodDecoder.scala
trunk/server/hotrod/src/test/scala/org/infinispan/server/hotrod/HotRodFunctionalTest.scala
trunk/server/hotrod/src/test/scala/org/infinispan/server/hotrod/HotRodMarshallingTest.scala
trunk/server/hotrod/src/test/scala/org/infinispan/server/hotrod/HotRodSingleNodeTest.scala
Log:
[ISPN-491] (HotRod Client and server not hashing on the same thing) Fixed.
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-06-10 12:16:05 UTC (rev 1893)
+++ trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodIntegrationTest.java 2010-06-10 12:39:02 UTC (rev 1894)
@@ -5,10 +5,10 @@
import org.infinispan.config.Configuration;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.server.core.CacheValue;
-import org.infinispan.server.hotrod.CacheKey;
import org.infinispan.server.hotrod.HotRodServer;
import org.infinispan.test.SingleCacheManagerTest;
import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.infinispan.util.ByteArrayKey;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
import org.testng.annotations.AfterClass;
@@ -189,7 +189,7 @@
SerializationMarshaller marshaller = new SerializationMarshaller();
byte[] keyBytes = marshaller.marshallObject(key);
byte[] valueBytes = marshaller.marshallObject(value);
- CacheKey cacheKey = new CacheKey(keyBytes);
+ ByteArrayKey cacheKey = new ByteArrayKey(keyBytes);
CacheValue cacheValue = (CacheValue) cache.get(cacheKey);
if (value == null) {
assert cacheValue == null : "Expected null value but received: " + cacheValue;
Modified: trunk/core/src/main/java/org/infinispan/marshall/Ids.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/marshall/Ids.java 2010-06-10 12:16:05 UTC (rev 1893)
+++ trunk/core/src/main/java/org/infinispan/marshall/Ids.java 2010-06-10 12:39:02 UTC (rev 1894)
@@ -114,7 +114,7 @@
*/
static final byte SERVER_CACHE_VALUE = 55;
static final byte MEMCACHED_CACHE_VALUE = 56;
- static final byte HOTROD_CACHE_KEY = 57;
+ static final byte BYTE_ARRAY_KEY = 57;
static final byte TOPOLOGY_ADDRESS = 58;
static final byte TOPOLOGY_VIEW = 59;
Modified: trunk/core/src/main/java/org/infinispan/marshall/jboss/ConstantObjectTable.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/marshall/jboss/ConstantObjectTable.java 2010-06-10 12:16:05 UTC (rev 1893)
+++ trunk/core/src/main/java/org/infinispan/marshall/jboss/ConstantObjectTable.java 2010-06-10 12:39:02 UTC (rev 1894)
@@ -74,6 +74,7 @@
import org.infinispan.remoting.transport.jgroups.JGroupsAddress;
import org.infinispan.transaction.xa.DeadlockDetectingGlobalTransaction;
import org.infinispan.transaction.xa.GlobalTransaction;
+import org.infinispan.util.ByteArrayKey;
import org.infinispan.util.FastCopyHashMap;
import org.infinispan.util.ReflectionUtil;
import org.infinispan.util.Util;
@@ -171,9 +172,10 @@
MARSHALLABLES.add("org.infinispan.server.core.CacheValue");
MARSHALLABLES.add("org.infinispan.server.memcached.MemcachedValue");
- MARSHALLABLES.add("org.infinispan.server.hotrod.CacheKey");
+ MARSHALLABLES.add(ByteArrayKey.class.getName());
MARSHALLABLES.add("org.infinispan.server.hotrod.TopologyAddress");
MARSHALLABLES.add("org.infinispan.server.hotrod.TopologyView");
+
}
/**
Added: trunk/core/src/main/java/org/infinispan/util/ByteArrayKey.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/util/ByteArrayKey.java (rev 0)
+++ trunk/core/src/main/java/org/infinispan/util/ByteArrayKey.java 2010-06-10 12:39:02 UTC (rev 1894)
@@ -0,0 +1,64 @@
+package org.infinispan.util;
+
+import org.infinispan.marshall.Ids;
+import org.infinispan.marshall.Marshallable;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Arrays;
+
+/**
+ * Wrapper class for byte[] keys.
+ *
+ * @author Galder Zamarreño
+ * @since 4.1
+ */
+ at Marshallable(externalizer = ByteArrayKey.Externalizer.class, id = Ids.BYTE_ARRAY_KEY)
+public class ByteArrayKey {
+
+ private final byte[] data;
+
+ public ByteArrayKey(byte[] data) {
+ this.data = data;
+ }
+
+ public byte[] getData() {
+ return data;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null || getClass() != obj.getClass()) return false;
+ ByteArrayKey key = (ByteArrayKey) obj;
+ return Arrays.equals(key.data, this.data);
+ }
+
+ @Override
+ public int hashCode() {
+ return 41 + Arrays.hashCode(data);
+ }
+
+ @Override
+ public String toString() {
+ return new StringBuilder().append("ByteArrayKey").append("{")
+ .append("data=").append(Util.printArray(data, true))
+ .append("}").toString();
+ }
+
+ public static class Externalizer implements org.infinispan.marshall.Externalizer {
+ public void writeObject(ObjectOutput output, Object object) throws IOException {
+ ByteArrayKey key = (ByteArrayKey) object;
+ output.writeInt(key.data.length);
+ output.write(key.data);
+ }
+
+ public Object readObject(ObjectInput input) throws IOException, ClassNotFoundException {
+ byte[] data = new byte[input.readInt()];
+ input.readFully(data);
+ return new ByteArrayKey(data);
+ }
+ }
+
+}
\ No newline at end of file
Modified: trunk/core/src/main/java/org/infinispan/util/hash/MurmurHash2.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/util/hash/MurmurHash2.java 2010-06-10 12:16:05 UTC (rev 1893)
+++ trunk/core/src/main/java/org/infinispan/util/hash/MurmurHash2.java 2010-06-10 12:39:02 UTC (rev 1894)
@@ -1,5 +1,7 @@
package org.infinispan.util.hash;
+import org.infinispan.util.ByteArrayKey;
+
import java.util.Random;
/**
@@ -88,6 +90,8 @@
return hash((byte[]) o);
else if (o instanceof String)
return hash(((String) o).getBytes());
+ else if (o instanceof ByteArrayKey)
+ return hash(((ByteArrayKey) o).getData());
else
return hash(o.hashCode());
}
Modified: trunk/server/hotrod/src/main/scala/org/infinispan/server/hotrod/AbstractVersionedDecoder.scala
===================================================================
--- trunk/server/hotrod/src/main/scala/org/infinispan/server/hotrod/AbstractVersionedDecoder.scala 2010-06-10 12:16:05 UTC (rev 1893)
+++ trunk/server/hotrod/src/main/scala/org/infinispan/server/hotrod/AbstractVersionedDecoder.scala 2010-06-10 12:39:02 UTC (rev 1894)
@@ -5,6 +5,7 @@
import org.infinispan.server.core.transport.{ChannelBuffer}
import org.infinispan.Cache
import org.infinispan.stats.Stats
+import org.infinispan.util.ByteArrayKey
/**
* // TODO: Document this
@@ -15,7 +16,7 @@
def readHeader(buffer: ChannelBuffer, messageId: Long): HotRodHeader
- def readKey(buffer: ChannelBuffer): CacheKey
+ def readKey(buffer: ChannelBuffer): ByteArrayKey
def readParameters(header: HotRodHeader, buffer: ChannelBuffer): Option[RequestParameters]
@@ -29,11 +30,11 @@
def createGetResponse(header: HotRodHeader, v: CacheValue, op: Enumeration#Value): AnyRef
- def handleCustomRequest(header: HotRodHeader, buffer: ChannelBuffer, cache: Cache[CacheKey, CacheValue]): AnyRef
+ def handleCustomRequest(header: HotRodHeader, buffer: ChannelBuffer, cache: Cache[ByteArrayKey, CacheValue]): AnyRef
def createStatsResponse(header: HotRodHeader, stats: Stats): AnyRef
def createErrorResponse(header: HotRodHeader, t: Throwable): AnyRef
- def getOptimizedCache(h: HotRodHeader, c: Cache[CacheKey, CacheValue]): Cache[CacheKey, CacheValue]
+ def getOptimizedCache(h: HotRodHeader, c: Cache[ByteArrayKey, CacheValue]): Cache[ByteArrayKey, CacheValue]
}
\ No newline at end of file
Modified: trunk/server/hotrod/src/main/scala/org/infinispan/server/hotrod/CacheKey.scala
===================================================================
--- trunk/server/hotrod/src/main/scala/org/infinispan/server/hotrod/CacheKey.scala 2010-06-10 12:16:05 UTC (rev 1893)
+++ trunk/server/hotrod/src/main/scala/org/infinispan/server/hotrod/CacheKey.scala 2010-06-10 12:39:02 UTC (rev 1894)
@@ -5,6 +5,7 @@
import org.infinispan.marshall.Marshallable
import java.io.{ObjectInput, ObjectOutput}
import org.infinispan.server.core.Logging
+import org.infinispan.util.hash.MurmurHash2
/**
* // TODO: Document this
@@ -26,6 +27,7 @@
override def hashCode: Int = {
41 + Arrays.hashCode(data)
+// MurmurHash2.hash(data)
}
override def toString = {
@@ -50,4 +52,4 @@
new CacheKey(data)
}
}
-}
\ No newline at end of file
+}
Modified: trunk/server/hotrod/src/main/scala/org/infinispan/server/hotrod/Decoder10.scala
===================================================================
--- trunk/server/hotrod/src/main/scala/org/infinispan/server/hotrod/Decoder10.scala 2010-06-10 12:16:05 UTC (rev 1893)
+++ trunk/server/hotrod/src/main/scala/org/infinispan/server/hotrod/Decoder10.scala 2010-06-10 12:39:02 UTC (rev 1894)
@@ -12,6 +12,7 @@
import org.infinispan.util.concurrent.TimeoutException
import java.io.IOException
import org.infinispan.context.Flag.SKIP_REMOTE_LOOKUP
+import org.infinispan.util.ByteArrayKey
/**
* HotRod protocol decoder specific for specification version 1.0.
@@ -53,7 +54,7 @@
new HotRodHeader(op, messageId, cacheName, flag, clientIntelligence, topologyId, this)
}
- override def readKey(buffer: ChannelBuffer): CacheKey = new CacheKey(buffer.readRangedBytes)
+ override def readKey(buffer: ChannelBuffer): ByteArrayKey = new ByteArrayKey(buffer.readRangedBytes)
override def readParameters(header: HotRodHeader, buffer: ChannelBuffer): Option[RequestParameters] = {
header.op match {
@@ -111,7 +112,7 @@
h.topologyId, None, 0)
}
- override def handleCustomRequest(h: HotRodHeader, buffer: ChannelBuffer, cache: Cache[CacheKey, CacheValue]): AnyRef = {
+ override def handleCustomRequest(h: HotRodHeader, buffer: ChannelBuffer, cache: Cache[ByteArrayKey, CacheValue]): AnyRef = {
h.op match {
case RemoveIfUnmodifiedRequest => {
val k = readKey(buffer)
@@ -172,7 +173,7 @@
}
}
- override def getOptimizedCache(h: HotRodHeader, c: Cache[CacheKey, CacheValue]): Cache[CacheKey, CacheValue] = {
+ override def getOptimizedCache(h: HotRodHeader, c: Cache[ByteArrayKey, CacheValue]): Cache[ByteArrayKey, CacheValue] = {
if (c.getConfiguration.getCacheMode.isDistributed && h.flag == ForceReturnPreviousValue) {
c.getAdvancedCache.withFlags(SKIP_REMOTE_LOOKUP)
} else {
@@ -220,4 +221,4 @@
type ProtocolFlag = Enumeration#Value
val NoFlag = Value
val ForceReturnPreviousValue = Value
-}
\ No newline at end of file
+}
Modified: trunk/server/hotrod/src/main/scala/org/infinispan/server/hotrod/HotRodDecoder.scala
===================================================================
--- trunk/server/hotrod/src/main/scala/org/infinispan/server/hotrod/HotRodDecoder.scala 2010-06-10 12:16:05 UTC (rev 1893)
+++ trunk/server/hotrod/src/main/scala/org/infinispan/server/hotrod/HotRodDecoder.scala 2010-06-10 12:39:02 UTC (rev 1894)
@@ -10,13 +10,14 @@
import org.infinispan.server.hotrod.OperationResponse._
import java.nio.channels.ClosedChannelException
import org.infinispan.{CacheException, Cache}
+import org.infinispan.util.ByteArrayKey
/**
* // TODO: Document this
* @author Galder Zamarreño
* @since 4.1
*/
-class HotRodDecoder(cacheManager: EmbeddedCacheManager) extends AbstractProtocolDecoder[CacheKey, CacheValue] {
+class HotRodDecoder(cacheManager: EmbeddedCacheManager) extends AbstractProtocolDecoder[ByteArrayKey, CacheValue] {
import HotRodDecoder._
import HotRodServer.TopologyCacheName
@@ -65,7 +66,7 @@
}
}
- override def getCache(header: HotRodHeader): Cache[CacheKey, CacheValue] = {
+ override def getCache(header: HotRodHeader): Cache[ByteArrayKey, CacheValue] = {
val cacheName = header.cacheName
if (cacheName == TopologyCacheName)
throw new CacheException("Remote requests are not allowed to topology cache. Do no send remote requests to cache "
@@ -74,11 +75,11 @@
if (cacheName != DefaultCacheManager.DEFAULT_CACHE_NAME && !cacheManager.getCacheNames.contains(cacheName))
throw new CacheNotFoundException("Cache with name '" + cacheName + "' not found amongst the configured caches")
- if (cacheName == DefaultCacheManager.DEFAULT_CACHE_NAME) cacheManager.getCache[CacheKey, CacheValue]
+ if (cacheName == DefaultCacheManager.DEFAULT_CACHE_NAME) cacheManager.getCache[ByteArrayKey, CacheValue]
else cacheManager.getCache(cacheName)
}
- override def readKey(h: HotRodHeader, b: ChannelBuffer): CacheKey =
+ override def readKey(h: HotRodHeader, b: ChannelBuffer): ByteArrayKey =
h.decoder.readKey(b)
override def readParameters(h: HotRodHeader, b: ChannelBuffer): Option[RequestParameters] =
@@ -96,13 +97,13 @@
override def createNotExistResponse(h: HotRodHeader, p: Option[RequestParameters]): AnyRef =
h.decoder.createNotExistResponse(h)
- override def createGetResponse(h: HotRodHeader, k: CacheKey, v: CacheValue): AnyRef =
+ override def createGetResponse(h: HotRodHeader, k: ByteArrayKey, v: CacheValue): AnyRef =
h.decoder.createGetResponse(h, v, h.op)
- override def createMultiGetResponse(h: HotRodHeader, pairs: Map[CacheKey, CacheValue]): AnyRef =
+ override def createMultiGetResponse(h: HotRodHeader, pairs: Map[ByteArrayKey, CacheValue]): AnyRef =
null // Unsupported
- override def handleCustomRequest(h: HotRodHeader, b: ChannelBuffer, cache: Cache[CacheKey, CacheValue]): AnyRef =
+ override def handleCustomRequest(h: HotRodHeader, b: ChannelBuffer, cache: Cache[ByteArrayKey, CacheValue]): AnyRef =
h.decoder.handleCustomRequest(h, b, cache)
override def createStatsResponse(h: HotRodHeader, stats: Stats): AnyRef =
@@ -124,7 +125,7 @@
}
}
- override protected def getOptimizedCache(h: HotRodHeader, c: Cache[CacheKey, CacheValue]): Cache[CacheKey, CacheValue] = {
+ override protected def getOptimizedCache(h: HotRodHeader, c: Cache[ByteArrayKey, CacheValue]): Cache[ByteArrayKey, CacheValue] = {
h.decoder.getOptimizedCache(h, c)
}
}
Modified: trunk/server/hotrod/src/test/scala/org/infinispan/server/hotrod/HotRodFunctionalTest.scala
===================================================================
--- trunk/server/hotrod/src/test/scala/org/infinispan/server/hotrod/HotRodFunctionalTest.scala 2010-06-10 12:16:05 UTC (rev 1893)
+++ trunk/server/hotrod/src/test/scala/org/infinispan/server/hotrod/HotRodFunctionalTest.scala 2010-06-10 12:39:02 UTC (rev 1894)
@@ -9,6 +9,7 @@
import org.infinispan.server.core.CacheValue
import org.infinispan.server.hotrod.OperationStatus._
import org.infinispan.server.hotrod.test._
+import org.infinispan.util.ByteArrayKey
/**
* Hot Rod server functional test.
@@ -50,8 +51,8 @@
def testPutOnDefaultCache(m: Method) {
val status = client.execute(0xA0, 0x01, DefaultCacheManager.DEFAULT_CACHE_NAME, k(m), 0, 0, v(m), 0, 1, 0).status
assertStatus(status, Success)
- val cache = cacheManager.getCache[CacheKey, CacheValue]
- val value = cache.get(new CacheKey(k(m)))
+ val cache = cacheManager.getCache[ByteArrayKey, CacheValue]
+ val value = cache.get(new ByteArrayKey(k(m)))
assertTrue(Arrays.equals(value.data, v(m)));
}
Modified: trunk/server/hotrod/src/test/scala/org/infinispan/server/hotrod/HotRodMarshallingTest.scala
===================================================================
--- trunk/server/hotrod/src/test/scala/org/infinispan/server/hotrod/HotRodMarshallingTest.scala 2010-06-10 12:16:05 UTC (rev 1893)
+++ trunk/server/hotrod/src/test/scala/org/infinispan/server/hotrod/HotRodMarshallingTest.scala 2010-06-10 12:39:02 UTC (rev 1894)
@@ -4,6 +4,7 @@
import org.testng.Assert._
import org.infinispan.commands.remote.ClusteredGetCommand
import org.infinispan.server.core.AbstractMarshallingTest
+import org.infinispan.util.ByteArrayKey
/**
* // TODO: Document this
@@ -14,18 +15,18 @@
class HotRodMarshallingTest extends AbstractMarshallingTest {
def testMarshallingBigByteArrayKey {
- val cacheKey = new CacheKey(getBigByteArray)
+ val cacheKey = new ByteArrayKey(getBigByteArray)
val bytes = marshaller.objectToByteBuffer(cacheKey)
- val readKey = marshaller.objectFromByteBuffer(bytes).asInstanceOf[CacheKey]
+ val readKey = marshaller.objectFromByteBuffer(bytes).asInstanceOf[ByteArrayKey]
assertEquals(readKey, cacheKey)
}
def testMarshallingCommandWithBigByteArrayKey {
- val cacheKey = new CacheKey(getBigByteArray)
+ val cacheKey = new ByteArrayKey(getBigByteArray)
val command = new ClusteredGetCommand(cacheKey, "mycache")
val bytes = marshaller.objectToByteBuffer(command)
val readCommand = marshaller.objectFromByteBuffer(bytes).asInstanceOf[ClusteredGetCommand]
assertEquals(readCommand, command)
}
-}
\ No newline at end of file
+}
Modified: trunk/server/hotrod/src/test/scala/org/infinispan/server/hotrod/HotRodSingleNodeTest.scala
===================================================================
--- trunk/server/hotrod/src/test/scala/org/infinispan/server/hotrod/HotRodSingleNodeTest.scala 2010-06-10 12:16:05 UTC (rev 1893)
+++ trunk/server/hotrod/src/test/scala/org/infinispan/server/hotrod/HotRodSingleNodeTest.scala 2010-06-10 12:39:02 UTC (rev 1894)
@@ -9,6 +9,7 @@
import org.jboss.netty.channel.ChannelFuture
import org.infinispan.test.fwk.TestCacheManagerFactory
import org.infinispan.manager.EmbeddedCacheManager
+import org.infinispan.util.ByteArrayKey
/**
* // TODO: Document this
@@ -19,13 +20,13 @@
val cacheName = "HotRodCache"
private var hotRodServer: HotRodServer = _
private var hotRodClient: HotRodClient = _
- private var advancedCache: AdvancedCache[CacheKey, CacheValue] = _
+ private var advancedCache: AdvancedCache[ByteArrayKey, CacheValue] = _
private var hotRodJmxDomain = getClass.getSimpleName
override def createCacheManager: EmbeddedCacheManager = {
val cacheManager = createTestCacheManager
cacheManager.defineConfiguration(cacheName, cacheManager.getDefaultConfiguration)
- advancedCache = cacheManager.getCache[CacheKey, CacheValue](cacheName).getAdvancedCache
+ advancedCache = cacheManager.getCache[ByteArrayKey, CacheValue](cacheName).getAdvancedCache
hotRodServer = createStartHotRodServer(cacheManager)
hotRodClient = connectClient
cacheManager
@@ -52,4 +53,4 @@
protected def shutdownClient: ChannelFuture = hotRodClient.stop
protected def connectClient: HotRodClient = new HotRodClient("127.0.0.1", hotRodServer.getPort, cacheName, 60)
-}
\ No newline at end of file
+}
More information about the infinispan-commits
mailing list