You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2016/05/10 21:09:48 UTC

[01/16] incubator-geode git commit: Moving a distributed lock service unit test to open-source.

Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-1371 7c28470bb -> 3bf13bac2


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/2c148caa/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java
old mode 100644
new mode 100755
index f45d2dd..e06958a
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java
@@ -92,7 +92,7 @@ public class DUnitLauncher {
   public static final boolean LOCATOR_LOG_TO_DISK = Boolean.getBoolean("locatorLogToDisk");
 
   static final String MASTER_PARAM = "DUNIT_MASTER";
-  static final String RMI_PORT_PARAM = "gemfire.DUnitLauncher.RMI_PORT";
+  public static final String RMI_PORT_PARAM = "gemfire.DUnitLauncher.RMI_PORT";
   static final String VM_NUM_PARAM = "gemfire.DUnitLauncher.VM_NUM";
 
   private static final String LAUNCHED_PROPERTY = "gemfire.DUnitLauncher.LAUNCHED";
@@ -158,6 +158,7 @@ public class DUnitLauncher {
     //create an RMI registry and add an object to share our tests config
     int namingPort = AvailablePortHelper.getRandomAvailableTCPPort();
     Registry registry = LocateRegistry.createRegistry(namingPort);
+    System.setProperty(RMI_PORT_PARAM, ""+namingPort);
 
     final ProcessManager processManager = new ProcessManager(namingPort, registry);
     master = new Master(registry, processManager);


[04/16] incubator-geode git commit: GEODE-596: change test to start servers on port 0

Posted by kl...@apache.org.
GEODE-596: change test to start servers on port 0


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/6c53d4f8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/6c53d4f8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/6c53d4f8

Branch: refs/heads/feature/GEODE-1371
Commit: 6c53d4f840abb874d2cb9d50f499acf50db61943
Parents: 2c148ca
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Mon May 9 15:08:28 2016 -0700
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Mon May 9 15:11:59 2016 -0700

----------------------------------------------------------------------
 .../MemoryThresholdsOffHeapDUnitTest.java       | 54 ++++++++------------
 1 file changed, 20 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6c53d4f8/geode-core/src/test/java/com/gemstone/gemfire/cache/management/MemoryThresholdsOffHeapDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/cache/management/MemoryThresholdsOffHeapDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/cache/management/MemoryThresholdsOffHeapDUnitTest.java
index be6b266..9216788 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/cache/management/MemoryThresholdsOffHeapDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/cache/management/MemoryThresholdsOffHeapDUnitTest.java
@@ -143,14 +143,11 @@ public class MemoryThresholdsOffHeapDUnitTest extends ClientServerTestCase {
     final VM server1 = host.getVM(0);
     final VM server2 = host.getVM(1);
     
-    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
-    final int port1 = ports[0];
-    final int port2 = ports[1];
     final String regionName = "offHeapEventDelivery";
 
-    startCacheServer(server1, port1, 0f, 0f,
+    startCacheServer(server1, 0f, 0f,
         regionName, false/*createPR*/, false/*notifyBySubscription*/, 0);
-    startCacheServer(server2, port2, 70f, 90f,
+    startCacheServer(server2, 70f, 90f,
         regionName, false/*createPR*/, false/*notifyBySubscription*/, 0);
 
     registerTestMemoryThresholdListener(server1);
@@ -245,10 +242,9 @@ public class MemoryThresholdsOffHeapDUnitTest extends ClientServerTestCase {
     
     final String regionName = "offHeapDisabledThresholds";
 
-    //set port to 0 in-order for system to pickup a random port.
-    startCacheServer(server1, 0, 0f, 0f,
+    startCacheServer(server1, 0f, 0f,
         regionName, false/*createPR*/, false/*notifyBySubscription*/, 0);
-    startCacheServer(server2, 0, 0f, 0f,
+    startCacheServer(server2, 0f, 0f,
         regionName, false/*createPR*/, false/*notifyBySubscription*/, 0);
 
     registerTestMemoryThresholdListener(server1);
@@ -358,14 +354,11 @@ public class MemoryThresholdsOffHeapDUnitTest extends ClientServerTestCase {
     final VM server2 = host.getVM(1);
     final VM client = host.getVM(2);
 
-    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
-    final int port1 = ports[0];
-    final int port2 = ports[1];
     final String regionName = "offHeapDRRemoteClientPutReject";
 
-    startCacheServer(server1, port1, 0f, 0f,
+    final int port1 = startCacheServer(server1, 0f, 0f,
         regionName, false/*createPR*/, false/*notifyBySubscription*/, 0);
-    startCacheServer(server2, port2, 0f, 90f,
+    startCacheServer(server2, 0f, 90f,
         regionName, false/*createPR*/, false/*notifyBySubscription*/, 0);
 
     startClient(client, server1, port1, regionName);
@@ -437,9 +430,9 @@ public class MemoryThresholdsOffHeapDUnitTest extends ClientServerTestCase {
     final String regionName = "offHeapDRRemotePutRejection";
 
     //set port to 0 in-order for system to pickup a random port.
-    startCacheServer(server1, 0, 0f, 0f,
+    startCacheServer(server1, 0f, 0f,
         regionName, false/*createPR*/, false/*notifyBySubscription*/, 0);
-    startCacheServer(server2, 0, 0f, 90f,
+    startCacheServer(server2, 0f, 90f,
         regionName, false/*createPR*/, false/*notifyBySubscription*/, 0);
 
     registerTestMemoryThresholdListener(server1);
@@ -729,7 +722,6 @@ public class MemoryThresholdsOffHeapDUnitTest extends ClientServerTestCase {
     prRemotePutRejection(false, true, false);
   }
 
-  @Category(FlakyTest.class) // GEODE-596: BindException, random ports
   public void testPR_RemotePutRejectionCacheClose() throws Exception {
     prRemotePutRejection(true, false, false);
   }
@@ -746,7 +738,7 @@ public class MemoryThresholdsOffHeapDUnitTest extends ClientServerTestCase {
     prRemotePutRejection(true, false, true);
   }
 
-  @Category(FlakyTest.class) // GEODE-500: random ports, time sensitive, memory sensitive and GC dependent, waitForCriterions
+  @Category(FlakyTest.class) // GEODE-500: time sensitive, memory sensitive and GC dependent, waitForCriterions
   public void testPR_RemotePutRejectionWithTx() throws Exception {
     prRemotePutRejection(false, false, true);
   }
@@ -759,15 +751,14 @@ public class MemoryThresholdsOffHeapDUnitTest extends ClientServerTestCase {
     servers[1] = host.getVM(2);
     servers[2] = host.getVM(3);
 
-    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(3);
     final String regionName = "offHeapPRRemotePutRejection";
     final int redundancy = 1;
 
-    startCacheServer(servers[0], ports[0], 0f, 90f,
+    startCacheServer(servers[0], 0f, 90f,
         regionName, true/*createPR*/, false/*notifyBySubscription*/, redundancy);
-    startCacheServer(servers[1], ports[1], 0f, 90f,
+    startCacheServer(servers[1], 0f, 90f,
         regionName, true/*createPR*/, false/*notifyBySubscription*/, redundancy);
-    startCacheServer(servers[2], ports[2], 0f, 90f,
+    startCacheServer(servers[2], 0f, 90f,
         regionName, true/*createPR*/, false/*notifyBySubscription*/, redundancy);
     accessor.invoke(new SerializableCallable() {
       public Object call() throws Exception {
@@ -1272,15 +1263,11 @@ public class MemoryThresholdsOffHeapDUnitTest extends ClientServerTestCase {
     final VM server2 = host.getVM(1);
     final VM server3 = host.getVM(2);
 
-    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(3);
-    final int port1 = ports[0];
-    final int port2 = ports[1];
-    final int port3 = ports[2];
     final String regionName = "testEventOrder";
 
-    startCacheServer(server1, port1, 0f, 0f,
+    startCacheServer(server1, 0f, 0f,
         regionName, false/*createPR*/, false/*notifyBySubscription*/, 0);
-    startCacheServer(server2, port2, 0f, 0f,
+    startCacheServer(server2, 0f, 0f,
         regionName, false/*createPR*/, false/*notifyBySubscription*/, 0);
 
     verifyProfiles(server1, 2);
@@ -1295,7 +1282,7 @@ public class MemoryThresholdsOffHeapDUnitTest extends ClientServerTestCase {
 
     verifyProfiles(server1, 1);
 
-    startCacheServer(server3, port3, 0f, 0f,
+    startCacheServer(server3, 0f, 0f,
         regionName, false/*createPR*/, false/*notifyBySubscription*/, 0);
 
     verifyProfiles(server1, 2);
@@ -1391,8 +1378,7 @@ public class MemoryThresholdsOffHeapDUnitTest extends ClientServerTestCase {
     final Object bigKey = -1;
     final Object smallKey = -2;
 
-    final int port = AvailablePortHelper.getRandomAvailableTCPPort();
-    startCacheServer(server, port, 0f, 90f,
+    final int port = startCacheServer(server, 0f, 90f,
         regionName, createPR, false, 0);
     startClient(client, server, port, regionName);
     doPuts(client, regionName, false/*catchServerException*/,
@@ -1604,11 +1590,11 @@ public class MemoryThresholdsOffHeapDUnitTest extends ClientServerTestCase {
     });
   }
 
-  private void startCacheServer(VM server, final int port,
+  private int startCacheServer(VM server,
       final float evictionThreshold, final float criticalThreshold, final String regionName,
       final boolean createPR, final boolean notifyBySubscription, final int prRedundancy) throws Exception {
 
-    server.invoke(new SerializableCallable() {
+    return (Integer)server.invoke(new SerializableCallable() {
       public Object call() throws Exception {
         getSystem(getOffHeapProperties());
         GemFireCacheImpl cache = (GemFireCacheImpl)getCache();
@@ -1636,10 +1622,10 @@ public class MemoryThresholdsOffHeapDUnitTest extends ClientServerTestCase {
           assertTrue(region instanceof DistributedRegion);
         }
         CacheServer cacheServer = getCache().addCacheServer();
-        cacheServer.setPort(port);
+        cacheServer.setPort(0);
         cacheServer.setNotifyBySubscription(notifyBySubscription);
         cacheServer.start();
-        return null;
+        return cacheServer.getPort();
       }
     });
   }


[08/16] incubator-geode git commit: GEODE-1234: add a test hook to track client transactions scheduled to be removed.

Posted by kl...@apache.org.
GEODE-1234: add a test hook to track client transactions scheduled to be removed.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/0bf54254
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/0bf54254
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/0bf54254

Branch: refs/heads/feature/GEODE-1371
Commit: 0bf5425491a0ddbe0d614ab174be98957072f962
Parents: 3fe55d4
Author: eshu <es...@pivotal.io>
Authored: Mon May 9 16:36:59 2016 -0700
Committer: eshu <es...@pivotal.io>
Committed: Mon May 9 16:36:59 2016 -0700

----------------------------------------------------------------------
 .../cache/tier/sockets/ClientHealthMonitor.java       | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/0bf54254/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/ClientHealthMonitor.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/ClientHealthMonitor.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/ClientHealthMonitor.java
index 93e543d..c0f5021 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/ClientHealthMonitor.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/ClientHealthMonitor.java
@@ -42,6 +42,7 @@ import com.gemstone.gemfire.internal.cache.IncomingGatewayStatus;
 import com.gemstone.gemfire.internal.cache.TXId;
 import com.gemstone.gemfire.internal.cache.TXManagerImpl;
 import com.gemstone.gemfire.internal.cache.tier.Acceptor;
+import com.gemstone.gemfire.internal.concurrent.ConcurrentHashSet;
 import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
 import com.gemstone.gemfire.internal.logging.LogService;
 import com.gemstone.gemfire.internal.logging.LoggingThreadGroup;
@@ -278,6 +279,16 @@ public class ClientHealthMonitor {
       }
     }
   }
+  
+  private final Set<TXId> scheduledToBeRemovedTx = Boolean.getBoolean("gemfire.trackScheduledToBeRemovedTx")? 
+      new ConcurrentHashSet<TXId>() : null;
+
+  /**
+   * provide a test hook to track client transactions to be removed
+   */
+  public Set<TXId> getScheduledToBeRemovedTx() {
+    return scheduledToBeRemovedTx;
+  }
 
   /**
    * expire the transaction states for the given client.  This uses the
@@ -298,13 +309,16 @@ public class ClientHealthMonitor {
       if (logger.isDebugEnabled()) {
         logger.debug("expiring {} transaction contexts for {} timeout={}", txids.size(), proxyID, timeout/1000);
       }
+
       if (timeout <= 0) {
         txMgr.removeTransactions(txids, true);
       } else {
+        if (scheduledToBeRemovedTx != null) scheduledToBeRemovedTx.addAll(txids);       
         SystemTimerTask task = new SystemTimerTask() {
           @Override
           public void run2() {
             txMgr.removeTransactions(txids, true);
+            if (scheduledToBeRemovedTx != null) scheduledToBeRemovedTx.removeAll(txids);
           }
         };
         ((GemFireCacheImpl)this._cache).getCCPTimer().schedule(task, timeout);


[09/16] incubator-geode git commit: GEODE-1139: mark test method as flaky

Posted by kl...@apache.org.
GEODE-1139: mark test method as flaky


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/c33de6d5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/c33de6d5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/c33de6d5

Branch: refs/heads/feature/GEODE-1371
Commit: c33de6d598db8b36a35b21e2698a33896889e6d3
Parents: 0bf5425
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Mon May 9 17:22:13 2016 -0700
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Mon May 9 17:23:11 2016 -0700

----------------------------------------------------------------------
 .../test/java/com/gemstone/gemfire/cache30/Bug44418JUnitTest.java   | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c33de6d5/geode-core/src/test/java/com/gemstone/gemfire/cache30/Bug44418JUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/cache30/Bug44418JUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/cache30/Bug44418JUnitTest.java
index ce46d6b..a2f92d7 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/cache30/Bug44418JUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/cache30/Bug44418JUnitTest.java
@@ -66,6 +66,7 @@ public class Bug44418JUnitTest { // TODO: rename this test to non-ticket descrip
   private static final int POLL_INTERVAL_MS = 1;       // How often to check for expiration
   private static final String TEST_KEY = "key";
   
+  @Category(FlakyTest.class) // GEODE-1139: time sensitive, thread sleep, expiration
   @Test
   public void testPut() throws Exception {
 


[02/16] incubator-geode git commit: Moving a distributed lock service unit test to open-source.

Posted by kl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/2c148caa/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockServiceDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockServiceDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockServiceDUnitTest.java
new file mode 100755
index 0000000..42c3f01
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockServiceDUnitTest.java
@@ -0,0 +1,3246 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.distributed;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import junit.framework.Assert;
+import junit.framework.AssertionFailedError;
+
+import com.gemstone.gemfire.SystemFailure;
+import com.gemstone.gemfire.distributed.internal.DistributionManager;
+import com.gemstone.gemfire.distributed.internal.DistributionMessage;
+import com.gemstone.gemfire.distributed.internal.DistributionMessageObserver;
+import com.gemstone.gemfire.distributed.internal.locks.DLockGrantor;
+import com.gemstone.gemfire.distributed.internal.locks.DLockRemoteToken;
+import com.gemstone.gemfire.distributed.internal.locks.DLockRequestProcessor;
+import com.gemstone.gemfire.distributed.internal.locks.DLockRequestProcessor.DLockRequestMessage;
+import com.gemstone.gemfire.distributed.internal.locks.DLockRequestProcessor.DLockResponseMessage;
+import com.gemstone.gemfire.distributed.internal.locks.DLockService;
+import com.gemstone.gemfire.distributed.internal.locks.DLockToken;
+import com.gemstone.gemfire.distributed.internal.locks.RemoteThread;
+import com.gemstone.gemfire.distributed.internal.membership.InternalDistributedMember;
+import com.gemstone.gemfire.internal.util.StopWatch;
+import com.gemstone.gemfire.test.dunit.AsyncInvocation;
+import com.gemstone.gemfire.test.dunit.DistributedTestCase;
+import com.gemstone.gemfire.test.dunit.Host;
+import com.gemstone.gemfire.test.dunit.Invoke;
+import com.gemstone.gemfire.test.dunit.LogWriterUtils;
+import com.gemstone.gemfire.test.dunit.RMIException;
+import com.gemstone.gemfire.test.dunit.SerializableCallable;
+import com.gemstone.gemfire.test.dunit.SerializableRunnable;
+import com.gemstone.gemfire.test.dunit.ThreadUtils;
+import com.gemstone.gemfire.test.dunit.VM;
+import com.gemstone.gemfire.test.dunit.Wait;
+import com.gemstone.gemfire.test.dunit.WaitCriterion;
+
+/**
+ * This class tests distributed ownership via the DistributedLockService api.
+ */
+public class DistributedLockServiceDUnitTest extends DistributedTestCase {
+  
+	protected static DistributedSystem dlstSystem;
+  private static DistributedLockBlackboard blackboard;
+  protected static Object monitor = new Object();
+
+  private int hits = 0;
+  private int completes = 0;
+  private boolean done;
+  private boolean got;
+
+
+  public DistributedLockServiceDUnitTest(String name) {
+    super(name);
+    if (blackboard == null) {
+      try {
+        blackboard = DistributedLockBlackboardImpl.getInstance();
+      } catch (Exception e) {
+        throw new RuntimeException("initialization error", e);
+      }
+    }
+  }
+  
+  /////////// Test lifecycle //////////
+ 
+  public static void caseSetUp() throws Exception {
+    disconnectAllFromDS();
+  }
+  
+  public static void caseTearDown() throws Exception {
+    disconnectAllFromDS();
+  }
+  
+  /**
+   * Returns a previously created (or new, if this is the first
+   * time this method is called in this VM) distributed system
+   * which is somewhat configurable via hydra test parameters.
+   */
+  @Override
+  public final void postSetUp() throws Exception {
+    // Create a DistributedSystem in every VM
+    connectDistributedSystem();
+
+    for (int h = 0; h < Host.getHostCount(); h++) {
+      Host host = Host.getHost(h);
+
+      for (int v = 0; v < host.getVMCount(); v++) {
+        host.getVM(v).invoke(
+          DistributedLockServiceDUnitTest.class, "connectDistributedSystem", null);
+      }
+    }
+  }
+
+  @Override
+  public final void preTearDown() throws Exception {
+    Invoke.invokeInEveryVM(DistributedLockServiceDUnitTest.class,
+                    "destroyAllDLockServices"); 
+//    invokeInEveryVM(DistributedLockServiceDUnitTest.class,
+//                    "remoteDumpAllDLockServices"); 
+                    
+    //InternalDistributedLockService.destroyAll();
+    
+//     // Disconnects the DistributedSystem in every VM - since
+//     // each test randomly chooses whether shared memory is used
+//     disconnectAllFromDS();
+    
+    this.lockGrantor = null;
+  }
+  
+  public static void destroyAllDLockServices() {
+    DLockService.destroyAll();
+    dlstSystem = null;
+  }
+
+  public static void remoteDumpAllDLockServices() {
+    DLockService.dumpAllServices();
+  }
+
+  ///////// Remote setup/teardown support
+
+  /**
+   * Connects a DistributedSystem, saves it in static variable "system"
+   */
+  protected static void connectDistributedSystem() {
+    dlstSystem = (new DistributedLockServiceDUnitTest("dummy")).getSystem();
+  }
+
+  /////////  Public test methods
+  
+  public void testBasic() {
+    String serviceName = getUniqueName();
+    String objectName = "object";
+    
+    // Create service
+    DistributedLockService service = DistributedLockService.create(serviceName, dlstSystem);
+    
+    // Not locked initially
+    assertFalse(service.isHeldByCurrentThread(objectName));
+
+    // Get lock
+    assertTrue(service.lock(objectName, 3000, -1));
+    assertTrue(service.isHeldByCurrentThread(objectName));
+    assertTrue(service.lock(objectName, 3000, -1));
+    assertTrue(service.isHeldByCurrentThread(objectName));
+    
+    // Release lock
+    service.unlock(objectName);
+    assertTrue(service.isHeldByCurrentThread(objectName));
+    service.unlock(objectName);
+    assertFalse(service.isHeldByCurrentThread(objectName));
+    
+    // Destroy service
+    DistributedLockService.destroy(serviceName);
+  }
+  
+  public void testCreateDestroy() throws Exception {
+    final String serviceName = getUniqueName();
+    final String abc = "abc";
+    
+    // create and destroy dls
+    assertNull(DistributedLockService.getServiceNamed(serviceName));
+    DistributedLockService service = DistributedLockService.create(serviceName, getSystem());
+    assertSame(service, DistributedLockService.getServiceNamed(serviceName));
+    DistributedLockService.destroy(serviceName);
+    
+    // assert attempt to use dls throws LockServiceDestroyedException
+    try {
+      service.lock(abc, -1, -1);
+      fail("didn't get LockServiceDestroyedException");
+    } catch (LockServiceDestroyedException ex) {
+    }
+    
+    // assert that destroyed dls is no longer available
+    service = DistributedLockService.getServiceNamed(serviceName);
+    assertNull("" + service, service);
+    
+    // recreate the dls
+    service = DistributedLockService.create(serviceName, getSystem());
+    assertTrue(!((DLockService)service).isDestroyed());
+    ((DLockService)service).checkDestroyed();
+    
+    // get the same dls from another thread and hold a lock
+    Thread thread = new Thread(new Runnable() {
+      public void run() {
+        DistributedLockService dls = 
+            DistributedLockService.getServiceNamed(serviceName);
+        assertTrue(!((DLockService)dls).isDestroyed());
+        ((DLockService)dls).checkDestroyed();
+        dls.lock(abc, -1, -1); // get lock on abc and hold it
+      }
+    });
+    thread.start();
+    ThreadUtils.join(thread, 30 * 1000);
+    
+    // start a new thread to wait for lock on abc
+    AsyncInvocation remoteWaitingThread = 
+      Host.getHost(0).getVM(0).invokeAsync(new SerializableRunnable() {
+      public void run() {
+        DistributedLockService dls = 
+            DistributedLockService.create(serviceName, getSystem());
+        try {
+          dls.lock(abc, -1, -1); // waiting to get lock abc
+          fail("remoteWaitingThread got lock after dls destroyed");
+        }
+        catch (LockServiceDestroyedException expected) {
+          return;
+        }
+        fail("remoteWaitingThread lock failed to throw LockServiceDestroyedException");
+      }
+    });
+    
+    // loop will handle race condition with 1 sec sleep and retry
+    int retry = 10;
+    for (int i = 0; i < retry; i++) {
+      try {
+        // destroy DLS and free up remoteWaitingThread
+        Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
+          public void run() {
+            DistributedLockService.destroy(serviceName);
+          }
+        });
+      }
+      catch (RMIException e) {
+        // race condition: remoteWaitingThread probably hasn't created DLS yet
+        if (i < retry && e.getCause() instanceof IllegalArgumentException) {
+          sleep(1000);
+          continue;
+        }
+        else {
+          throw e;
+        }
+      }
+      break; // completed so break out of loop
+    }
+    
+    DistributedLockService.destroy(serviceName);
+    
+    // make sure remoteWaitingThread stopped waiting and threw LockServiceDestroyedException
+    ThreadUtils.join(remoteWaitingThread, 10 * 1000);
+    if (remoteWaitingThread.exceptionOccurred()) {
+      Throwable e = remoteWaitingThread.getException();
+      com.gemstone.gemfire.test.dunit.Assert.fail(e.getMessage(), e);
+    }
+    
+    // make sure LockServiceDestroyedException is thrown
+    try {
+      service.lock(abc, -1, -1);
+      fail("didn't get LockServiceDestroyedException");
+    } catch (LockServiceDestroyedException ex) {
+    }
+    
+    // make sure getServiceNamed returns null
+    service = DistributedLockService.getServiceNamed(serviceName);
+    assertNull("" + service, service);
+  }
+
+  protected static DistributedLockService dls_testFairness;
+  protected static int count_testFairness[] = new int[16];
+  protected static volatile boolean stop_testFairness;
+  protected static volatile boolean[] done_testFairness = new boolean[16];
+  static { Arrays.fill(done_testFairness, true); }
+  public void testFairness() throws Exception {
+    final String serviceName = "testFairness_" + getUniqueName();
+    final Object lock = "lock";
+    
+    // get the lock and hold it until all threads are ready to go
+    DistributedLockService service = 
+        DistributedLockService.create(serviceName, dlstSystem);
+    assertTrue(service.lock(lock, -1, -1));
+    
+    final int[] vmThreads = new int[] { 1, 4, 8, 16 };
+    forNumVMsInvoke(vmThreads.length,
+                    "remoteCreateService", 
+                    new Object[] { serviceName });
+    sleep(100);
+
+    // line up threads for the fairness race...
+    for (int i = 0; i < vmThreads.length; i++) {
+      final int vm = i;
+      LogWriterUtils.getLogWriter().info("[testFairness] lining up " + vmThreads[vm] + 
+                          " threads in vm " + vm); 
+                          
+      for (int j = 0; j < vmThreads[vm]; j++) {
+        final int thread = j;
+        /*getLogWriter().info("[testFairness] setting up thread " + thread +
+                            " in vm " + vm);*/
+        
+        Host.getHost(0).getVM(vm).invokeAsync(new SerializableRunnable() {
+          public void run() {
+            // lock, inc count, and unlock until stop_testFairness is set true
+            try {
+              done_testFairness[thread] = false;
+              dls_testFairness = DistributedLockService.getServiceNamed(serviceName);
+              while (!stop_testFairness) {
+                assertTrue(dls_testFairness.lock(lock, -1, -1));
+                count_testFairness[thread]++;
+                dls_testFairness.unlock(lock);
+              }
+              done_testFairness[thread] = true;
+            }
+            catch (VirtualMachineError e) {
+              SystemFailure.initiateFailure(e);
+              throw e;
+            }
+            catch (Throwable t) {
+              LogWriterUtils.getLogWriter().warning(t);
+              fail(t.getMessage());
+            }
+          }
+        });
+      }
+    }
+    sleep(500); // 500 ms
+    
+    // start the race!
+    service.unlock(lock);
+    sleep(1000 * 5); // 5 seconds
+    assertTrue(service.lock(lock, -1, -1));
+    
+    // stop the race...
+    for (int i = 0; i < vmThreads.length; i++) {
+      final int vm = i;
+      Host.getHost(0).getVM(vm).invoke(new SerializableRunnable() {
+        public void run() {
+          stop_testFairness = true;
+        }
+      });
+    }
+    service.unlock(lock);
+    for (int i = 0; i < vmThreads.length; i++) {
+      final int vm = i;
+      Host.getHost(0).getVM(vm).invoke(new SerializableRunnable() {
+        public void run() {
+          try {
+            boolean testIsDone = false;
+            while (!stop_testFairness || !testIsDone) {
+              testIsDone = true;
+              for (int i2 = 0; i2 < done_testFairness.length; i2++) {
+                if (!done_testFairness[i2]) testIsDone = false;
+              }
+            }
+            DistributedLockService.destroy(serviceName);
+          }
+          catch (VirtualMachineError e) {
+            SystemFailure.initiateFailure(e);
+            throw e;
+          }
+          catch (Throwable t) {
+            fail(t.getMessage());
+          }
+        }
+      });
+    }
+    
+    // calc total locks granted...
+    int totalLocks = 0;
+    int minLocks = Integer.MAX_VALUE;
+    int maxLocks = 0;
+
+    // add up total locks across all vms and threads...
+    int numThreads = 0;
+    for (int i = 0; i < vmThreads.length; i++) {
+      final int vm = i;
+      for (int j = 0; j < vmThreads[vm]; j++) {
+        final int thread = j;
+        Integer count = (Integer)Host.getHost(0).getVM(vm).invoke(() -> DistributedLockServiceDUnitTest.get_count_testFairness( new Integer(thread) ));
+        int numLocks = count.intValue();
+        if (numLocks < minLocks) minLocks = numLocks;
+        if (numLocks > maxLocks) maxLocks = numLocks;
+        totalLocks = totalLocks + numLocks;
+        numThreads++;
+      }
+    }
+
+    LogWriterUtils.getLogWriter().info("[testFairness] totalLocks=" + totalLocks + 
+                        " minLocks=" + minLocks +
+                        " maxLocks=" + maxLocks);
+
+    int expectedLocks = (totalLocks / numThreads) + 1;
+    
+    int deviation = (int)(expectedLocks * 0.3);
+    int lowThreshold = expectedLocks - deviation;
+    int highThreshold = expectedLocks + deviation;
+
+    LogWriterUtils.getLogWriter().info("[testFairness] deviation=" + deviation +
+                        " expectedLocks=" + expectedLocks + 
+                        " lowThreshold=" + lowThreshold +
+                        " highThreshold=" + highThreshold);
+                        
+    assertTrue("minLocks is less than lowThreshold",
+               minLocks >= lowThreshold);
+    assertTrue("maxLocks is greater than highThreshold",
+               maxLocks <= highThreshold);
+  }
+  
+  /**
+   * Accessed by reflection.  DO NOT REMOVE
+   * @param i
+   * @return
+   */
+  public static Integer get_count_testFairness(Integer i) {
+    return new Integer(count_testFairness[i.intValue()]);
+  }
+  
+  public void testOneGetsAndOthersTimeOut() throws Exception {
+    doOneGetsAndOthersTimeOut(1, 1);
+//     doOneGetsAndOthersTimeOut(2, 2);
+//     doOneGetsAndOthersTimeOut(3, 2);
+    doOneGetsAndOthersTimeOut(4, 3);
+  }
+  
+  private InternalDistributedMember lockGrantor;
+  private synchronized void assertGrantorIsConsistent(InternalDistributedMember id) {
+    if (this.lockGrantor == null) {
+      this.lockGrantor = id;
+    } else {
+      assertEquals("assertGrantorIsConsistent failed", lockGrantor, id);
+    }
+  }
+  
+  /**
+   * Accessed via reflection.  DO NOT REMOVE
+   * @param serviceName
+   * @return
+   */
+  public static InternalDistributedMember identifyLockGrantor(String serviceName) {
+    DLockService service = (DLockService)
+        DistributedLockService.getServiceNamed(serviceName);
+    assertNotNull(service);
+    InternalDistributedMember grantor = service.getLockGrantorId().getLockGrantorMember();
+    assertNotNull(grantor);
+    logInfo("In identifyLockGrantor - grantor is " + grantor);
+    return grantor;
+  }
+  
+  /**
+   * Accessed via reflection.  DO NOT REMOVE.
+   * @param serviceName
+   * @return
+   */
+  public static Boolean isLockGrantor(String serviceName) {
+    DLockService service = (DLockService)
+        DistributedLockService.getServiceNamed(serviceName);
+    assertNotNull(service);
+    Boolean result = Boolean.valueOf(service.isLockGrantor());
+    logInfo("In isLockGrantor: " + result);
+    return result;
+  }
+
+  /**
+   * Accessed via reflection.  DO NOT REMOVE.
+   * @param serviceName
+   */
+  protected static void becomeLockGrantor(String serviceName) {
+    DLockService service = (DLockService)
+        DistributedLockService.getServiceNamed(serviceName);
+    assertNotNull(service);
+    logInfo("About to call becomeLockGrantor...");
+    service.becomeLockGrantor();
+  }
+  
+  public void testGrantorSelection() {
+    // TODO change distributedCreateService usage to be concurrent threads
+    
+    // bring up 4 members and make sure all identify one as grantor
+    int numVMs = 4;
+    final String serviceName = "testGrantorSelection_" + getUniqueName();
+    distributedCreateService(numVMs, serviceName);
+    try {
+      Thread.sleep(100);
+    }
+    catch (InterruptedException ignore) {fail("interrupted");}
+
+    final Object[] args = new Object[] {serviceName};
+    final Host host = Host.getHost(0);
+    for (int vm=0; vm<numVMs; vm++) {
+      final int finalvm = vm;
+      logInfo("VM " + finalvm + " in " + serviceName + " about to invoke");
+      InternalDistributedMember id = (InternalDistributedMember)host.getVM(finalvm).invoke(
+          DistributedLockServiceDUnitTest.class, 
+          "identifyLockGrantor", 
+          args);
+      logInfo("VM " + finalvm + " in " + serviceName + " got " + id);
+      assertGrantorIsConsistent(id);
+    }
+  }
+  
+  public void testBasicGrantorRecovery() {
+    //DLockGrantor.setUncleanDestroyEnabled(true);
+//    try {
+      // 1) start up 4 VM members...
+      int numVMs = 4;
+      final String serviceName = "testBasicGrantorRecovery_" + getUniqueName();
+      distributedCreateService(numVMs, serviceName);
+      try {
+        Thread.sleep(100);
+      }
+      catch (InterruptedException ignore) {fail("interrupted");}
+      
+      final Object[] args = new Object[] {serviceName};
+      final Host host = Host.getHost(0);
+      
+      int originalGrantor = 3;
+      host.getVM(originalGrantor).invoke(
+          DistributedLockServiceDUnitTest.class, "identifyLockGrantor", args);
+            
+      // 2) find the grantor and disconnect him...
+      int originalVM = -1;
+      InternalDistributedMember oldGrantor = null;
+      for (int vm = 0; vm < numVMs; vm++) {
+        final int finalvm = vm;
+        Boolean isGrantor = (Boolean)host.getVM(finalvm).invoke(
+            DistributedLockServiceDUnitTest.class, "isLockGrantor", args);
+        if (isGrantor.booleanValue()) {
+          originalVM = vm;
+          oldGrantor = (InternalDistributedMember)host.getVM(finalvm).invoke(
+            DistributedLockServiceDUnitTest.class, "identifyLockGrantor", args);
+          break;
+        }
+      }
+      
+      assertTrue(originalVM == originalGrantor);
+      
+      host.getVM(originalVM).invoke(new SerializableRunnable() {
+        public void run() {
+          disconnectFromDS();
+        }
+      });
+      
+      try {
+        Thread.sleep(100);
+      }
+      catch (InterruptedException ignore) {fail("interrupted");}
+        
+      // 3) verify that another member recovers for grantor
+      int attempts = 3;
+      for (int attempt = 0; attempt < attempts; attempt++) {
+        try {
+          for (int vm = 0; vm < numVMs; vm++) {
+            if (vm == originalVM) continue; // skip because he's disconnected
+            final int finalvm = vm;
+            logInfo("[testBasicGrantorRecovery] VM " + finalvm + 
+                    " in " + serviceName + " about to invoke");
+            InternalDistributedMember id = (InternalDistributedMember)host.getVM(finalvm).invoke(
+                DistributedLockServiceDUnitTest.class, 
+                "identifyLockGrantor", 
+                args);
+            logInfo("[testBasicGrantorRecovery] VM " + finalvm + 
+                    " in " + serviceName + " got " + id);
+            assertGrantorIsConsistent(id);
+            logInfo("[testBasicGrantorRecovery] new grantor " + id + 
+                    " is not old grantor " + oldGrantor);
+            assertEquals("New grantor must not equal the old grantor", true,
+                         !id.equals(oldGrantor)); // new grantor != old grantor
+          } // loop thru vms
+          logInfo("[testBasicGrantorRecovery] succeeded attempt " + attempt);
+          break; // success
+        }
+        catch (AssertionFailedError e) {
+          logInfo("[testBasicGrantorRecovery] failed attempt " + attempt);
+          if (attempt == attempts-1) throw e;
+        }
+      } // loop thru attempts
+//    }
+//    finally {
+      //DLockGrantor.setUncleanDestroyEnabled(false);
+//    }
+  }
+  
+  public void testLockFailover() {
+    final int originalGrantorVM = 0;
+    final int oneVM = 1;
+    final int twoVM = 2;
+    final String serviceName = "testLockFailover-" + getUniqueName();
+    
+    // create lock services...
+    LogWriterUtils.getLogWriter().fine("[testLockFailover] create services");
+    
+    Host.getHost(0).getVM(originalGrantorVM).invoke(() -> DistributedLockServiceDUnitTest.remoteCreateService( serviceName ));
+    
+    Host.getHost(0).getVM(oneVM).invoke(() -> DistributedLockServiceDUnitTest.remoteCreateService( serviceName ));
+    
+    Host.getHost(0).getVM(twoVM).invoke(() -> DistributedLockServiceDUnitTest.remoteCreateService( serviceName ));
+    
+    Host.getHost(0).getVM(originalGrantorVM).invoke(() -> DistributedLockServiceDUnitTest.identifyLockGrantor( serviceName ));
+        
+    Boolean isGrantor = (Boolean) Host.getHost(0).getVM(originalGrantorVM).invoke(() -> DistributedLockServiceDUnitTest.isLockGrantor( serviceName ));
+    assertEquals("First member calling getLockGrantor failed to become grantor", 
+                 Boolean.TRUE, isGrantor);
+
+    // get locks...
+    LogWriterUtils.getLogWriter().fine("[testLockFailover] get lock");
+    
+    Boolean locked = (Boolean) Host.getHost(0).getVM(originalGrantorVM).invoke(() -> DistributedLockServiceDUnitTest.lock( serviceName, "KEY-"+originalGrantorVM ));
+    assertEquals("Failed to get lock in testLockFailover", 
+                 Boolean.TRUE, locked);
+                 
+    locked = (Boolean) Host.getHost(0).getVM(twoVM).invoke(() -> DistributedLockServiceDUnitTest.lock( serviceName, "KEY-"+twoVM ));
+    assertEquals("Failed to get lock in testLockFailover", 
+                 Boolean.TRUE, locked);
+                 
+    locked = (Boolean) Host.getHost(0).getVM(oneVM).invoke(() -> DistributedLockServiceDUnitTest.lock( serviceName, "KEY-"+oneVM ));
+    assertEquals("Failed to get lock in testLockFailover", 
+                 Boolean.TRUE, locked);
+                 
+    // disconnect originalGrantorVM...
+    LogWriterUtils.getLogWriter().fine("[testLockFailover] disconnect originalGrantorVM");
+
+    Host.getHost(0).getVM(originalGrantorVM).invoke(new SerializableRunnable() {
+      public void run() {
+        disconnectFromDS();
+      }
+    });
+    
+    try {
+      Thread.sleep(100);
+    }
+    catch (InterruptedException ignore) {fail("interrupted");}
+                 
+    // verify locks by unlocking...
+    LogWriterUtils.getLogWriter().fine("[testLockFailover] release locks");
+                 
+    Boolean unlocked = (Boolean) Host.getHost(0).getVM(twoVM).invoke(() -> DistributedLockServiceDUnitTest.unlock( serviceName, "KEY-"+twoVM ));
+    assertEquals("Failed to release lock in testLockFailover", 
+                 Boolean.TRUE, unlocked);
+
+    unlocked = (Boolean) Host.getHost(0).getVM(oneVM).invoke(() -> DistributedLockServiceDUnitTest.unlock( serviceName, "KEY-"+oneVM ));
+    assertEquals("Failed to release lock in testLockFailover", 
+                 Boolean.TRUE, unlocked);
+
+    // switch locks...
+    locked = (Boolean) Host.getHost(0).getVM(oneVM).invoke(() -> DistributedLockServiceDUnitTest.lock( serviceName, "KEY-"+twoVM ));
+    assertEquals("Failed to get lock in testLockFailover", 
+                 Boolean.TRUE, locked);
+                 
+    locked = (Boolean) Host.getHost(0).getVM(twoVM).invoke(() -> DistributedLockServiceDUnitTest.lock( serviceName, "KEY-"+oneVM ));
+    assertEquals("Failed to get lock in testLockFailover", 
+                 Boolean.TRUE, locked);
+                 
+    unlocked = (Boolean) Host.getHost(0).getVM(oneVM).invoke(() -> DistributedLockServiceDUnitTest.unlock( serviceName, "KEY-"+twoVM ));
+    assertEquals("Failed to release lock in testLockFailover", 
+                 Boolean.TRUE, unlocked);
+
+    unlocked = (Boolean) Host.getHost(0).getVM(twoVM).invoke(() -> DistributedLockServiceDUnitTest.unlock( serviceName, "KEY-"+oneVM ));
+    assertEquals("Failed to release lock in testLockFailover", 
+                 Boolean.TRUE, unlocked);
+                 
+    // verify grantor is unique...
+    LogWriterUtils.getLogWriter().fine("[testLockFailover] verify grantor identity");
+    
+    InternalDistributedMember oneID = (InternalDistributedMember)Host.getHost(0).getVM(oneVM).invoke(() -> DistributedLockServiceDUnitTest.identifyLockGrantor(serviceName));
+    InternalDistributedMember twoID = (InternalDistributedMember)Host.getHost(0).getVM(twoVM).invoke(() -> DistributedLockServiceDUnitTest.identifyLockGrantor(serviceName));
+    assertTrue("Failed to identifyLockGrantor in testLockFailover",
+               oneID != null && twoID != null);
+    assertEquals("Failed grantor uniqueness in testLockFailover", 
+                 oneID, twoID);
+  }
+  
+  public void testLockThenBecomeLockGrantor() {
+    final int originalGrantorVM = 0;
+    final int becomeGrantorVM = 1;
+    final int thirdPartyVM = 2;
+    final String serviceName = "testLockThenBecomeLockGrantor-" + getUniqueName();
+    
+    // create lock services...
+    LogWriterUtils.getLogWriter().fine("[testLockThenBecomeLockGrantor] create services");
+    
+    Host.getHost(0).getVM(originalGrantorVM).invoke(() -> DistributedLockServiceDUnitTest.remoteCreateService( serviceName ));
+    
+    try {
+      Thread.sleep(20);
+    } catch (InterruptedException ignore) {fail("interrupted");}
+
+    Host.getHost(0).getVM(becomeGrantorVM).invoke(() -> DistributedLockServiceDUnitTest.remoteCreateService( serviceName ));
+    
+    Host.getHost(0).getVM(thirdPartyVM).invoke(() -> DistributedLockServiceDUnitTest.remoteCreateService( serviceName ));
+    
+    Host.getHost(0).getVM(originalGrantorVM).invoke(() -> DistributedLockServiceDUnitTest.identifyLockGrantor( serviceName ));
+        
+    Boolean isGrantor = (Boolean) Host.getHost(0).getVM(originalGrantorVM).invoke(() -> DistributedLockServiceDUnitTest.isLockGrantor( serviceName ));
+    assertEquals("First member calling getLockGrantor failed to become grantor", 
+                 Boolean.TRUE, isGrantor);
+
+    // control...
+    LogWriterUtils.getLogWriter().fine("[testLockThenBecomeLockGrantor] check control");
+    Boolean check = (Boolean) Host.getHost(0).getVM(becomeGrantorVM).invoke(() -> DistributedLockServiceDUnitTest.unlock( serviceName, "KEY-"+becomeGrantorVM ));
+    assertEquals("Check of control failed... unlock succeeded but nothing locked", 
+                 Boolean.FALSE, check);
+                 
+    // get locks...
+    LogWriterUtils.getLogWriter().fine("[testLockThenBecomeLockGrantor] get lock");
+    
+    Boolean locked = (Boolean) Host.getHost(0).getVM(originalGrantorVM).invoke(() -> DistributedLockServiceDUnitTest.lock( serviceName, "KEY-"+originalGrantorVM ));
+    assertEquals("Failed to get lock in testLockThenBecomeLockGrantor", 
+                 Boolean.TRUE, locked);
+                 
+    locked = (Boolean) Host.getHost(0).getVM(thirdPartyVM).invoke(() -> DistributedLockServiceDUnitTest.lock( serviceName, "KEY-"+thirdPartyVM ));
+    assertEquals("Failed to get lock in testLockThenBecomeLockGrantor", 
+                 Boolean.TRUE, locked);
+                 
+    locked = (Boolean) Host.getHost(0).getVM(becomeGrantorVM).invoke(() -> DistributedLockServiceDUnitTest.lock( serviceName, "KEY-"+becomeGrantorVM ));
+    assertEquals("Failed to get lock in testLockThenBecomeLockGrantor", 
+                 Boolean.TRUE, locked);
+                 
+    // become lock grantor...
+    LogWriterUtils.getLogWriter().fine("[testLockThenBecomeLockGrantor] become lock grantor");
+    
+    Host.getHost(0).getVM(becomeGrantorVM).invoke(() -> DistributedLockServiceDUnitTest.becomeLockGrantor( serviceName ));
+        
+    try {
+      Thread.sleep(20);
+    } catch (InterruptedException ignore) {fail("interrupted");}
+    
+    isGrantor = (Boolean) Host.getHost(0).getVM(becomeGrantorVM).invoke(() -> DistributedLockServiceDUnitTest.isLockGrantor( serviceName ));
+    assertEquals("Failed to become lock grantor", 
+                 Boolean.TRUE, isGrantor);    
+
+    // verify locks by unlocking...
+    LogWriterUtils.getLogWriter().fine("[testLockThenBecomeLockGrantor] release locks");
+                 
+    Boolean unlocked = (Boolean) Host.getHost(0).getVM(originalGrantorVM).invoke(() -> DistributedLockServiceDUnitTest.unlock( serviceName, "KEY-"+originalGrantorVM ));
+    assertEquals("Failed to release lock in testLockThenBecomeLockGrantor", 
+                 Boolean.TRUE, unlocked);
+                 
+    unlocked = (Boolean) Host.getHost(0).getVM(thirdPartyVM).invoke(() -> DistributedLockServiceDUnitTest.unlock( serviceName, "KEY-"+thirdPartyVM ));
+    assertEquals("Failed to release lock in testLockThenBecomeLockGrantor", 
+                 Boolean.TRUE, unlocked);
+
+    unlocked = (Boolean) Host.getHost(0).getVM(becomeGrantorVM).invoke(() -> DistributedLockServiceDUnitTest.unlock( serviceName, "KEY-"+becomeGrantorVM ));
+    assertEquals("Failed to release lock in testLockThenBecomeLockGrantor", 
+                 Boolean.TRUE, unlocked);
+
+    // test for bug in which transferred token gets re-entered causing lock recursion
+    unlocked = (Boolean) Host.getHost(0).getVM(becomeGrantorVM).invoke(() -> DistributedLockServiceDUnitTest.unlock( serviceName, "KEY-"+becomeGrantorVM ));
+    assertEquals("Transfer of tokens caused lock recursion in held lock", 
+                 Boolean.FALSE, unlocked);
+  }
+  
+  public void testBecomeLockGrantor() {
+    // create lock services...
+    int numVMs = 4;
+    final String serviceName = "testBecomeLockGrantor-" + getUniqueName();
+    distributedCreateService(numVMs, serviceName);
+    
+    // each one gets a lock...
+    for (int vm = 0; vm < numVMs; vm++) {
+      final int finalvm = vm;
+      Boolean locked = Host.getHost(0).getVM(finalvm).invoke(() -> DistributedLockServiceDUnitTest.lock( serviceName, "obj-"+finalvm ));
+      assertEquals("Failed to get lock in testBecomeLockGrantor", 
+                   Boolean.TRUE, locked);
+    }
+    
+    // find the grantor...
+    final Object[] args = new Object[] {serviceName};
+    int originalVM = -1;
+    InternalDistributedMember oldGrantor = null;
+    for (int vm = 0; vm < numVMs; vm++) {
+      final int finalvm = vm;
+      Boolean isGrantor = (Boolean)Host.getHost(0).getVM(finalvm).invoke(
+          DistributedLockServiceDUnitTest.class, "isLockGrantor", args);
+      if (isGrantor.booleanValue()) {
+        originalVM = vm;
+        oldGrantor = (InternalDistributedMember)Host.getHost(0).getVM(finalvm).invoke(
+          DistributedLockServiceDUnitTest.class, "identifyLockGrantor", args);
+        break;
+      }
+    }
+    
+    LogWriterUtils.getLogWriter().fine("[testBecomeLockGrantor] original grantor is " + oldGrantor);
+    
+    // have one call becomeLockGrantor
+    for (int vm = 0; vm < numVMs; vm++) {
+      if (vm != originalVM) {
+        final int finalvm = vm;
+        Host.getHost(0).getVM(finalvm).invoke(
+            DistributedLockServiceDUnitTest.class, "becomeLockGrantor", args);
+        Boolean isGrantor = (Boolean)Host.getHost(0).getVM(finalvm).invoke(
+            DistributedLockServiceDUnitTest.class, "isLockGrantor", args);
+        assertEquals("isLockGrantor is false after calling becomeLockGrantor", 
+                     Boolean.TRUE, isGrantor);
+        break;
+      }
+    }
+    
+    LogWriterUtils.getLogWriter().fine("[testBecomeLockGrantor] one vm has called becomeLockGrantor...");
+    
+    InternalDistributedMember newGrantor = null;
+    for (int vm = 0; vm < numVMs; vm++) {
+      final int finalvm = vm;
+      Boolean isGrantor = (Boolean)Host.getHost(0).getVM(finalvm).invoke(
+          DistributedLockServiceDUnitTest.class, "isLockGrantor", args);
+      if (isGrantor.booleanValue()) {
+        newGrantor = (InternalDistributedMember)Host.getHost(0).getVM(finalvm).invoke(
+          DistributedLockServiceDUnitTest.class, "identifyLockGrantor", args);
+        break;
+      }
+    }
+    LogWriterUtils.getLogWriter().fine("[testBecomeLockGrantor] new Grantor is " + newGrantor);
+    assertEquals(false, newGrantor.equals(oldGrantor));
+    
+    // verify locks still held by unlocking
+    // each one unlocks...
+    for (int vm = 0; vm < numVMs; vm++) {
+      final int finalvm = vm;
+      Boolean unlocked = (Boolean) Host.getHost(0).getVM(finalvm).invoke(() -> DistributedLockServiceDUnitTest.unlock( serviceName, "obj-"+finalvm ));
+      assertEquals("Failed to unlock in testBecomeLockGrantor", 
+                   Boolean.TRUE, unlocked);
+    }
+    
+    LogWriterUtils.getLogWriter().fine("[testBecomeLockGrantor] finished");
+    
+    // verify that pending requests are granted by unlocking them also
+  }
+
+  public void testTryLock() {
+    final Long waitMillis = new Long(100);
+    
+    // create lock services...
+    LogWriterUtils.getLogWriter().fine("[testTryLock] create lock services");
+    final String serviceName = "testTryLock-" + getUniqueName();
+    distributedCreateService(4, serviceName);
+    
+    // all 4 vms scramble to get tryLock but only one should succeed...
+    LogWriterUtils.getLogWriter().fine("[testTryLock] attempt to get tryLock");
+    int lockCount = 0;
+    for (int vm = 0; vm < 4; vm++) {
+      final int finalvm = vm;
+      Boolean locked = (Boolean) Host.getHost(0).getVM(finalvm).invoke(() -> DistributedLockServiceDUnitTest.tryLock( serviceName, "KEY", waitMillis ));
+      if (locked.booleanValue()) lockCount++;
+    }
+
+    assertEquals("More than one vm acquired the tryLock", 
+                 1, lockCount);    
+
+    LogWriterUtils.getLogWriter().fine("[testTryLock] unlock tryLock");
+    int unlockCount = 0;
+    for (int vm = 0; vm < 4; vm++) {
+      final int finalvm = vm;
+      Boolean unlocked = (Boolean) Host.getHost(0).getVM(finalvm).invoke(() -> DistributedLockServiceDUnitTest.unlock( serviceName, "KEY" ));
+      if (unlocked.booleanValue()) unlockCount++;
+    }
+
+    assertEquals("More than one vm unlocked the tryLock", 
+                 1, unlockCount);    
+  }
+  
+  public void testOneGetsThenOtherGets()  throws Exception  { // (numVMs, numThreadsPerVM)
+    doOneGetsThenOtherGets(1, 1);
+//     doOneGetsThenOtherGets(2, 2);
+//     doOneGetsThenOtherGets(3, 3);
+    doOneGetsThenOtherGets(4, 3);
+  }
+  
+  public void testLockDifferentNames() throws Exception  {
+    String serviceName = getUniqueName();
+
+    // Same VM
+    remoteCreateService(serviceName);
+    DistributedLockService service = DistributedLockService.getServiceNamed(serviceName);
+    assertTrue(service.lock("obj1", -1, -1));
+    assertTrue(service.lock("obj2", -1, -1));
+    service.unlock("obj1");
+    service.unlock("obj2");
+    
+    // Different VMs
+    VM vm = Host.getHost(0).getVM(0);
+    vm.invoke(() -> this.remoteCreateService(serviceName));
+    assertTrue(service.lock("masterVMobj", -1, -1));
+    
+    assertEquals(Boolean.TRUE, vm.invoke(() -> this.getLockAndIncrement(
+        serviceName, "otherVMobj", new Integer(-1), new Integer(0)
+      )));
+    
+    service.unlock("masterVMobj");
+  }
+  
+  public void testLocalGetLockAndIncrement()  throws Exception {
+    String serviceName = getUniqueName();
+    remoteCreateService(serviceName);
+    DistributedLockService.getServiceNamed(serviceName);
+    assertEquals(Boolean.TRUE, 
+                 getLockAndIncrement(serviceName, "localVMobj", -1, 0));
+  }
+  public void testRemoteGetLockAndIncrement() {
+    String serviceName = getUniqueName();
+    VM vm = Host.getHost(0).getVM(0);
+    vm.invoke(() -> this.remoteCreateService(serviceName));
+    assertEquals(Boolean.TRUE, vm.invoke(() -> this.getLockAndIncrement(
+        serviceName, "remoteVMobj", new Integer(-1), new Integer(0)
+      )));
+  }
+  
+  public void testLockSameNameDifferentService() 
+  {
+    String serviceName1 = getUniqueName() + "_1";
+    String serviceName2 = getUniqueName() + "_2";
+    String objName = "obj";
+
+    // Same VM
+    remoteCreateService(serviceName1);
+    remoteCreateService(serviceName2);
+    DistributedLockService service1 = DistributedLockService.getServiceNamed(serviceName1);
+    DistributedLockService service2 = DistributedLockService.getServiceNamed(serviceName2);
+    assertTrue(service1.lock(objName, -1, -1));
+    assertTrue(service2.lock(objName, -1, -1));
+    service1.unlock(objName);
+    service2.unlock(objName);
+    
+    // Different VMs
+    VM vm = Host.getHost(0).getVM(0);
+    vm.invoke(() -> this.remoteCreateService(serviceName1));
+    vm.invoke(() -> this.remoteCreateService(serviceName2));
+    assertTrue(service1.lock(objName, -1, -1));
+    assertEquals(Boolean.TRUE, vm.invoke(() -> this.getLockAndIncrement(
+        serviceName2, objName, new Integer(-1), new Integer(0)
+      )));
+    service1.unlock(objName);
+  }
+  
+  public void testLeaseDoesntExpire()
+  throws InterruptedException
+  {
+    String serviceName = getUniqueName();
+    final Object objName = new Integer(3);
+
+    // Same VM
+    remoteCreateService(serviceName);
+    final DistributedLockService service = DistributedLockService.getServiceNamed(serviceName);
+    // lock objName with a sufficiently long lease
+    assertTrue(service.lock(objName, -1, 60000));
+    // try to lock in another thread, with a timeout shorter than above lease
+    final boolean[] resultHolder = new boolean[] { false };
+    Thread thread = new Thread(new Runnable() {
+      public void run() {
+        resultHolder[0] = !service.lock(objName, 1000, -1);
+      }
+    });
+    thread.start();
+    ThreadUtils.join(thread, 30 * 1000);
+    assertTrue(resultHolder[0]);
+    // the unlock should succeed without throwing LeaseExpiredException
+    service.unlock(objName);
+    
+    // Different VM
+    VM vm = Host.getHost(0).getVM(0);
+    vm.invoke(() -> this.remoteCreateService(serviceName));
+    // lock objName in this VM with a sufficiently long lease
+    assertTrue(service.lock(objName, -1, 60000));
+    // try to lock in another VM, with a timeout shorter than above lease
+    assertEquals(Boolean.FALSE, vm.invoke(() -> this.getLockAndIncrement(
+        serviceName, objName, new Long(1000), new Long(0)
+      )));
+    // the unlock should succeed without throwing LeaseExpiredException
+    service.unlock(objName);
+  }
+
+  public void testLockUnlock() {
+    String serviceName = getUniqueName();
+    Object objName = new Integer(42);
+    
+    remoteCreateService(serviceName);
+    DistributedLockService service = 
+        DistributedLockService.getServiceNamed(serviceName);
+
+    Assert.assertTrue(!service.isHeldByCurrentThread(objName));
+    
+    service.lock(objName, -1, -1);
+    Assert.assertTrue(service.isHeldByCurrentThread(objName));
+    
+    service.unlock(objName);
+    Assert.assertTrue(!service.isHeldByCurrentThread(objName));
+  }
+  
+  public void testLockExpireUnlock() {
+    long leaseMs = 200;
+    long waitBeforeLockingMs = 210;
+    
+    String serviceName = getUniqueName();
+    Object objName = new Integer(42);
+    
+    remoteCreateService(serviceName);
+    DistributedLockService service = 
+        DistributedLockService.getServiceNamed(serviceName);
+
+    assertTrue(!service.isHeldByCurrentThread(objName));
+    
+    assertTrue(service.lock(objName, -1, leaseMs));
+    assertTrue(service.isHeldByCurrentThread(objName));
+    
+    sleep(waitBeforeLockingMs); // should expire...
+    assertTrue(!service.isHeldByCurrentThread(objName));
+   
+    try {
+      service.unlock(objName);
+      fail("unlock should have thrown LeaseExpiredException");
+    } catch (LeaseExpiredException ex) {
+    }
+  }
+  
+  public void testLockRecursion() {
+    String serviceName = getUniqueName();
+    Object objName = new Integer(42);
+    
+    remoteCreateService(serviceName);
+    DistributedLockService service = 
+        DistributedLockService.getServiceNamed(serviceName);
+
+    Assert.assertTrue(!service.isHeldByCurrentThread(objName));
+    
+    // initial lock...
+    Assert.assertTrue(service.lock(objName, -1, -1));
+    Assert.assertTrue(service.isHeldByCurrentThread(objName));
+
+    // recursion +1...
+    Assert.assertTrue(service.lock(objName, -1, -1));
+
+    // recursion -1...    
+    service.unlock(objName);
+    Assert.assertTrue(service.isHeldByCurrentThread(objName));
+
+    // and unlock...    
+    service.unlock(objName);
+    Assert.assertTrue(!service.isHeldByCurrentThread(objName));
+  }
+  
+  public void testLockRecursionWithExpiration() {
+    long leaseMs = 500;
+    long waitBeforeLockingMs = 750;
+    
+    String serviceName = getUniqueName();
+    Object objName = new Integer(42);
+    
+    remoteCreateService(serviceName);
+    DistributedLockService service = 
+        DistributedLockService.getServiceNamed(serviceName);
+
+    Assert.assertTrue(!service.isHeldByCurrentThread(objName));
+    
+    // initial lock...
+    Assert.assertTrue(service.lock(objName, -1, leaseMs));
+    Assert.assertTrue(service.isHeldByCurrentThread(objName));
+
+    // recursion +1...
+    Assert.assertTrue(service.lock(objName, -1, leaseMs));
+    Assert.assertTrue(service.isHeldByCurrentThread(objName));
+    
+    // expire...
+    sleep(waitBeforeLockingMs);
+    Assert.assertTrue(!service.isHeldByCurrentThread(objName));
+
+    // should fail...
+    try {
+      service.unlock(objName);
+      fail("unlock should have thrown LeaseExpiredException");
+    } catch (LeaseExpiredException ex) {
+    }
+    
+    // relock it...
+    Assert.assertTrue(service.lock(objName, -1, leaseMs));
+    Assert.assertTrue(service.isHeldByCurrentThread(objName));
+
+    // and unlock to verify no recursion...    
+    service.unlock(objName);
+    Assert.assertTrue(!service.isHeldByCurrentThread(objName)); // throws failure!!
+    
+    // go thru again in different order...
+    Assert.assertTrue(!service.isHeldByCurrentThread(objName));
+    
+    // initial lock...
+    Assert.assertTrue(service.lock(objName, -1, leaseMs));
+    Assert.assertTrue(service.isHeldByCurrentThread(objName));
+
+    // expire...
+    sleep(waitBeforeLockingMs);
+    Assert.assertTrue(!service.isHeldByCurrentThread(objName));
+
+    // relock it...
+    Assert.assertTrue(service.lock(objName, -1, leaseMs));
+    Assert.assertTrue(service.isHeldByCurrentThread(objName));
+    
+    // and unlock to verify no recursion...    
+    service.unlock(objName);
+    Assert.assertTrue(!service.isHeldByCurrentThread(objName));
+  }
+  
+  public void testLeaseExpiresBeforeOtherLocks()
+  throws InterruptedException 
+  {
+    leaseExpiresTest(false);
+  }
+  
+  public void testLeaseExpiresWhileOtherLocks()
+  throws InterruptedException 
+  {
+    leaseExpiresTest(true);
+  }
+  
+  private void leaseExpiresTest(boolean tryToLockBeforeExpiration)
+  throws InterruptedException
+  {
+    LogWriterUtils.getLogWriter().fine("[testLeaseExpires] prepping");
+    long leaseMs = 100;
+    long waitBeforeLockingMs = tryToLockBeforeExpiration ? 50 : 110;
+
+    final String serviceName = getUniqueName();
+    final Object objName = new Integer(3);
+
+    // Same VM
+    remoteCreateService(serviceName);
+    final DistributedLockService service = DistributedLockService.getServiceNamed(serviceName);
+    
+    LogWriterUtils.getLogWriter().fine("[testLeaseExpires] acquire first lock");
+    // lock objName with a short lease
+    assertTrue(service.lock(objName, -1, leaseMs));
+    sleep(waitBeforeLockingMs);
+
+    if (waitBeforeLockingMs > leaseMs) {
+      Assert.assertTrue(!service.isHeldByCurrentThread(objName));
+    }
+    
+    LogWriterUtils.getLogWriter().fine("[testLeaseExpires] acquire lock that expired");
+    // try to lock in another thread - lease should have expired
+    final boolean[] resultHolder = new boolean[] { false };
+    Thread thread = new Thread(new Runnable() {
+      public void run() {
+        resultHolder[0] = service.lock(objName, -1, -1);
+        service.unlock(objName);
+        Assert.assertTrue(!service.isHeldByCurrentThread(objName));
+      }
+    });
+    thread.start();
+    ThreadUtils.join(thread, 30 * 1000);
+    assertTrue(resultHolder[0]);
+    
+    LogWriterUtils.getLogWriter().fine("[testLeaseExpires] unlock should throw LeaseExpiredException");
+    // this thread's unlock should throw LeaseExpiredException
+    try {
+      service.unlock(objName);
+      fail("unlock should have thrown LeaseExpiredException");
+    } catch (LeaseExpiredException ex) {
+    }
+    
+    LogWriterUtils.getLogWriter().fine("[testLeaseExpires] create service in other vm");
+    // Different VM
+    VM vm = Host.getHost(0).getVM(0);
+    vm.invoke(() -> this.remoteCreateService(serviceName));
+    
+    LogWriterUtils.getLogWriter().fine("[testLeaseExpires] acquire lock again and expire");
+    // lock objName in this VM with a short lease
+    assertTrue(service.lock(objName, -1, leaseMs));
+    sleep(waitBeforeLockingMs);
+    
+    LogWriterUtils.getLogWriter().fine("[testLeaseExpires] succeed lock in other vm");
+    // try to lock in another VM - should succeed
+    assertEquals(Boolean.TRUE, vm.invoke(() -> this.getLockAndIncrement(
+        serviceName, objName, new Long(-1), new Long(0)
+      )));
+      
+    LogWriterUtils.getLogWriter().fine("[testLeaseExpires] unlock should throw LeaseExpiredException again");
+    // this VMs unlock should throw LeaseExpiredException
+    try {
+      service.unlock(objName);
+      fail("unlock should have thrown LeaseExpiredException");
+    } catch (LeaseExpiredException ex) {
+    }
+  }
+
+  public void testSuspendLockingAfterExpiration() throws Exception {
+    LogWriterUtils.getLogWriter().fine("[leaseExpiresThenSuspendTest]");
+    
+    final long leaseMillis = 100;
+    final long suspendWaitMillis = 10000;
+
+    final String serviceName = getUniqueName();
+    final Object key = new Integer(3);
+
+    // controller locks key and then expires - controller is grantor
+    
+    DistributedLockService dls 
+        = DistributedLockService.create(serviceName, getSystem());
+    
+    assertTrue(dls.lock(key, -1, leaseMillis));
+    
+    // wait for expiration
+    sleep(leaseMillis*2);
+    
+    LogWriterUtils.getLogWriter().fine("[leaseExpiresThenSuspendTest] unlock should throw LeaseExpiredException");
+    // this thread's unlock should throw LeaseExpiredException
+    try {
+      dls.unlock(key);
+      fail("unlock should have thrown LeaseExpiredException");
+    } catch (LeaseExpiredException ex) {
+    }
+    
+    // other vm calls suspend 
+    
+    LogWriterUtils.getLogWriter().fine("[leaseExpiresThenSuspendTest] call to suspend locking");
+    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
+      public void run() {
+        final DistributedLockService dlock 
+            = DistributedLockService.create(serviceName, getSystem());
+        dlock.suspendLocking(suspendWaitMillis);
+        dlock.resumeLocking();
+        assertTrue(dlock.lock(key, -1, leaseMillis));
+        dlock.unlock(key);
+      }
+    });
+  }
+  
+  volatile boolean started = false;
+  volatile boolean gotLock = false;
+  volatile Throwable exception = null;
+  volatile Throwable throwable = null;
+
+  public void testLockInterruptiblyIsInterruptible() {
+    started = false;
+    gotLock = false;
+    exception = null;
+    throwable = null;
+
+    // Lock entire service in first thread
+    LogWriterUtils.getLogWriter().info("[testLockInterruptiblyIsInterruptible] get and hold the lock");
+    final String serviceName = getUniqueName();
+    final DistributedLockService service = 
+      DistributedLockService.create(serviceName, dlstSystem);
+    service.becomeLockGrantor();
+    assertTrue(service.lock("obj", 1000, -1));
+
+    // Start second thread that tries to lock in second thread
+    LogWriterUtils.getLogWriter().info("[testLockInterruptiblyIsInterruptible] call lockInterruptibly");
+    Thread thread2 = new Thread(new Runnable() {
+      public void run() {
+        try {
+          started = true;
+          gotLock = service.lockInterruptibly("obj", -1, -1);
+        } catch (InterruptedException ex) {
+          exception = ex;
+        } 
+        catch (VirtualMachineError e) {
+          SystemFailure.initiateFailure(e);
+          throw e;
+        }
+        catch (Throwable t) {
+          throwable = t;
+        }
+      }
+    });
+    thread2.start();
+    
+    // Interrupt second thread
+    LogWriterUtils.getLogWriter().info("[testLockInterruptiblyIsInterruptible] interrupt calling thread");
+    while (!started) Thread.yield();
+    thread2.interrupt();
+    ThreadUtils.join(thread2, 20 * 1000);
+
+    // Expect it got InterruptedException and didn't lock the service
+    LogWriterUtils.getLogWriter().info("[testLockInterruptiblyIsInterruptible] verify failed to get lock");
+    assertFalse(gotLock);
+    if (throwable != null) {
+      LogWriterUtils.getLogWriter().warning(
+        "testLockInterruptiblyIsInterruptible threw unexpected Throwable", 
+        throwable);
+    }
+    assertNotNull(exception);
+
+    // Unlock "obj" in first thread
+    LogWriterUtils.getLogWriter().info("[testLockInterruptiblyIsInterruptible] unlock the lock");
+    service.unlock("obj");
+
+    // Make sure it didn't get locked by second thread
+    LogWriterUtils.getLogWriter().info("[testLockInterruptiblyIsInterruptible] try to get lock with timeout should not fail");
+    assertTrue(service.lock("obj", 5000, -1));
+    DistributedLockService.destroy(serviceName);
+  }
+  
+  volatile boolean wasFlagSet = false;
+
+  public void testLockIsNotInterruptible() {
+    // Lock entire service in first thread
+    LogWriterUtils.getLogWriter().fine("[testLockIsNotInterruptible] lock in first thread");
+    started = false;
+    gotLock = false;
+    exception = null;
+    wasFlagSet = false;
+    
+    final String serviceName = getUniqueName();
+    final DistributedLockService service = 
+      DistributedLockService.create(serviceName, dlstSystem);
+    assertTrue(service.lock("obj", 1000, -1));
+
+    // Start second thread that tries to lock in second thread
+    LogWriterUtils.getLogWriter().fine("[testLockIsNotInterruptible] attempt lock in second thread");
+    Thread thread2 = new Thread(new Runnable() {
+      public void run() {
+        try {
+          started = true;
+          gotLock = service.lock("obj", -1, -1);
+          LogWriterUtils.getLogWriter().fine("[testLockIsNotInterruptible] thread2 finished lock() - got " + gotLock);
+        } 
+        catch (VirtualMachineError e) {
+          SystemFailure.initiateFailure(e);
+          throw e;
+        }
+        catch (Throwable ex) {
+          LogWriterUtils.getLogWriter().warning("[testLockIsNotInterruptible] Caught...", ex);
+          exception = ex;
+        }
+        wasFlagSet = Thread.currentThread().isInterrupted();
+      }
+    });
+    thread2.start();
+    
+    // Interrupt second thread
+    LogWriterUtils.getLogWriter().fine("[testLockIsNotInterruptible] interrupt second thread");
+    while (!started) Thread.yield();
+    sleep(500);
+    thread2.interrupt();
+    // Expect it didn't get an exception and didn't lock the service
+    sleep(500);
+    assertFalse(gotLock);
+    assertNull(exception);
+
+    // Unlock entire service in first thread
+    LogWriterUtils.getLogWriter().fine("[testLockIsNotInterruptible] unlock in first thread");
+    service.unlock("obj");
+    sleep(500);
+
+    // Expect that thread2 should now complete execution.
+    ThreadUtils.join(thread2, 20 * 1000);
+
+    // Now thread2 should have gotten the lock, not the exception, but the
+    // thread's flag should be set
+    LogWriterUtils.getLogWriter().fine("[testLockIsNotInterruptible] verify second thread got lock");
+    assertNull(exception);
+    assertTrue(gotLock);
+    assertTrue(wasFlagSet);
+  }
+  
+  /**
+   * Test DistributedLockService.acquireExclusiveLocking(), releaseExclusiveLocking()
+   */
+  public void testSuspendLockingBasic() 
+  throws InterruptedException {
+    final DistributedLockService service = 
+      DistributedLockService.create(getUniqueName(), dlstSystem);
+
+    try {
+      service.resumeLocking();
+      fail("Didn't throw LockNotHeldException");
+    } catch (LockNotHeldException ex) {
+      // expected
+    }
+
+    assertTrue(service.suspendLocking(-1));
+    service.resumeLocking();
+
+    // It's not reentrant
+    assertTrue(service.suspendLocking(1000));
+    try {
+      service.suspendLocking(1);
+      fail("didn't get IllegalStateException");
+    } catch (IllegalStateException ex) {
+      // expected
+    }
+    service.resumeLocking();
+    
+    // Get "false" if another thread is holding it
+    Thread thread = new Thread(new Runnable() {
+      public void run() {
+        logInfo("new thread about to suspendLocking()");
+        assertTrue(service.suspendLocking(1000));
+      }
+    });
+    thread.start();
+    ThreadUtils.join(thread, 30 * 1000);
+    logInfo("main thread about to suspendLocking");
+    assertTrue(!service.suspendLocking(1000));
+  }
+
+  /**
+   * Test that exlusive locking prohibits locking activity
+   */
+  public void testSuspendLockingProhibitsLocking() 
+  {
+    final String name = getUniqueName();
+    distributedCreateService(2, name);
+    DistributedLockService service = 
+      DistributedLockService.getServiceNamed(name);
+    
+    // Should be able to lock from other VM
+    VM vm1 = Host.getHost(0).getVM(1);
+    assertTrue(vm1.invoke(() -> DistributedLockServiceDUnitTest.tryToLock( name )));
+
+    assertTrue(service.suspendLocking(1000));
+    
+    // vm1 is the grantor... use debugHandleSuspendTimeouts
+    vm1.invoke(new SerializableRunnable("setDebugHandleSuspendTimeouts") {
+      public void run() {
+        DLockService dls = 
+          (DLockService) DistributedLockService.getServiceNamed(name);
+        assertTrue(dls.isLockGrantor());
+        DLockGrantor grantor = dls.getGrantorWithNoSync();
+        grantor.setDebugHandleSuspendTimeouts(5000);
+      }
+    });
+    
+    // Shouldn't be able to lock a name from another VM
+    assertTrue(!vm1.invoke(() -> DistributedLockServiceDUnitTest.tryToLock( name )));
+    
+    service.resumeLocking();
+
+    vm1.invoke(new SerializableRunnable("unsetDebugHandleSuspendTimeouts") {
+      public void run() {
+        DLockService dls = 
+          (DLockService) DistributedLockService.getServiceNamed(name);
+        assertTrue(dls.isLockGrantor());
+        DLockGrantor grantor = dls.getGrantorWithNoSync();
+        grantor.setDebugHandleSuspendTimeouts(0);
+      }
+    });
+    
+    // Should be able to lock again
+    assertTrue(vm1.invoke(() -> DistributedLockServiceDUnitTest.tryToLock( name )));
+    
+  }
+
+  /**
+   * Test that suspend locking behaves under various usage patterns. This
+   * ensures that suspend and regular locks behave as ReadWriteLocks and
+   * processing occurs in order.
+   */
+  public void notestSuspendLockingBehaves() throws Exception {
+    try {
+      doTestSuspendLockingBehaves();
+    }
+    finally {
+      Invoke.invokeInEveryVM(new SerializableRunnable() {
+        public void run() {
+          try {
+            if (suspendClientSuspendLockingBehaves != null) {
+              suspendClientSuspendLockingBehaves.stop();
+              suspendClientSuspendLockingBehaves = null;
+            }
+          }
+          catch (VirtualMachineError e) {
+            SystemFailure.initiateFailure(e);
+            throw e;
+          }
+          catch (Throwable t) {
+            LogWriterUtils.getLogWriter().error("Error in testSuspendLockingBehaves finally", t);
+          }
+          try {
+            if (lockClientSuspendLockingBehaves != null) {
+              lockClientSuspendLockingBehaves.stop();
+              lockClientSuspendLockingBehaves = null;
+            }
+          }
+          catch (VirtualMachineError e) {
+            SystemFailure.initiateFailure(e);
+            throw e;
+          }
+          catch (Throwable t) {
+            LogWriterUtils.getLogWriter().error("Error in testSuspendLockingBehaves finally", t);
+          }
+        }
+      });
+    }
+  }
+  private void doTestSuspendLockingBehaves() throws Exception {
+    final String dlsName = getUniqueName();
+    final VM vmGrantor = Host.getHost(0).getVM(0);
+    final VM vmOne = Host.getHost(0).getVM(1);
+    final VM vmTwo = Host.getHost(0).getVM(2);
+    final VM vmThree = Host.getHost(0).getVM(3);
+    final String key1 = "key1";
+    
+    // TODO: make sure suspend thread can get other locks
+    
+    // TODO: test local (in grantor) locks and suspends also
+    
+    // define some SerializableRunnables
+    final SerializableRunnable createDLS = 
+    new SerializableRunnable("Create "+dlsName) {
+      public void run() {
+        DistributedLockService.create(dlsName, getSystem());
+        lockClientSuspendLockingBehaves = new BasicLockClient(dlsName, key1);
+        suspendClientSuspendLockingBehaves = new BasicLockClient(dlsName, key1);
+        assertFalse(isLockGrantor(dlsName).booleanValue());
+      }
+    };
+    final SerializableRunnable suspendLocking = 
+    new SerializableRunnable("Suspend locking "+dlsName) {
+      public void run() {
+        suspendClientSuspendLockingBehaves.suspend();
+      }
+    };
+    final SerializableRunnable resumeLocking = 
+    new SerializableRunnable("Resume locking "+dlsName) {
+      public void run() {
+        suspendClientSuspendLockingBehaves.resume();
+      }
+    };
+    final SerializableRunnable lockKey = 
+    new SerializableRunnable("Get lock "+dlsName) {
+      public void run() {
+        lockClientSuspendLockingBehaves.lock();
+      }
+    };
+    final SerializableRunnable unlockKey = 
+    new SerializableRunnable("Unlock "+dlsName) {
+      public void run() {
+        lockClientSuspendLockingBehaves.unlock();
+      }
+    };
+    
+    // create grantor
+    LogWriterUtils.getLogWriter().info("[testSuspendLockingBehaves] Create grantor "+dlsName);
+    vmGrantor.invoke(new SerializableRunnable("Create grantor "+dlsName) {
+      public void run() {
+        DistributedLockService.create(dlsName, getSystem());
+        DistributedLockService.getServiceNamed(dlsName).lock(key1, -1, -1);
+        DistributedLockService.getServiceNamed(dlsName).unlock(key1);
+        assertTrue(isLockGrantor(dlsName).booleanValue());
+      }
+    });
+
+    // create dls in other vms
+//    getLogWriter().info("[testSuspendLockingBehaves] Create DLS in vmOne");
+    vmOne.invoke(createDLS);
+//    getLogWriter().info("[testSuspendLockingBehaves] Create DLS in vmTwo");
+    vmTwo.invoke(createDLS);
+//    getLogWriter().info("[testSuspendLockingBehaves] Create DLS in vmThree");
+    vmThree.invoke(createDLS);
+    
+    // get a lock
+    LogWriterUtils.getLogWriter().info("[testSuspendLockingBehaves] line up vms for lock");
+//    getLogWriter().info("[testSuspendLockingBehaves] vmOne lock");
+    vmOne.invoke(lockKey);
+//    getLogWriter().info("[testSuspendLockingBehaves] start vmTwoLocking");
+    AsyncInvocation vmTwoLocking =  vmTwo.invokeAsync(lockKey);
+    Wait.pause(2000); // make sure vmTwo is first in line
+//    getLogWriter().info("[testSuspendLockingBehaves] start vmThreeLocking");
+    AsyncInvocation vmThreeLocking = vmThree.invokeAsync(lockKey);
+    Wait.pause(2000);
+    
+    // make sure vmTwo and vmThree are still waiting for lock on key1
+//    getLogWriter().info("[testSuspendLockingBehaves] assert vmTwoLocking still alive");
+    Wait.pause(100);
+    assertTrue(vmTwoLocking.isAlive());
+//    getLogWriter().info("[testSuspendLockingBehaves] assert vmThreeLocking still alive");
+    Wait.pause(100);
+    assertTrue(vmThreeLocking.isAlive());
+    
+    // let vmTwo get key
+    LogWriterUtils.getLogWriter().info("[testSuspendLockingBehaves] unlock so vmTwo can get key");
+//    getLogWriter().info("[testSuspendLockingBehaves] vmOne unlock");
+    vmOne.invoke(unlockKey);
+    ThreadUtils.join(vmTwoLocking, 10 * 1000);
+
+    // start suspending in vmOne and vmTwo
+    LogWriterUtils.getLogWriter().info("[testSuspendLockingBehaves] start suspending requests");
+//    getLogWriter().info("[testSuspendLockingBehaves] start vmOneSuspending");
+    AsyncInvocation vmOneSuspending = vmOne.invokeAsync(suspendLocking);
+    Wait.pause(2000); // make sure vmOne is first in line
+//    getLogWriter().info("[testSuspendLockingBehaves] start vmTwoSuspending");
+    AsyncInvocation vmTwoSuspending  = vmTwo.invokeAsync(suspendLocking);
+    Wait.pause(2000); 
+    
+    // let vmThree finish locking key
+    LogWriterUtils.getLogWriter().info("[testSuspendLockingBehaves] unlock so vmThree can get key");
+//    getLogWriter().info("[testSuspendLockingBehaves] vmTwo unlock");
+    vmTwo.invoke(unlockKey);
+    ThreadUtils.join(vmThreeLocking, 10 * 1000);
+    
+    // have vmOne get back in line for locking key
+    LogWriterUtils.getLogWriter().info("[testSuspendLockingBehaves] start another lock request");
+//    getLogWriter().info("[testSuspendLockingBehaves] start vmOneLockingAgain");
+    AsyncInvocation vmOneLockingAgain = vmOne.invokeAsync(lockKey);
+    Wait.pause(2000); 
+    
+    // let vmOne suspend locking
+    LogWriterUtils.getLogWriter().info("[testSuspendLockingBehaves] let vmOne suspend locking");
+//    getLogWriter().info("[testSuspendLockingBehaves] assert vmOneSuspending still alive");
+    Wait.pause(100);
+    assertTrue(vmOneSuspending.isAlive());
+//    getLogWriter().info("[testSuspendLockingBehaves] vmThree unlock");
+    vmThree.invoke(unlockKey);
+    ThreadUtils.join(vmOneSuspending, 10 * 1000);
+    
+    // start suspending in vmThree
+    LogWriterUtils.getLogWriter().info("[testSuspendLockingBehaves] line up vmThree for suspending");
+//    getLogWriter().info("[testSuspendLockingBehaves] start vmThreeSuspending");
+    AsyncInvocation vmThreeSuspending  = vmThree.invokeAsync(suspendLocking);
+    Wait.pause(2000); 
+
+    // let vmTwo suspend locking
+    LogWriterUtils.getLogWriter().info("[testSuspendLockingBehaves] let vmTwo suspend locking");
+//    getLogWriter().info("[testSuspendLockingBehaves] assert vmTwoSuspending still alive");
+    Wait.pause(100);
+    assertTrue(vmTwoSuspending.isAlive());
+//    getLogWriter().info("[testSuspendLockingBehaves] vmOne resumes locking");
+    vmOne.invoke(resumeLocking);
+    ThreadUtils.join(vmTwoSuspending, 10 * 1000);
+    
+    // let vmOne get that lock
+    LogWriterUtils.getLogWriter().info("[testSuspendLockingBehaves] let vmOne get that lock");
+//    getLogWriter().info("[testSuspendLockingBehaves] assert vmOneLockingAgain still alive");
+    Wait.pause(100);
+    assertTrue(vmOneLockingAgain.isAlive());
+//    getLogWriter().info("[testSuspendLockingBehaves] vmTwo resumes locking");
+    vmTwo.invoke(resumeLocking);
+    ThreadUtils.join(vmOneLockingAgain, 10 * 1000);
+    
+    // let vmThree suspend locking
+    LogWriterUtils.getLogWriter().info("[testSuspendLockingBehaves] let vmThree suspend locking");
+//    getLogWriter().info("[testSuspendLockingBehaves] assert vmThreeSuspending still alive");
+    Wait.pause(100);
+    assertTrue(vmThreeSuspending.isAlive());
+//    getLogWriter().info("[testSuspendLockingBehaves] vmOne unlocks again");
+    vmOne.invoke(unlockKey);
+    ThreadUtils.join(vmThreeSuspending, 10 * 1000);
+
+    // done
+//    getLogWriter().info("[testSuspendLockingBehaves] vmThree resumes locking");
+    vmThree.invoke(resumeLocking);
+  }
+  protected static BasicLockClient suspendClientSuspendLockingBehaves;
+  protected static BasicLockClient lockClientSuspendLockingBehaves;
+  
+  /**
+   * Test that exlusive locking prohibits locking activity
+   */
+  public void testSuspendLockingBlocksUntilNoLocks() 
+  throws InterruptedException
+  {
+
+    final String name = getUniqueName();
+    distributedCreateService(2, name);
+    final DistributedLockService service = 
+      DistributedLockService.getServiceNamed(name);
+    
+    // Get lock from other VM.  Since same thread needs to lock and unlock,
+    // invoke asynchronously, get lock, wait to be notified, then unlock.
+    VM vm1 = Host.getHost(0).getVM(1);
+    vm1.invokeAsync(new SerializableRunnable("Lock & unlock in vm1") {
+      public void run() {
+        DistributedLockService service2 = 
+          DistributedLockService.getServiceNamed(name);
+        assertTrue(service2.lock("lock", -1, -1));
+        synchronized (monitor) {
+          try {
+            monitor.wait();
+          } catch (InterruptedException ex) {
+            System.out.println("Unexpected InterruptedException");
+            fail("interrupted");
+          }
+        }
+        service2.unlock("lock");
+      }
+    });
+    // Let vm1's thread get the lock and go into wait()
+    Thread.sleep(100);
+    
+    Thread thread = new Thread(new Runnable() {
+      public void run() {
+        setGot(service.suspendLocking(-1));
+        setDone(true);
+        service.resumeLocking();
+      }
+    });
+    setGot(false);
+    setDone(false);
+    thread.start();
+    
+    // Let thread start, make sure it's blocked in suspendLocking
+    Thread.sleep(100);
+    assertFalse("Before release, got: " + getGot() + ", done: " + getDone(), getGot() || getDone());
+    
+    vm1.invoke(new SerializableRunnable("notify vm1 to unlock") {
+      public void run() {
+        synchronized (monitor) {
+          monitor.notify();
+        }
+      }
+    });
+
+    // Let thread finish, make sure it successfully suspended and is done
+    WaitCriterion ev = new WaitCriterion() {
+      public boolean done() {
+        return getDone();
+      }
+      public String description() {
+        return null;
+      }
+    };
+    Wait.waitForCriterion(ev, 30 * 1000, 200, true);
+    if (!getGot() || !getDone()) {
+      ThreadUtils.dumpAllStacks();
+    }
+    assertTrue("After release, got: " + getGot() + ", done: " + getDone(), getGot() && getDone());
+    
+  }
+  
+  public void testSuspendLockingInterruptiblyIsInterruptible() {
+    
+    started = false;
+    gotLock = false;
+    exception = null;
+
+    // Lock entire service in first thread
+    final String name = getUniqueName();
+    final DistributedLockService service = 
+      DistributedLockService.create(name, dlstSystem);
+    assertTrue(service.suspendLocking(1000));
+
+    // Start second thread that tries to lock in second thread
+    Thread thread2 = new Thread(new Runnable() {
+      public void run() {
+        try {
+          started = true;
+          gotLock = service.suspendLockingInterruptibly(-1);
+        } catch (InterruptedException ex) {
+          exception = ex;
+        }
+      }
+    });
+    thread2.start();
+    
+    // Interrupt second thread
+    while (!started) Thread.yield();
+    thread2.interrupt();
+    ThreadUtils.join(thread2, 20 * 1000);
+
+    // Expect it got InterruptedException and didn't lock the service
+    sleep(500);
+    assertFalse(gotLock);
+    assertNotNull(exception);
+
+    // Unlock entire service in first thread
+    service.resumeLocking();
+    sleep(500);
+
+    // Make sure it didn't get locked by second thread
+    assertTrue(service.suspendLocking(1000));
+    DistributedLockService.destroy(name);
+  }
+  
+  public void testSuspendLockingIsNotInterruptible() {
+    
+    started = false;
+    gotLock = false;
+    exception = null;
+    wasFlagSet = false;
+
+    // Lock entire service in first thread
+    final String name = getUniqueName();
+    final DistributedLockService service = 
+      DistributedLockService.create(name, dlstSystem);
+    assertTrue(service.suspendLocking(1000));
+
+    // Start second thread that tries to lock in second thread
+    Thread thread2 = new Thread(new Runnable() {
+      public void run() {
+        try {
+          started = true;
+          gotLock = service.suspendLocking(-1);
+        } 
+        catch (VirtualMachineError e) {
+          SystemFailure.initiateFailure(e);
+          throw e;
+        }
+        catch (Throwable ex) {
+          exception = ex;
+        }
+        wasFlagSet = Thread.currentThread().isInterrupted();
+     }
+    });
+    thread2.start();
+    
+    // Interrupt second thread
+    while (!started) Thread.yield();
+    thread2.interrupt();
+    // Expect it didn't get an exception and didn't lock the service
+    sleep(500);
+    assertFalse(gotLock);
+    assertNull(exception);
+
+    // Unlock entire service in first thread
+    service.resumeLocking();
+    ThreadUtils.join(thread2, 20 * 1000);
+
+    // Now thread2 should have gotten the lock, not the exception, but the
+    // thread's flag should be set
+    LogWriterUtils.getLogWriter().info("[testSuspendLockingIsNotInterruptible]" +
+      " gotLock=" + gotLock +
+      " wasFlagSet=" + wasFlagSet +
+      " exception=" + exception, exception);
+    assertTrue(gotLock);
+    assertNull(exception);
+    assertTrue(wasFlagSet);
+  }
+  
+  /**
+   * Tests what happens when you attempt to lock a name on a lock
+   * service that has been destroyed.
+   *
+   * @author David Whitlock
+   */
+  public void testLockDestroyedService() {
+    String serviceName = this.getUniqueName();
+    DistributedLockService service =
+      DistributedLockService.create(serviceName, dlstSystem);
+    DistributedLockService.destroy(serviceName);
+    try {
+      boolean locked = service.lock("TEST", -1, -1);
+      fail("Lock of destroyed service returned: " + locked);
+
+    } catch (LockServiceDestroyedException ex) {
+      // pass...
+    }
+  }
+  
+  public void testDepartedLastOwnerWithLease() {
+    final String serviceName = this.getUniqueName();
+
+    // Create service in this VM
+    DistributedLockService service =
+      DistributedLockService.create(serviceName, dlstSystem);
+    assertTrue(service.lock("key", -1, -1));
+    service.unlock("key");
+    
+    // Create service in other VM
+    VM otherVm = Host.getHost(0).getVM(0);
+    otherVm.invoke(new SerializableRunnable() {
+      public void run() {
+        DistributedLockService service2 =
+          DistributedLockService.create(serviceName, dlstSystem);
+        service2.lock("key", -1, 360000);
+        service2.unlock("key");
+        // Wait for asynchronous messaging to complete
+        try {
+          Thread.sleep(100);
+        } catch (InterruptedException ex) {
+          fail("interrupted");
+        }
+        disconnectFromDS();
+      }
+    });
+    
+    // Now lock back in this VM
+    assertTrue(service.lock("key", -1, -1));
+    
+  }
+  
+  public void testDepartedLastOwnerNoLease() {
+    final String serviceName = this.getUniqueName();
+
+    // Create service in this VM
+    DistributedLockService service =
+      DistributedLockService.create(serviceName, dlstSystem);
+    assertTrue(service.lock("key", -1, -1));
+    service.unlock("key");
+    
+    // Create service in other VM
+    VM otherVm = Host.getHost(0).getVM(0);
+    otherVm.invoke(new SerializableRunnable() {
+      public void run() {
+        DistributedLockService service2 =
+          DistributedLockService.create(serviceName, dlstSystem);
+        service2.lock("key", -1, -1);
+        service2.unlock("key");
+        // Wait for asynchronous messaging to complete
+        try {
+          Thread.sleep(100);
+        } catch (InterruptedException ex) {
+          fail("interrupted");
+        }
+        disconnectFromDS();
+      }
+    });
+    
+    // Now lock back in this VM
+    assertTrue(service.lock("key", -1, -1));
+    
+  }
+  
+  /** 
+   * Tests for 32461 R3 StuckLocks can occur on locks with an expiration lease
+   * <p>
+   * VM-A locks/unlocks "lock", VM-B leases "lock" and disconnects, VM-C
+   * attempts to lock "lock" and old dlock throws StuckLockException. VM-C
+   * should now succeed in acquiring the lock.
+   */
+  public void testBug32461() throws Exception {
+    LogWriterUtils.getLogWriter().fine("[testBug32461] prepping");
+
+    final String serviceName = getUniqueName();
+    final Object objName = "32461";
+    final int VM_A = 0;
+    final int VM_B = 1;
+    final int VM_C = 2;
+
+    // VM-A locks/unlocks "lock"...
+    LogWriterUtils.getLogWriter().fine("[testBug32461] VM-A locks/unlocks '32461'");
+    
+    Host.getHost(0).getVM(VM_A).invoke(new SerializableRunnable() {
+      public void run() {
+        remoteCreateService(serviceName);
+        final DistributedLockService service = 
+            DistributedLockService.getServiceNamed(serviceName);
+        assertTrue(service.lock(objName, -1, Long.MAX_VALUE));
+        service.unlock(objName);
+      }
+    });
+    
+    // VM-B leases "lock" and disconnects,
+    LogWriterUtils.getLogWriter().fine("[testBug32461] VM_B leases '32461' and disconnects");
+    
+    Host.getHost(0).getVM(VM_B).invoke(new SerializableRunnable() {
+      public void run() {
+        remoteCreateService(serviceName);
+        final DistributedLockService service = 
+            DistributedLockService.getServiceNamed(serviceName);
+        assertTrue(service.lock(objName, -1, Long.MAX_VALUE));
+        DistributedLockService.destroy(serviceName);
+        disconnectFromDS();
+      }
+    });
+    
+    LogWriterUtils.getLogWriter().fine("[testBug32461] VM_C attempts to lock '32461'");
+
+    Host.getHost(0).getVM(VM_C).invoke(new SerializableRunnable() {
+      public void run() {
+        remoteCreateService(serviceName);
+        final DistributedLockService service = 
+            DistributedLockService.getServiceNamed(serviceName);
+        assertTrue(service.lock(objName, -1, -1));
+        service.unlock(objName);
+      }
+    });
+  }
+  
+  public void testNoStuckLock() {
+    final String serviceName = this.getUniqueName();
+    final Object keyWithLease = "key-with-lease";
+    final Object keyNoLease = "key-no-lease";
+
+    // Create service in this VM
+    DistributedLockService service =
+      DistributedLockService.create(serviceName, dlstSystem);
+
+    assertTrue(service.lock(keyWithLease, -1, -1));
+    service.unlock(keyWithLease);
+
+    assertTrue(service.lock(keyNoLease, -1, -1));
+    service.unlock(keyNoLease);
+    
+    // Create service in other VM
+    VM otherVm = Host.getHost(0).getVM(0);
+    otherVm.invoke(new SerializableRunnable() {
+      public void run() {
+        DistributedLockService service2 =
+          DistributedLockService.create(serviceName, dlstSystem);
+        service2.lock(keyWithLease, -1, 360000);
+        service2.lock(keyNoLease, -1, -1);
+        disconnectFromDS();
+      }
+    });
+    
+    // Now lock back in this VM... no stuck locks anymore
+    assertTrue(service.lock(keyWithLease, -1, -1));
+    service.unlock(keyWithLease);
+    assertTrue(service.lock(keyNoLease, -1, -1));
+    service.unlock(keyNoLease);
+  }
+  
+  volatile boolean startedThread1_testReleaseOrphanedGrant;
+  volatile boolean releaseThread1_testReleaseOrphanedGrant;
+  volatile boolean startedThread2_testReleaseOrphanedGrant;
+  volatile boolean gotLockThread2_testReleaseOrphanedGrant;
+  /**
+   * Client requests lock and then interrupts lock request before processing
+   * the grant reply. This causes the Client to send a release msg to the
+   * grantor.
+   */
+  public void testReleaseOrphanedGrant_Local() {
+    DLockRequestProcessor.setDebugReleaseOrphanedGrant(true);
+    DLockRequestProcessor.setWaitToProcessDLockResponse(false);
+    try {
+      startedThread2_testReleaseOrphanedGrant = false;
+      gotLockThread2_testReleaseOrphanedGrant = false;
+      releaseThread1_testReleaseOrphanedGrant = false;
+      
+      LogWriterUtils.getLogWriter().info("[testReleaseOrphanedGrant_Local] create lock service");
+      final String serviceName = getUniqueName();
+      final DistributedLockService service = 
+        DistributedLockService.create(serviceName, dlstSystem);
+      
+      // thread to get lock and wait and then unlock
+      final Thread thread1 = new Thread(new Runnable() {
+        public void run() {
+          LogWriterUtils.getLogWriter().info("[testReleaseOrphanedGrant_Local] get the lock");
+          assertTrue(service.lock("obj", -1, -1));
+          DLockRequestProcessor.setWaitToProcessDLockResponse(true);
+          startedThread1_testReleaseOrphanedGrant = true;
+          synchronized(Thread.currentThread()) {
+            while (!releaseThread1_testReleaseOrphanedGrant) {
+              try {
+                Thread.currentThread().wait();
+              } catch (InterruptedException ignore) {fail("interrupted");}
+            }
+          }
+          LogWriterUtils.getLogWriter().info("[testReleaseOrphanedGrant_Local] unlock the lock");
+          service.unlock("obj");
+        }
+      });
+      thread1.start();
+      while (!startedThread1_testReleaseOrphanedGrant) {
+        Thread.yield();
+      }
+      
+      // thread to interrupt lockInterruptibly call to cause zombie grant
+      final Thread thread2 = new Thread(new Runnable() {
+        public void run() {
+          try {
+            LogWriterUtils.getLogWriter().info("[testReleaseOrphanedGrant_Local] call lockInterruptibly");
+            startedThread2_testReleaseOrphanedGrant = true;
+            assertFalse(service.lockInterruptibly("obj", -1, -1));
+          } catch (InterruptedException expected) {
+            Thread.currentThread().interrupt();
+          }
+        }
+      });
+      thread2.start();
+      while (!startedThread2_testReleaseOrphanedGrant) {
+        Thread.yield();
+      }
+          
+      // release first thread to unlock
+      LogWriterUtils.getLogWriter().info("[testReleaseOrphanedGrant_Local] release 1st thread");
+      sleep(500);
+      synchronized(thread1) {
+        releaseThread1_testReleaseOrphanedGrant = true;
+        thread1.notifyAll();
+      }
+      sleep(500);
+  
+      // while first thread is stuck on waitToProcessDLockResponse,
+      //   interrupt 2nd thread
+      LogWriterUtils.getLogWriter().info("[testReleaseOrphanedGrant_Local] interrupt 2nd thread");
+      thread2.interrupt();
+      ThreadUtils.join(thread2, 20 * 1000);
+  
+      // release waitToProcessDLockResponse
+      LogWriterUtils.getLogWriter().info("[testReleaseOrphanedGrant_Local] process lock response");
+      sleep(500);
+      DLockRequestProcessor.setWaitToProcessDLockResponse(false);
+      
+      // relock obj to make sure zombie release worked
+      LogWriterUtils.getLogWriter().info("[testReleaseOrphanedGrant_Local] verify lock not held");
+      assertTrue(service.lock("obj", 1000, -1));
+    }
+    finally {
+      DLockRequestProcessor.setDebugReleaseOrphanedGrant(false);
+      DLockRequestProcessor.setWaitToProcessDLockResponse(false);
+    }
+  }
+  
+  static volatile Thread threadVM1_testReleaseOrphanedGrant_Remote;
+  static volatile Thread threadVM2_testReleaseOrphanedGrant_Remote;
+  static volatile boolean startedThreadVM1_testReleaseOrphanedGrant_Remote;
+  static volatile boolean releaseThreadVM1_testReleaseOrphanedGrant_Remote;
+  static volatile boolean unlockedThreadVM1_testReleaseOrphanedGrant_Remote;
+  static volatile boolean startedThreadVM2_testReleaseOrphanedGrant_Remote;
+  static volatile boolean gotLockThreadVM2_testReleaseOrphanedGrant_Remote;
+  public void testReleaseOrphanedGrant_Remote() {
+    doTestReleaseOrphanedGrant_Remote(false);
+  }
+  public void testReleaseOrphanedGrant_RemoteWithDestroy() {
+    doTestReleaseOrphanedGrant_Remote(true);
+  }
+  public void doTestReleaseOrphanedGrant_Remote(final boolean destroyLockService) {
+    final VM vm1 = Host.getHost(0).getVM(0);
+    final VM vm2 = Host.getHost(0).getVM(1);
+
+    try {
+      LogWriterUtils.getLogWriter().info("[testReleaseOrphanedGrant_Remote] create lock service");
+      final String serviceName = getUniqueName();
+      final DistributedLockService service = 
+        DistributedLockService.create(serviceName, dlstSystem);
+        
+      // lock and unlock to make sure this vm is grantor
+      assertTrue(service.lock("obj", -1, -1));
+      service.unlock("obj");
+      
+      // thread to get lock and wait and then unlock
+      vm1.invokeAsync(new SerializableRunnable() {
+        public void run() {
+          LogWriterUtils.getLogWriter().info("[testReleaseOrphanedGrant_Remote] get the lock");
+          threadVM1_testReleaseOrphanedGrant_Remote = Thread.currentThread();
+          connectDistributedSystem();
+          DistributedLockService service_vm1 =
+            DistributedLockService.create(serviceName, getSystem());
+          assertTrue(service_vm1.lock("obj", -1, -1));
+          synchronized(threadVM1_testReleaseOrphanedGrant_Remote) {
+            while (!releaseThreadVM1_testReleaseOrphanedGrant_Remote) {
+              try {
+                startedThreadVM1_testReleaseOrphanedGrant_Remote = true;
+                Thread.currentThread().wait();
+              } catch (InterruptedException ignore) {fail("interrupted");}
+            }
+          }
+          LogWriterUtils.getLogWriter().info("[testReleaseOrphanedGrant_Remote] unlock the lock");
+          service_vm1.unlock("obj");
+          unlockedThreadVM1_testReleaseOrphanedGrant_Remote = true;
+        }
+      });
+      vm1.invoke(new SerializableRunnable() {
+        public void run() {
+          while (!startedThreadVM1_testReleaseOrphanedGrant_Remote) {
+            Thread.yield();
+          }
+        }
+      });
+      sleep(500);
+      
+      // thread to interrupt lockInterruptibly call to cause zombie grant
+      vm2.invokeAsync(new SerializableRunnable() {
+        public void run() {
+          LogWriterUtils.getLogWriter().info("[testReleaseOrphanedGrant_Remote] call lockInterruptibly");
+          threadVM2_testReleaseOrphanedGrant_Remote = Thread.currentThread();
+          DistributedLockService service_vm2 =
+            DistributedLockService.create(serviceName, getSystem());
+          startedThreadVM2_testReleaseOrphanedGrant_Remote = true;
+          try {
+            DLockRequestProcessor.setDebugReleaseOrphanedGrant(true);
+            DLockRequestProcessor.setWaitToProcessDLockResponse(true);
+            assertFalse(service_vm2.lockInterruptibly("obj", -1, -1));
+          } catch (InterruptedException expected) {Thread.currentThread().interrupt();}
+        }
+      });
+      vm2.invoke(new SerializableRunnable() {
+        public void run() {
+          while (!startedThreadVM2_testReleaseOrphanedGrant_Remote) {
+            Thread.yield();
+          }
+        }
+      });
+      sleep(500);
+          
+      // release first thread to unlock
+      vm1.invoke(new SerializableRunnable() {
+        public void run() {
+          LogWriterUtils.getLogWriter().info("[testReleaseOrphanedGrant_Remote] release 1st thread");
+          synchronized(threadVM1_testReleaseOrphanedGrant_Remote) {
+            releaseThreadVM1_testReleaseOrphanedGrant_Remote = true;
+            threadVM1_testReleaseOrphanedGrant_Remote.notifyAll();
+          }
+        }
+      });
+      sleep(500); // lock is being released, grantor will grant lock to vm2
+  
+      // while first thread is stuck on waitToProcessDLockResponse,
+      //   interrupt 2nd thread
+      vm2.invoke(new SerializableRunnable() {
+        public void run() {
+          LogWriterUtils.getLogWriter().info("[testReleaseOrphanedGrant_Remote] interrupt 2nd thread");
+          threadVM2_testReleaseOrphanedGrant_Remote.interrupt();
+          ThreadUtils.join(threadVM2_testReleaseOrphanedGrant_Remote, 
+              5 * 60 * 1000);
+          if (destroyLockService) {
+            LogWriterUtils.getLogWriter().info("[testReleaseOrphanedGrant_Remote] destroy lock service");
+            DistributedLockService.destroy(serviceName);
+            assertNull(DistributedLockService.getServiceNamed(serviceName));
+          }
+        }
+      });
+      sleep(500); // grant is blocked while reply processor is being destroyed
+  
+      // release waitToProcessDLockResponse
+      vm2.invoke(new SerializableRunnable() {
+        public void run() {
+          LogWriterUtils.getLogWriter().info("[testReleaseOrphanedGrant_Remote] process lock response");
+          DLockRequestProcessor.setWaitToProcessDLockResponse(false);
+        }
+      });
+      sleep(500); // process grant and send zombie release to grantor
+      
+      // relock obj to make sure zombie release worked
+      LogWriterUtils.getLogWriter().info("[testReleaseOrphanedGrant_Remote] verify lock not held");
+      assertTrue(service.lock("obj", 1000, -1));
+    }
+    finally {
+      vm2.invoke(new SerializableRunnable() {
+        public void run() {
+          LogWriterUtils.getLogWriter().info("[testReleaseOrphanedGrant_Remote] clean up DebugReleaseOrphanedGrant");
+          DLockRequestProcessor.setDebugReleaseOrphanedGrant(false);
+          DLockRequestProcessor.setWaitToProcessDLockResponse(false);
+        }
+      });
+    }
+  }
+  
+  public void testDestroyLockServiceAfterGrantResponse() throws Throwable {
+    Host host = Host.getHost(0);
+    VM vm0 = host.getVM(0);
+    
+    final String serviceName = getUniqueName();
+
+    vm0.invoke(new SerializableRunnable("Create the grantor") {
+      
+      public void run() {
+        connectDistributedSystem();
+        final DistributedLockService service = 
+          DistributedLockService.create(serviceName, dlstSystem);
+          
+        // lock and unlock to make sure this vm is grantor
+        assertTrue(service.lock("obj", -1, -1));
+        service.unlock("obj");
+      }
+    });
+    
+    DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
+
+      @Override
+      public void beforeProcessMessage(DistributionManager dm,
+          DistributionMessage message) {
+        if(message instanceof DLockResponseMessage) {
+          DistributedLockService.destroy(serviceName);  
+        }
+      }
+    });
+
+    connectDistributedSystem();
+    final DistributedLockService service = 
+      DistributedLockService.create(serviceName, dlstSystem);
+    try {
+      service.lock("obj", -1, -1);
+      fail("The lock service should have been destroyed");
+    } catch(LockServiceDestroyedException expected) {
+      //Do nothing
+    }
+
+    vm0.invoke(new SerializableRunnable("check to make sure the lock is not orphaned") {
+
+      public void run() {
+        final DistributedLockService service = 
+          DistributedLockService.getServiceNamed(serviceName);
+
+        // lock and unlock to make sure this vm is grantor
+        assertTrue(service.lock("obj", -1, -1));
+        service.unlock("obj");


<TRUNCATED>


[10/16] incubator-geode git commit: GEODE-1260: Cache SCM metadata for source distributions

Posted by kl...@apache.org.
GEODE-1260: Cache SCM metadata for source distributions

The GemFireVersion.properties file is generated by the build and
contains the git branch, commit, and source date. This change
caches the SCM info in the build root (.buildinfo) for use by the
source distribution.

Actually works this time.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/44c2f398
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/44c2f398
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/44c2f398

Branch: refs/heads/feature/GEODE-1371
Commit: 44c2f398ff0a67d3e639c224c7df3ec861fe2c70
Parents: c33de6d
Author: Anthony Baker <ab...@apache.org>
Authored: Wed May 4 15:19:39 2016 -0700
Committer: Anthony Baker <ab...@apache.org>
Committed: Mon May 9 19:48:25 2016 -0700

----------------------------------------------------------------------
 geode-assembly/build.gradle | 12 +++++++
 geode-core/build.gradle     | 68 +++++++++++++++++++++++-----------------
 gradle/rat.gradle           |  1 +
 3 files changed, 52 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/44c2f398/geode-assembly/build.gradle
----------------------------------------------------------------------
diff --git a/geode-assembly/build.gradle b/geode-assembly/build.gradle
index e786b24..ed5154e 100755
--- a/geode-assembly/build.gradle
+++ b/geode-assembly/build.gradle
@@ -227,6 +227,17 @@ task docs(type: Javadoc) {
    }
 }
 
+task writeBuildInfo {
+  def buildInfo = file "$buildDir/.buildinfo"
+  outputs.file buildInfo
+  doLast {
+    buildInfo.getParentFile().mkdirs();
+    new FileOutputStream(buildInfo).withStream { fos ->
+      project(':geode-core').readScmInfo().store(fos, '')
+    }
+  }
+}
+
 gradle.taskGraph.whenReady( { graph ->
   tasks.withType(AbstractArchiveTask).findAll {
     it.name.toLowerCase().contains("dist")
@@ -242,6 +253,7 @@ distributions {
   src {
     baseName = 'apache-geode-src'
     contents {
+      from writeBuildInfo
       from (rootDir) {
         exclude 'KEYS'
         exclude 'gradlew'

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/44c2f398/geode-core/build.gradle
----------------------------------------------------------------------
diff --git a/geode-core/build.gradle b/geode-core/build.gradle
index 45051dc..8cd5bf3 100755
--- a/geode-core/build.gradle
+++ b/geode-core/build.gradle
@@ -131,7 +131,40 @@ sourceSets {
     output.dir(generatedResources, builtBy: 'createVersionPropertiesFile')
   }
 }
- 
+
+ext.readScmInfo = {
+  try {
+    def git = org.ajoberstar.grgit.Grgit.open(currentDir: projectDir)
+    try {
+      return [
+        'Source-Repository': git.branch.getCurrent().name,
+        'Source-Revision'  : git.head().id,
+        'Source-Date'      : git.head().getDate().format('yyyy-MM-dd HH:mm:ss Z')
+      ] as Properties
+    } finally {
+      git.close()
+    }
+  } catch (IllegalArgumentException e) {
+    // if we're building from the source distribution, we don't have git so
+    // use cached info written during the assembly process
+    def buildInfo = file "$rootDir/.buildinfo"
+    if (buildInfo.exists()) {
+      def props = new Properties()
+      new FileInputStream(buildInfo).withStream { fis ->
+        props.load(fis)
+      }
+      return props
+    }
+
+    logger.warn( '***** Unable to find Git workspace. Using default version information *****' )
+    return [
+      'Source-Repository': 'UNKNOWN',
+      'Source-Revision'  : 'UNKNOWN',
+      'Source-Date'      : new Date().format('yyyy-MM-dd HH:mm:ss Z')
+    ] as Properties
+  }
+}
+
 // Creates the version properties file and writes it to the classes dir
 task createVersionPropertiesFile {
   def propertiesFile = file(generatedResources + "/com/gemstone/gemfire/internal/GemFireVersion.properties");
@@ -139,38 +172,15 @@ task createVersionPropertiesFile {
   inputs.dir compileJava.destinationDir
 
   doLast {
-
-    try {
-      def grgit = org.ajoberstar.grgit.Grgit.open(currentDir: projectDir)
-      ext.branch = grgit.branch.getCurrent().name
-      ext.commitId = grgit.head().id
-      ext.sourceDate = grgit.head().getDate().format('yyyy-MM-dd HH:mm:ss Z')
-      grgit.close()
-    } catch (Exception e) {
-      logger.warn( '***** Unable to find Git workspace. Using default version information *****' )
-      ext.branch = 'UNKNOWN'
-      ext.commitId = 'UNKNOWN'
-      ext.sourceDate = new Date().format('yyyy-MM-dd HH:mm:ss Z')
-    }
-
-    ext.osArch = System.getProperty('os.arch')
-    ext.osName = System.getProperty('os.name')
-    ext.osVersion = System.getProperty('os.version')
-    ext.buildDate = new Date().format('yyyy-MM-dd HH:mm:ss Z')
-    ext.buildNumber = new Date().format('MMddyy')
-    ext.jdkVersion = System.getProperty('java.version')
-
     def props = [
       "Product-Name"      : "Apache Geode (incubating)",
       "Product-Version"   : version,
-      "Build-Id"          : System.env.USER + ' ' + ext.buildNumber,
-      "Build-Date"        : ext.buildDate,
-      "Build-Platform"    : ext.osName + ' ' + ext.osVersion + ' ' + ext.osArch,
-      "Build-Java-Version": ext.jdkVersion,
-      "Source-Date"       : ext.sourceDate,
-      "Source-Revision"   : ext.commitId,
-      "Source-Repository" : ext.branch
+      "Build-Id"          : "${System.env.USER} ${new Date().format('MMddyy')}".toString(),
+      "Build-Date"        : new Date().format('yyyy-MM-dd HH:mm:ss Z'),
+      "Build-Platform"    : "${System.properties['os.name']} ${System.properties['os.version']} ${System.properties['os.arch']}".toString(),
+      "Build-Java-Version": System.properties['java.version']
     ] as Properties
+    props.putAll(readScmInfo())
 
     propertiesFile.getParentFile().mkdirs();
     new FileOutputStream(propertiesFile).withStream { fos ->

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/44c2f398/gradle/rat.gradle
----------------------------------------------------------------------
diff --git a/gradle/rat.gradle b/gradle/rat.gradle
index f35b157..3d0826a 100644
--- a/gradle/rat.gradle
+++ b/gradle/rat.gradle
@@ -37,6 +37,7 @@ rat {
     'native/**',
     'wrapper/**',
     '**/build/**',
+    '.buildinfo',
 
     // SBT
     'geode-spark-connector/**/target/**',


[11/16] incubator-geode git commit: GEODE-92: PR with entry eviction 1 leaves 3 entries in memory with async overflow

Posted by kl...@apache.org.
GEODE-92: PR with entry eviction 1 leaves 3 entries in memory with async overflow

 Found that invoking lruUpdateCallback multiple times with in a single get
 could mess up entry eviction state. So disabled lru callback and invoked
 at the end of the operation.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/f4b06438
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/f4b06438
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/f4b06438

Branch: refs/heads/feature/GEODE-1371
Commit: f4b0643829b00d0ba9b0852fdd3a679812395545
Parents: 44c2f39
Author: Sai Boorlagadda <sb...@pivotal.io>
Authored: Tue Apr 26 13:31:25 2016 -0700
Committer: Sai Boorlagadda <sb...@pivotal.io>
Committed: Tue May 10 08:33:09 2016 -0700

----------------------------------------------------------------------
 .../gemfire/internal/cache/AbstractLRURegionMap.java  |  9 +++------
 .../gemstone/gemfire/internal/cache/LocalRegion.java  |  6 ++++++
 .../cache/PartitionedRegionStatsJUnitTest.java        | 14 ++------------
 3 files changed, 11 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f4b06438/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractLRURegionMap.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractLRURegionMap.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractLRURegionMap.java
index 2cc7a55..14c431d 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractLRURegionMap.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractLRURegionMap.java
@@ -197,17 +197,14 @@ public abstract class AbstractLRURegionMap extends AbstractRegionMap {
     int delta = le.updateEntrySize(_getCCHelper(), new CDValueWrapper(v));
     if (delta != 0) {
       result = true;
-      boolean needToDisableCallbacks = !getCallbackDisabled();
-      if (needToDisableCallbacks) {
-        setCallbackDisabled(true);
-      }
+      boolean disabledLURCallbacks = disableLruUpdateCallback();
       // by making sure that callbacks are disabled when we call
       // setDelta; it ensures that the setDelta will just inc the delta
       // value and not call lruUpdateCallback which we call in
       // finishChangeValueForm
       setDelta(delta);
-      if (needToDisableCallbacks) {
-        setCallbackDisabled(false);
+      if (disabledLURCallbacks) {
+        enableLruUpdateCallback();
       }
     }
     // fix for bug 42090

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f4b06438/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
index 3ad294c..e9f5819 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
@@ -1298,6 +1298,7 @@ public class LocalRegion extends AbstractRegion
   @Retained
   protected final Object getDeserialized(RegionEntry re, boolean updateStats, boolean disableCopyOnRead, boolean preferCD, boolean retainResult) {
     assert !retainResult || preferCD;
+    boolean disabledLRUCallback = this.entries.disableLruUpdateCallback();
     try {
       @Retained Object v = null;
       try {
@@ -1340,6 +1341,11 @@ public class LocalRegion extends AbstractRegion
       IllegalArgumentException iae = new IllegalArgumentException(LocalizedStrings.DONT_RELEASE.toLocalizedString("Error while deserializing value for key="+re.getKey()));
       iae.initCause(i);
       throw iae;
+    } finally {
+      if(disabledLRUCallback) {
+        this.entries.enableLruUpdateCallback();
+        this.entries.lruUpdateCallback();
+      }
     }
   }
   

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f4b06438/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/PartitionedRegionStatsJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/PartitionedRegionStatsJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/PartitionedRegionStatsJUnitTest.java
index 167b89b..1a3277c 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/PartitionedRegionStatsJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/PartitionedRegionStatsJUnitTest.java
@@ -436,11 +436,7 @@ public class PartitionedRegionStatsJUnitTest
     
     pr.getDiskStore().flush();
     
-    //Workaround for GEODE-92. We are leaving more than 1 entry in memory. To
-    //validate that stats, let's confirm the stats match what is actually in
-    //memory
-    //int entriesInMem = 1;
-    int entriesInMem = countEntriesInMem(pr);
+    int entriesInMem = 1;
     
     assertEquals(singleEntryMemSize * entriesInMem, stats.getLong("dataStoreBytesInUse"));
     assertEquals(numEntries , stats.getInt("dataStoreEntryCount"));
@@ -475,13 +471,7 @@ public class PartitionedRegionStatsJUnitTest
     System.out.println("----Done with random operations");
 
     numEntries = pr.entryCount();
-    
-    //Workaround for GEODE-92. We are leaving more than 1 entry in memory. To
-    //validate that stats, let's confirm the stats match what is actually in
-    //memory
-    //entriesInMem = 1;
-    entriesInMem = countEntriesInMem(pr);
-    
+        
     assertEquals(singleEntryMemSize * entriesInMem, stats.getLong("dataStoreBytesInUse"));
     assertEquals(numEntries , stats.getInt("dataStoreEntryCount"));
     assertEquals((numEntries - entriesInMem) * entryOverflowSize, diskStats.getNumOverflowBytesOnDisk());


[13/16] incubator-geode git commit: GEODE-1369: change ConfigCommandsDUnitTest to use TemporaryFolder

Posted by kl...@apache.org.
GEODE-1369: change ConfigCommandsDUnitTest to use TemporaryFolder

* use TemporaryFolder for all disk files
* re-enable testAlterUpdatesSharedConfig (might be a FlakyTest) -- was disabled for TRAC #52204 but it passes
* use static imports


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/f93c87f1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/f93c87f1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/f93c87f1

Branch: refs/heads/feature/GEODE-1371
Commit: f93c87f13b4bf1bda67d994587d1299163694772
Parents: c8ca8a0
Author: Kirk Lund <kl...@apache.org>
Authored: Tue May 10 11:03:09 2016 -0700
Committer: Kirk Lund <kl...@apache.org>
Committed: Tue May 10 11:03:09 2016 -0700

----------------------------------------------------------------------
 .../cli/commands/ConfigCommandsDUnitTest.java   | 319 ++++++++++---------
 1 file changed, 171 insertions(+), 148 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f93c87f1/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ConfigCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ConfigCommandsDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ConfigCommandsDUnitTest.java
index c342142..1d861c6 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ConfigCommandsDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ConfigCommandsDUnitTest.java
@@ -16,10 +16,13 @@
  */
 package com.gemstone.gemfire.management.internal.cli.commands;
 
+import static com.gemstone.gemfire.distributed.internal.DistributionConfig.*;
+import static com.gemstone.gemfire.internal.AvailablePort.*;
+import static com.gemstone.gemfire.internal.AvailablePortHelper.*;
 import static com.gemstone.gemfire.test.dunit.Assert.*;
-import static com.gemstone.gemfire.test.dunit.Invoke.*;
 import static com.gemstone.gemfire.test.dunit.LogWriterUtils.*;
 import static com.gemstone.gemfire.test.dunit.Wait.*;
+import static org.apache.commons.io.FileUtils.*;
 
 import java.io.File;
 import java.io.FileReader;
@@ -32,6 +35,9 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Properties;
 
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
 import com.gemstone.gemfire.cache.Cache;
 import com.gemstone.gemfire.cache.server.CacheServer;
 import com.gemstone.gemfire.distributed.Locator;
@@ -39,9 +45,6 @@ import com.gemstone.gemfire.distributed.internal.DistributionConfig;
 import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
 import com.gemstone.gemfire.distributed.internal.InternalLocator;
 import com.gemstone.gemfire.distributed.internal.SharedConfiguration;
-import com.gemstone.gemfire.internal.AvailablePort;
-import com.gemstone.gemfire.internal.AvailablePortHelper;
-import com.gemstone.gemfire.internal.FileUtil;
 import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
 import com.gemstone.gemfire.internal.cache.xmlcache.CacheXmlGenerator;
 import com.gemstone.gemfire.internal.logging.LogWriterImpl;
@@ -58,10 +61,6 @@ import com.gemstone.gemfire.test.dunit.VM;
 import com.gemstone.gemfire.test.dunit.WaitCriterion;
 import com.gemstone.gemfire.test.junit.categories.DistributedTest;
 
-import org.apache.commons.io.FileUtils;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
 /**
  * Dunit class for testing GemFire config commands : export config
  *
@@ -71,110 +70,113 @@ import org.junit.experimental.categories.Category;
 @SuppressWarnings("serial")
 public class ConfigCommandsDUnitTest extends CliCommandTestBase {
 
-  File managerConfigFile = new File("Manager-cache.xml");
-  File managerPropsFile = new File("Manager-gf.properties");
-  File vm1ConfigFile = new File("VM1-cache.xml");
-  File vm1PropsFile = new File("VM1-gf.properties");
-  File vm2ConfigFile = new File("VM2-cache.xml");
-  File vm2PropsFile = new File("VM2-gf.properties");
-  File shellConfigFile = new File("Shell-cache.xml");
-  File shellPropsFile = new File("Shell-gf.properties");
-  File subDir = new File("ConfigCommandsDUnitTestSubDir");
-  File subManagerConfigFile = new File(subDir, managerConfigFile.getName());
+  private File managerConfigFile;
+  private File managerPropsFile;
+  private File vm1ConfigFile;
+  private File vm1PropsFile;
+  private File vm2ConfigFile;
+  private File vm2PropsFile;
+  private File shellConfigFile;
+  private File shellPropsFile;
+  private File subDir;
+  private File subManagerConfigFile;
 
   @Override
-  protected void preTearDownCliCommandTestBase() throws Exception {
-    deleteTestFiles();
-    invokeInEveryVM(new SerializableRunnable() {
-
-      @Override
-      public void run() {
-        try {
-          deleteTestFiles();
-        } catch (IOException e) {
-          fail("error", e);
-        }
-      }
-    });
+  protected final void postSetUpCliCommandTestBase() throws Exception {
+    this.managerConfigFile = this.temporaryFolder.newFile("Manager-cache.xml");
+    this.managerPropsFile = this.temporaryFolder.newFile("Manager-gf.properties");
+    this.vm1ConfigFile = this.temporaryFolder.newFile("VM1-cache.xml");
+    this.vm1PropsFile = this.temporaryFolder.newFile("VM1-gf.properties");
+    this.vm2ConfigFile = this.temporaryFolder.newFile("VM2-cache.xml");
+    this.vm2PropsFile = this.temporaryFolder.newFile("VM2-gf.properties");
+    this.shellConfigFile = this.temporaryFolder.newFile("Shell-cache.xml");
+    this.shellPropsFile = this.temporaryFolder.newFile("Shell-gf.properties");
+    this.subDir = this.temporaryFolder.newFolder(getName());
+    this.subManagerConfigFile = new File(this.subDir, this.managerConfigFile.getName());
   }
 
   @Test
-  public void testDescribeConfig() throws ClassNotFoundException, IOException {
+  public void testDescribeConfig() throws Exception {
     setUpJmxManagerOnVm0ThenConnect(null);
     final String controllerName = "Member2";
 
-    /***
+    /*
      * Create properties for the controller VM
      */
     final Properties localProps = new Properties();
-    localProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
-    localProps.setProperty(DistributionConfig.LOG_LEVEL_NAME, "info");
-    localProps.setProperty(DistributionConfig.STATISTIC_SAMPLING_ENABLED_NAME, "true");
-    localProps.setProperty(DistributionConfig.ENABLE_TIME_STATISTICS_NAME, "true");
-    localProps.setProperty(DistributionConfig.NAME_NAME, controllerName);
-    localProps.setProperty(DistributionConfig.GROUPS_NAME, "G1");
+    localProps.setProperty(MCAST_PORT_NAME, "0");
+    localProps.setProperty(LOG_LEVEL_NAME, "info");
+    localProps.setProperty(STATISTIC_SAMPLING_ENABLED_NAME, "true");
+    localProps.setProperty(ENABLE_TIME_STATISTICS_NAME, "true");
+    localProps.setProperty(NAME_NAME, controllerName);
+    localProps.setProperty(GROUPS_NAME, "G1");
     getSystem(localProps);
     Cache cache = getCache();
-    int ports[] = AvailablePortHelper.getRandomAvailableTCPPorts(1);
+
+    int ports[] = getRandomAvailableTCPPorts(1);
     CacheServer cs = getCache().addCacheServer();
     cs.setPort(ports[0]);
     cs.setMaxThreads(10);
     cs.setMaxConnections(9);
     cs.start();
+    try {
 
-    RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
-    List<String> jvmArgs = runtimeBean.getInputArguments();
+      RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
+      List<String> jvmArgs = runtimeBean.getInputArguments();
 
-    getLogWriter().info("#SB Actual JVM Args : ");
+      getLogWriter().info("#SB Actual JVM Args : ");
 
-    for (String jvmArg : jvmArgs) {
-      getLogWriter().info("#SB JVM " + jvmArg);
-    }
+      for (String jvmArg : jvmArgs) {
+        getLogWriter().info("#SB JVM " + jvmArg);
+      }
 
-    InternalDistributedSystem system = (InternalDistributedSystem) cache.getDistributedSystem();
-    DistributionConfig config = system.getConfig();
-    config.setArchiveFileSizeLimit(1000);
+      InternalDistributedSystem system = (InternalDistributedSystem) cache.getDistributedSystem();
+      DistributionConfig config = system.getConfig();
+      config.setArchiveFileSizeLimit(1000);
 
-    String command = CliStrings.DESCRIBE_CONFIG + " --member=" + controllerName;
-    CommandProcessor cmdProcessor = new CommandProcessor();
-    cmdProcessor.createCommandStatement(command, Collections.EMPTY_MAP).process();
+      String command = CliStrings.DESCRIBE_CONFIG + " --member=" + controllerName;
+      CommandProcessor cmdProcessor = new CommandProcessor();
+      cmdProcessor.createCommandStatement(command, Collections.EMPTY_MAP).process();
 
-    CommandResult cmdResult = executeCommand(command);
+      CommandResult cmdResult = executeCommand(command);
 
-    String resultStr = commandResultToString(cmdResult);
-    getLogWriter().info("#SB Hiding the defaults\n" + resultStr);
+      String resultStr = commandResultToString(cmdResult);
+      getLogWriter().info("#SB Hiding the defaults\n" + resultStr);
 
-    assertEquals(true, cmdResult.getStatus().equals(Status.OK));
-    assertEquals(true, resultStr.contains("G1"));
-    assertEquals(true, resultStr.contains(controllerName));
-    assertEquals(true, resultStr.contains("archive-file-size-limit"));
-    assertEquals(true, !resultStr.contains("copy-on-read"));
+      assertEquals(true, cmdResult.getStatus().equals(Status.OK));
+      assertEquals(true, resultStr.contains("G1"));
+      assertEquals(true, resultStr.contains(controllerName));
+      assertEquals(true, resultStr.contains("archive-file-size-limit"));
+      assertEquals(true, !resultStr.contains("copy-on-read"));
 
-    cmdResult = executeCommand(command + " --" + CliStrings.DESCRIBE_CONFIG__HIDE__DEFAULTS + "=false");
-    resultStr = commandResultToString(cmdResult);
-    getLogWriter().info("#SB No hiding of defaults\n" + resultStr);
+      cmdResult = executeCommand(command + " --" + CliStrings.DESCRIBE_CONFIG__HIDE__DEFAULTS + "=false");
+      resultStr = commandResultToString(cmdResult);
 
-    assertEquals(true, cmdResult.getStatus().equals(Status.OK));
-    assertEquals(true, resultStr.contains("is-server"));
-    assertEquals(true, resultStr.contains(controllerName));
-    assertEquals(true, resultStr.contains("copy-on-read"));
+      getLogWriter().info("#SB No hiding of defaults\n" + resultStr);
+
+      assertEquals(true, cmdResult.getStatus().equals(Status.OK));
+      assertEquals(true, resultStr.contains("is-server"));
+      assertEquals(true, resultStr.contains(controllerName));
+      assertEquals(true, resultStr.contains("copy-on-read"));
 
-    cs.stop();
+    } finally {
+      cs.stop();
+    }
   }
 
   @Test
-  public void testExportConfig() throws IOException {
+  public void testExportConfig() throws Exception {
     Properties localProps = new Properties();
-    localProps.setProperty(DistributionConfig.NAME_NAME, "Manager");
-    localProps.setProperty(DistributionConfig.GROUPS_NAME, "Group1");
+    localProps.setProperty(NAME_NAME, "Manager");
+    localProps.setProperty(GROUPS_NAME, "Group1");
     setUpJmxManagerOnVm0ThenConnect(localProps);
 
     // Create a cache in another VM (VM1)
     Host.getHost(0).getVM(1).invoke(new SerializableRunnable() {
       public void run() {
         Properties localProps = new Properties();
-        localProps.setProperty(DistributionConfig.NAME_NAME, "VM1");
-        localProps.setProperty(DistributionConfig.GROUPS_NAME, "Group2");
+        localProps.setProperty(NAME_NAME, "VM1");
+        localProps.setProperty(GROUPS_NAME, "Group2");
         getSystem(localProps);
         getCache();
       }
@@ -184,8 +186,8 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
     Host.getHost(0).getVM(2).invoke(new SerializableRunnable() {
       public void run() {
         Properties localProps = new Properties();
-        localProps.setProperty(DistributionConfig.NAME_NAME, "VM2");
-        localProps.setProperty(DistributionConfig.GROUPS_NAME, "Group2");
+        localProps.setProperty(NAME_NAME, "VM2");
+        localProps.setProperty(GROUPS_NAME, "Group2");
         getSystem(localProps);
         getCache();
       }
@@ -193,47 +195,47 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
 
     // Create a cache in the local VM
     localProps = new Properties();
-    localProps.setProperty(DistributionConfig.NAME_NAME, "Shell");
+    localProps.setProperty(NAME_NAME, "Shell");
     getSystem(localProps);
     Cache cache = getCache();
 
     // Test export config for all members
     deleteTestFiles();
-    CommandResult cmdResult = executeCommand("export config");
+    CommandResult cmdResult = executeCommand("export config --dir=" + this.temporaryFolder.getRoot().getAbsolutePath());
     assertEquals(Result.Status.OK, cmdResult.getStatus());
 
-    assertTrue(this.managerConfigFile.exists());
-    assertTrue(this.managerPropsFile.exists());
-    assertTrue(this.vm1ConfigFile.exists());
-    assertTrue(this.vm1PropsFile.exists());
-    assertTrue(this.vm2ConfigFile.exists());
-    assertTrue(this.vm2PropsFile.exists());
-    assertTrue(this.shellConfigFile.exists());
-    assertTrue(this.shellPropsFile.exists());
+    assertTrue(this.managerConfigFile + " should exist", this.managerConfigFile.exists());
+    assertTrue(this.managerPropsFile + " should exist", this.managerPropsFile.exists());
+    assertTrue(this.vm1ConfigFile + " should exist", this.vm1ConfigFile.exists());
+    assertTrue(this.vm1PropsFile + " should exist", this.vm1PropsFile.exists());
+    assertTrue(this.vm2ConfigFile + " should exist", this.vm2ConfigFile.exists());
+    assertTrue(this.vm2PropsFile + " should exist", this.vm2PropsFile.exists());
+    assertTrue(this.shellConfigFile + " should exist", this.shellConfigFile.exists());
+    assertTrue(this.shellPropsFile + " should exist", this.shellPropsFile.exists());
 
     // Test exporting member
     deleteTestFiles();
-    cmdResult = executeCommand("export config --member=Manager");
+    cmdResult = executeCommand("export config --member=Manager --dir=" + this.temporaryFolder.getRoot().getAbsolutePath());
     assertEquals(Result.Status.OK, cmdResult.getStatus());
 
-    assertTrue(this.managerConfigFile.exists());
-    assertFalse(this.vm1ConfigFile.exists());
-    assertFalse(this.vm2ConfigFile.exists());
-    assertFalse(this.shellConfigFile.exists());
+    assertTrue(this.managerConfigFile + " should exist", this.managerConfigFile.exists());
+    assertFalse(this.vm1ConfigFile + " should not exist", this.vm1ConfigFile.exists());
+    assertFalse(this.vm2ConfigFile + " should not exist", this.vm2ConfigFile.exists());
+    assertFalse(this.shellConfigFile + " should not exist", this.shellConfigFile.exists());
 
     // Test exporting group
     deleteTestFiles();
-    cmdResult = executeCommand("export config --group=Group2");
+    cmdResult = executeCommand("export config --group=Group2 --dir=" + this.temporaryFolder.getRoot().getAbsolutePath());
     assertEquals(Result.Status.OK, cmdResult.getStatus());
 
-    assertFalse(this.managerConfigFile.exists());
-    assertTrue(this.vm1ConfigFile.exists());
-    assertTrue(this.vm2ConfigFile.exists());
-    assertFalse(this.shellConfigFile.exists());
+    assertFalse(this.managerConfigFile + " should not exist", this.managerConfigFile.exists());
+    assertTrue(this.vm1ConfigFile + " should exist", this.vm1ConfigFile.exists());
+    assertTrue(this.vm2ConfigFile + " should exist", this.vm2ConfigFile.exists());
+    assertFalse(this.shellConfigFile + " should not exist", this.shellConfigFile.exists());
 
     // Test export to directory
     deleteTestFiles();
-    cmdResult = executeCommand("export config --dir=" + subDir.getAbsolutePath());
+    cmdResult = executeCommand("export config --dir=" + this.subDir.getAbsolutePath());
     assertEquals(Result.Status.OK, cmdResult.getStatus());
 
     assertFalse(this.managerConfigFile.exists());
@@ -246,30 +248,32 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
     String configToMatch = stringWriter.toString();
 
     deleteTestFiles();
-    cmdResult = executeCommand("export config --member=Shell");
+    cmdResult = executeCommand("export config --member=Shell --dir=" + this.temporaryFolder.getRoot().getAbsolutePath());
     assertEquals(Result.Status.OK, cmdResult.getStatus());
 
     char[] fileContents = new char[configToMatch.length()];
-    try {
-      FileReader reader = new FileReader(shellConfigFile);
-      reader.read(fileContents);
-    } catch (Exception ex) {
-      fail("Unable to read file contents for comparison", ex);
-    }
+    FileReader reader = new FileReader(this.shellConfigFile);
+    reader.read(fileContents);
 
     assertEquals(configToMatch, new String(fileContents));
   }
 
   @Test
-  public void testAlterRuntimeConfig() throws ClassNotFoundException, IOException {
+  public void testAlterRuntimeConfig() throws Exception {
     final String controller = "controller";
+    String directory = this.temporaryFolder.newFolder(controller).getAbsolutePath();
+    String statFilePath = new File(directory, "stat.gfs").getAbsolutePath();
+
     setUpJmxManagerOnVm0ThenConnect(null);
+
     Properties localProps = new Properties();
-    localProps.setProperty(DistributionConfig.NAME_NAME, controller);
-    localProps.setProperty(DistributionConfig.LOG_LEVEL_NAME, "error");
+    localProps.setProperty(NAME_NAME, controller);
+    localProps.setProperty(LOG_LEVEL_NAME, "error");
     getSystem(localProps);
+
     final GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
     final DistributionConfig config = cache.getSystem().getConfig();
+
     CommandStringBuilder csb = new CommandStringBuilder(CliStrings.ALTER_RUNTIME_CONFIG);
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__MEMBER, controller);
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__LEVEL, "info");
@@ -277,13 +281,16 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__DISK__SPACE__LIMIT, "32");
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__FILE__SIZE__LIMIT, "49");
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLE__RATE, "2000");
-    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE, "stat.gfs");
+    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE, statFilePath);
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLING__ENABLED, "true");
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT, "10");
+
     CommandResult cmdResult = executeCommand(csb.getCommandString());
     String resultString = commandResultToString(cmdResult);
+
     getLogWriter().info("Result\n");
     getLogWriter().info(resultString);
+
     assertEquals(true, cmdResult.getStatus().equals(Status.OK));
     assertEquals(LogWriterImpl.INFO_LEVEL, config.getLogLevel());
     assertEquals(50, config.getLogFileSizeLimit());
@@ -293,27 +300,29 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
     assertEquals(true, config.getStatisticSamplingEnabled());
     assertEquals(10, config.getLogDiskSpaceLimit());
 
-
     CommandProcessor commandProcessor = new CommandProcessor();
     Result result = commandProcessor.createCommandStatement("alter runtime", Collections.EMPTY_MAP).process();
   }
 
   @Test
-  public void testAlterRuntimeConfigRandom() {
+  public void testAlterRuntimeConfigRandom() throws Exception {
     final String member1 = "VM1";
     final String controller = "controller";
+
     setUpJmxManagerOnVm0ThenConnect(null);
+
     Properties localProps = new Properties();
-    localProps.setProperty(DistributionConfig.NAME_NAME, controller);
-    localProps.setProperty(DistributionConfig.LOG_LEVEL_NAME, "error");
+    localProps.setProperty(NAME_NAME, controller);
+    localProps.setProperty(LOG_LEVEL_NAME, "error");
     getSystem(localProps);
+
     final GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
     final DistributionConfig config = cache.getSystem().getConfig();
 
     Host.getHost(0).getVM(1).invoke(new SerializableRunnable() {
       public void run() {
         Properties localProps = new Properties();
-        localProps.setProperty(DistributionConfig.NAME_NAME, member1);
+        localProps.setProperty(NAME_NAME, member1);
         getSystem(localProps);
         Cache cache = getCache();
       }
@@ -322,8 +331,10 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
     CommandStringBuilder csb = new CommandStringBuilder(CliStrings.ALTER_RUNTIME_CONFIG);
     CommandResult cmdResult = executeCommand(csb.getCommandString());
     String resultAsString = commandResultToString(cmdResult);
+
     getLogWriter().info("#SB Result\n");
     getLogWriter().info(resultAsString);
+
     assertEquals(true, cmdResult.getStatus().equals(Status.ERROR));
     assertTrue(resultAsString.contains(CliStrings.ALTER_RUNTIME_CONFIG__RELEVANT__OPTION__MESSAGE));
 
@@ -331,45 +342,56 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT, "2000000000");
     cmdResult = executeCommand(csb.getCommandString());
     resultAsString = commandResultToString(cmdResult);
+
     getLogWriter().info("#SB Result\n");
     getLogWriter().info(resultAsString);
-    assertEquals(true, cmdResult.getStatus().equals(Status.ERROR));
 
+    assertEquals(true, cmdResult.getStatus().equals(Status.ERROR));
   }
 
   @Test
-  public void testAlterRuntimeConfigOnAllMembers() {
+  public void testAlterRuntimeConfigOnAllMembers() throws Exception {
     final String member1 = "VM1";
     final String controller = "controller";
+
+    String controllerDirectory = this.temporaryFolder.newFolder(controller).getAbsolutePath();
+    String controllerStatFilePath = new File(controllerDirectory, "stat.gfs").getAbsolutePath();
+
     setUpJmxManagerOnVm0ThenConnect(null);
+
     Properties localProps = new Properties();
-    localProps.setProperty(DistributionConfig.NAME_NAME, controller);
-    localProps.setProperty(DistributionConfig.LOG_LEVEL_NAME, "error");
+    localProps.setProperty(NAME_NAME, controller);
+    localProps.setProperty(LOG_LEVEL_NAME, "error");
     getSystem(localProps);
+
     final GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
     final DistributionConfig config = cache.getSystem().getConfig();
 
     Host.getHost(0).getVM(1).invoke(new SerializableRunnable() {
       public void run() {
         Properties localProps = new Properties();
-        localProps.setProperty(DistributionConfig.NAME_NAME, member1);
+        localProps.setProperty(NAME_NAME, member1);
         getSystem(localProps);
         Cache cache = getCache();
       }
     });
+
     CommandStringBuilder csb = new CommandStringBuilder(CliStrings.ALTER_RUNTIME_CONFIG);
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__LEVEL, "info");
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__FILE__SIZE__LIMIT, "50");
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__DISK__SPACE__LIMIT, "32");
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__FILE__SIZE__LIMIT, "49");
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLE__RATE, "2000");
-    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE, "stat.gfs");
+    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE, controllerStatFilePath);
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLING__ENABLED, "true");
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT, "10");
+
     CommandResult cmdResult = executeCommand(csb.getCommandString());
     String resultString = commandResultToString(cmdResult);
+
     getLogWriter().info("#SB Result\n");
     getLogWriter().info(resultString);
+
     assertEquals(true, cmdResult.getStatus().equals(Status.OK));
     assertEquals(LogWriterImpl.INFO_LEVEL, config.getLogLevel());
     assertEquals(50, config.getLogFileSizeLimit());
@@ -384,7 +406,8 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
     Host.getHost(0).getVM(1).invoke(new SerializableRunnable() {
       public void run() {
         GemFireCacheImpl cacheVM1 = (GemFireCacheImpl) getCache();
-        final DistributionConfig configVM1 = cacheVM1.getSystem().getConfig();
+        DistributionConfig configVM1 = cacheVM1.getSystem().getConfig();
+
         assertEquals(LogWriterImpl.INFO_LEVEL, configVM1.getLogLevel());
         assertEquals(50, configVM1.getLogFileSizeLimit());
         assertEquals(49, configVM1.getArchiveFileSizeLimit());
@@ -399,51 +422,51 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
 
   /**
    * Asserts that altering the runtime config correctly updates the shared configuration.
-   * <p>
-   * Disabled: this test frequently fails during unit test runs. See ticket #52204
    */
-  public void disabledtestAlterUpdatesSharedConfig() {
-    disconnectAllFromDS();
-
-    final String groupName = "testAlterRuntimeConfigSharedConfigGroup";
+  @Test
+  public void testAlterUpdatesSharedConfig() throws Exception {
+    final String groupName = getName();
 
     // Start the Locator and wait for shared configuration to be available
-    final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
+    final int locatorPort = getRandomAvailablePort(SOCKET);
+    final String locatorDirectory = this.temporaryFolder.newFolder("Locator").getAbsolutePath();
+
     Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
       @Override
       public void run() {
+        final File locatorLogFile = new File(locatorDirectory, "locator-" + locatorPort + ".log");
 
-        final File locatorLogFile = new File("locator-" + locatorPort + ".log");
         final Properties locatorProps = new Properties();
-        locatorProps.setProperty(DistributionConfig.NAME_NAME, "Locator");
-        locatorProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
-        locatorProps.setProperty(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "true");
+        locatorProps.setProperty(NAME_NAME, "Locator");
+        locatorProps.setProperty(MCAST_PORT_NAME, "0");
+        locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION_NAME, "true");
+        locatorProps.setProperty(CLUSTER_CONFIGURATION_DIR, locatorDirectory);
+
         try {
-          final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort, locatorLogFile, null,
-              locatorProps);
+          final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort, locatorLogFile, null, locatorProps);
 
           WaitCriterion wc = new WaitCriterion() {
             @Override
             public boolean done() {
               return locator.isSharedConfigurationRunning();
             }
-
             @Override
             public String description() {
               return "Waiting for shared configuration to be started";
             }
           };
           waitForCriterion(wc, 5000, 500, true);
-        } catch (IOException ioex) {
-          fail("Unable to create a locator with a shared configuration");
+
+        } catch (IOException e) {
+          fail("Unable to create a locator with a shared configuration", e);
         }
       }
     });
 
     // Start the default manager
     Properties managerProps = new Properties();
-    managerProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
-    managerProps.setProperty(DistributionConfig.LOCATORS_NAME, "localhost:" + locatorPort);
+    managerProps.setProperty(MCAST_PORT_NAME, "0");
+    managerProps.setProperty(LOCATORS_NAME, "localhost:" + locatorPort);
     setUpJmxManagerOnVm0ThenConnect(managerProps);
 
     // Create a cache in VM 1
@@ -451,18 +474,15 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
     vm.invoke(new SerializableCallable() {
       @Override
       public Object call() throws Exception {
-        //Make sure no previous shared config is screwing up this test.
-        FileUtil.delete(new File("ConfigDiskDir_Locator"));
-        FileUtil.delete(new File("cluster_config"));
         Properties localProps = new Properties();
-        localProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
-        localProps.setProperty(DistributionConfig.LOCATORS_NAME, "localhost:" + locatorPort);
-        localProps.setProperty(DistributionConfig.LOG_LEVEL_NAME, "error");
-        localProps.setProperty(DistributionConfig.GROUPS_NAME, groupName);
+        localProps.setProperty(MCAST_PORT_NAME, "0");
+        localProps.setProperty(LOCATORS_NAME, "localhost:" + locatorPort);
+        localProps.setProperty(LOG_LEVEL_NAME, "error");
+        localProps.setProperty(GROUPS_NAME, groupName);
         getSystem(localProps);
 
         assertNotNull(getCache());
-        assertEquals("error", basicGetSystem().getConfig().getAttribute(DistributionConfig.LOG_LEVEL_NAME));
+        assertEquals("error", basicGetSystem().getConfig().getAttribute(LOG_LEVEL_NAME));
         return null;
       }
     });
@@ -472,6 +492,7 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
     commandStringBuilder.addOption(CliStrings.ALTER_RUNTIME_CONFIG__GROUP, groupName);
     commandStringBuilder.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__LEVEL, "fine");
     CommandResult cmdResult = executeCommand(commandStringBuilder.toString());
+
     assertEquals(Result.Status.OK, cmdResult.getStatus());
 
     // Make sure the shared config was updated
@@ -479,13 +500,15 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
       @Override
       public void run() {
         SharedConfiguration sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
-        Properties gemfireProperties;
+        Properties gemfireProperties = null;
+
         try {
           gemfireProperties = sharedConfig.getConfiguration(groupName).getGemfireProperties();
-          assertEquals("fine", gemfireProperties.get(DistributionConfig.LOG_LEVEL_NAME));
         } catch (Exception e) {
           fail("Error occurred in cluster configuration service", e);
         }
+
+        assertEquals("fine", gemfireProperties.get(LOG_LEVEL_NAME));
       }
     });
   }
@@ -500,6 +523,6 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
     this.shellConfigFile.delete();
     this.shellPropsFile.delete();
 
-    FileUtils.deleteDirectory(this.subDir);
+    deleteDirectory(this.subDir);
   }
 }


[05/16] incubator-geode git commit: Revert "GEODE-1360: Enabling to specify log4j2.xml for junit/dunit/intgrationtest"

Posted by kl...@apache.org.
Revert "GEODE-1360: Enabling to specify log4j2.xml for junit/dunit/intgrationtest"

This reverts commit 717ba5c8b45394c691b77d6a1bb83318bfa182da.

This commit caused all dunit tests to fail, because if the log4j file
was not specified, it added an empty parameter when launching the dunit
VMs.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/af119cfd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/af119cfd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/af119cfd

Branch: refs/heads/feature/GEODE-1371
Commit: af119cfd38e4545b0d7deb0321f5142434fa5f5e
Parents: 6c53d4f
Author: Dan Smith <up...@apache.org>
Authored: Mon May 9 15:10:54 2016 -0700
Committer: Dan Smith <up...@apache.org>
Committed: Mon May 9 15:15:29 2016 -0700

----------------------------------------------------------------------
 .../gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java    | 1 -
 .../gemstone/gemfire/test/dunit/standalone/ProcessManager.java   | 1 -
 gradle/test.gradle                                               | 4 ----
 3 files changed, 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/af119cfd/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java
index e06958a..0c294ec 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java
@@ -75,7 +75,6 @@ public class DUnitLauncher {
 
   /** change this to use a different log level in unit tests */
   public static final String LOG_LEVEL = System.getProperty("logLevel", "info");
-  public static final String LOG4J = System.getProperty("log4j.configurationFile");
   
   static int locatorPort;
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/af119cfd/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/ProcessManager.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/ProcessManager.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/ProcessManager.java
index 489f72b..dd532c4 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/ProcessManager.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/ProcessManager.java
@@ -172,7 +172,6 @@ public class ProcessManager {
       "-Xrunjdwp:transport=dt_socket,server=y,suspend=" + jdkSuspend + jdkDebug,
       "-XX:+HeapDumpOnOutOfMemoryError",
       "-Xmx512m",
-      DUnitLauncher.LOG4J==null?"":"-Dlog4j.configurationFile="+DUnitLauncher.LOG4J,
       "-Dgemfire.DEFAULT_MAX_OPLOG_SIZE=10",
       "-Dgemfire.disallowMcastDefaults=true",
       "-ea", "-XX:+PrintGC", "-XX:+PrintGCDetails","-XX:+PrintGCTimeStamps",

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/af119cfd/gradle/test.gradle
----------------------------------------------------------------------
diff --git a/gradle/test.gradle b/gradle/test.gradle
index 96fbfc5..2dd7521 100644
--- a/gradle/test.gradle
+++ b/gradle/test.gradle
@@ -211,10 +211,6 @@ subprojects {
         if (logLevel != null) {
           systemProperty 'logLevel', logLevel
         }
-        def log4jLocation = System.getProperty('log4j.configurationFile')
-        if (log4jLocation != null) {
-          systemProperty 'log4j.configurationFile', log4jLocation
-        }
 
         def eol = System.getProperty('line.separator')
         def progress = new File(resultsDir, "$test.name-progress.txt")


[07/16] incubator-geode git commit: adding the required license header to a generated test class

Posted by kl...@apache.org.
adding the required license header to a generated test class


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/3fe55d4a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/3fe55d4a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/3fe55d4a

Branch: refs/heads/feature/GEODE-1371
Commit: 3fe55d4ad0701ede358c87629f3f13d4de965cfa
Parents: 625d491
Author: Bruce Schuchardt <bs...@pivotal.io>
Authored: Mon May 9 16:13:38 2016 -0700
Committer: Bruce Schuchardt <bs...@pivotal.io>
Committed: Mon May 9 16:14:33 2016 -0700

----------------------------------------------------------------------
 .../distributed/DistributedLockBlackboard.java     | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3fe55d4a/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockBlackboard.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockBlackboard.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockBlackboard.java
index de8809c..e475bcc 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockBlackboard.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockBlackboard.java
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package com.gemstone.gemfire.distributed;
 
 import java.io.Serializable;


[16/16] incubator-geode git commit: Merge remote-tracking branch 'origin/develop' into feature/GEODE-1371

Posted by kl...@apache.org.
Merge remote-tracking branch 'origin/develop' into feature/GEODE-1371


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/3bf13bac
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/3bf13bac
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/3bf13bac

Branch: refs/heads/feature/GEODE-1371
Commit: 3bf13bac2c528cbc34192ca51dfe35f9712232b8
Parents: 7c28470 9a77054
Author: Kirk Lund <kl...@apache.org>
Authored: Tue May 10 14:09:39 2016 -0700
Committer: Kirk Lund <kl...@apache.org>
Committed: Tue May 10 14:09:39 2016 -0700

----------------------------------------------------------------------
 geode-assembly/build.gradle                     |   12 +
 geode-core/build.gradle                         |   68 +-
 .../internal/cache/AbstractLRURegionMap.java    |    9 +-
 .../gemfire/internal/cache/LocalRegion.java     |    6 +
 .../cache/tier/sockets/ClientHealthMonitor.java |   14 +
 .../internal/security/GeodeSecurityUtil.java    |   69 +-
 .../security/shiro/JMXShiroAuthenticator.java   |   13 +-
 .../internal/security/shiro/ShiroPrincipal.java |   39 +
 .../MemoryThresholdsOffHeapDUnitTest.java       |   54 +-
 .../gemfire/cache30/Bug44418JUnitTest.java      |    3 +
 .../distributed/DistributedLockBlackboard.java  |   37 +
 .../DistributedLockBlackboardImpl.java          |   97 +
 .../DistributedLockServiceDUnitTest.java        | 3246 ++++++++++++++++++
 .../cache/PartitionedRegionStatsJUnitTest.java  |   14 +-
 .../internal/cache/SingleHopStatsDUnitTest.java |  448 ++-
 .../cli/commands/ConfigCommandsDUnitTest.java   |  319 +-
 .../test/dunit/standalone/DUnitLauncher.java    |    4 +-
 .../test/dunit/standalone/ProcessManager.java   |    1 -
 .../lucene/internal/directory/package-info.java |   23 +
 .../internal/distributed/package-info.java      |   25 +
 .../lucene/internal/filesystem/FileSystem.java  |   11 +-
 .../internal/filesystem/package-info.java       |   26 +
 .../cache/lucene/internal/package-info.java     |   23 +
 .../internal/repository/package-info.java       |   25 +
 .../repository/serializer/package-info.java     |   23 +
 .../cache/lucene/internal/xml/package-info.java |   24 +
 .../gemfire/cache/lucene/package-info.java      |   32 +
 gradle/rat.gradle                               |    1 +
 gradle/test.gradle                              |    4 -
 29 files changed, 4170 insertions(+), 500 deletions(-)
----------------------------------------------------------------------



[14/16] incubator-geode git commit: GEODE-364: Amending Pool configuration to avoid the changing of connections, which could cause the test to fail.

Posted by kl...@apache.org.
GEODE-364: Amending Pool configuration to avoid the changing of connections, which could cause the test to fail.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/bcf7c94f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/bcf7c94f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/bcf7c94f

Branch: refs/heads/feature/GEODE-1371
Commit: bcf7c94fb8247754eb2d73749d05be3a5011624c
Parents: f93c87f
Author: Udo Kohlmeyer <uk...@pivotal.io>
Authored: Wed May 11 05:47:10 2016 +1000
Committer: Udo Kohlmeyer <uk...@pivotal.io>
Committed: Wed May 11 05:51:44 2016 +1000

----------------------------------------------------------------------
 .../internal/cache/SingleHopStatsDUnitTest.java | 448 ++++++++-----------
 1 file changed, 198 insertions(+), 250 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bcf7c94f/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/SingleHopStatsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/SingleHopStatsDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/SingleHopStatsDUnitTest.java
index 307f18f..671bdf7 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/SingleHopStatsDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/SingleHopStatsDUnitTest.java
@@ -16,20 +16,8 @@
  */
 package com.gemstone.gemfire.internal.cache;
 
-import java.io.IOException;
-import java.util.Map;
-import java.util.Properties;
-
-import org.junit.experimental.categories.Category;
-
-import com.gemstone.gemfire.cache.AttributesFactory;
-import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.cache.CacheFactory;
-import com.gemstone.gemfire.cache.DataPolicy;
-import com.gemstone.gemfire.cache.PartitionAttributesFactory;
-import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.cache.RegionAttributes;
-import com.gemstone.gemfire.cache.Scope;
+import com.gemstone.gemfire.cache.*;
+import com.gemstone.gemfire.cache.client.ClientCache;
 import com.gemstone.gemfire.cache.client.Pool;
 import com.gemstone.gemfire.cache.client.PoolManager;
 import com.gemstone.gemfire.cache.client.internal.ClientMetadataService;
@@ -37,71 +25,43 @@ import com.gemstone.gemfire.cache.client.internal.ClientPartitionAdvisor;
 import com.gemstone.gemfire.cache.server.CacheServer;
 import com.gemstone.gemfire.cache30.CacheTestCase;
 import com.gemstone.gemfire.distributed.DistributedSystem;
-import com.gemstone.gemfire.distributed.Locator;
-import com.gemstone.gemfire.internal.AvailablePort;
 import com.gemstone.gemfire.internal.cache.execute.data.CustId;
 import com.gemstone.gemfire.internal.cache.execute.data.OrderId;
 import com.gemstone.gemfire.internal.cache.execute.data.ShipmentId;
 import com.gemstone.gemfire.internal.cache.tier.sockets.CacheServerTestUtil;
-import com.gemstone.gemfire.test.dunit.Assert;
-import com.gemstone.gemfire.test.dunit.DistributedTestUtils;
-import com.gemstone.gemfire.test.dunit.Host;
-import com.gemstone.gemfire.test.dunit.Invoke;
-import com.gemstone.gemfire.test.dunit.LogWriterUtils;
-import com.gemstone.gemfire.test.dunit.SerializableRunnable;
-import com.gemstone.gemfire.test.dunit.VM;
-import com.gemstone.gemfire.test.dunit.Wait;
-import com.gemstone.gemfire.test.dunit.WaitCriterion;
+import com.gemstone.gemfire.test.dunit.*;
 import com.gemstone.gemfire.test.junit.categories.FlakyTest;
+import com.jayway.awaitility.Awaitility;
+import org.junit.experimental.categories.Category;
 
-public class SingleHopStatsDUnitTest extends CacheTestCase {
+import java.io.IOException;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
 
-  private static final String Region_Name = "42010";
+public class SingleHopStatsDUnitTest extends CacheTestCase {
 
+  private final String Region_Name = "42010";
+  private final String ORDER_REGION_NAME = "ORDER";
+  private final String SHIPMENT_REGION_NAME = "SHIPMENT";
+  private final String CUSTOMER_REGION_NAME = "CUSTOMER";
   private VM member0 = null;
-
   private VM member1 = null;
-
   private VM member2 = null;
-
   private VM member3 = null;
 
-  private static Region region = null;
-
-  private static Region customerRegion = null;
-
-  private static Region orderRegion = null;
-
-  private static Region shipmentRegion = null;
-
-  private static Region regionWithResolver = null;
-
-  private static Cache cache = null;
-
-  private static final int locatorPort = 12345;
-
-  private static Locator locator = null;
-  
   private static long metaDataRefreshCount;
-  
   private static long nonSingleHopsCount;
-  
   private static long metaDataRefreshCount_Customer;
-  
   private static long nonSingleHopsCount_Customer;
-  
   private static long metaDataRefreshCount_Order;
-  
   private static long nonSingleHopsCount_Order;
-  
   private static long metaDataRefreshCount_Shipment;
-  
   private static long nonSingleHopsCount_Shipment;
-  
+
+
   public SingleHopStatsDUnitTest(String name) {
     super(name);
-
-    // TODO Auto-generated constructor stub
   }
 
   @Override
@@ -116,13 +76,13 @@ public class SingleHopStatsDUnitTest extends CacheTestCase {
   @Override
   public final void preTearDownCacheTestCase() throws Exception {
     // close the clients first
-    member0.invoke(() -> SingleHopStatsDUnitTest.closeCacheAndDisconnect());
-    member1.invoke(() -> SingleHopStatsDUnitTest.closeCacheAndDisconnect());
-    member2.invoke(() -> SingleHopStatsDUnitTest.closeCacheAndDisconnect());
-    member3.invoke(() -> SingleHopStatsDUnitTest.closeCacheAndDisconnect());
+    member0.invoke(() -> closeCacheAndDisconnect());
+    member1.invoke(() -> closeCacheAndDisconnect());
+    member2.invoke(() -> closeCacheAndDisconnect());
+    member3.invoke(() -> closeCacheAndDisconnect());
     closeCacheAndDisconnect();
   }
-  
+
   @Override
   public final void postTearDownCacheTestCase() throws Exception {
     try {
@@ -130,104 +90,95 @@ public class SingleHopStatsDUnitTest extends CacheTestCase {
       member1 = null;
       member2 = null;
       member3 = null;
-      cache = null;
-      Invoke.invokeInEveryVM(new SerializableRunnable() { public void run() { cache = null; } });
-
-    }
-    finally {
+    } finally {
       DistributedTestUtils.unregisterAllDataSerializersFromAllVms();
     }
   }
 
-  public static void closeCacheAndDisconnect() {
-    if (cache != null && !cache.isClosed()) {
-      cache.close();
-      cache.getDistributedSystem().disconnect();
+  private void closeCacheAndDisconnect() {
+    try {
+      Cache cache = CacheFactory.getAnyInstance();
+      if (cache != null && !cache.isClosed()) {
+        cache.close();
+        cache.getDistributedSystem().disconnect();
+      }
+    } catch (CacheClosedException e) {
     }
   }
 
   @Category(FlakyTest.class) // GEODE-364: random ports, time sensitive, waitForCriterions, magic numbers (113, 226)
   public void testClientStatsPR() {
-    VM server1 = member0;
-    VM server2 = member1;
-    VM server3 = member2;
-    VM client1 = member3;
-    
-    Integer port0 = (Integer)member0.invoke(() -> SingleHopStatsDUnitTest.createServerForStats( 0, 113,"No_Colocation"));
-    Integer port1 = (Integer)member1.invoke(() -> SingleHopStatsDUnitTest.createServerForStats( 0, 113,"No_Colocation"));
-    Integer port2 = (Integer)member2.invoke(() -> SingleHopStatsDUnitTest.createServerForStats( 0, 113,"No_Colocation"));
-     client1.invoke(() -> SingleHopStatsDUnitTest.createClient(port0, port1, port2,"No_Colocation"));
-     
+    Integer port0 = (Integer) member0.invoke(() -> createServerForStats(0, 113, "No_Colocation"));
+    Integer port1 = (Integer) member1.invoke(() -> createServerForStats(0, 113, "No_Colocation"));
+    Integer port2 = (Integer) member2.invoke(() -> createServerForStats(0, 113, "No_Colocation"));
+
+    member3.invoke(() -> createClient(port0, port1, port2, "No_Colocation"));
     createClient(port0, port1, port2, "No_Colocation");
 
-    client1.invoke(() -> SingleHopStatsDUnitTest.createPR("FirstClient", "No_Colocation"));
+    member3.invoke(() -> createPR("FirstClient", "No_Colocation"));
     createPR("SecondClient", "No_Colocation");
-    
-    client1.invoke(() -> SingleHopStatsDUnitTest.getPR("FirstClient", "No_Colocation"));
+
+    member3.invoke(() -> getPR("FirstClient", "No_Colocation"));
     getPR("SecondClient", "No_Colocation");
-    
-    client1.invoke(() -> SingleHopStatsDUnitTest.updatePR("FirstClient", "No_Colocation"));
+
+    member3.invoke(() -> updatePR("FirstClient", "No_Colocation"));
   }
-  
-  public void testClientStatsColocationPR(){
-    VM server1 = member0;
-    VM server2 = member1;
-    VM server3 = member2;
-    VM client1 = member3;
-    
-    Integer port0 = (Integer)member0.invoke(() -> SingleHopStatsDUnitTest.createServerForStats( 0, 4, "Colocation" ));
-    Integer port1 = (Integer)member1.invoke(() -> SingleHopStatsDUnitTest.createServerForStats( 0, 4, "Colocation" ));
-    Integer port2 = (Integer)member2.invoke(() -> SingleHopStatsDUnitTest.createServerForStats( 0, 4, "Colocation"));
-     client1.invoke(() -> SingleHopStatsDUnitTest.createClient(port0, port1, port2, "Colocation"));
+
+  public void testClientStatsColocationPR() {
+    Integer port0 = (Integer) member0.invoke(() -> createServerForStats(0, 4, "Colocation"));
+    Integer port1 = (Integer) member1.invoke(() -> createServerForStats(0, 4, "Colocation"));
+    Integer port2 = (Integer) member2.invoke(() -> createServerForStats(0, 4, "Colocation"));
+    member3.invoke(() -> createClient(port0, port1, port2, "Colocation"));
     createClient(port0, port1, port2, "Colocation");
 
-    client1.invoke(() -> SingleHopStatsDUnitTest.createPR("FirstClient", "Colocation"));
-    
-    client1.invoke(() -> SingleHopStatsDUnitTest.getPR("FirstClient", "Colocation"));
+    member3.invoke(() -> createPR("FirstClient", "Colocation"));
+
+    member3.invoke(() -> getPR("FirstClient", "Colocation"));
   }
 
-  
-  public static void createClient(int port0, int port1, int port2, String colocation) {
+  private void createClient(int port0, int port1, int port2, String colocation) {
     Properties props = new Properties();
     props = new Properties();
     props.setProperty("mcast-port", "0");
     props.setProperty("locators", "");
     CacheTestCase test = new SingleHopStatsDUnitTest(
         "SingleHopStatsDUnitTest");
-    DistributedSystem ds = test.getSystem(props);
-    cache = CacheFactory.create(ds);
+    DistributedSystem distributedSystem = test.getSystem(props);
+    Cache cache = CacheFactory.create(distributedSystem);
     assertNotNull(cache);
     CacheServerTestUtil.disableShufflingOfEndpoints();
     Pool p;
     try {
-      p = PoolManager.createFactory().addServer("localhost", port0).addServer(
-          "localhost", port1).addServer("localhost", port2)
+      p = PoolManager.createFactory().addServer("localhost", port0)
+          .addServer("localhost", port1).addServer("localhost", port2)
+          .setRetryAttempts(5)
+          .setMinConnections(1)
+          .setMaxConnections(1)
           .setSubscriptionEnabled(false)
           .create(Region_Name);
-    }
-    finally {
+    } finally {
       CacheServerTestUtil.enableShufflingOfEndpoints();
     }
-    createRegionInClientCache(p.getName(), colocation);
+    createRegionInClientCache(p.getName(), colocation, cache);
   }
 
-  public static int createServerForStats(int redundantCopies, int totalNoofBuckets, String colocation) {
+  private int createServerForStats(int redundantCopies, int totalNoofBuckets, String colocation) {
     CacheTestCase test = new SingleHopStatsDUnitTest(
         "SingleHopStatsDUnitTest");
-    cache = test.getCache();
+    Cache cache = test.getCache();
     CacheServer server = cache.addCacheServer();
-    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-    server.setPort(port);
+    server.setPort(0);
     server.setHostnameForClients("localhost");
     try {
       server.start();
-    }
-    catch (IOException e) {
+    } catch (IOException e) {
       Assert.fail("Failed to start server ", e);
     }
 
+    Region region = null;
+
     if (colocation.equals("No_Colocation")) {
-      if(totalNoofBuckets == 0){ //DR
+      if (totalNoofBuckets == 0) { //DR
         AttributesFactory attr = new AttributesFactory();
         attr.setScope(Scope.DISTRIBUTED_ACK);
         attr.setDataPolicy(DataPolicy.REPLICATE);
@@ -236,27 +187,27 @@ public class SingleHopStatsDUnitTest extends CacheTestCase {
         LogWriterUtils.getLogWriter().info(
             "Distributed Region " + Region_Name + " created Successfully :"
                 + region.toString());
-      }else{
-      PartitionAttributesFactory paf = new PartitionAttributesFactory();
-      paf.setRedundantCopies(redundantCopies).setTotalNumBuckets(
-          totalNoofBuckets);
-      AttributesFactory attr = new AttributesFactory();
-      attr.setPartitionAttributes(paf.create());
-      region = cache.createRegion(Region_Name, attr.create());
-      assertNotNull(region);
-      LogWriterUtils.getLogWriter().info(
-          "Partitioned Region " + Region_Name + " created Successfully :"
-              + region.toString());
+      } else {
+        PartitionAttributesFactory paf = new PartitionAttributesFactory();
+        paf.setRedundantCopies(redundantCopies).setTotalNumBuckets(
+            totalNoofBuckets);
+        AttributesFactory attr = new AttributesFactory();
+        attr.setPartitionAttributes(paf.create());
+        region = cache.createRegion(Region_Name, attr.create());
+        assertNotNull(region);
+        LogWriterUtils.getLogWriter().info(
+            "Partitioned Region " + Region_Name + " created Successfully :"
+                + region.toString());
       }
-    }
-    else {
+    } else {
       PartitionAttributesFactory paf = new PartitionAttributesFactory();
       paf.setRedundantCopies(redundantCopies).setTotalNumBuckets(
           totalNoofBuckets).setPartitionResolver(
-          new CustomerIDPartitionResolver("CustomerIDPartitionResolver"));
+          new CustomerIDPartitionResolver("CustomerIDPartitio"
+              + "nResolver"));
       AttributesFactory attr = new AttributesFactory();
       attr.setPartitionAttributes(paf.create());
-      customerRegion = cache.createRegion("CUSTOMER", attr.create());
+      Region customerRegion = cache.createRegion(CUSTOMER_REGION_NAME, attr.create());
       assertNotNull(customerRegion);
       LogWriterUtils.getLogWriter().info(
           "Partitioned Region CUSTOMER created Successfully :"
@@ -264,11 +215,11 @@ public class SingleHopStatsDUnitTest extends CacheTestCase {
 
       paf = new PartitionAttributesFactory();
       paf.setRedundantCopies(redundantCopies).setTotalNumBuckets(
-          totalNoofBuckets).setColocatedWith("CUSTOMER").setPartitionResolver(
+          totalNoofBuckets).setColocatedWith(CUSTOMER_REGION_NAME).setPartitionResolver(
           new CustomerIDPartitionResolver("CustomerIDPartitionResolver"));
       attr = new AttributesFactory();
       attr.setPartitionAttributes(paf.create());
-      orderRegion = cache.createRegion("ORDER", attr.create());
+      Region orderRegion = cache.createRegion(ORDER_REGION_NAME, attr.create());
       assertNotNull(orderRegion);
       LogWriterUtils.getLogWriter().info(
           "Partitioned Region ORDER created Successfully :"
@@ -276,20 +227,21 @@ public class SingleHopStatsDUnitTest extends CacheTestCase {
 
       paf = new PartitionAttributesFactory();
       paf.setRedundantCopies(redundantCopies).setTotalNumBuckets(
-          totalNoofBuckets).setColocatedWith("ORDER").setPartitionResolver(
+          totalNoofBuckets).setColocatedWith(ORDER_REGION_NAME).setPartitionResolver(
           new CustomerIDPartitionResolver("CustomerIDPartitionResolver"));
       attr = new AttributesFactory();
       attr.setPartitionAttributes(paf.create());
-      shipmentRegion = cache.createRegion("SHIPMENT", attr.create());
+      Region shipmentRegion = cache.createRegion(SHIPMENT_REGION_NAME, attr.create());
       assertNotNull(shipmentRegion);
       LogWriterUtils.getLogWriter().info(
           "Partitioned Region SHIPMENT created Successfully :"
               + shipmentRegion.toString());
     }
-    return port;
+    return server.getPort();
   }
-  
-  private static void createRegionInClientCache(String poolName, String colocation) {
+
+  private void createRegionInClientCache(String poolName, String colocation, Cache cache) {
+    Region region = null;
     if (colocation.equals("No_Colocation")) {
       AttributesFactory factory = new AttributesFactory();
       factory.setPoolName(poolName);
@@ -299,12 +251,11 @@ public class SingleHopStatsDUnitTest extends CacheTestCase {
       assertNotNull(region);
       LogWriterUtils.getLogWriter().info(
           "Region " + Region_Name + " created Successfully :" + region.toString());
-    }
-    else {
+    } else {
       AttributesFactory factory = new AttributesFactory();
       factory.setPoolName(poolName);
       RegionAttributes attrs = factory.create();
-      customerRegion = cache.createRegion("CUSTOMER", attrs);
+      Region customerRegion = cache.createRegion(CUSTOMER_REGION_NAME, attrs);
       assertNotNull(customerRegion);
       LogWriterUtils.getLogWriter().info(
           "Partitioned Region CUSTOMER created Successfully :"
@@ -313,7 +264,7 @@ public class SingleHopStatsDUnitTest extends CacheTestCase {
       factory = new AttributesFactory();
       factory.setPoolName(poolName);
       attrs = factory.create();
-      orderRegion = cache.createRegion("ORDER", attrs);
+      Region orderRegion = cache.createRegion(ORDER_REGION_NAME, attrs);
       assertNotNull(orderRegion);
       LogWriterUtils.getLogWriter().info(
           "Partitioned Region ORDER created Successfully :"
@@ -322,24 +273,27 @@ public class SingleHopStatsDUnitTest extends CacheTestCase {
       factory = new AttributesFactory();
       factory.setPoolName(poolName);
       attrs = factory.create();
-      shipmentRegion = cache.createRegion("SHIPMENT", attrs);
+      Region shipmentRegion = cache.createRegion("SHIPMENT", attrs);
       assertNotNull(shipmentRegion);
       LogWriterUtils.getLogWriter().info(
           "Partitioned Region SHIPMENT created Successfully :"
               + shipmentRegion.toString());
     }
   }
-  
-  public static void createPR(String fromClient,
-      String colocation) {
+
+  private void createPR(String fromClient, String colocation) {
+    GemFireCacheImpl cache = (GemFireCacheImpl) CacheFactory.getAnyInstance();
+    Region region = cache.getRegion(Region_Name);
+
+
     if (colocation.equals("No_Colocation")) {
       if (fromClient.equals("FirstClient")) {
-        
+
         System.out.println("first pass...");
         for (int i = 0; i < 113; i++) {
           region.create(new Integer(i), "create" + i);
         }
-        ClientMetadataService cms = ((GemFireCacheImpl)cache)
+        ClientMetadataService cms = ((GemFireCacheImpl) cache)
             .getClientMetadataService();
         final Map<String, ClientPartitionAdvisor> regionMetaData = cms
             .getClientPRMetadata_TEST_ONLY();
@@ -349,124 +303,121 @@ public class SingleHopStatsDUnitTest extends CacheTestCase {
         for (int i = 113; i < 226; i++) {
           region.create(new Integer(i), "create" + i);
         }
-        cms = ((GemFireCacheImpl)cache).getClientMetadataService();
+        cms = ((GemFireCacheImpl) cache).getClientMetadataService();
         // since PR metadata is fetched in a background executor thread
         // we need to wait for it to arrive for a bit
-        Wait.waitForCriterion(new WaitCriterion(){
-          public boolean done() {
-            return regionMetaData.size() == 1;
-          }
-          public String description() {
-            return "waiting for metadata to arrive: " + regionMetaData;
-          }
-          
-        }, 30000, 500, true);
+        Awaitility.await().timeout(120, TimeUnit.SECONDS).pollDelay(100, TimeUnit.MILLISECONDS)
+            .pollInterval(500, TimeUnit.MILLISECONDS).until(() -> {
+          return regionMetaData.size() == 1;
+        });
+
         assertTrue(regionMetaData.containsKey(region.getFullPath()));
-        ClientPartitionAdvisor prMetaData = regionMetaData.get(region
-            .getFullPath());
-        metaDataRefreshCount = ((LocalRegion)region).getCachePerfStats().getMetaDataRefreshCount();
-        nonSingleHopsCount = ((LocalRegion)region).getCachePerfStats().getNonSingleHopsCount();
+        regionMetaData.get(region.getFullPath());
+        metaDataRefreshCount = ((LocalRegion) region).getCachePerfStats().getMetaDataRefreshCount();
+        nonSingleHopsCount = ((LocalRegion) region).getCachePerfStats().getNonSingleHopsCount();
         assertTrue(metaDataRefreshCount != 0); // hops are not predictable
         assertTrue(nonSingleHopsCount != 0);
-      }
-      else {
+      } else {
         for (int i = 0; i < 226; i++) {
           region.create(new Integer(i), "create" + i);
         }
-        ClientMetadataService cms = ((GemFireCacheImpl)cache)
+        ClientMetadataService cms = ((GemFireCacheImpl) cache)
             .getClientMetadataService();
         Map<String, ClientPartitionAdvisor> regionMetaData = cms
             .getClientPRMetadata_TEST_ONLY();
         assertEquals(1, regionMetaData.size());
         assertTrue(regionMetaData.containsKey(region.getFullPath()));
-        ClientPartitionAdvisor prMetaData = regionMetaData.get(region
-            .getFullPath());
-        metaDataRefreshCount = ((LocalRegion)region).getCachePerfStats().getMetaDataRefreshCount();
-        nonSingleHopsCount = ((LocalRegion)region).getCachePerfStats().getNonSingleHopsCount();
+
+        regionMetaData.get(region.getFullPath());
+        metaDataRefreshCount = ((LocalRegion) region).getCachePerfStats().getMetaDataRefreshCount();
+        nonSingleHopsCount = ((LocalRegion) region).getCachePerfStats().getNonSingleHopsCount();
         assertTrue(metaDataRefreshCount != 0); // hops are not predictable
         assertTrue(nonSingleHopsCount != 0);
       }
+    } else {
+      createdColocatedPRData(cache);
     }
-    else {
-      for (int i = 0; i <= 20; i++) {
-        CustId custid = new CustId(i);
-        Customer customer = new Customer("name" + i, "Address" + i);
-        customerRegion.put(custid, customer);
-        for (int j = 1; j <= 10; j++) {
-          int oid = (i * 10) + j;
-          OrderId orderId = new OrderId(oid, custid);
-          Order order = new Order("OREDR" + oid);
-          orderRegion.put(orderId, order);
-          for (int k = 1; k <= 10; k++) {
-            int sid = (oid * 10) + k;
-            ShipmentId shipmentId = new ShipmentId(sid, orderId);
-            Shipment shipment = new Shipment("Shipment" + sid);
-            shipmentRegion.put(shipmentId, shipment);
-          }
+  }
+
+  private void createdColocatedPRData(GemFireCacheImpl cache) {
+    Region customerRegion = cache.getRegion(CUSTOMER_REGION_NAME);
+    Region orderRegion = cache.getRegion(ORDER_REGION_NAME);
+    Region shipmentRegion = cache.getRegion(SHIPMENT_REGION_NAME);
+    for (int i = 0; i <= 20; i++) {
+      CustId custid = new CustId(i);
+      Customer customer = new Customer("name" + i, "Address" + i);
+
+      customerRegion.put(custid, customer);
+      for (int j = 1; j <= 10; j++) {
+        int oid = (i * 10) + j;
+        OrderId orderId = new OrderId(oid, custid);
+        Order order = new Order(ORDER_REGION_NAME + oid);
+        orderRegion.put(orderId, order);
+        for (int k = 1; k <= 10; k++) {
+          int sid = (oid * 10) + k;
+          ShipmentId shipmentId = new ShipmentId(sid, orderId);
+          Shipment shipment = new Shipment("Shipment" + sid);
+          shipmentRegion.put(shipmentId, shipment);
         }
       }
-      ClientMetadataService cms = ((GemFireCacheImpl)cache)
-          .getClientMetadataService();
-      Map<String, ClientPartitionAdvisor> regionMetaData = cms
-          .getClientPRMetadata_TEST_ONLY();
-      assertEquals(3, regionMetaData.size());
-      assertTrue(regionMetaData.containsKey(customerRegion.getFullPath()));
-      ClientPartitionAdvisor prMetaData_Customer = regionMetaData
-          .get(customerRegion.getFullPath());
-      metaDataRefreshCount_Customer = ((LocalRegion)customerRegion).getCachePerfStats().getMetaDataRefreshCount();
-      nonSingleHopsCount_Customer = ((LocalRegion)customerRegion).getCachePerfStats().getNonSingleHopsCount();
-      assertTrue(metaDataRefreshCount_Customer != 0); // hops are not predictable
-      assertTrue(nonSingleHopsCount_Customer != 0);
-
-      ClientPartitionAdvisor prMetaData_Order = regionMetaData
-          .get(orderRegion.getFullPath());
-      metaDataRefreshCount_Order = ((LocalRegion)orderRegion).getCachePerfStats().getMetaDataRefreshCount();
-      nonSingleHopsCount_Order = ((LocalRegion)orderRegion).getCachePerfStats().getNonSingleHopsCount();
-      assertTrue(metaDataRefreshCount_Order == 0); 
-      assertTrue(nonSingleHopsCount_Order != 0);
-
-      ClientPartitionAdvisor prMetaData_Shipment = regionMetaData
-          .get(shipmentRegion.getFullPath());
-      metaDataRefreshCount_Shipment = ((LocalRegion)shipmentRegion).getCachePerfStats().getMetaDataRefreshCount();
-      nonSingleHopsCount_Shipment = ((LocalRegion)shipmentRegion).getCachePerfStats().getNonSingleHopsCount();
-      assertTrue(metaDataRefreshCount_Shipment == 0); 
-      assertTrue(nonSingleHopsCount_Shipment != 0);
     }
+    ClientMetadataService cms = cache.getClientMetadataService();
+    Map<String, ClientPartitionAdvisor> regionMetaData = cms
+        .getClientPRMetadata_TEST_ONLY();
+    assertEquals(3, regionMetaData.size());
+    assertTrue(regionMetaData.containsKey(customerRegion.getFullPath()));
+    regionMetaData.get(customerRegion.getFullPath());
+    metaDataRefreshCount_Customer = ((LocalRegion) customerRegion).getCachePerfStats().getMetaDataRefreshCount();
+    nonSingleHopsCount_Customer = ((LocalRegion) customerRegion).getCachePerfStats().getNonSingleHopsCount();
+    assertTrue(metaDataRefreshCount_Customer != 0); // hops are not predictable
+    assertTrue(nonSingleHopsCount_Customer != 0);
+
+    regionMetaData.get(orderRegion.getFullPath());
+    metaDataRefreshCount_Order = ((LocalRegion) orderRegion).getCachePerfStats().getMetaDataRefreshCount();
+    nonSingleHopsCount_Order = ((LocalRegion) orderRegion).getCachePerfStats().getNonSingleHopsCount();
+    assertTrue(metaDataRefreshCount_Order == 0);
+    assertTrue(nonSingleHopsCount_Order != 0);
+
+    regionMetaData.get(shipmentRegion.getFullPath());
+    metaDataRefreshCount_Shipment = ((LocalRegion) shipmentRegion).getCachePerfStats().getMetaDataRefreshCount();
+    nonSingleHopsCount_Shipment = ((LocalRegion) shipmentRegion).getCachePerfStats().getNonSingleHopsCount();
+    assertTrue(metaDataRefreshCount_Shipment == 0);
+    assertTrue(nonSingleHopsCount_Shipment != 0);
   }
-  
-  public static void getPR(String FromClient,
-      String colocation) {
+
+  private void getPR(String FromClient, String colocation) {
+    Cache cache = CacheFactory.getAnyInstance();
+    Region region = cache.getRegion(Region_Name);
+    Region customerRegion = cache.getRegion(CUSTOMER_REGION_NAME);
+    Region orderRegion = cache.getRegion(ORDER_REGION_NAME);
+    Region shipmentRegion = cache.getRegion("SHIPMENT");
     if (colocation.equals("No_Colocation")) {
       if (FromClient.equals("FirstClient")) {
         for (int i = 0; i < 226; i++) {
           region.get(new Integer(i));
         }
-        ClientMetadataService cms = ((GemFireCacheImpl)cache)
+        ClientMetadataService cms = ((GemFireCacheImpl) cache)
             .getClientMetadataService();
         Map<String, ClientPartitionAdvisor> regionMetaData = cms
             .getClientPRMetadata_TEST_ONLY();
         assertEquals(1, regionMetaData.size());
-        ClientPartitionAdvisor prMetaData = regionMetaData.get(region
-            .getFullPath());
-        assertEquals(metaDataRefreshCount , ((LocalRegion)region).getCachePerfStats().getMetaDataRefreshCount());
-        assertEquals(nonSingleHopsCount , ((LocalRegion)region).getCachePerfStats().getNonSingleHopsCount());
-      }
-      else {
+        regionMetaData.get(region.getFullPath());
+        assertEquals(metaDataRefreshCount, ((LocalRegion) region).getCachePerfStats().getMetaDataRefreshCount());
+        assertEquals(nonSingleHopsCount, ((LocalRegion) region).getCachePerfStats().getNonSingleHopsCount());
+      } else {
         for (int i = 0; i < 226; i++) {
           region.get(new Integer(i));
         }
-        ClientMetadataService cms = ((GemFireCacheImpl)cache)
+        ClientMetadataService cms = ((GemFireCacheImpl) cache)
             .getClientMetadataService();
         Map<String, ClientPartitionAdvisor> regionMetaData = cms
             .getClientPRMetadata_TEST_ONLY();
         assertEquals(1, regionMetaData.size());
-        ClientPartitionAdvisor prMetaData = regionMetaData.get(region
-            .getFullPath());
-        assertEquals(metaDataRefreshCount , ((LocalRegion)region).getCachePerfStats().getMetaDataRefreshCount());
-        assertEquals(nonSingleHopsCount , ((LocalRegion)region).getCachePerfStats().getNonSingleHopsCount());
+        regionMetaData.get(region.getFullPath());
+        assertEquals(metaDataRefreshCount, ((LocalRegion) region).getCachePerfStats().getMetaDataRefreshCount());
+        assertEquals(nonSingleHopsCount, ((LocalRegion) region).getCachePerfStats().getNonSingleHopsCount());
       }
-    }
-    else {
+    } else {
       for (int i = 0; i <= 20; i++) {
         CustId custid = new CustId(i);
         customerRegion.get(custid);
@@ -481,45 +432,42 @@ public class SingleHopStatsDUnitTest extends CacheTestCase {
           }
         }
       }
-      ClientMetadataService cms = ((GemFireCacheImpl)cache)
+      ClientMetadataService cms = ((GemFireCacheImpl) cache)
           .getClientMetadataService();
       Map<String, ClientPartitionAdvisor> regionMetaData = cms
           .getClientPRMetadata_TEST_ONLY();
       assertEquals(3, regionMetaData.size());
       assertTrue(regionMetaData.containsKey(customerRegion.getFullPath()));
-      ClientPartitionAdvisor prMetaData_Customer = regionMetaData
-          .get(customerRegion.getFullPath());
-      assertEquals(metaDataRefreshCount_Customer , ((LocalRegion)customerRegion).getCachePerfStats().getMetaDataRefreshCount());
-      assertEquals(nonSingleHopsCount_Customer , ((LocalRegion)customerRegion).getCachePerfStats().getNonSingleHopsCount());
-
-      ClientPartitionAdvisor prMetaData_Order = regionMetaData
-          .get(orderRegion.getFullPath());
-      assertEquals(metaDataRefreshCount_Order , ((LocalRegion)orderRegion).getCachePerfStats().getMetaDataRefreshCount());
-      assertEquals(nonSingleHopsCount_Order , ((LocalRegion)orderRegion).getCachePerfStats().getNonSingleHopsCount());
-
-      ClientPartitionAdvisor prMetaData_Shipment = regionMetaData
-          .get(shipmentRegion.getFullPath());
-      assertEquals(metaDataRefreshCount_Shipment , ((LocalRegion)shipmentRegion).getCachePerfStats().getMetaDataRefreshCount());
-      assertEquals(nonSingleHopsCount_Shipment , ((LocalRegion)shipmentRegion).getCachePerfStats().getNonSingleHopsCount());
+      regionMetaData.get(customerRegion.getFullPath());
+      assertEquals(metaDataRefreshCount_Customer, ((LocalRegion) customerRegion).getCachePerfStats().getMetaDataRefreshCount());
+      assertEquals(nonSingleHopsCount_Customer, ((LocalRegion) customerRegion).getCachePerfStats().getNonSingleHopsCount());
+
+      regionMetaData.get(orderRegion.getFullPath());
+      assertEquals(metaDataRefreshCount_Order, ((LocalRegion) orderRegion).getCachePerfStats().getMetaDataRefreshCount());
+      assertEquals(nonSingleHopsCount_Order, ((LocalRegion) orderRegion).getCachePerfStats().getNonSingleHopsCount());
+
+      regionMetaData.get(shipmentRegion.getFullPath());
+      assertEquals(metaDataRefreshCount_Shipment, ((LocalRegion) shipmentRegion).getCachePerfStats().getMetaDataRefreshCount());
+      assertEquals(nonSingleHopsCount_Shipment, ((LocalRegion) shipmentRegion).getCachePerfStats().getNonSingleHopsCount());
     }
   }
-  
-  public static void updatePR(String FromClient,
-      String colocation) {
+
+  private void updatePR(String FromClient, String colocation) {
+    Cache cache = CacheFactory.getAnyInstance();
+    Region region = cache.getRegion(Region_Name);
     if (colocation.equals("No_Colocation")) {
       if (FromClient.equals("FirstClient")) {
         for (int i = 0; i < 226; i++) {
           region.put(new Integer(i), "Update" + i);
         }
-        ClientMetadataService cms = ((GemFireCacheImpl)cache)
+        ClientMetadataService cms = ((GemFireCacheImpl) cache)
             .getClientMetadataService();
         Map<String, ClientPartitionAdvisor> regionMetaData = cms
             .getClientPRMetadata_TEST_ONLY();
         assertEquals(1, regionMetaData.size());
-        ClientPartitionAdvisor prMetaData = regionMetaData.get(region
-            .getFullPath());
-        assertEquals(metaDataRefreshCount , ((LocalRegion)region).getCachePerfStats().getMetaDataRefreshCount());
-        assertEquals(nonSingleHopsCount , ((LocalRegion)region).getCachePerfStats().getNonSingleHopsCount());
+        regionMetaData.get(region.getFullPath());
+        assertEquals(metaDataRefreshCount, ((LocalRegion) region).getCachePerfStats().getMetaDataRefreshCount());
+        assertEquals(nonSingleHopsCount, ((LocalRegion) region).getCachePerfStats().getNonSingleHopsCount());
       }
     }
   }


[06/16] incubator-geode git commit: GEODE-924: added FlakyTest category

Posted by kl...@apache.org.
GEODE-924: added FlakyTest category


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/625d491c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/625d491c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/625d491c

Branch: refs/heads/feature/GEODE-1371
Commit: 625d491c02855ddae04b17b2319f0514b41d6064
Parents: af119cf
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Mon May 9 15:49:00 2016 -0700
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Mon May 9 15:49:30 2016 -0700

----------------------------------------------------------------------
 .../test/java/com/gemstone/gemfire/cache30/Bug44418JUnitTest.java  | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/625d491c/geode-core/src/test/java/com/gemstone/gemfire/cache30/Bug44418JUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/cache30/Bug44418JUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/cache30/Bug44418JUnitTest.java
index 9fa771b..ce46d6b 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/cache30/Bug44418JUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/cache30/Bug44418JUnitTest.java
@@ -38,6 +38,7 @@ import com.gemstone.gemfire.cache.Region.Entry;
 import com.gemstone.gemfire.cache.RegionShortcut;
 import com.gemstone.gemfire.distributed.DistributedSystem;
 import com.gemstone.gemfire.internal.cache.LocalRegion;
+import com.gemstone.gemfire.test.junit.categories.FlakyTest;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
 import com.jayway.awaitility.core.ConditionTimeoutException;
 
@@ -89,6 +90,7 @@ public class Bug44418JUnitTest { // TODO: rename this test to non-ticket descrip
     }
   }
 
+  @Category(FlakyTest.class) // GEODE-924: expiration, time sensitive, expects action in 1 second
   @Test
   public void testGet() throws Exception {
 


[03/16] incubator-geode git commit: Moving a distributed lock service unit test to open-source.

Posted by kl...@apache.org.
Moving a distributed lock service unit test to open-source.

There are still a few distributed unit tests that haven't been ported to
Geode.  This one covers a lot of the functionality of the distributed lock
service.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/2c148caa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/2c148caa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/2c148caa

Branch: refs/heads/feature/GEODE-1371
Commit: 2c148caaf6a484bce065843d4d6ba8e916bd9ad2
Parents: 717ba5c
Author: Bruce Schuchardt <bs...@pivotal.io>
Authored: Mon May 9 15:08:31 2016 -0700
Committer: Bruce Schuchardt <bs...@pivotal.io>
Committed: Mon May 9 15:09:47 2016 -0700

----------------------------------------------------------------------
 .../distributed/DistributedLockBlackboard.java  |   20 +
 .../DistributedLockBlackboardImpl.java          |   97 +
 .../DistributedLockServiceDUnitTest.java        | 3246 ++++++++++++++++++
 .../test/dunit/standalone/DUnitLauncher.java    |    3 +-
 4 files changed, 3365 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/2c148caa/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockBlackboard.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockBlackboard.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockBlackboard.java
new file mode 100755
index 0000000..de8809c
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockBlackboard.java
@@ -0,0 +1,20 @@
+package com.gemstone.gemfire.distributed;
+
+import java.io.Serializable;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+/**
+ * Created by bschuchardt on 5/9/2016.
+ */
+public interface DistributedLockBlackboard extends Remote, Serializable {
+  void initCount() throws RemoteException;
+
+  void incCount() throws RemoteException;
+
+  long getCount() throws RemoteException;
+
+  void setIsLocked(boolean isLocked) throws RemoteException;
+
+  boolean getIsLocked() throws RemoteException;
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/2c148caa/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockBlackboardImpl.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockBlackboardImpl.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockBlackboardImpl.java
new file mode 100755
index 0000000..6525cd1
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockBlackboardImpl.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.distributed;
+
+import com.gemstone.gemfire.internal.Assert;
+import com.gemstone.gemfire.test.dunit.standalone.DUnitLauncher;
+
+import java.rmi.Naming;
+import java.rmi.NotBoundException;
+import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
+
+
+public class DistributedLockBlackboardImpl extends UnicastRemoteObject implements DistributedLockBlackboard {
+  public static int Count;
+  public static int IsLocked;
+
+  public static DistributedLockBlackboard blackboard;
+
+  /**
+   *  Zero-arg constructor for remote method invocations.
+   */
+  public DistributedLockBlackboardImpl() throws RemoteException {
+    super();
+  }
+
+  /**
+   *  Creates a singleton event listeners blackboard.
+   */
+  public static DistributedLockBlackboard getInstance() throws Exception {
+    if ( blackboard == null )
+      initialize();
+    return blackboard;
+  }
+  private static synchronized void initialize() throws Exception {
+    if ( blackboard == null ) {
+      System.out.println(DUnitLauncher.RMI_PORT_PARAM + "=" + System.getProperty(DUnitLauncher.RMI_PORT_PARAM));
+      int namingPort = Integer.getInteger(DUnitLauncher.RMI_PORT_PARAM).intValue();
+      String name = "//localhost:" + namingPort + "/" + "DistributedLockBlackboard";
+      try {
+        blackboard = (DistributedLockBlackboard)Naming.lookup(name);
+      } catch (NotBoundException e) {
+        // create the master blackboard in this VM
+        blackboard = new DistributedLockBlackboardImpl();
+        Naming.bind(name, blackboard);
+      }
+    }
+  }
+  
+  @Override
+  public synchronized void initCount() {
+    Count = 0;
+  }
+
+  @Override
+  public synchronized void incCount() {
+    Count = Count + 1;
+  }
+  
+  
+  @Override
+  public synchronized long getCount() {
+    return Count;
+  }
+  
+  @Override
+  public synchronized void setIsLocked(boolean isLocked) {
+    if (isLocked) {
+      if (IsLocked < 1) IsLocked = 1;
+    } else {
+      if (IsLocked > 0) IsLocked = 0;
+    }
+  }
+  
+  @Override
+  public synchronized boolean getIsLocked() {
+    long isLocked = IsLocked;
+    Assert.assertTrue(isLocked == 0 || isLocked == 1, 
+      "DistributedLockBlackboard internal error - IsLocked is " + isLocked);
+    return isLocked == 1;
+  }
+  
+}


[15/16] incubator-geode git commit: GEODE-1373: resolve the shiro subject in JMX AccessControlContext first

Posted by kl...@apache.org.
GEODE-1373: resolve the shiro subject in JMX AccessControlContext first


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/9a770540
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/9a770540
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/9a770540

Branch: refs/heads/feature/GEODE-1371
Commit: 9a770540795691fb16a5ef5fef6dbb64c7e5183d
Parents: bcf7c94
Author: Jinmei Liao <ji...@pivotal.io>
Authored: Mon May 9 21:31:02 2016 -0700
Committer: Jinmei Liao <ji...@pivotal.io>
Committed: Tue May 10 13:06:12 2016 -0700

----------------------------------------------------------------------
 .../internal/security/GeodeSecurityUtil.java    | 69 ++++++++++++++++----
 .../security/shiro/JMXShiroAuthenticator.java   | 13 +++-
 .../internal/security/shiro/ShiroPrincipal.java | 39 +++++++++++
 3 files changed, 108 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9a770540/geode-core/src/main/java/com/gemstone/gemfire/internal/security/GeodeSecurityUtil.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/security/GeodeSecurityUtil.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/security/GeodeSecurityUtil.java
index 1f1f4eb..6e10f3f 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/security/GeodeSecurityUtil.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/security/GeodeSecurityUtil.java
@@ -17,12 +17,15 @@
 
 package com.gemstone.gemfire.internal.security;
 
+import java.security.AccessController;
+import java.util.Set;
 import java.util.concurrent.Callable;
 
 import com.gemstone.gemfire.cache.operations.OperationContext;
 import com.gemstone.gemfire.cache.operations.OperationContext.OperationCode;
 import com.gemstone.gemfire.cache.operations.OperationContext.Resource;
 import com.gemstone.gemfire.internal.logging.LogService;
+import com.gemstone.gemfire.internal.security.shiro.ShiroPrincipal;
 import com.gemstone.gemfire.management.internal.security.ResourceOperation;
 import com.gemstone.gemfire.management.internal.security.ResourceOperationContext;
 import com.gemstone.gemfire.security.AuthenticationFailedException;
@@ -41,9 +44,15 @@ public class GeodeSecurityUtil {
 
   private static Logger logger = LogService.getLogger();
 
-  public static void login(String username, String password){
-    if(!isShiroConfigured())
-      return;
+  /**
+   *
+   * @param username
+   * @param password
+   * @return null if security is not enabled, otherwise return a shiro subject
+   */
+  public static Subject login(String username, String password){
+    if(!isSecured())
+      return null;
 
     Subject currentUser = SecurityUtils.getSubject();
 
@@ -56,13 +65,52 @@ public class GeodeSecurityUtil {
       logger.info(e.getMessage(), e);
       throw new AuthenticationFailedException(e.getMessage(), e);
     }
+
+    return currentUser;
+  }
+
+  /**
+   * It first looks the shiro subject in AccessControlContext since JMX will use multiple threads to process operations from the same client.
+   * then it looks into Shiro's thead context.
+   *
+   * @return the shiro subject, null if security is not enabled
+   */
+  public static Subject getSubject(){
+    if(!isSecured())
+      return null;
+
+    Subject currentUser = null;
+
+    // First try get the principal out of AccessControlContext instead of Shiro's Thread context
+    // since threads can be shared between JMX clients.
+    javax.security.auth.Subject jmxSubject =
+      javax.security.auth.Subject.getSubject(AccessController.getContext());
+
+    if(jmxSubject!=null){
+      Set<ShiroPrincipal> principals = jmxSubject.getPrincipals(ShiroPrincipal.class);
+      if(principals.size()>0){
+        ShiroPrincipal principal = principals.iterator().next();
+        currentUser = principal.getSubject();
+        ThreadContext.bind(currentUser);
+        return currentUser;
+      }
+    }
+
+    // in other cases like admin rest call or pulse authorization
+    currentUser = SecurityUtils.getSubject();
+
+    if(currentUser==null || currentUser.getPrincipal()==null){
+      throw new GemFireSecurityException("Error: Anonymous User");
+    }
+
+    return currentUser;
   }
 
   public static void logout(){
-    if(!isShiroConfigured())
+    Subject currentUser = getSubject();
+    if(currentUser==null)
       return;
 
-    Subject currentUser = SecurityUtils.getSubject();
     try {
       logger.info("Logging out "+currentUser.getPrincipal());
       currentUser.logout();
@@ -76,10 +124,10 @@ public class GeodeSecurityUtil {
   }
 
   public static Callable associateWith(Callable callable){
-    if(!isShiroConfigured())
+    Subject currentUser = getSubject();
+    if(currentUser==null)
       return callable;
 
-    Subject currentUser = SecurityUtils.getSubject();
     return currentUser.associateWith(callable);
   }
 
@@ -140,11 +188,10 @@ public class GeodeSecurityUtil {
     if(context.getResource()== Resource.NULL && context.getOperationCode()== OperationCode.NULL)
       return;
 
-    if(!isShiroConfigured())
+    Subject currentUser = getSubject();
+    if(currentUser==null)
       return;
 
-
-    Subject currentUser = SecurityUtils.getSubject();
     try {
       currentUser.checkPermission(context);
     }
@@ -154,7 +201,7 @@ public class GeodeSecurityUtil {
     }
   }
 
-  private static boolean isShiroConfigured(){
+  private static boolean isSecured(){
     try{
       SecurityUtils.getSecurityManager();
     }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9a770540/geode-core/src/main/java/com/gemstone/gemfire/internal/security/shiro/JMXShiroAuthenticator.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/security/shiro/JMXShiroAuthenticator.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/security/shiro/JMXShiroAuthenticator.java
index 4a4cc28..984a2bf 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/security/shiro/JMXShiroAuthenticator.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/security/shiro/JMXShiroAuthenticator.java
@@ -18,6 +18,7 @@ package com.gemstone.gemfire.internal.security.shiro;
 
 import static com.gemstone.gemfire.management.internal.security.ResourceConstants.*;
 
+import java.security.Principal;
 import java.util.Collections;
 import java.util.Properties;
 import javax.management.Notification;
@@ -50,9 +51,17 @@ public class JMXShiroAuthenticator implements JMXAuthenticator, NotificationList
       throw new SecurityException(WRONGE_CREDENTIALS_MESSAGE);
     }
 
-    GeodeSecurityUtil.login(username, password);
+    org.apache.shiro.subject.Subject shiroSubject = GeodeSecurityUtil.login(username, password);
+    Principal principal;
 
-    return new Subject(true, Collections.singleton(new JMXPrincipal(username)), Collections.EMPTY_SET,
+    if(shiroSubject==null){
+      principal = new JMXPrincipal(username);
+    }
+    else{
+      principal = new ShiroPrincipal(shiroSubject);
+    }
+
+    return new Subject(true, Collections.singleton(principal), Collections.EMPTY_SET,
       Collections.EMPTY_SET);
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9a770540/geode-core/src/main/java/com/gemstone/gemfire/internal/security/shiro/ShiroPrincipal.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/security/shiro/ShiroPrincipal.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/security/shiro/ShiroPrincipal.java
new file mode 100644
index 0000000..8413ebb
--- /dev/null
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/security/shiro/ShiroPrincipal.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.gemstone.gemfire.internal.security.shiro;
+
+import java.security.Principal;
+
+import org.apache.shiro.subject.Subject;
+
+public class ShiroPrincipal implements Principal {
+  private Subject subject;
+
+  public ShiroPrincipal(Subject subject){
+    this.subject = subject;
+  }
+
+  @Override
+  public String getName() {
+    return subject.toString();
+  }
+
+  public Subject getSubject(){
+    return subject;
+  }
+}


[12/16] incubator-geode git commit: GEODE-11: Adding package level javadocs for lucene

Posted by kl...@apache.org.
GEODE-11: Adding package level javadocs for lucene

Adding package-info.java files to all of the lucene packages. The public
API javadocs provide and overview of the what the lucene package does
and where to start.

The internal javadocs provide an overview of the purpose of each
internal package.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/c8ca8a0e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/c8ca8a0e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/c8ca8a0e

Branch: refs/heads/feature/GEODE-1371
Commit: c8ca8a0ed893d19e6da395cb13b72a61532ee555
Parents: f4b0643
Author: Dan Smith <up...@apache.org>
Authored: Mon May 9 18:09:47 2016 -0700
Committer: Dan Smith <up...@apache.org>
Committed: Tue May 10 10:03:49 2016 -0700

----------------------------------------------------------------------
 .../lucene/internal/directory/package-info.java | 23 ++++++++++++++
 .../internal/distributed/package-info.java      | 25 +++++++++++++++
 .../lucene/internal/filesystem/FileSystem.java  | 11 ++++++-
 .../internal/filesystem/package-info.java       | 26 ++++++++++++++++
 .../cache/lucene/internal/package-info.java     | 23 ++++++++++++++
 .../internal/repository/package-info.java       | 25 +++++++++++++++
 .../repository/serializer/package-info.java     | 23 ++++++++++++++
 .../cache/lucene/internal/xml/package-info.java | 24 +++++++++++++++
 .../gemfire/cache/lucene/package-info.java      | 32 ++++++++++++++++++++
 9 files changed, 211 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c8ca8a0e/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/directory/package-info.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/directory/package-info.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/directory/package-info.java
new file mode 100644
index 0000000..2dd0606
--- /dev/null
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/directory/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/**
+ * An implementation of Lucene's {@link org.apache.lucene.store.Directory} interface that uses the filesystem
+ * API in {@link com.gemstone.gemfire.cache.lucene.internal.filesystem.FileSystem}
+ */
+package com.gemstone.gemfire.cache.lucene.internal.directory;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c8ca8a0e/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/package-info.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/package-info.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/package-info.java
new file mode 100644
index 0000000..4079ad4
--- /dev/null
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/package-info.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/**
+ * Classes used for distributing lucene queries to geode nodes. Contains the lucene related functions
+ * like {@link com.gemstone.gemfire.cache.lucene.internal.distributed.LuceneFunction} as well as objects that are
+ * passed between nodes like {@link com.gemstone.gemfire.cache.lucene.internal.distributed.EntryScore}
+ */
+
+package com.gemstone.gemfire.cache.lucene.internal.distributed;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c8ca8a0e/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/FileSystem.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/FileSystem.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/FileSystem.java
index 44513f1..fdafcbe 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/FileSystem.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/FileSystem.java
@@ -25,7 +25,7 @@ import java.util.Collection;
 import java.util.concurrent.ConcurrentMap;
 
 /**
- * A Filesystem like interface that stores file data in gemfire regions.
+ * A Filesystem like interface that stores file data in geode regions.
  * 
  * This filesystem is safe for use with multiple threads if the threads are not
  * modifying the same files. A single file is not safe to modify by multiple
@@ -33,6 +33,7 @@ import java.util.concurrent.ConcurrentMap;
  * 
  * Changes to a file may not be visible to other members of the system until the
  * FileOutputStream is closed.
+ *
  */
 public class FileSystem {
   // private final Cache cache;
@@ -41,6 +42,14 @@ public class FileSystem {
   
   static final int CHUNK_SIZE = 1024 * 1024; //1 MB
 
+  /**
+   * Create filesystem that will store data in the two provided regions. The fileRegion contains
+   * metadata about the files, and the chunkRegion contains the actual data. If data from either region is missing
+   * or inconsistent, no guarantees are made about what this class will do, so it's best if these regions are colocated
+   * and in the same disk store to ensure the data remains together.
+   * @param fileRegion the region to store metadata about the files
+   * @param chunkRegion the region to store actual file data.
+   */
   public FileSystem(ConcurrentMap<String, File> fileRegion, ConcurrentMap<ChunkKey, byte[]> chunkRegion) {
     super();
     this.fileRegion = fileRegion;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c8ca8a0e/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/package-info.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/package-info.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/package-info.java
new file mode 100644
index 0000000..f8b612c
--- /dev/null
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/package-info.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/**
+ * A distributed filesystem implementation that uses a geode region as the underlying storage mechanism.
+ *
+ * Users of this filesystem should interact with the {@link com.gemstone.gemfire.cache.lucene.internal.filesystem.FileSystem} class.
+ *
+ */
+
+package com.gemstone.gemfire.cache.lucene.internal.filesystem;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c8ca8a0e/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/package-info.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/package-info.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/package-info.java
new file mode 100644
index 0000000..22670f3
--- /dev/null
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/**
+ * Internal lucene classes, not intended to be used directly.
+ */
+
+package com.gemstone.gemfire.cache.lucene.internal;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c8ca8a0e/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/package-info.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/package-info.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/package-info.java
new file mode 100644
index 0000000..894b464
--- /dev/null
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/package-info.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/**
+ * The repository package contains classes for managing a Lucene index in geode.
+ *
+ * All lucene index access should be through the {@link com.gemstone.gemfire.cache.lucene.internal.repository.IndexRepository}
+ * class.
+ */
+package com.gemstone.gemfire.cache.lucene.internal.repository;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c8ca8a0e/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/package-info.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/package-info.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/package-info.java
new file mode 100644
index 0000000..dca7737
--- /dev/null
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/**
+ * Classes for converting gemfire objects into lucene documents.
+ */
+
+package com.gemstone.gemfire.cache.lucene.internal.repository.serializer;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c8ca8a0e/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/xml/package-info.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/xml/package-info.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/xml/package-info.java
new file mode 100644
index 0000000..4eb1ca3
--- /dev/null
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/xml/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/**
+ * Classes for parsing lucene index elements a cache.xml file. See the lucene-1.0.xsd file for
+ * the schema.
+ */
+
+package com.gemstone.gemfire.cache.lucene.internal.xml;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c8ca8a0e/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/package-info.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/package-info.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/package-info.java
new file mode 100644
index 0000000..0e0c89b
--- /dev/null
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/package-info.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/**
+ * This package provides an integration with Apache Lucene that allows Geode regions to be indexed in a distributed
+ * Lucene index and queries using Lucene queries.
+ * <p>
+ * All indexing and query operations are performed through the {@link com.gemstone.gemfire.cache.lucene.LuceneService} class.
+ * See {@link com.gemstone.gemfire.cache.lucene.LuceneService} for an example of how to add a lucene index to a geode region.
+ * <p>
+ *
+ * The Lucene indexes created using this API are stored in geode and colocated with the indexed region, which means they
+ * have the same availability guarantees as the underlying region. The indexes are maintained asynchronously, so changes
+ * to the region may not be immediately visible in the lucene index.
+ */
+
+package com.gemstone.gemfire.cache.lucene;
\ No newline at end of file