geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [07/32] geode git commit: GEODE-1793: Fix a flaky test, clean up SSL tests. This closes #360
Date Fri, 03 Feb 2017 18:35:36 GMT
GEODE-1793: Fix a flaky test, clean up SSL tests. This closes #360

* Add a couple of common test methods.
* Get random port numbers a bit more robustly.
* Check to make sure that locator2 has died at the end.


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

Branch: refs/heads/feature/GEODE-1930-2
Commit: 8426c675c464896eab659a86fdb7a8c17706c607
Parents: 296b15e
Author: Galen O'Sullivan <gosullivan@pivotal.io>
Authored: Tue Jan 10 19:56:42 2017 -0800
Committer: Udo Kohlmeyer <ukohlmeyer@pivotal.io>
Committed: Tue Jan 31 11:10:29 2017 -0800

----------------------------------------------------------------------
 .../internal/tcpserver/TcpClient.java           |   4 +-
 .../geode/distributed/LocatorDUnitTest.java     | 116 ++++++++++++-------
 2 files changed, 74 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/8426c675/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpClient.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpClient.java
b/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpClient.java
index a558598..2e27f3d 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpClient.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpClient.java
@@ -284,8 +284,8 @@ public class TcpClient {
       try {
         Object readObject = DataSerializer.readObject(in);
         if (!(readObject instanceof VersionResponse)) {
-          throw new LocatorCancelException("Unrecognisable response received");
-          // throw new IOException("Unexpected response received from locator");
+          throw new LocatorCancelException(
+              "Unrecognisable response received: object is null. This could be the result
of trying to connect a non-SSL-enabled locator to an SSL-enabled locator.");
         }
         VersionResponse response = (VersionResponse) readObject;
         if (response != null) {

http://git-wip-us.apache.org/repos/asf/geode/blob/8426c675/geode-core/src/test/java/org/apache/geode/distributed/LocatorDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/LocatorDUnitTest.java b/geode-core/src/test/java/org/apache/geode/distributed/LocatorDUnitTest.java
index b92ab25..7091fa6 100644
--- a/geode-core/src/test/java/org/apache/geode/distributed/LocatorDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/distributed/LocatorDUnitTest.java
@@ -414,8 +414,10 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
     } finally {
       try {
         // verify that they found each other
-        loc2.invoke("verifyLocatorNotInSplitBrain", () -> verifyLocatorNotInSplitBrain(2));
-        loc1.invoke("verifyLocatorNotInSplitBrain", () -> verifyLocatorNotInSplitBrain(2));
+        loc2.invoke("expectSystemToContainThisManyMembers",
+            () -> expectSystemToContainThisManyMembers(2));
+        loc1.invoke("expectSystemToContainThisManyMembers",
+            () -> expectSystemToContainThisManyMembers(2));
       } finally {
         loc2.invoke("stop locator", () -> stopLocator());
         loc1.invoke("stop locator", () -> stopLocator());
@@ -424,26 +426,18 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
   }
 
   @Test
-  public void testStartTwoLocatorsOneWithSSLAndTheOtherNonSSL() throws Exception {
+  public void testNonSSLLocatorDiesWhenConnectingToSSLLocator() throws Exception {
     IgnoredException.addIgnoredException("Unrecognized SSL message, plaintext connection");
     IgnoredException.addIgnoredException("LocatorCancelException");
     disconnectAllFromDS();
+
     Host host = Host.getHost(0);
+    final String hostname = NetworkUtils.getServerHostName(host);
     VM loc1 = host.getVM(1);
     VM loc2 = host.getVM(2);
 
-    int ports[] = AvailablePortHelper.getRandomAvailableTCPPorts(2);
-    final int port1 = ports[0];
-    this.port1 = port1;
-    final int port2 = ports[1];
-    this.port2 = port2; // for cleanup in tearDown2
-    DistributedTestUtils.deleteLocatorStateFile(port1);
-    DistributedTestUtils.deleteLocatorStateFile(port2);
-    final String host0 = NetworkUtils.getServerHostName(host);
-    final String locators = host0 + "[" + port1 + "]," + host0 + "[" + port2 + "]";
     final Properties properties = new Properties();
     properties.put(MCAST_PORT, "0");
-    properties.put(LOCATORS, locators);
     properties.put(ENABLE_NETWORK_PARTITION_DETECTION, "false");
     properties.put(DISABLE_AUTO_RECONNECT, "true");
     properties.put(MEMBER_TIMEOUT, "2000");
@@ -460,22 +454,40 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
     properties.put(SSL_ENABLED_COMPONENTS, SecurableCommunicationChannel.LOCATOR.getConstant());
 
     try {
-      loc1.invoke("start Locator1", () -> startLocator(port1, properties));
-      loc1.invoke("verifyLocatorNotInSplitBrain", () -> verifyLocatorNotInSplitBrain(1));
+      // we set port1 so that the state file gets cleaned up later.
+      port1 = loc1.invoke(() -> startLocatorWithRandomPort(properties));
+
+      loc1.invoke("expect only one member in system",
+          () -> expectSystemToContainThisManyMembers(1));
+
       properties.remove(SSL_ENABLED_COMPONENTS);
+      properties.put(LOCATORS, hostname + "[" + port1 + "]");
+      // we set port2 so that the state file gets cleaned up later.
+      port2 = loc2.invoke("start Locator2", () -> {
+        // Sometimes the LocatorCancelException becomes a SystemConnectException, which then
causes
+        // an RMIException. This is a normal part of the connect failing.
+        int port;
+        try {
+          port = startLocatorWithRandomPort(properties);
+        } catch (SystemConnectException expected_sometimes) {
+          return 0;
+        }
+        return port;
+      });
+
+      loc1.invoke("expect only one member in system",
+          () -> expectSystemToContainThisManyMembers(1));
 
-      loc2.invoke("start Locator2", () -> startLocator(port2, properties));
     } finally {
-      try {
-        loc1.invoke("verifyLocatorNotInSplitBrain", () -> verifyLocatorNotInSplitBrain(1));
-      } finally {
-        loc1.invoke("stop locator", () -> stopLocator());
-      }
+      loc1.invoke("stop locator", () -> stopLocator());
+      // loc2 should die from inability to connect.
+      loc2.invoke(() -> Awaitility.await("locator2 dies").atMost(15, TimeUnit.SECONDS)
+          .until(() -> Locator.getLocator() == null));
     }
   }
 
   @Test
-  public void testStartTwoLocatorsOneWithNonSSLAndTheOtherSSL() throws Exception {
+  public void testSSLEnabledLocatorDiesWhenConnectingToNonSSLLocator() {
     IgnoredException.addIgnoredException("Remote host closed connection during handshake");
     IgnoredException.addIgnoredException("Unrecognized SSL message, plaintext connection");
     IgnoredException.addIgnoredException("LocatorCancelException");
@@ -485,18 +497,9 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
     VM loc1 = host.getVM(1);
     VM loc2 = host.getVM(2);
 
-    int ports[] = AvailablePortHelper.getRandomAvailableTCPPorts(2);
-    final int port1 = ports[0];
-    this.port1 = port1;
-    final int port2 = ports[1];
-    this.port2 = port2; // for cleanup in tearDown2
-    DistributedTestUtils.deleteLocatorStateFile(port1);
-    DistributedTestUtils.deleteLocatorStateFile(port2);
-    final String host0 = NetworkUtils.getServerHostName(host);
-    final String locators = host0 + "[" + port1 + "]," + host0 + "[" + port2 + "]";
+    final String hostname = NetworkUtils.getServerHostName(host);
     final Properties properties = new Properties();
     properties.put(MCAST_PORT, "0");
-    properties.put(LOCATORS, locators);
     properties.put(ENABLE_NETWORK_PARTITION_DETECTION, "false");
     properties.put(DISABLE_AUTO_RECONNECT, "true");
     properties.put(MEMBER_TIMEOUT, "2000");
@@ -506,8 +509,10 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
     properties.put(SSL_PROTOCOLS, "any");
 
     try {
-      loc1.invoke("start Locator1", () -> startLocator(port1, properties));
-      loc1.invoke("verifyLocatorNotInSplitBrain", () -> verifyLocatorNotInSplitBrain(1));
+      // we set port1 so that the state file gets cleaned up later.
+      port1 = loc1.invoke("start Locator1", () -> startLocatorWithRandomPort(properties));
+      loc1.invoke("expectSystemToContainThisManyMembers",
+          () -> expectSystemToContainThisManyMembers(1));
 
       properties.put(SSL_KEYSTORE, getSingleKeyKeystore());
       properties.put(SSL_KEYSTORE_PASSWORD, "password");
@@ -517,13 +522,20 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
       properties.put(SSL_REQUIRE_AUTHENTICATION, "true");
       properties.put(SSL_ENABLED_COMPONENTS, SecurableCommunicationChannel.LOCATOR.getConstant());
 
-      loc2.invoke("start Locator2", () -> startLocator(port2, properties));
+      final String locators = hostname + "[" + port1 + "]";
+      properties.put(LOCATORS, locators);
+
+      // we set port2 so that the state file gets cleaned up later.
+      port2 = loc2.invoke("start Locator2", () -> startLocatorWithRandomPort(properties));
+      loc1.invoke("expectSystemToContainThisManyMembers",
+          () -> expectSystemToContainThisManyMembers(1));
     } finally {
-      try {
-        loc1.invoke("verifyLocatorNotInSplitBrain", () -> verifyLocatorNotInSplitBrain(1));
-      } finally {
-        loc1.invoke("stop locator", () -> stopLocator());
-      }
+      // loc2 should die from inability to connect.
+      loc2.invoke(() -> Awaitility.await("locator2 dies").atMost(30, TimeUnit.SECONDS)
+          .until(() -> Locator.getLocator() == null));
+      loc1.invoke("expectSystemToContainThisManyMembers",
+          () -> expectSystemToContainThisManyMembers(1));
+      loc1.invoke("stop locator", () -> stopLocator());
     }
   }
 
@@ -570,7 +582,8 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
 
     try {
       loc1.invoke("start Locator1", () -> startLocator(port1, properties));
-      loc1.invoke("verifyLocatorNotInSplitBrain", () -> verifyLocatorNotInSplitBrain(1));
+      loc1.invoke("expectSystemToContainThisManyMembers",
+          () -> expectSystemToContainThisManyMembers(1));
 
       properties.put(SSL_KEYSTORE, getMultiKeyKeystore());
       properties.put(SSL_TRUSTSTORE, getMultiKeyTruststore());
@@ -579,14 +592,15 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
       loc2.invoke("start Locator2", () -> startLocator(port2, properties));
     } finally {
       try {
-        loc1.invoke("verifyLocatorNotInSplitBrain", () -> verifyLocatorNotInSplitBrain(1));
+        loc1.invoke("expectSystemToContainThisManyMembers",
+            () -> expectSystemToContainThisManyMembers(1));
       } finally {
         loc1.invoke("stop locator", () -> stopLocator());
       }
     }
   }
 
-  private Object verifyLocatorNotInSplitBrain(final int expectedMembers) {
+  private Object expectSystemToContainThisManyMembers(final int expectedMembers) {
     InternalDistributedSystem sys = InternalDistributedSystem.getAnyInstance();
     if (sys == null) {
       Assert.fail("no distributed system found");
@@ -596,14 +610,28 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
   }
 
   private void startLocator(final int port, final Properties properties) throws IOException
{
+    startLocatorInternal(port, properties);
+  }
+
+  // Don't call this directly for RMI -- the locator isn't RMI serializable.
+  private Locator startLocatorInternal(final int port, final Properties properties)
+      throws IOException {
+    Locator locator;
     try {
       System.setProperty("p2p.joinTimeout", "5000"); // set a short join timeout. default
is 17000ms
-      Locator.startLocatorAndDS(port, new File(""), properties);
+      locator = Locator.startLocatorAndDS(port, new File(""), properties);
     } finally {
       System.getProperties().remove("p2p.joinTimeout");
     }
+    return locator;
   }
 
+  public int startLocatorWithRandomPort(Properties properties) throws IOException {
+    Locator locator = startLocatorInternal(0, properties);
+    return locator.getPort();
+  }
+
+
   /**
    * test lead member selection
    */


Mime
View raw message