[infinispan-commits] Infinispan SVN: r2089 - in branches/4.1.x: core and 5 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Wed Jul 21 02:55:44 EDT 2010


Author: galder.zamarreno at jboss.com
Date: 2010-07-21 02:55:43 -0400 (Wed, 21 Jul 2010)
New Revision: 2089

Added:
   branches/4.1.x/core/src/test/java/org/infinispan/api/lazy/
   branches/4.1.x/core/src/test/java/org/infinispan/api/lazy/LazyCacheAPITest.java
Modified:
   branches/4.1.x/
   branches/4.1.x/core/
   branches/4.1.x/core/src/main/java/org/infinispan/commands/write/ReplaceCommand.java
   branches/4.1.x/core/src/main/java/org/infinispan/config/Configuration.java
   branches/4.1.x/core/src/main/java/org/infinispan/interceptors/MarshalledValueInterceptor.java
Log:
[ISPN-546] (Lazy deserialization not working for replace() calls) Fixed.


Property changes on: branches/4.1.x
___________________________________________________________________
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



Property changes on: branches/4.1.x/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: branches/4.1.x/core/src/main/java/org/infinispan/commands/write/ReplaceCommand.java
===================================================================
--- branches/4.1.x/core/src/main/java/org/infinispan/commands/write/ReplaceCommand.java	2010-07-20 16:10:20 UTC (rev 2088)
+++ branches/4.1.x/core/src/main/java/org/infinispan/commands/write/ReplaceCommand.java	2010-07-21 06:55:43 UTC (rev 2089)
@@ -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: branches/4.1.x/core/src/main/java/org/infinispan/config/Configuration.java
===================================================================
--- branches/4.1.x/core/src/main/java/org/infinispan/config/Configuration.java	2010-07-20 16:10:20 UTC (rev 2088)
+++ branches/4.1.x/core/src/main/java/org/infinispan/config/Configuration.java	2010-07-21 06:55:43 UTC (rev 2089)
@@ -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() {

Modified: branches/4.1.x/core/src/main/java/org/infinispan/interceptors/MarshalledValueInterceptor.java
===================================================================
--- branches/4.1.x/core/src/main/java/org/infinispan/interceptors/MarshalledValueInterceptor.java	2010-07-20 16:10:20 UTC (rev 2088)
+++ branches/4.1.x/core/src/main/java/org/infinispan/interceptors/MarshalledValueInterceptor.java	2010-07-21 06:55:43 UTC (rev 2089)
@@ -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: branches/4.1.x/core/src/test/java/org/infinispan/api/lazy/LazyCacheAPITest.java
===================================================================
--- branches/4.1.x/core/src/test/java/org/infinispan/api/lazy/LazyCacheAPITest.java	                        (rev 0)
+++ branches/4.1.x/core/src/test/java/org/infinispan/api/lazy/LazyCacheAPITest.java	2010-07-21 06:55:43 UTC (rev 2089)
@@ -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