[infinispan-commits] Infinispan SVN: r1784 - in trunk/server: core/src/test/scala/org/infinispan/server/core and 3 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Tue May 11 12:35:36 EDT 2010
Author: galder.zamarreno at jboss.com
Date: 2010-05-11 12:35:35 -0400 (Tue, 11 May 2010)
New Revision: 1784
Added:
trunk/server/core/src/test/scala/org/infinispan/server/core/AbstractMarshallingTest.scala
trunk/server/core/src/test/scala/org/infinispan/server/core/MarshallingTest.scala
trunk/server/hotrod/src/test/scala/org/infinispan/server/hotrod/HotRodMarshallingTest.scala
Modified:
trunk/server/core/src/main/scala/org/infinispan/server/core/CacheValue.scala
trunk/server/hotrod/pom.xml
trunk/server/hotrod/src/main/scala/org/infinispan/server/hotrod/CacheKey.scala
Log:
[ISPN-438] (Hot Rod CacheKey's data byte array's length should be written as an integer and not a byte.) Fixed.
Modified: trunk/server/core/src/main/scala/org/infinispan/server/core/CacheValue.scala
===================================================================
--- trunk/server/core/src/main/scala/org/infinispan/server/core/CacheValue.scala 2010-05-11 16:33:06 UTC (rev 1783)
+++ trunk/server/core/src/main/scala/org/infinispan/server/core/CacheValue.scala 2010-05-11 16:35:35 UTC (rev 1784)
@@ -3,6 +3,7 @@
import org.infinispan.util.Util
import java.io.{ObjectOutput, ObjectInput}
import org.infinispan.marshall.Marshallable
+import java.util.Arrays
/**
* // TODO: Document this
@@ -20,19 +21,32 @@
.append("}").toString
}
+ override def equals(obj: Any) = {
+ obj match {
+ // Apparenlty this is the way arrays should be compared for equality of contents, see:
+ // http://old.nabble.com/-scala--Array-equality-td23149094.html
+ case k: CacheValue => Arrays.equals(k.data, this.data) && k.version == this.version
+ case _ => false
+ }
+ }
+
+ override def hashCode: Int = {
+ 41 + Arrays.hashCode(data)
+ }
+
}
object CacheValue {
class Externalizer extends org.infinispan.marshall.Externalizer {
override def writeObject(output: ObjectOutput, obj: AnyRef) {
val cacheValue = obj.asInstanceOf[CacheValue]
- output.write(cacheValue.data.length)
+ output.writeInt(cacheValue.data.length)
output.write(cacheValue.data)
output.writeLong(cacheValue.version)
}
override def readObject(input: ObjectInput): AnyRef = {
- val data = new Array[Byte](input.read())
+ val data = new Array[Byte](input.readInt())
input.readFully(data)
val version = input.readLong
new CacheValue(data, version)
Added: trunk/server/core/src/test/scala/org/infinispan/server/core/AbstractMarshallingTest.scala
===================================================================
--- trunk/server/core/src/test/scala/org/infinispan/server/core/AbstractMarshallingTest.scala (rev 0)
+++ trunk/server/core/src/test/scala/org/infinispan/server/core/AbstractMarshallingTest.scala 2010-05-11 16:35:35 UTC (rev 1784)
@@ -0,0 +1,42 @@
+package org.infinispan.server.core
+
+import org.infinispan.marshall.VersionAwareMarshaller
+import org.testng.annotations.{AfterClass, BeforeTest}
+import org.infinispan.commands.RemoteCommandsFactory
+import java.util.Random
+import java.io.{ObjectOutputStream, ByteArrayOutputStream}
+
+/**
+ * // TODO: Document this
+ * @author Galder Zamarreño
+ * @since 4.1
+ */
+abstract class AbstractMarshallingTest {
+
+ val marshaller = new VersionAwareMarshaller
+
+ @BeforeTest
+ def setUp {
+ marshaller.inject(Thread.currentThread.getContextClassLoader, new RemoteCommandsFactory)
+ marshaller.start
+ }
+
+ @AfterClass
+ def tearDown = marshaller.stop
+
+ protected def getBigByteArray: Array[Byte] = {
+ val value = new String(randomByteArray(1000))
+ val result = new ByteArrayOutputStream(1000)
+ val oos = new ObjectOutputStream(result)
+ oos.writeObject(value)
+ result.toByteArray
+ }
+
+ private def randomByteArray(i: Int): Array[Byte] = {
+ val r = new Random
+ val result = new Array[Byte](i)
+ r.nextBytes(result)
+ result
+ }
+
+}
\ No newline at end of file
Added: trunk/server/core/src/test/scala/org/infinispan/server/core/MarshallingTest.scala
===================================================================
--- trunk/server/core/src/test/scala/org/infinispan/server/core/MarshallingTest.scala (rev 0)
+++ trunk/server/core/src/test/scala/org/infinispan/server/core/MarshallingTest.scala 2010-05-11 16:35:35 UTC (rev 1784)
@@ -0,0 +1,21 @@
+package org.infinispan.server.core
+
+import org.testng.annotations.Test
+import org.testng.Assert._
+
+/**
+ * // TODO: Document this
+ * @author Galder Zamarreño
+ * @since 4.1
+ */
+ at Test(groups = Array("functional"), testName = "server.core.MarshallingTest")
+class MarshallingTest extends AbstractMarshallingTest {
+
+ def testMarshallingBigByteArrayValue {
+ val cacheValue = new CacheValue(getBigByteArray, 9)
+ val bytes = marshaller.objectToByteBuffer(cacheValue)
+ val readValue = marshaller.objectFromByteBuffer(bytes).asInstanceOf[CacheValue]
+ assertEquals(readValue, cacheValue)
+ }
+
+}
\ No newline at end of file
Modified: trunk/server/hotrod/pom.xml
===================================================================
--- trunk/server/hotrod/pom.xml 2010-05-11 16:33:06 UTC (rev 1783)
+++ trunk/server/hotrod/pom.xml 2010-05-11 16:35:35 UTC (rev 1784)
@@ -20,6 +20,13 @@
<artifactId>infinispan-server-core</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>infinispan-server-core</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
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-05-11 16:33:06 UTC (rev 1783)
+++ trunk/server/hotrod/src/main/scala/org/infinispan/server/hotrod/CacheKey.scala 2010-05-11 16:35:35 UTC (rev 1784)
@@ -40,12 +40,12 @@
class Externalizer extends org.infinispan.marshall.Externalizer {
override def writeObject(output: ObjectOutput, obj: AnyRef) {
val cacheKey = obj.asInstanceOf[CacheKey]
- output.write(cacheKey.data.length)
+ output.writeInt(cacheKey.data.length)
output.write(cacheKey.data)
}
override def readObject(input: ObjectInput): AnyRef = {
- val data = new Array[Byte](input.read())
+ val data = new Array[Byte](input.readInt())
input.readFully(data)
new CacheKey(data)
}
Added: trunk/server/hotrod/src/test/scala/org/infinispan/server/hotrod/HotRodMarshallingTest.scala
===================================================================
--- trunk/server/hotrod/src/test/scala/org/infinispan/server/hotrod/HotRodMarshallingTest.scala (rev 0)
+++ trunk/server/hotrod/src/test/scala/org/infinispan/server/hotrod/HotRodMarshallingTest.scala 2010-05-11 16:35:35 UTC (rev 1784)
@@ -0,0 +1,31 @@
+package org.infinispan.server.hotrod
+
+import org.testng.annotations.Test
+import org.testng.Assert._
+import org.infinispan.commands.remote.ClusteredGetCommand
+import org.infinispan.server.core.AbstractMarshallingTest
+
+/**
+ * // TODO: Document this
+ * @author Galder Zamarreño
+ * @since 4.1
+ */
+ at Test(groups = Array("functional"), testName = "server.hotrod.HotRodMarshallingTest")
+class HotRodMarshallingTest extends AbstractMarshallingTest {
+
+ def testMarshallingBigByteArrayKey {
+ val cacheKey = new CacheKey(getBigByteArray)
+ val bytes = marshaller.objectToByteBuffer(cacheKey)
+ val readKey = marshaller.objectFromByteBuffer(bytes).asInstanceOf[CacheKey]
+ assertEquals(readKey, cacheKey)
+ }
+
+ def testMarshallingCommandWithBigByteArrayKey {
+ val cacheKey = new CacheKey(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
More information about the infinispan-commits
mailing list