[infinispan-commits] Infinispan SVN: r2078 - in trunk: core and 5 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Tue Jul 20 06:38:46 EDT 2010
Author: galder.zamarreno at jboss.com
Date: 2010-07-20 06:38:46 -0400 (Tue, 20 Jul 2010)
New Revision: 2078
Added:
trunk/core/src/test/java/org/infinispan/api/lazy/
trunk/core/src/test/java/org/infinispan/api/lazy/LazyCacheAPITest.java
Modified:
trunk/
trunk/core/
trunk/core/src/main/java/org/infinispan/commands/write/ReplaceCommand.java
trunk/core/src/main/java/org/infinispan/config/Configuration.java
trunk/core/src/main/java/org/infinispan/interceptors/MarshalledValueInterceptor.java
Log:
[ISPN-546] (Lazy deserialization not working for replace() calls) Fixed.
Property changes on: trunk
___________________________________________________________________
Name: svn:ignore
- Infinispan-BdbjeCacheStore
infinispan-config-4.0.xsd
.classpath
.project
target
.settings
*.iml
*.ipr
*.log
+ Infinispan-BdbjeCacheStore
infinispan-config-4.0.xsd
.classpath
.project
target
.settings
*.iml
*.ipr
*.log
coretarget
person
PutObjectStoreDirHere
Property changes on: trunk/core
___________________________________________________________________
Name: svn:ignore
- target
.settings
eclipse-output
test-output
output
.classpath
.project
temp-testng-customsuite.xml
Infinispan-FileCacheStore
+ target
.settings
eclipse-output
test-output
output
.classpath
.project
temp-testng-customsuite.xml
Infinispan-FileCacheStore
*.iml
*.log
Modified: trunk/core/src/main/java/org/infinispan/commands/write/ReplaceCommand.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/commands/write/ReplaceCommand.java 2010-07-20 10:29:01 UTC (rev 2077)
+++ trunk/core/src/main/java/org/infinispan/commands/write/ReplaceCommand.java 2010-07-20 10:38:46 UTC (rev 2078)
@@ -31,6 +31,7 @@
/**
* @author Mircea.Markus at jboss.com
+ * @author Galder Zamarre�o
* @since 4.0
*/
@Marshallable(externalizer = ReplicableCommandExternalizer.class, id = Ids.REPLACE_COMMAND)
@@ -151,6 +152,22 @@
return maxIdleTimeMillis;
}
+ public Object getOldValue() {
+ return oldValue;
+ }
+
+ public void setOldValue(Object oldValue) {
+ this.oldValue = oldValue;
+ }
+
+ public Object getNewValue() {
+ return newValue;
+ }
+
+ public void setNewValue(Object newValue) {
+ this.newValue = newValue;
+ }
+
@Override
public String toString() {
return "ReplaceCommand{" +
Modified: trunk/core/src/main/java/org/infinispan/config/Configuration.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/config/Configuration.java 2010-07-20 10:29:01 UTC (rev 2077)
+++ trunk/core/src/main/java/org/infinispan/config/Configuration.java 2010-07-20 10:38:46 UTC (rev 2078)
@@ -166,7 +166,7 @@
/**
*
- * will be removed, please use {@link org.infinispan.manager.CacheContainer#getGlobalConfiguration()}
+ * will be removed, please use {@link org.infinispan.manager.EmbeddedCacheManager#getGlobalConfiguration()}
*/
@Deprecated
public GlobalConfiguration getGlobalConfiguration() {
@@ -2095,4 +2095,4 @@
}
}
}
-}
\ No newline at end of file
+}
Modified: trunk/core/src/main/java/org/infinispan/interceptors/MarshalledValueInterceptor.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/interceptors/MarshalledValueInterceptor.java 2010-07-20 10:29:01 UTC (rev 2077)
+++ trunk/core/src/main/java/org/infinispan/interceptors/MarshalledValueInterceptor.java 2010-07-20 10:38:46 UTC (rev 2078)
@@ -28,6 +28,7 @@
import org.infinispan.commands.write.PutKeyValueCommand;
import org.infinispan.commands.write.PutMapCommand;
import org.infinispan.commands.write.RemoveCommand;
+import org.infinispan.commands.write.ReplaceCommand;
import org.infinispan.container.entries.InternalCacheEntry;
import org.infinispan.container.entries.InternalEntryFactory;
import org.infinispan.context.InvocationContext;
@@ -179,6 +180,28 @@
return Immutables.immutableSetWrap(copy);
}
+ @Override
+ public Object visitReplaceCommand(InvocationContext ctx, ReplaceCommand command) throws Throwable {
+ MarshalledValue key = null, newValue = null, oldValue = null;
+ if (!MarshalledValue.isTypeExcluded(command.getKey().getClass())) {
+ key = createMarshalledValue(command.getKey(), ctx);
+ command.setKey(key);
+ }
+ if (!MarshalledValue.isTypeExcluded(command.getNewValue().getClass())) {
+ newValue = createMarshalledValue(command.getNewValue(), ctx);
+ command.setNewValue(newValue);
+ }
+ if (command.getOldValue() != null && !MarshalledValue.isTypeExcluded(command.getOldValue().getClass())) {
+ oldValue = createMarshalledValue(command.getOldValue(), ctx);
+ command.setOldValue(oldValue);
+ }
+ Object retVal = invokeNextInterceptor(ctx, command);
+ compact(key);
+ compact(newValue);
+ compact(oldValue);
+ return processRetVal(retVal);
+ }
+
private Object compactAndProcessRetVal(Set<MarshalledValue> marshalledValues, Object retVal)
throws IOException, ClassNotFoundException {
if (trace) log.trace("Compacting MarshalledValues created");
Added: trunk/core/src/test/java/org/infinispan/api/lazy/LazyCacheAPITest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/api/lazy/LazyCacheAPITest.java (rev 0)
+++ trunk/core/src/test/java/org/infinispan/api/lazy/LazyCacheAPITest.java 2010-07-20 10:38:46 UTC (rev 2078)
@@ -0,0 +1,92 @@
+package org.infinispan.api.lazy;
+
+import org.infinispan.config.Configuration;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.test.SingleCacheManagerTest;
+import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
+import org.testng.annotations.Test;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+
+/**
+ * Cache API test with lazy deserialization turned on.
+ *
+ * @author Galder Zamarre�o
+ * @since 4.1
+ */
+ at Test(groups = "functional", testName = "api.lazy.LazyCacheAPITest")
+public class LazyCacheAPITest extends SingleCacheManagerTest {
+
+ @Override
+ protected EmbeddedCacheManager createCacheManager() throws Exception {
+ // start a single cache instance
+ Configuration c = getDefaultStandaloneConfig(true);
+ c.setUseLazyDeserialization(true);
+ EmbeddedCacheManager cm = TestCacheManagerFactory.createLocalCacheManager();
+ cm.defineConfiguration("lazy-cache-test", c);
+ cache = cm.getCache("lazy-cache-test");
+ return cm;
+ }
+
+ public void testReplace(Method m) {
+ CustomPojo key = new CustomPojo(m.getName());
+ cache.put(key, "1");
+ assert "1".equals(cache.get(new CustomPojo(m.getName())));
+ Object oldValue = cache.replace(new CustomPojo(m.getName()), "2");
+ assert "1".equals(oldValue);
+ assert "2".equals(cache.get(new CustomPojo(m.getName())));
+ }
+
+ public void testReplaceWithOld(Method m) {
+ CustomPojo key = new CustomPojo(m.getName());
+ cache.put(key, "1");
+ assert "1".equals(cache.get(new CustomPojo(m.getName())));
+ assert !cache.replace(new CustomPojo(m.getName()), "99", "2");
+ assert cache.replace(new CustomPojo(m.getName()), "1", "2");
+
+ key = new CustomPojo(m.getName() + "-withCustomValue");
+ CustomPojo v1 = new CustomPojo("value1");
+ cache.put(key, v1);
+ assert v1.equals(cache.get(key));
+ CustomPojo v99 = new CustomPojo("value99");
+ CustomPojo v2 = new CustomPojo("value2");
+ assert !cache.replace(key, v99, v2);
+ assert cache.replace(key, v1, v2);
+ }
+
+ public static class CustomPojo implements Serializable {
+ static final Log log = LogFactory.getLog(CustomPojo.class);
+
+ private String name;
+
+ public CustomPojo(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ log.debug(obj.getClass());
+ if (obj == null) {
+ log.debug("null -> false");
+ return false;
+
+ }
+ if (getClass() != obj.getClass()) {
+ log.debug("class not same -> false");
+ return false;
+ }
+ final CustomPojo other = (CustomPojo) obj;
+ return this.name.equals(other.name);
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ }
+
+}
More information about the infinispan-commits
mailing list