You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ir...@apache.org on 2019/12/25 08:33:22 UTC
[ignite] branch master updated: IGNITE-12465 Extend test coverage
[IGNITE-11995] - Fixes #7158.
This is an automated email from the ASF dual-hosted git repository.
irakov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 44240bc IGNITE-12465 Extend test coverage [IGNITE-11995] - Fixes #7158.
44240bc is described below
commit 44240bc39f5cfa5ca74ca5c65ac64208d35468e5
Author: Kirill Tkalenko <tk...@yandex.ru>
AuthorDate: Wed Dec 25 10:08:08 2019 +0300
IGNITE-12465 Extend test coverage [IGNITE-11995] - Fixes #7158.
Signed-off-by: Ivan Rakov <ir...@apache.org>
---
.../ignite/internal/commandline/Command.java | 20 ++++
.../ignite/internal/commandline/WalCommands.java | 15 +--
.../util/GridCommandHandlerClusterByClassTest.java | 122 ++++++++++++++++++---
3 files changed, 133 insertions(+), 24 deletions(-)
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/commandline/Command.java b/modules/core/src/main/java/org/apache/ignite/internal/commandline/Command.java
index 6f033a2..eae71e6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/commandline/Command.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/commandline/Command.java
@@ -18,10 +18,12 @@
package org.apache.ignite.internal.commandline;
import java.util.logging.Logger;
+import org.apache.ignite.IgniteSystemProperties;
import org.apache.ignite.internal.client.GridClient;
import org.apache.ignite.internal.client.GridClientConfiguration;
import org.apache.ignite.internal.client.GridClientFactory;
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_ENABLE_EXPERIMENTAL_COMMAND;
import static org.apache.ignite.internal.commandline.CommandHandler.UTILITY_NAME;
import static org.apache.ignite.internal.commandline.CommandLogger.DOUBLE_INDENT;
import static org.apache.ignite.internal.commandline.CommandLogger.INDENT;
@@ -115,4 +117,22 @@ public interface Command<T> {
* @return command name.
*/
String name();
+
+ /**
+ * @return Value of {@link IgniteSystemProperties#IGNITE_ENABLE_EXPERIMENTAL_COMMAND}
+ */
+ default boolean experimentalEnabled() {
+ return IgniteSystemProperties.getBoolean(IGNITE_ENABLE_EXPERIMENTAL_COMMAND, false);
+ }
+
+ /**
+ * Return {@code true} if the command is experimental or {@code false}
+ * otherwise.
+ *
+ * @return {@code true} if the command is experimental or {@code false}
+ * otherwise.
+ */
+ default boolean experimental() {
+ return false;
+ }
}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/commandline/WalCommands.java b/modules/core/src/main/java/org/apache/ignite/internal/commandline/WalCommands.java
index 2960b36..99ef018 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/commandline/WalCommands.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/commandline/WalCommands.java
@@ -22,7 +22,6 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
-import org.apache.ignite.IgniteSystemProperties;
import org.apache.ignite.internal.client.GridClient;
import org.apache.ignite.internal.client.GridClientConfiguration;
import org.apache.ignite.internal.util.typedef.F;
@@ -69,7 +68,7 @@ public class WalCommands implements Command<T2<String, String>> {
/** {@inheritDoc} */
@Override public void printUsage(Logger logger) {
- if (!enableExperimental())
+ if (!experimentalEnabled())
return;
Command.usage(logger, "Print absolute paths of unused archived wal segments on each node:", WAL,
@@ -85,7 +84,7 @@ public class WalCommands implements Command<T2<String, String>> {
* @throws Exception If failed to execute wal action.
*/
@Override public Object execute(GridClientConfiguration clientCfg, Logger logger) throws Exception {
- if (enableExperimental()) {
+ if (experimentalEnabled()) {
this.logger = logger;
try (GridClient client = Command.startClient(clientCfg)) {
@@ -129,7 +128,7 @@ public class WalCommands implements Command<T2<String, String>> {
? argIter.nextArg("Unexpected argument for " + WAL.text() + ": " + walAct)
: "";
- if (enableExperimental()) {
+ if (experimentalEnabled()) {
this.walAct = walAct;
this.walArgs = walArgs;
}
@@ -276,10 +275,8 @@ public class WalCommands implements Command<T2<String, String>> {
return WAL.toCommandName();
}
- /**
- * @return Value of {@link IgniteSystemProperties#IGNITE_ENABLE_EXPERIMENTAL_COMMAND}
- */
- private boolean enableExperimental() {
- return IgniteSystemProperties.getBoolean(IGNITE_ENABLE_EXPERIMENTAL_COMMAND, false);
+ /** {@inheritDoc} */
+ @Override public boolean experimental() {
+ return true;
}
}
diff --git a/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java b/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java
index 3aec19f..cd4b2dc 100644
--- a/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java
@@ -35,11 +35,15 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.Collection;
+import java.util.EnumMap;
+import java.util.function.Consumer;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteCluster;
import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.IgniteSystemProperties;
import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.configuration.AtomicConfiguration;
@@ -75,8 +79,9 @@ import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import static java.util.Arrays.asList;
+import static java.util.Arrays.stream;
+import static java.util.Objects.nonNull;
import static java.util.stream.Collectors.toList;
-import static java.util.stream.Stream.of;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_ENABLE_EXPERIMENTAL_COMMAND;
import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
@@ -1503,33 +1508,120 @@ public class GridCommandHandlerClusterByClassTest extends GridCommandHandlerClus
}
/**
- * Don't show wal commands by --help in case
- * {@link org.apache.ignite.IgniteSystemProperties#IGNITE_ENABLE_EXPERIMENTAL_COMMAND} = false or empty.
+ * Test is that when the --help control.sh command is executed, output
+ * will contain non-experimental commands. In case system property
+ * {@link IgniteSystemProperties#IGNITE_ENABLE_EXPERIMENTAL_COMMAND} =
+ * {@code true}.
+ */
+ @Test
+ @WithSystemProperty(key = IGNITE_ENABLE_EXPERIMENTAL_COMMAND, value = "true")
+ public void testContainsNotExperimentalCmdInHelpOutputWhenEnableExperimentalTrue() {
+ checkContainsNotExperimentalCmdInHelpOutput();
+ }
+
+ /**
+ * Test is that when the --help control.sh command is executed, output
+ * will contain non-experimental commands. In case system property
+ * {@link IgniteSystemProperties#IGNITE_ENABLE_EXPERIMENTAL_COMMAND} =
+ * {@code false}.
*/
@Test
@WithSystemProperty(key = IGNITE_ENABLE_EXPERIMENTAL_COMMAND, value = "false")
- public void testHideWalInHelpWhenDisableExperimentalCommand() {
- injectTestSystemOut();
+ public void testContainsNotExperimentalCmdInHelpOutputWhenEnableExperimentalFalse() {
+ checkContainsNotExperimentalCmdInHelpOutput();
+ }
- execute("--help");
+ /**
+ * Test for contains of experimental commands in output of the --help
+ * control.sh command.
+ */
+ @Test
+ @WithSystemProperty(key = IGNITE_ENABLE_EXPERIMENTAL_COMMAND, value = "true")
+ public void testContainsExperimentalCmdInHelpOutput() {
+ checkExperimentalCmdInHelpOutput(true);
+ }
- assertNotContains(log, testOut.toString(), WAL.text());
+ /**
+ * Test for not contains of experimental commands in output of the --help
+ * control.sh command.
+ */
+ @Test
+ @WithSystemProperty(key = IGNITE_ENABLE_EXPERIMENTAL_COMMAND, value = "false")
+ public void testNotContainsExperimentalCmdInHelpOutput() {
+ checkExperimentalCmdInHelpOutput(false);
}
/**
- * Wal commands should ignored and print warning in case
- * {@link org.apache.ignite.IgniteSystemProperties#IGNITE_ENABLE_EXPERIMENTAL_COMMAND} = false or empty.
+ * Test to verify that the experimental command will not be executed if
+ * {@link IgniteSystemProperties#IGNITE_ENABLE_EXPERIMENTAL_COMMAND} =
+ * {@code false}, a warning will be displayed instead.
* */
@Test
@WithSystemProperty(key = IGNITE_ENABLE_EXPERIMENTAL_COMMAND, value = "false")
- public void testWalCommandsInCaseDisableExperimentalCommand() {
+ public void testContainsWarnInsteadExecExperimentalCmdWhenEnableExperimentalFalse() {
+ injectTestSystemOut();
+
+ Map<CommandList, Collection<String>> cmdArgs = new EnumMap<>(CommandList.class);
+
+ cmdArgs.put(WAL, asList("print", "delete"));
+
+ String warning = String.format(
+ "For use experimental command add %s=true to JVM_OPTS in %s",
+ IGNITE_ENABLE_EXPERIMENTAL_COMMAND,
+ UTILITY_NAME
+ );
+
+ stream(CommandList.values()).filter(cmd -> cmd.command().experimental())
+ .peek(cmd -> assertTrue(cmdArgs.containsKey(cmd)))
+ .forEach(cmd -> cmdArgs.get(cmd).forEach(cmdArg -> {
+ assertEquals(EXIT_CODE_OK, execute(cmd.text(), cmdArg));
+
+ assertContains(log, testOut.toString(), warning);
+ }));
+ }
+
+ /**
+ * Checking for contains or not of experimental commands in output of the
+ * --help control.sh command.
+ *
+ * @param contains Check contains or not.
+ */
+ private void checkExperimentalCmdInHelpOutput(boolean contains) {
+ execHelpCmd(helpOut -> {
+ stream(CommandList.values()).filter(cmd -> cmd.command().experimental())
+ .forEach(cmd -> {
+ if (contains)
+ assertContains(log, helpOut, cmd.text());
+ else
+ assertNotContains(log, helpOut, cmd.text());
+ });
+ });
+ }
+
+ /**
+ * Check that when executing the "--help" control.sh command, the output
+ * will contain non-experimental commands.
+ */
+ private void checkContainsNotExperimentalCmdInHelpOutput() {
+ execHelpCmd(helpOut -> {
+ stream(CommandList.values()).filter(cmd -> !cmd.command().experimental())
+ .forEach(cmd -> assertContains(log, helpOut, cmd.text()));
+ });
+ }
+
+ /**
+ * Executing the command "--help" control.sh with transfer of output to
+ * consumer.
+ *
+ * @param consumer Consumer.
+ */
+ private void execHelpCmd(Consumer<String> consumer) {
+ assert nonNull(consumer);
+
injectTestSystemOut();
- String warning = String.format("For use experimental command add %s=true to JVM_OPTS in %s",
- IGNITE_ENABLE_EXPERIMENTAL_COMMAND, UTILITY_NAME);
+ execute("--help");
- of("print", "delete")
- .peek(c -> assertEquals(EXIT_CODE_OK, execute(WAL.text(), c)))
- .forEach(c -> assertContains(log, testOut.toString(), warning));
+ consumer.accept(testOut.toString());
}
}