From d38f54b1a792ca75c387415806a23ab6998f5988 Mon Sep 17 00:00:00 2001 From: gitseti Date: Mon, 5 Sep 2022 16:58:51 +0200 Subject: [PATCH] System Tests > Fix failing tests --- .../java/com/hivemq/cli/commands/cli/PublishST.java | 7 ++++--- .../com/hivemq/cli/commands/cli/SubscribeST.java | 2 +- .../hivemq/cli/commands/cli/shell/ConnectST.java | 6 ++---- .../java/com/hivemq/cli/utils/CLITestExtension.java | 13 +++++-------- .../java/com/hivemq/cli/utils/CommandConsumer.java | 12 ------------ 5 files changed, 12 insertions(+), 28 deletions(-) diff --git a/src/systemTest/java/com/hivemq/cli/commands/cli/PublishST.java b/src/systemTest/java/com/hivemq/cli/commands/cli/PublishST.java index d337cfb6e..8c666411f 100644 --- a/src/systemTest/java/com/hivemq/cli/commands/cli/PublishST.java +++ b/src/systemTest/java/com/hivemq/cli/commands/cli/PublishST.java @@ -94,7 +94,7 @@ void test_publish_missing_topic() throws Exception { final Process pub = new ProcessBuilder(publishCommand).start(); - cliTestExtension.waitForErrorWithTimeout(pub, "Missing required option: '--topic '"); + cliTestExtension.waitForErrorWithTimeout(pub, "Missing required option: '--topic='"); assertEquals(pub.waitFor(), 2); } @@ -113,8 +113,9 @@ void test_publish_missing_message() throws Exception { final Process pub = new ProcessBuilder(publishCommand).start(); cliTestExtension.waitForErrorWithTimeout(pub, Set.of( - "Error: Missing required argument (specify one of these): (-m | -m:file )", - "Error: Missing required argument (specify one of these): (-m:file | -m )")); + "Error: Missing required argument (specify one of these): (-m= | -m:file=)", + "Error: Missing required argument (specify one of these): (-m:file= | -m=)")); + assertEquals(pub.waitFor(), 2); } } \ No newline at end of file diff --git a/src/systemTest/java/com/hivemq/cli/commands/cli/SubscribeST.java b/src/systemTest/java/com/hivemq/cli/commands/cli/SubscribeST.java index 424c147f4..9738c2ee1 100644 --- a/src/systemTest/java/com/hivemq/cli/commands/cli/SubscribeST.java +++ b/src/systemTest/java/com/hivemq/cli/commands/cli/SubscribeST.java @@ -92,7 +92,7 @@ void test_subscribe_missing_topic() throws Exception { publishCommand.add(String.valueOf(hivemq.getMqttPort())); final Process sub = new ProcessBuilder(publishCommand).start(); - cliTestExtension.waitForErrorWithTimeout(sub, "Missing required option: '--topic '"); + cliTestExtension.waitForErrorWithTimeout(sub, "Missing required option: '--topic='"); assertEquals(sub.waitFor(), 2); } } diff --git a/src/systemTest/java/com/hivemq/cli/commands/cli/shell/ConnectST.java b/src/systemTest/java/com/hivemq/cli/commands/cli/shell/ConnectST.java index d00736baf..8420c3204 100644 --- a/src/systemTest/java/com/hivemq/cli/commands/cli/shell/ConnectST.java +++ b/src/systemTest/java/com/hivemq/cli/commands/cli/shell/ConnectST.java @@ -58,9 +58,7 @@ void test_successful_connect() { @Test @Timeout(value = 3, unit = TimeUnit.MINUTES) void test_unsuccessful_connect() { - cliShellTestExtension.executeCommandWithErrorWithTimeout("con -h localhost -p 22 -i cliTest", Set.of( - "Connection refused: localhost/127.0.0.1:22", - "readAddress(..) failed: Connection reset by peer", - "Connection reset")); + cliShellTestExtension.executeCommandWithErrorWithTimeout("con -h localhost -p 22 -i cliTest", + "Unable to connect. Connection refused"); } } diff --git a/src/systemTest/java/com/hivemq/cli/utils/CLITestExtension.java b/src/systemTest/java/com/hivemq/cli/utils/CLITestExtension.java index e8344d497..fd51e65b0 100644 --- a/src/systemTest/java/com/hivemq/cli/utils/CLITestExtension.java +++ b/src/systemTest/java/com/hivemq/cli/utils/CLITestExtension.java @@ -30,6 +30,8 @@ import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; +import static org.testcontainers.shaded.org.awaitility.Awaitility.await; + public class CLITestExtension { public static final @NotNull List CLI_EXEC = @@ -81,11 +83,6 @@ public void waitForErrorWithTimeout( waitForErrorWithTimeout(process, Set.of(expectedError)); } - public @NotNull CompletableFuture waitForError( - final @NotNull Process process, final @NotNull String expectedError) { - return waitForError(process, Set.of(expectedError)); - } - public void waitForErrorWithTimeout( final @NotNull Process process, final @NotNull Set expectedErrors) { try { @@ -101,14 +98,14 @@ public void waitForErrorWithTimeout( final InputStreamReader errorStreamReader = new InputStreamReader(errorStream, StandardCharsets.UTF_8); final BufferedReader bufferedErrorReader = new BufferedReader(errorStreamReader); - final ArrayList> commandFinished = new ArrayList<>(); + final ArrayList> errorReadFutures = new ArrayList<>(); for (final String expectedError : expectedErrors) { - commandFinished.add(errorConsumer.waitFor(expectedError)); + errorReadFutures.add(errorConsumer.waitFor(expectedError)); } final StringBuilder errorBuilder = new StringBuilder(); return CompletableFuture.runAsync(() -> { - while (commandFinished.stream().filter(CompletableFuture::isDone).findAny().isEmpty()) { + while (errorReadFutures.stream().filter(CompletableFuture::isDone).findAny().isEmpty()) { try { final int inputChar = bufferedErrorReader.read(); if (inputChar == -1) { diff --git a/src/systemTest/java/com/hivemq/cli/utils/CommandConsumer.java b/src/systemTest/java/com/hivemq/cli/utils/CommandConsumer.java index 27c3e2c85..7a85b12e8 100644 --- a/src/systemTest/java/com/hivemq/cli/utils/CommandConsumer.java +++ b/src/systemTest/java/com/hivemq/cli/utils/CommandConsumer.java @@ -25,16 +25,10 @@ public class CommandConsumer implements Consumer { - private final @NotNull Map> patterns = new ConcurrentHashMap<>(); private final @NotNull Map> contains = new ConcurrentHashMap<>(); @Override public void accept(final @NotNull String commandLine) { - patterns.forEach((pattern, future) -> { - if (commandLine.trim().matches(pattern)) { - future.complete(null); - } - }); contains.forEach((command, future) -> { if (commandLine.contains(command)) { future.complete(null); @@ -42,12 +36,6 @@ public void accept(final @NotNull String commandLine) { }); } - public @NotNull CompletableFuture waitForPattern(final @NotNull String pattern) { - final CompletableFuture future = new CompletableFuture<>(); - patterns.put(pattern, future); - return future; - } - public @NotNull CompletableFuture waitFor(final @NotNull String command) { final CompletableFuture future = new CompletableFuture<>(); contains.put(command, future);