[infinispan-commits] Infinispan SVN: r1004 - in trunk/core/src: test/java/org/infinispan/distribution and 1 other directory.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Mon Oct 26 06:57:52 EDT 2009


Author: galder.zamarreno at jboss.com
Date: 2009-10-26 06:57:52 -0400 (Mon, 26 Oct 2009)
New Revision: 1004

Added:
   trunk/core/src/test/java/org/infinispan/distribution/SingleOwnerTest.java
Modified:
   trunk/core/src/main/java/org/infinispan/interceptors/DistributionInterceptor.java
   trunk/core/src/test/java/org/infinispan/distribution/BaseDistFunctionalTest.java
Log:
[ISPN-237] (Cache put on key owner with single owner configuration shouldn't go remote) Fixed and added test.

Modified: trunk/core/src/main/java/org/infinispan/interceptors/DistributionInterceptor.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/interceptors/DistributionInterceptor.java	2009-10-26 09:51:43 UTC (rev 1003)
+++ trunk/core/src/main/java/org/infinispan/interceptors/DistributionInterceptor.java	2009-10-26 10:57:52 UTC (rev 1004)
@@ -263,7 +263,7 @@
     * time. If the operation didn't originate locally we won't do any replication either.
     */
    private Object handleWriteCommand(InvocationContext ctx, WriteCommand command, RecipientGenerator recipientGenerator, boolean skipRemoteGet) throws Throwable {
-      boolean localModeForced = isLocalModeForced(ctx);
+      boolean localModeForced = isLocalModeForced(ctx) || isSingleOwnerAndLocal(recipientGenerator);
       // see if we need to load values from remote srcs first
       if (!skipRemoteGet) remoteGetBeforeWrite(ctx, command.isConditional(), recipientGenerator);
 
@@ -302,6 +302,13 @@
       return returnValue;
    }
 
+   /**
+    * If a single owner has been configured and the target for the key is the local address, it returns true.
+    */
+   private boolean isSingleOwnerAndLocal(RecipientGenerator recipientGenerator) {
+      return configuration.getNumOwners() == 1 && recipientGenerator.generateRecipients().get(0).equals(rpcManager.getTransport().getAddress());
+   }
+   
    interface KeyGenerator {
       Object[] getKeys();
    }

Modified: trunk/core/src/test/java/org/infinispan/distribution/BaseDistFunctionalTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/distribution/BaseDistFunctionalTest.java	2009-10-26 09:51:43 UTC (rev 1003)
+++ trunk/core/src/test/java/org/infinispan/distribution/BaseDistFunctionalTest.java	2009-10-26 10:57:52 UTC (rev 1004)
@@ -222,7 +222,11 @@
    }
 
    protected Cache<Object, String>[] getOwners(Object key) {
-      Cache<Object, String>[] owners = new Cache[2];
+      return getOwners(key, 2);
+   }
+
+   protected Cache<Object, String>[] getOwners(Object key, int expectedNumberOwners) {
+      Cache<Object, String>[] owners = new Cache[expectedNumberOwners];
       int i = 0;
       for (Cache<Object, String> c : caches) {
          if (isOwner(c, key)) owners[i++] = c;

Added: trunk/core/src/test/java/org/infinispan/distribution/SingleOwnerTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/distribution/SingleOwnerTest.java	                        (rev 0)
+++ trunk/core/src/test/java/org/infinispan/distribution/SingleOwnerTest.java	2009-10-26 10:57:52 UTC (rev 1004)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.distribution;
+
+
+import java.util.ArrayList;
+import java.util.concurrent.TimeUnit;
+
+import org.infinispan.Cache;
+import org.infinispan.config.Configuration;
+import org.infinispan.remoting.transport.Address;
+import org.infinispan.util.concurrent.IsolationLevel;
+import org.testng.annotations.Test;
+
+/**
+ * Ispn234Test.
+ * 
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+ at Test(groups = "unit", testName = "distribution.Ispn234Test")
+public class SingleOwnerTest extends BaseDistFunctionalTest {
+   
+   @Override
+   protected void createCacheManagers() throws Throwable {
+      cacheName = "dist";
+      configuration = getDefaultClusteredConfig(sync ? Configuration.CacheMode.DIST_SYNC : Configuration.CacheMode.DIST_ASYNC, tx);
+      if (!testRetVals) {
+         configuration.setUnsafeUnreliableReturnValues(true);
+         // we also need to use repeatable read for tests to work when we dont have reliable return values, since the
+         // tests repeatedly queries changes
+         configuration.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
+      }
+      configuration.setSyncReplTimeout(60, TimeUnit.SECONDS);
+      configuration.setNumOwners(1);
+      configuration.setLockAcquisitionTimeout(45, TimeUnit.SECONDS);
+      caches = createClusteredCaches(2, cacheName, configuration);
+
+      c1 = caches.get(0);
+      c2 = caches.get(1);
+
+      cacheAddresses = new ArrayList<Address>(2);
+      for (Cache cache : caches) cacheAddresses.add(cache.getCacheManager().getAddress());
+
+      RehashWaiter.waitForInitRehashToComplete(c1, c2);
+   }
+
+   public void testPutOnKeyOwner() {
+      Cache[] caches = getOwners("mykey", 1);
+      assert caches.length == 1;
+      Cache ownerCache = caches[0];
+      ownerCache.put("mykey", new Object());
+   }
+
+}



More information about the infinispan-commits mailing list