[infinispan-commits] Infinispan SVN: r756 - in trunk/core/src: test/java/org/infinispan/marshall and 1 other directory.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Mon Aug 31 12:07:07 EDT 2009
Author: galder.zamarreno at jboss.com
Date: 2009-08-31 12:07:06 -0400 (Mon, 31 Aug 2009)
New Revision: 756
Modified:
trunk/core/src/main/java/org/infinispan/marshall/MarshalledValue.java
trunk/core/src/test/java/org/infinispan/marshall/MarshalledValueTest.java
Log:
[ISPN-175] (MarshalledValue's raw form needs trimming to avoid reading too far) Fixed by checking using the BAOS.size() method.
Modified: trunk/core/src/main/java/org/infinispan/marshall/MarshalledValue.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/marshall/MarshalledValue.java 2009-08-31 13:29:49 UTC (rev 755)
+++ trunk/core/src/main/java/org/infinispan/marshall/MarshalledValue.java 2009-08-31 16:07:06 UTC (rev 756)
@@ -91,7 +91,10 @@
} finally {
marshaller.finishObjectOutput(out);
}
- raw = baos.getRawBuffer();
+ byte[] buf = baos.getRawBuffer();
+ int length = baos.size();
+ raw = new byte[length];
+ System.arraycopy(buf, 0, raw, 0, length);
} catch (Exception e) {
throw new CacheException("Unable to marshall value " + instance, e);
} finally {
Modified: trunk/core/src/test/java/org/infinispan/marshall/MarshalledValueTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/marshall/MarshalledValueTest.java 2009-08-31 13:29:49 UTC (rev 755)
+++ trunk/core/src/test/java/org/infinispan/marshall/MarshalledValueTest.java 2009-08-31 16:07:06 UTC (rev 756)
@@ -30,7 +30,9 @@
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
+import java.io.ObjectInputStream;
import java.io.ObjectOutput;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -311,6 +313,12 @@
assert mv.equals(mv2);
}
+ public void testMarshallValueWithCustomReadObjectMethod() {
+ CustomReadObjectMethod obj = new CustomReadObjectMethod();
+ cache1.put("ab-key", obj);
+ assert cache2.get("ab-key").equals(obj);
+ }
+
public void assertUseOfMagicNumbers() throws Exception {
Pojo pojo = new Pojo();
MarshalledValue mv = new MarshalledValue(pojo, true, marshaller);
@@ -473,4 +481,43 @@
deserializationCount++;
}
}
+
+ public static class CustomReadObjectMethod implements Serializable {
+ private static final long serialVersionUID = 1L;
+ String lastName;
+ String ssn;
+ transient boolean deserialized;
+
+ public CustomReadObjectMethod( ) {
+ this("Zamarreno", "234-567-8901");
+ }
+
+ public CustomReadObjectMethod(String lastName, String ssn) {
+ this.lastName = lastName;
+ this.ssn = ssn;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) return true;
+ if (!(obj instanceof CustomReadObjectMethod)) return false;
+ CustomReadObjectMethod pk = (CustomReadObjectMethod) obj;
+ if (!lastName.equals(pk.lastName)) return false;
+ if (!ssn.equals(pk.ssn)) return false;
+ return true;
+ }
+
+ @Override
+ public int hashCode( ) {
+ int result = 17;
+ result = result * 31 + lastName.hashCode();
+ result = result * 31 + ssn.hashCode();
+ return result;
+ }
+
+ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
+ ois.defaultReadObject();
+ deserialized = true;
+ }
+ }
}
More information about the infinispan-commits
mailing list