You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by jj...@apache.org on 2020/10/27 11:10:48 UTC
[geode] branch develop updated: GEODE-8071: Prevent Test Flakiness
(#5676)
This is an automated email from the ASF dual-hosted git repository.
jjramos 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 38ed638 GEODE-8071: Prevent Test Flakiness (#5676)
38ed638 is described below
commit 38ed63838f7cdaf7ff2f5089bda3df3b75a4c4c2
Author: Juan José Ramos <ju...@users.noreply.github.com>
AuthorDate: Tue Oct 27 11:09:47 2020 +0000
GEODE-8071: Prevent Test Flakiness (#5676)
Different versions of the embedded Jetty server can launch non-daemon
threads, so the fix implies preventing any flakiness by just checking
for the thread we're interested in.
---
.../commands/RebalanceCommandDistributedTest.java | 25 ++++++++--------------
.../internal/cli/commands/RebalanceCommand.java | 6 +++++-
2 files changed, 14 insertions(+), 17 deletions(-)
diff --git a/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandDistributedTest.java b/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandDistributedTest.java
index a1a2bdd..ee105eb 100644
--- a/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandDistributedTest.java
+++ b/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandDistributedTest.java
@@ -183,25 +183,18 @@ public class RebalanceCommandDistributedTest implements Serializable {
/**
* See GEODE-8071.
- * The test asserts that the amount of non-daemon threads on the locator VM remains constant
- * before and after executing the re-balance command.
+ * The test simply asserts that the re-balance command doesn't launch a non daemon thread
+ * during its execution.
*/
@Test
public void rebalanceCommandShouldNotLaunchNonDaemonThreads() {
- long nonDaemonThreadsBeforeCommand = locator.invoke(() -> Thread.getAllStackTraces()
- .keySet()
- .stream()
- .filter(thread -> !thread.isDaemon())
- .count());
-
gfsh.executeAndAssertThat("rebalance").statusIsSuccess();
-
- long daemonThreadsAfterCommand = locator.invoke(() -> Thread.getAllStackTraces()
- .keySet()
- .stream()
- .filter(thread -> !thread.isDaemon())
- .count());
-
- assertThat(daemonThreadsAfterCommand).isEqualTo(nonDaemonThreadsBeforeCommand);
+ locator.invoke(() -> {
+ assertThat(Thread.getAllStackTraces().keySet().stream()
+ .anyMatch(thread -> !thread.isDaemon()
+ && thread.getName().contains(RebalanceCommand.THREAD_NAME)))
+ .as("Rebalance Command should not launch non daemon threads")
+ .isFalse();
+ });
}
}
diff --git a/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/RebalanceCommand.java b/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/RebalanceCommand.java
index 589512b..62cc54c 100644
--- a/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/RebalanceCommand.java
+++ b/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/RebalanceCommand.java
@@ -30,6 +30,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption;
+import org.apache.geode.annotations.VisibleForTesting;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.logging.internal.executors.LoggingExecutors;
import org.apache.geode.management.cli.CliMetaData;
@@ -46,6 +47,9 @@ import org.apache.geode.management.runtime.RebalanceResult;
import org.apache.geode.security.ResourcePermission;
public class RebalanceCommand extends GfshCommand {
+ @VisibleForTesting
+ public static String THREAD_NAME = "RebalanceCommand";
+
@CliCommand(value = CliStrings.REBALANCE, help = CliStrings.REBALANCE__HELP)
@CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_DATA, CliStrings.TOPIC_GEODE_REGION})
@ResourceOperation(resource = ResourcePermission.Resource.DATA,
@@ -62,7 +66,7 @@ public class RebalanceCommand extends GfshCommand {
help = CliStrings.REBALANCE__SIMULATE__HELP) boolean simulate) {
ExecutorService commandExecutors =
- LoggingExecutors.newSingleThreadExecutor("RebalanceCommand", true);
+ LoggingExecutors.newSingleThreadExecutor(THREAD_NAME, true);
List<Future<ResultModel>> commandResult = new ArrayList<>();
ResultModel result;
try {