[infinispan-commits] Infinispan SVN: r2551 - 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
Thu Oct 21 10:04:39 EDT 2010


Author: mircea.markus
Date: 2010-10-21 10:04:39 -0400 (Thu, 21 Oct 2010)
New Revision: 2551

Added:
   trunk/core/src/test/java/org/infinispan/distribution/ConsistentHashBackupTest.java
   trunk/core/src/test/java/org/infinispan/distribution/DistributionManagerImplTest.java
Modified:
   trunk/core/src/main/java/org/infinispan/commands/read/AbstractLocalCommand.java
   trunk/core/src/main/java/org/infinispan/commands/read/KeySetCommand.java
   trunk/core/src/main/java/org/infinispan/commands/read/SizeCommand.java
   trunk/core/src/test/java/org/infinispan/distribution/DistSyncFuncTest.java
Log:
migrated 2550 to trunk

Modified: trunk/core/src/main/java/org/infinispan/commands/read/AbstractLocalCommand.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/commands/read/AbstractLocalCommand.java	2010-10-21 13:58:54 UTC (rev 2550)
+++ trunk/core/src/main/java/org/infinispan/commands/read/AbstractLocalCommand.java	2010-10-21 14:04:39 UTC (rev 2551)
@@ -39,7 +39,7 @@
       return !ctx.isInTxScope() || !((TxInvocationContext)ctx).hasModifications();
    }
 
-   protected Set<Object> ketKeySetWithinTransaction(InvocationContext ctx, DataContainer container) {
+   protected Set<Object> getKeySetWithinTransaction(InvocationContext ctx, DataContainer container) {
       Set<Object> objects = container.keySet();
       Set<Object> result = new HashSet<Object>();
       result.addAll(objects);

Modified: trunk/core/src/main/java/org/infinispan/commands/read/KeySetCommand.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/commands/read/KeySetCommand.java	2010-10-21 13:58:54 UTC (rev 2550)
+++ trunk/core/src/main/java/org/infinispan/commands/read/KeySetCommand.java	2010-10-21 14:04:39 UTC (rev 2551)
@@ -52,7 +52,7 @@
       if (noTxModifications(ctx)) {
          return Immutables.immutableSetWrap(objects);
       }
-      Set<Object> result = ketKeySetWithinTransaction(ctx, container);
+      Set<Object> result = getKeySetWithinTransaction(ctx, container);
       return Immutables.immutableSetWrap(result);
    }
 

Modified: trunk/core/src/main/java/org/infinispan/commands/read/SizeCommand.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/commands/read/SizeCommand.java	2010-10-21 13:58:54 UTC (rev 2550)
+++ trunk/core/src/main/java/org/infinispan/commands/read/SizeCommand.java	2010-10-21 14:04:39 UTC (rev 2551)
@@ -48,7 +48,7 @@
       if (noTxModifications(ctx)) {
          return container.size();
       }
-      return super.ketKeySetWithinTransaction(ctx, container).size();
+      return super.getKeySetWithinTransaction(ctx, container).size();
    }
 
    @Override

Copied: trunk/core/src/test/java/org/infinispan/distribution/ConsistentHashBackupTest.java (from rev 2550, branches/4.2.x/core/src/test/java/org/infinispan/distribution/ConsistentHashBackupTest.java)
===================================================================
--- trunk/core/src/test/java/org/infinispan/distribution/ConsistentHashBackupTest.java	                        (rev 0)
+++ trunk/core/src/test/java/org/infinispan/distribution/ConsistentHashBackupTest.java	2010-10-21 14:04:39 UTC (rev 2551)
@@ -0,0 +1,88 @@
+package org.infinispan.distribution;
+
+import org.infinispan.remoting.transport.Address;
+import org.infinispan.test.AbstractInfinispanTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * @author Mircea.Markus at jboss.com
+ * @since 4.2
+ */
+ at Test(groups = "functional", testName = "distribution.ConsistentHashBackupTest")
+public class ConsistentHashBackupTest extends AbstractInfinispanTest {
+
+   List<Address> servers;
+   DefaultConsistentHash ch;
+
+   @BeforeTest
+   public void setUp() {
+      servers = new LinkedList<Address>();
+      int numServers = 5;
+      for (int i = 0; i < numServers; i++) {
+         servers.add(new TestAddress(i));
+      }
+
+      ch = (DefaultConsistentHash) BaseDistFunctionalTest.createNewConsistentHash(servers);
+   }
+
+
+   private List<Address> getNext(Address a, int count) {
+      List<Address> addressList = ch.getAddressOnTheWheel();
+      int pos = addressList.indexOf(a);
+      List<Address> result = new ArrayList<Address>();
+      for (int i = 1; i <= count; i++) {
+         result.add(addressList.get((pos + i) % addressList.size()) );
+      }
+      return result;
+   }
+
+   private List<Address> getPrevious(Address a, int count) {
+      List<Address> addressList = ch.getAddressOnTheWheel();
+      int pos = addressList.indexOf(a);
+      List<Address> result = new ArrayList<Address>();
+      for (int i = 1; i <= count; i++) {
+         int index;
+         if (pos - i < 0) {
+            index = addressList.size() + (pos - i);
+         } else {
+            index = pos - i;
+         }
+         result.add(addressList.get((index)));
+      }
+      return result;
+   }
+
+   public void testGetBackupsForNode() {
+      TestAddress testAddress = new TestAddress(0);
+      List<Address> addressList = ch.getBackupsForNode(testAddress, 2);
+      assert addressList.size() == 1;
+
+      assert addressList.get(0).equals(getNext(testAddress, 1).get(0));
+
+      TestAddress ta2 = new TestAddress(3);
+      addressList = ch.getBackupsForNode(ta2, 3);
+      assert addressList.size() == 2;
+
+      assert addressList.equals(getNext(ta2, 2));
+   }
+
+   public void testNodesBackup() {
+      TestAddress testAddress = new TestAddress(0);
+      List<Address> addressList = ch.getNodesThatBackupHere(testAddress, 2);
+      assert addressList.size() == 1;
+      assert addressList.get(0).equals(getPrevious(testAddress, 1).get(0));
+
+      TestAddress ta2 = new TestAddress(3);
+      addressList = ch.getNodesThatBackupHere(ta2, 3);
+      assert addressList.size() == 2;
+
+      List<Address> prev = getPrevious(ta2, 2);
+      assert addressList.containsAll(prev);
+      assert prev.containsAll(addressList);
+   }   
+}

Modified: trunk/core/src/test/java/org/infinispan/distribution/DistSyncFuncTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/distribution/DistSyncFuncTest.java	2010-10-21 13:58:54 UTC (rev 2550)
+++ trunk/core/src/test/java/org/infinispan/distribution/DistSyncFuncTest.java	2010-10-21 14:04:39 UTC (rev 2551)
@@ -117,6 +117,7 @@
       assertOnAllCachesAndOwnership("k1", "value2");
    }
 
+   @Test(invocationCount = 20)
    public void testRemoveFromNonOwner() {
       initAndTest();
       Object retval = getFirstNonOwner("k1").remove("k1");

Copied: trunk/core/src/test/java/org/infinispan/distribution/DistributionManagerImplTest.java (from rev 2550, branches/4.2.x/core/src/test/java/org/infinispan/distribution/DistributionManagerImplTest.java)
===================================================================
--- trunk/core/src/test/java/org/infinispan/distribution/DistributionManagerImplTest.java	                        (rev 0)
+++ trunk/core/src/test/java/org/infinispan/distribution/DistributionManagerImplTest.java	2010-10-21 14:04:39 UTC (rev 2551)
@@ -0,0 +1,77 @@
+package org.infinispan.distribution;
+
+import org.infinispan.config.Configuration;
+import org.infinispan.remoting.transport.Address;
+import org.infinispan.test.AbstractInfinispanTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * @author Mircea.Markus at jboss.com
+ * @since 4.2
+ */
+ at Test (groups = "functional", testName = "distribution.DistributionManagerImplTest")
+public class DistributionManagerImplTest extends AbstractInfinispanTest {
+   List<Address> servers;
+   DefaultConsistentHash ch;
+   Address a0;
+   Address a1;
+   Address a2;
+   Address a3;
+   Address a4;
+
+   @BeforeTest
+   public void setUp() {
+      servers = new LinkedList<Address>();
+      int numServers = 5;
+      for (int i = 0; i < numServers; i++) {
+         servers.add(new TestAddress(i));
+      }
+      ch = (DefaultConsistentHash) BaseDistFunctionalTest.createNewConsistentHash(servers);
+      a0 = ch.getAddressOnTheWheel().get(0);
+      a1 = ch.getAddressOnTheWheel().get(1);
+      a2 = ch.getAddressOnTheWheel().get(2);
+      a3 = ch.getAddressOnTheWheel().get(3);
+      a4 = ch.getAddressOnTheWheel().get(4);
+   }
+
+
+   /**
+    * numOwners = 3. Let's a a2 leaves.
+    */
+   public void testLeaver() {
+      DistributionManagerImpl dm = newDM(3);
+      dm.setSelf(a0);
+      assert dm.willReceiveLeaverState(a2) : " a0 will be the 2nd backup for a3's state";
+      dm.setSelf(a1);
+      assert !dm.willReceiveLeaverState(a2) : " a1 is not affected";
+      dm.setSelf(a3);
+      assert dm.willReceiveLeaverState(a2) : "this needs to receive state from a0";
+      dm.setSelf(a4);
+      assert dm.willReceiveLeaverState(a2) : "this needs to receive state from a1";
+   }
+
+   public void testWillSendLeaverState() {
+      DistributionManagerImpl dm = newDM(3);
+      dm.setSelf(a0);
+      assert dm.willSendLeaverState(a2) : " a0 will need to send state to a3 so that it has 3 backups";
+      dm.setSelf(a1);
+      assert dm.willSendLeaverState(a2) : " a1 backups to a4";
+      dm.setSelf(a3);
+      assert dm.willSendLeaverState(a2) : "needs to send a2 state to a0 (new state backup)";
+      dm.setSelf(a4);
+      assert !dm.willSendLeaverState(a2) : "don't need to send any state as its backups are not affected";
+   }
+
+   private DistributionManagerImpl newDM(int numOwners) {
+      DistributionManagerImpl dm = new DistributionManagerImpl();
+      Configuration configuration = new Configuration();
+      configuration.setNumOwners(numOwners);
+      dm.setConfiguration(configuration);
+      dm.setConsistentHash(ch);
+      return dm;
+   }
+}



More information about the infinispan-commits mailing list