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

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Sun Nov 8 11:38:31 EST 2009


Author: manik.surtani at jboss.com
Date: 2009-11-08 11:38:31 -0500 (Sun, 08 Nov 2009)
New Revision: 1114

Added:
   trunk/core/src/test/java/org/infinispan/distribution/rehash/WorkDuringJoinTest.java
Modified:
   trunk/core/src/test/java/org/infinispan/distribution/BaseDistFunctionalTest.java
Log:
[ISPN-258] added test

Modified: trunk/core/src/test/java/org/infinispan/distribution/BaseDistFunctionalTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/distribution/BaseDistFunctionalTest.java	2009-11-08 11:34:50 UTC (rev 1113)
+++ trunk/core/src/test/java/org/infinispan/distribution/BaseDistFunctionalTest.java	2009-11-08 16:38:31 UTC (rev 1114)
@@ -28,7 +28,8 @@
 @Test(groups = "functional", testName = "distribution.BaseDistFunctionalTest")
 public abstract class BaseDistFunctionalTest extends MultipleCacheManagersTest {
    protected String cacheName;
-   protected Cache<Object, String> c1, c2, c3, c4;
+   protected int INIT_CLUSTER_SIZE = 4;
+   protected Cache<Object, String> c1 = null, c2 = null, c3 = null, c4 = null;
    protected Configuration configuration;
    protected List<Cache<Object, String>> caches;
    protected List<Address> cacheAddresses;
@@ -37,11 +38,13 @@
    protected boolean testRetVals = true;
    protected boolean l1CacheEnabled = true;
    protected boolean performRehashing = false;
+   protected static final int NUM_OWNERS = 2;
 
    protected void createCacheManagers() throws Throwable {
       cacheName = "dist";
       configuration = getDefaultClusteredConfig(sync ? Configuration.CacheMode.DIST_SYNC : Configuration.CacheMode.DIST_ASYNC, tx);
       configuration.setRehashEnabled(performRehashing);
+      configuration.setNumOwners(NUM_OWNERS);
       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
@@ -51,19 +54,19 @@
       configuration.setSyncReplTimeout(60, TimeUnit.SECONDS);
       configuration.setLockAcquisitionTimeout(45, TimeUnit.SECONDS);
       configuration.setL1CacheEnabled(l1CacheEnabled);
-      caches = createClusteredCaches(4, cacheName, configuration);
+      caches = createClusteredCaches(INIT_CLUSTER_SIZE, cacheName, configuration);
 
       reorderBasedOnCHPositions();
 
-      c1 = caches.get(0);
-      c2 = caches.get(1);
-      c3 = caches.get(2);
-      c4 = caches.get(3);
+      if (INIT_CLUSTER_SIZE > 0) c1 = caches.get(0);
+      if (INIT_CLUSTER_SIZE > 1) c2 = caches.get(1);
+      if (INIT_CLUSTER_SIZE > 2) c3 = caches.get(2);
+      if (INIT_CLUSTER_SIZE > 3) c4 = caches.get(3);
 
-      cacheAddresses = new ArrayList<Address>(4);
+      cacheAddresses = new ArrayList<Address>(INIT_CLUSTER_SIZE);
       for (Cache cache : caches) cacheAddresses.add(cache.getCacheManager().getAddress());
 
-      RehashWaiter.waitForInitRehashToComplete(c1, c2, c3, c4);
+      RehashWaiter.waitForInitRehashToComplete(caches.toArray(new Cache[INIT_CLUSTER_SIZE]));
 
    }
 
@@ -103,7 +106,7 @@
       // wait for all joiners to join
       List<Cache> clist = new ArrayList<Cache>(cacheManagers.size());
       for (CacheManager cm : cacheManagers) clist.add(cm.getCache(cacheName));
-      assert clist.size() == 4;
+      assert clist.size() == INIT_CLUSTER_SIZE;
       waitForJoinTasksToComplete(SECONDS.toMillis(480), clist.toArray(new Cache[clist.size()]));
 
       // seed this with an initial cache.  Any one will do.

Added: trunk/core/src/test/java/org/infinispan/distribution/rehash/WorkDuringJoinTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/distribution/rehash/WorkDuringJoinTest.java	                        (rev 0)
+++ trunk/core/src/test/java/org/infinispan/distribution/rehash/WorkDuringJoinTest.java	2009-11-08 16:38:31 UTC (rev 1114)
@@ -0,0 +1,68 @@
+package org.infinispan.distribution.rehash;
+
+import org.infinispan.Cache;
+import org.infinispan.distribution.BaseDistFunctionalTest;
+import org.infinispan.distribution.ConsistentHash;
+import org.infinispan.distribution.ConsistentHashHelper;
+import org.infinispan.manager.CacheManager;
+import org.infinispan.remoting.transport.Address;
+import org.testng.annotations.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Tests performing some work on the joiner during a JOIN
+ *
+ * @author Manik Surtani
+ * @since 4.0
+ */
+ at Test(groups = "functional", testName = "distribution.rehash.WorkDuringJoinTest")
+public class WorkDuringJoinTest extends BaseDistFunctionalTest {
+
+   CacheManager joinerManager;
+   Cache<Object, String> joiner;
+
+   public WorkDuringJoinTest() {
+      INIT_CLUSTER_SIZE = 2;
+   }
+
+   private List<MagicKey> init() {
+      List<MagicKey> keys = new ArrayList<MagicKey>(Arrays.asList(
+            new MagicKey(c1, "k1"), new MagicKey(c2, "k2"),
+            new MagicKey(c1, "k3"), new MagicKey(c2, "k4")
+      ));
+
+      int i = 0;
+      for (Cache<Object, String> c : caches) c.put(keys.get(i++), "v" + i);
+
+      log.info("Initialized with keys {0}", keys);
+      return keys;
+   }
+
+   Address startNewMember() {
+      joinerManager = addClusterEnabledCacheManager();
+      joinerManager.defineConfiguration(cacheName, configuration);
+      joiner = joinerManager.getCache(cacheName);
+      return joiner.getCacheManager().getAddress();
+   }
+
+   public void testJoinAndGet() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
+      List<MagicKey> keys = init();
+      ConsistentHash chOld = getConsistentHash(c1);
+      Address joinerAddress = startNewMember();
+      ConsistentHash chNew = ConsistentHashHelper.createConsistentHash(chOld.getClass(), chOld.getCaches(), joinerAddress);
+      // which key should me mapped to the joiner?
+      MagicKey keyToTest = null;
+      for (MagicKey k: keys) {
+         if (chNew.isKeyLocalToAddress(joinerAddress, k, NUM_OWNERS)) {
+            keyToTest = k;
+            break;
+         }
+      }
+
+      if (keyToTest == null) throw new NullPointerException("Couldn't find a key mapped to J!");
+      assert joiner.get(keyToTest) != null;
+   }
+}


Property changes on: trunk/core/src/test/java/org/infinispan/distribution/rehash/WorkDuringJoinTest.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF



More information about the infinispan-commits mailing list