Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D01B2200C0D for ; Tue, 31 Jan 2017 20:11:49 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id CEAE6160B52; Tue, 31 Jan 2017 19:11:49 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D58BB160B36 for ; Tue, 31 Jan 2017 20:11:48 +0100 (CET) Received: (qmail 63322 invoked by uid 500); 31 Jan 2017 19:11:48 -0000 Mailing-List: contact commits-help@geode.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.apache.org Delivered-To: mailing list commits@geode.apache.org Received: (qmail 63313 invoked by uid 99); 31 Jan 2017 19:11:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 31 Jan 2017 19:11:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id F101CDFC61; Tue, 31 Jan 2017 19:11:47 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: udo@apache.org To: commits@geode.apache.org Message-Id: <84d5ada422474933adeaac081515fa09@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: geode git commit: GEODE-1793: Fix a flaky test, clean up SSL tests. This closes #360 Date: Tue, 31 Jan 2017 19:11:47 +0000 (UTC) archived-at: Tue, 31 Jan 2017 19:11:50 -0000 Repository: geode Updated Branches: refs/heads/develop 296b15e2b -> 8426c675c 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/develop Commit: 8426c675c464896eab659a86fdb7a8c17706c607 Parents: 296b15e Author: Galen O'Sullivan Authored: Tue Jan 10 19:56:42 2017 -0800 Committer: Udo Kohlmeyer 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 */