This is an automated email from the ASF dual-hosted git repository. upthewaterspout pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push: new a383053 GEODE-5623: Use Awaitility in StopLcoatorCommandDUnitTest (#2379) a383053 is described below commit a3830536834fa70dbf00bd70ce381c94bf264307 Author: Dan Smith <dsm...@pivotal.io> AuthorDate: Mon Aug 27 09:34:11 2018 -0700 GEODE-5623: Use Awaitility in StopLcoatorCommandDUnitTest (#2379) Apparently members are not immmediately visible to stop after gfsh start locator. Changing the test to use awaitility to wait until the members can be stopped. --- .../cli/commands/StopLocatorCommandDUnitTest.java | 29 +++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/StopLocatorCommandDUnitTest.java b/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/StopLocatorCommandDUnitTest.java index 5903796..28c2829 100644 --- a/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/StopLocatorCommandDUnitTest.java +++ b/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/StopLocatorCommandDUnitTest.java @@ -15,6 +15,7 @@ package org.apache.geode.management.internal.cli.commands; import static org.apache.geode.distributed.internal.DistributionConfig.GEMFIRE_PREFIX; +import static org.apache.geode.management.MXBeanAwaitility.await; import static org.apache.geode.management.cli.Result.Status.ERROR; import static org.apache.geode.management.cli.Result.Status.OK; import static org.apache.geode.management.internal.cli.i18n.CliStrings.GROUP; @@ -34,6 +35,7 @@ import java.io.File; import java.io.IOException; import java.util.Properties; import java.util.Set; +import java.util.concurrent.TimeUnit; import javax.management.MBeanServerConnection; import javax.management.ObjectName; @@ -154,27 +156,39 @@ public class StopLocatorCommandDUnitTest { .addOption(STOP_LOCATOR__MEMBER, memberName) .getCommandString(); - CommandResult result = gfsh.executeCommand(command); - assertThat(result.getStatus()).isEqualTo(OK); + // The new locator is not immediately available to be stopped because its mbean + // has to be propagated to the existing locator that gfsh is connected to. Wait + // for the stop to work + waitForCommandToSucceed(command); gfsh.executeAndAssertThat("list members").doesNotContainOutput(memberName); } @Test public void testWithMemberID() { int port = jmxPort; // this assignment is needed to pass a local var into the invocation below + final String memberID = locator.invoke(() -> getMemberId(port)); final String command = new CommandStringBuilder(STOP_LOCATOR) .addOption(STOP_LOCATOR__MEMBER, memberID) .getCommandString(); - CommandResult result = gfsh.executeCommand(command); + // The new locator is not immediately available to be stopped because its mbean + // has to be propagated to the existing locator that gfsh is connected to. Wait + // for the stop to work + waitForCommandToSucceed(command); - assertThat(result.getStatus()).isEqualTo(OK); gfsh.executeAndAssertThat("list members").doesNotContainOutput(memberName); } + private void waitForCommandToSucceed(String command) { + await().atMost(5, TimeUnit.MINUTES).untilAsserted(() -> { + CommandResult result = gfsh.executeCommand(command); + assertThat(result.getStatus()).isEqualTo(OK); + }); + } + @Test public void testWithDirOnline() throws IOException { final String command = new CommandStringBuilder(STOP_LOCATOR) @@ -246,9 +260,12 @@ public class StopLocatorCommandDUnitTest { final MBeanServerConnection connection = conn.getMBeanServerConnection(); assertThat(connection).isInstanceOf(MBeanServerConnection.class); - final Set<ObjectName> objectNames = connection.queryNames(objectNamePattern, query); - assertThat(objectNames).isNotNull().isNotEmpty().hasSize(1); + await().untilAsserted(() -> { + final Set<ObjectName> objectNames = connection.queryNames(objectNamePattern, query); + assertThat(objectNames).isNotNull().isNotEmpty().hasSize(1); + }); + final Set<ObjectName> objectNames = connection.queryNames(objectNamePattern, query); final ObjectName objectName = objectNames.iterator().next(); final Object memberId = connection.getAttribute(objectName, "Id");