From a00f18de72ebc282e32fb2f67049fd21da58cfa6 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Fri, 30 Oct 2020 10:01:28 -0700 Subject: [PATCH] GEODE-8659: Consolidating locator-wait-time-tests We had two different tests of this functionality that were testing almost the same thing. The first test had a slightly odd configuration - only one of the locators knew about the other. Combining these into a single test that locators wait for locator-wait-time and stop waiting when all locators are found. --- .../gms/MembershipIntegrationTest.java | 100 ++++-------------- 1 file changed, 18 insertions(+), 82 deletions(-) diff --git a/geode-membership/src/integrationTest/java/org/apache/geode/distributed/internal/membership/gms/MembershipIntegrationTest.java b/geode-membership/src/integrationTest/java/org/apache/geode/distributed/internal/membership/gms/MembershipIntegrationTest.java index 4ed92899781b..3420d36a2ce7 100644 --- a/geode-membership/src/integrationTest/java/org/apache/geode/distributed/internal/membership/gms/MembershipIntegrationTest.java +++ b/geode-membership/src/integrationTest/java/org/apache/geode/distributed/internal/membership/gms/MembershipIntegrationTest.java @@ -187,41 +187,26 @@ public void secondMembershipCanJoinUsingTheSecondLocatorToStart() } @Test - public void secondMembershipPausesForLocatorWaitTime() - throws IOException, MemberStartupException, InterruptedException { + public void locatorWaitsForLocatorWaitTimeUntilAllLocatorsContacted() + throws InterruptedException, TimeoutException, ExecutionException { - /* - * Start a locator for the coordinator (membership) so we have a port for it. - * - * Its locator-wait-time is set to 0 so it eventually (soon after membership is started) forms a - * distributed system and becomes a coordinator. - */ - - final MembershipLocator coordinatorLocator = createLocator(0); - coordinatorLocator.start(); - final int coordinatorLocatorPort = coordinatorLocator.getPort(); + final Supplier executorServiceSupplier = + () -> LoggingExecutors.newCachedThreadPool("membership", false); - final Membership coordinatorMembership = - createMembership(coordinatorLocator, coordinatorLocatorPort); + int[] locatorPorts = AvailablePortHelper.getRandomAvailableTCPPorts(2); - /* - * We have not even started the membership yet — connection attempts will certainly fail until - * we do. This is a bit like the locator (host) not being present in DNS (yet). - */ + int locatorWaitTime = (int) Duration.ofMinutes(5).getSeconds(); + final MembershipConfig config = + createMembershipConfig(true, locatorWaitTime, locatorPorts[0], locatorPorts[1]); /* - * Start a second locator and membership trying to join via the coordinator (membership) that - * hasn't yet started behind the port. + * Start a locator trying to contact the locator that hasn't started it's port * * Set its locator-wait-time so it'll not become a coordinator right away, allowing time for the * other member to start and become a coordinator. */ - - final MembershipLocator lateJoiningLocator = createLocator(0); - lateJoiningLocator.start(); - final int lateJoiningLocatorPort = lateJoiningLocator.getPort(); - - final int[] locatorPorts = new int[] {coordinatorLocatorPort, lateJoiningLocatorPort}; + CompletableFuture> createMembership0 = + launchLocator(executorServiceSupplier, locatorPorts[0], config); // minimum duration a locator waits to become the coordinator, regardless of locatorWaitTime final Duration minimumJoinWaitTime = Duration @@ -230,27 +215,6 @@ public void secondMembershipPausesForLocatorWaitTime() // expected number of retries in GMSJoinLeave.join() .multipliedBy(getMinimumRetriesBeforeBecomingCoordinator(locatorPorts.length)); - /* - * By setting locatorWaitTime to 10x the minimumJoinWaitTime, we are trying to make sure the - * locatorWaitTime is sufficiently larger than the minimum so we can reliably detect whether - * the lateJoiningMembership is waiting for the full locatorWaitTime and not just the minimum - * wait time. - */ - final int locatorWaitTime = (int) (10 * minimumJoinWaitTime.getSeconds()); - - final MembershipConfig lateJoiningMembershipConfig = - createMembershipConfig(true, locatorWaitTime, locatorPorts); - final Membership lateJoiningMembership = - createMembership(lateJoiningMembershipConfig, lateJoiningLocator); - - CompletableFuture lateJoiningMembershipStartup = executorServiceRule.runAsync(() -> { - try { - start(lateJoiningMembership); - } catch (MemberStartupException e) { - throw new RuntimeException(e); - } - }); - /* * By sleeping for 2x the minimumJoinWaitTime, we are trying to make sure we sleep for * longer than the minimum but shorter than the locatorWaitTime so we can detect whether the @@ -259,47 +223,16 @@ public void secondMembershipPausesForLocatorWaitTime() */ Thread.sleep(2 * minimumJoinWaitTime.toMillis()); + assertThat(createMembership0.getNow(null)).isNull(); + /* - * Now start the coordinator (membership), after waiting longer than the minimum wait time for + * Now start the other locator, after waiting longer than the minimum wait time for * connecting to a locator but shorter than the locator-wait-time. */ - start(coordinatorMembership); - - await().untilAsserted(() -> assertThat(lateJoiningMembershipStartup).isCompleted()); - - await().untilAsserted( - () -> assertThat(coordinatorMembership.getView().getMembers()).hasSize(2)); - await().untilAsserted( - () -> assertThat(lateJoiningMembership.getView().getMembers()).hasSize(2)); - - stop(coordinatorMembership, lateJoiningMembership); - stop(coordinatorLocator, lateJoiningLocator); - } - - @Test - public void locatorsStopWaitingForLocatorWaitTimeIfAllLocatorsContacted() - throws IOException, MemberStartupException, InterruptedException, TimeoutException, - ExecutionException { - - final Supplier executorServiceSupplier = - () -> LoggingExecutors.newCachedThreadPool("membership", false); - - int[] locatorPorts = AvailablePortHelper.getRandomAvailableTCPPorts(2); - - int locatorWaitTime = (int) Duration.ofMinutes(5).getSeconds(); - final MembershipConfig config = - createMembershipConfig(true, locatorWaitTime, locatorPorts[0], locatorPorts[1]); - - CompletableFuture> createMembership0 = - launchLocator(executorServiceSupplier, locatorPorts[0], config); - - // Assert that membership 0 is waiting for the other locator to start - Thread.sleep(5000); - assertThat(createMembership0.getNow(null)).isNull(); - CompletableFuture> createMembership1 = launchLocator(executorServiceSupplier, locatorPorts[1], config); + // Make sure the members are created in less than the locator-wait-time Membership membership0 = createMembership0.get(2, TimeUnit.MINUTES); Membership membership1 = createMembership1.get(2, TimeUnit.MINUTES); @@ -307,8 +240,11 @@ public void locatorsStopWaitingForLocatorWaitTimeIfAllLocatorsContacted() // Make sure the members see each other in the view await().untilAsserted(() -> assertThat(membership0.getView().getMembers()).hasSize(2)); await().untilAsserted(() -> assertThat(membership1.getView().getMembers()).hasSize(2)); + + stop(membership0, membership1); } + private CompletableFuture> launchLocator( Supplier executorServiceSupplier, int locatorPort, MembershipConfig config) { return executorServiceRule.supplyAsync(() -> {