You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by dg...@apache.org on 2019/06/27 14:39:27 UTC
[ignite] branch master updated: IGNITE-11869 Rework control.sh
tests structure - Fixes #6564.
This is an automated email from the ASF dual-hosted git repository.
dgovorukhin 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 b38ab54 IGNITE-11869 Rework control.sh tests structure - Fixes #6564.
b38ab54 is described below
commit b38ab5489daefd35c440ed31d8db4edcd44295d4
Author: Sergey Antonov <an...@gmail.com>
AuthorDate: Thu Jun 27 17:39:11 2019 +0300
IGNITE-11869 Rework control.sh tests structure - Fixes #6564.
Signed-off-by: Dmitriy Govorukhin <dm...@gmail.com>
---
.../cache/verify/IdleVerifyResultV2.java | 14 +-
.../apache/ignite/internal/util/lang/GridFunc.java | 40 ++
.../apache/ignite/testframework/GridTestUtils.java | 82 ++++
.../util/GridCommandHandlerAbstractTest.java | 203 +++++++++
.../apache/ignite/util/GridCommandHandlerTest.java | 478 ++++++++-------------
.../util/GridCommandHandlerIndexingTest.java | 69 ++-
6 files changed, 584 insertions(+), 302 deletions(-)
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/verify/IdleVerifyResultV2.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/verify/IdleVerifyResultV2.java
index d5e9d36..b6b347c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/verify/IdleVerifyResultV2.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/verify/IdleVerifyResultV2.java
@@ -27,6 +27,7 @@ import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
+import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
import org.apache.ignite.internal.util.typedef.F;
@@ -159,7 +160,18 @@ public class IdleVerifyResultV2 extends VisorDataTransferObject {
print(printer, false);
if (!F.isEmpty(exceptions)) {
- File f = new File(IDLE_VERIFY_FILE_PREFIX + LocalDateTime.now().format(TIME_FORMATTER) + ".txt");
+ File wd = null;
+
+ try {
+ wd = U.resolveWorkDirectory(U.defaultWorkDirectory(), "", false);
+ }
+ catch (IgniteCheckedException e) {
+ printer.accept("Can't find work directory. " + e.getMessage() + "\n");
+
+ e.printStackTrace();
+ }
+
+ File f = new File(wd, IDLE_VERIFY_FILE_PREFIX + LocalDateTime.now().format(TIME_FORMATTER) + ".txt");
try (PrintWriter pw = new PrintWriter(f)) {
print(pw::write, true);
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
index 64213c7..8fe1a67 100755
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
@@ -2796,6 +2796,46 @@ public class GridFunc {
}
/**
+ * Check's that {@code val} contains ignore case in collection {@code col}.
+ *
+ * @param col Collection of values.
+ * @param val Checked value.
+ * @return {@code true}, if at least one element of {@code col} and {@code @val} are equal ignore case, and
+ * {@code false} otherwise.
+ */
+ public static boolean constainsStringIgnoreCase(@Nullable Collection<String> col, String val) {
+ if (F.isEmpty(col))
+ return false;
+
+ for (String v : col) {
+ if (v.equalsIgnoreCase(val))
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Check's that {@code val} contains ignore case in array {@code arr}.
+ *
+ * @param arr Array of values.
+ * @param val Checked value.
+ * @return {@code true}, if at least one element of {@code arr} and {@code val} are equal ignore case, and
+ * {@code false} otherwise.
+ */
+ public static boolean constainsStringIgnoreCase(@Nullable String[] arr, String val) {
+ if (F.isEmpty(arr))
+ return false;
+
+ for (String v : arr) {
+ if (v.equalsIgnoreCase(val))
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
* @param arr Array.
* @param val Value to find.
* @return {@code True} if array contains given value.
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
index 0873bfc..0d24c7c 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
@@ -114,7 +114,9 @@ import org.apache.ignite.testframework.junits.GridAbstractTest;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
/**
* Utility class for tests.
@@ -299,6 +301,86 @@ public final class GridTestUtils {
// }
/**
+ * Checks that string {@param str} doesn't contains substring {@param substr}. Logs both strings
+ * and throws {@link java.lang.AssertionError}, if contains.
+ *
+ * @param log Logger (optional).
+ * @param str String.
+ * @param substr Substring.
+ */
+ public static void assertNotContains(@Nullable IgniteLogger log, String str, String substr) {
+ try {
+ assertFalse(str.contains(substr));
+ } catch (AssertionError e) {
+ U.warn(log, String.format("String contain substring: '%s', but shouldn't:", substr));
+ U.warn(log, "String:");
+ U.warn(log, str);
+
+ throw e;
+ }
+ }
+
+ /**
+ * Checks that string {@param str} contains substring {@param substr}. Logs both strings
+ * and throws {@link java.lang.AssertionError}, if not.
+ *
+ * @param log Logger (optional).
+ * @param str String.
+ * @param substr Substring.
+ */
+ public static void assertContains(@Nullable IgniteLogger log, String str, String substr) {
+ try {
+ assertTrue(str.contains(substr));
+ } catch (AssertionError e) {
+ U.warn(log, String.format("String does not contain substring: '%s':", substr));
+ U.warn(log, "String:");
+ U.warn(log, str);
+
+ throw e;
+ }
+ }
+
+ /**
+ * Checks that collection {@param col} contains string {@param str}. Logs collection, string
+ * and throws {@link java.lang.AssertionError}, if not.
+ *
+ * @param log Logger (optional).
+ * @param col Collection.
+ * @param str String.
+ */
+ public static <C extends Collection<String>> void assertContains(@Nullable IgniteLogger log, C col, String str) {
+ try {
+ assertTrue(col.contains(str));
+ } catch (AssertionError e) {
+ U.warn(log, String.format("Collection does not contain string: '%s':", str));
+ U.warn(log, "Collection:");
+ U.warn(log, col);
+
+ throw e;
+ }
+ }
+
+ /**
+ * Checks that collection {@param col} doesn't contains string {@param str}. Logs collection, string
+ * and throws {@link java.lang.AssertionError}, if contains.
+ *
+ * @param log Logger (optional).
+ * @param col Collection.
+ * @param str String.
+ */
+ public static <C extends Collection<String>> void assertNotContains(@Nullable IgniteLogger log, C col, String str) {
+ try {
+ assertFalse(col.contains(str));
+ } catch (AssertionError e) {
+ U.warn(log, String.format("Collection contain string: '%s' but shouldn't:", str));
+ U.warn(log, "Collection:");
+ U.warn(log, col);
+
+ throw e;
+ }
+ }
+
+ /**
* Checks whether callable throws expected exception or not.
*
* @param log Logger (optional).
diff --git a/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerAbstractTest.java
new file mode 100644
index 0000000..69bc64c
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerAbstractTest.java
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.util;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.ignite.configuration.AtomicConfiguration;
+import org.apache.ignite.configuration.ConnectorConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.WALMode;
+import org.apache.ignite.internal.TestRecordingCommunicationSpi;
+import org.apache.ignite.internal.commandline.CommandHandler;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static java.nio.file.Files.delete;
+import static java.nio.file.Files.newDirectoryStream;
+import static java.util.Arrays.asList;
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_BASELINE_AUTO_ADJUST_ENABLED;
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_ENABLE_EXPERIMENTAL_COMMAND;
+import static org.apache.ignite.internal.processors.cache.verify.VerifyBackupPartitionsDumpTask.IDLE_DUMP_FILE_PREFIX;
+
+/**
+ *
+ */
+public class GridCommandHandlerAbstractTest extends GridCommonAbstractTest {
+ /** Option is used for auto confirmation. */
+ protected static final String CMD_AUTO_CONFIRMATION = "--yes";
+
+ /** System out. */
+ protected PrintStream sysOut;
+
+ /** Test out - can be injected via {@link #injectTestSystemOut()} instead of System.out and analyzed in test. */
+ protected ByteArrayOutputStream testOut;
+
+ /** Atomic configuration. */
+ protected AtomicConfiguration atomicConfiguration;
+
+ /** Additional data region configuration. */
+ protected DataRegionConfiguration dataRegionConfiguration;
+
+ /** Checkpoint frequency. */
+ protected long checkpointFreq;
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ super.afterTestsStopped();
+
+ GridTestUtils.cleanIdleVerifyLogFiles();
+
+ System.clearProperty(IGNITE_BASELINE_AUTO_ADJUST_ENABLED);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ System.setProperty(IGNITE_BASELINE_AUTO_ADJUST_ENABLED, "false");
+
+ super.beforeTestsStarted();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ System.setProperty(IGNITE_ENABLE_EXPERIMENTAL_COMMAND, "true");
+
+ cleanPersistenceDir();
+
+ stopAllGrids();
+
+ sysOut = System.out;
+
+ testOut = new ByteArrayOutputStream(1024 * 1024);
+
+ checkpointFreq = DataStorageConfiguration.DFLT_CHECKPOINT_FREQ;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+
+ cleanPersistenceDir();
+
+ // Delete idle-verify dump files.
+ try (DirectoryStream<Path> files = newDirectoryStream(
+ Paths.get(U.defaultWorkDirectory()),
+ entry -> entry.toFile().getName().startsWith(IDLE_DUMP_FILE_PREFIX)
+ )
+ ) {
+ for (Path path : files)
+ delete(path);
+ }
+
+ System.clearProperty(IGNITE_ENABLE_EXPERIMENTAL_COMMAND);
+
+ System.setOut(sysOut);
+
+ log.info("----------------------------------------");
+ if (testOut != null)
+ System.out.println(testOut.toString());
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+ if (atomicConfiguration != null)
+ cfg.setAtomicConfiguration(atomicConfiguration);
+
+ cfg.setCommunicationSpi(new TestRecordingCommunicationSpi());
+
+ cfg.setConnectorConfiguration(new ConnectorConfiguration());
+
+ DataStorageConfiguration memCfg = new DataStorageConfiguration()
+ .setCheckpointFrequency(checkpointFreq)
+ .setDefaultDataRegionConfiguration(new DataRegionConfiguration().setMaxSize(50L * 1024 * 1024));
+
+ if (dataRegionConfiguration != null)
+ memCfg.setDataRegionConfigurations(dataRegionConfiguration);
+
+ cfg.setDataStorageConfiguration(memCfg);
+
+ DataStorageConfiguration dsCfg = cfg.getDataStorageConfiguration();
+ dsCfg.setWalMode(WALMode.LOG_ONLY);
+ dsCfg.getDefaultDataRegionConfiguration().setPersistenceEnabled(true);
+
+ cfg.setConsistentId(igniteInstanceName);
+
+ cfg.setClientMode(igniteInstanceName.startsWith("client"));
+
+ return cfg;
+ }
+
+ /**
+ * @param args Arguments.
+ * @return Result of execution.
+ */
+ protected int execute(String... args) {
+ return execute(new ArrayList<>(asList(args)));
+ }
+
+ /**
+ * @param args Arguments.
+ * @return Result of execution
+ */
+ protected int execute(List<String> args) {
+ return execute(new CommandHandler(), args);
+ }
+
+ /**
+ * @param hnd Handler.
+ * @param args Arguments.
+ * @return Result of execution
+ */
+ protected int execute(CommandHandler hnd, String... args) {
+ return execute(hnd, new ArrayList<>(asList(args)));
+ }
+
+ /** */
+ protected int execute(CommandHandler hnd, List<String> args) {
+ if (!F.isEmpty(args) && !"--help".equalsIgnoreCase(args.get(0)))
+ addExtraArguments(args);
+
+ return hnd.execute(args);
+ }
+
+ /**
+ * Adds extra arguments required for tests.
+ *
+ * @param args Incoming arguments;
+ */
+ protected void addExtraArguments(List<String> args) {
+ // Add force to avoid interactive confirmation.
+ args.add(CMD_AUTO_CONFIRMATION);
+ }
+
+ /** */
+ protected void injectTestSystemOut() {
+ System.setOut(new PrintStream(testOut));
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java b/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
index eb0e82c..7b26636 100644
--- a/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
@@ -17,13 +17,10 @@
package org.apache.ignite.util;
-import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
-import java.io.PrintStream;
import java.io.RandomAccessFile;
import java.io.Serializable;
-import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -41,6 +38,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.LongAdder;
import java.util.regex.Matcher;
@@ -60,11 +58,7 @@ import org.apache.ignite.cluster.BaselineNode;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.configuration.AtomicConfiguration;
import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.ConnectorConfiguration;
import org.apache.ignite.configuration.DataRegionConfiguration;
-import org.apache.ignite.configuration.DataStorageConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.configuration.WALMode;
import org.apache.ignite.internal.GridJobExecuteResponse;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.IgniteInternalFuture;
@@ -108,7 +102,6 @@ import org.apache.ignite.lang.IgniteInClosure;
import org.apache.ignite.lang.IgnitePredicate;
import org.apache.ignite.plugin.extensions.communication.Message;
import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.apache.ignite.transactions.Transaction;
import org.apache.ignite.transactions.TransactionRollbackException;
import org.apache.ignite.transactions.TransactionState;
@@ -117,11 +110,7 @@ import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import static java.io.File.separatorChar;
-import static java.nio.file.Files.delete;
-import static java.nio.file.Files.newDirectoryStream;
import static java.util.Arrays.asList;
-import static org.apache.ignite.IgniteSystemProperties.IGNITE_BASELINE_AUTO_ADJUST_ENABLED;
-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;
import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_INVALID_ARGUMENTS;
@@ -130,8 +119,9 @@ import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_UN
import static org.apache.ignite.internal.commandline.OutputFormat.MULTI_LINE;
import static org.apache.ignite.internal.commandline.OutputFormat.SINGLE_LINE;
import static org.apache.ignite.internal.commandline.cache.CacheSubcommands.HELP;
-import static org.apache.ignite.internal.processors.cache.verify.VerifyBackupPartitionsDumpTask.IDLE_DUMP_FILE_PREFIX;
import static org.apache.ignite.internal.processors.diagnostic.DiagnosticProcessor.DEFAULT_TARGET_FOLDER;
+import static org.apache.ignite.testframework.GridTestUtils.assertContains;
+import static org.apache.ignite.testframework.GridTestUtils.assertNotContains;
import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;
import static org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC;
import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
@@ -140,94 +130,32 @@ import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED
/**
* Command line handler test.
*/
-public class GridCommandHandlerTest extends GridCommonAbstractTest {
- /** System out. */
- protected PrintStream sysOut;
-
- /** Test out - can be injected via {@link #injectTestSystemOut()} instead of System.out and analyzed in test. */
- protected ByteArrayOutputStream testOut;
-
- /** Option is used for auto confirmation. */
- private static final String CMD_AUTO_CONFIRMATION = "--yes";
-
- /** Atomic configuration. */
- private AtomicConfiguration atomicConfiguration;
-
- /** Additional data region configuration. */
- private DataRegionConfiguration dataRegionConfiguration;
-
+public class GridCommandHandlerTest extends GridCommandHandlerAbstractTest {
/** */
private File defaultDiagnosticDir;
/** */
private File customDiagnosticDir;
- /**
- * @return Folder in work directory.
- * @throws IgniteCheckedException If failed to resolve folder name.
- */
- protected File folder(String folder) throws IgniteCheckedException {
- return U.resolveWorkDirectory(U.defaultWorkDirectory(), folder, false);
- }
-
/** {@inheritDoc} */
- @Override protected void afterTestsStopped() throws Exception {
- super.afterTestsStopped();
-
- GridTestUtils.cleanIdleVerifyLogFiles();
-
- System.clearProperty(IGNITE_BASELINE_AUTO_ADJUST_ENABLED);
- }
-
- /** {@inheritDoc} */
- @Override protected void beforeTestsStarted() throws Exception {
- System.setProperty(IGNITE_BASELINE_AUTO_ADJUST_ENABLED, "false");
-
- super.beforeTestsStarted();
+ @Override public String getTestIgniteInstanceName() {
+ return "gridCommandHandlerTest";
}
/** {@inheritDoc} */
- @Override protected void beforeTest() throws Exception {
- System.setProperty(IGNITE_ENABLE_EXPERIMENTAL_COMMAND, "true");
-
- cleanPersistenceDir();
-
- stopAllGrids();
-
- initDiagnosticDir();
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
cleanDiagnosticDir();
-
- sysOut = System.out;
-
- testOut = new ByteArrayOutputStream(1024 * 1024);
}
/** {@inheritDoc} */
- @Override protected void afterTest() throws Exception {
- stopAllGrids();
-
- cleanPersistenceDir();
-
- // Delete idle-verify dump files.
- try (DirectoryStream<Path> files = newDirectoryStream(
- Paths.get(U.defaultWorkDirectory()),
- entry -> entry.toFile().getName().startsWith(IDLE_DUMP_FILE_PREFIX)
- )
- ) {
- for (Path path : files)
- delete(path);
- }
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
cleanDiagnosticDir();
- System.clearProperty(IGNITE_ENABLE_EXPERIMENTAL_COMMAND);
-
- System.setOut(sysOut);
-
- log.info("----------------------------------------");
- if (testOut != null)
- System.out.println(testOut.toString());
+ initDiagnosticDir();
}
/**
@@ -249,48 +177,6 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
U.delete(customDiagnosticDir);
}
- /**
- *
- */
- protected void injectTestSystemOut() {
- System.setOut(new PrintStream(testOut));
- }
-
- /** {@inheritDoc} */
- @Override public String getTestIgniteInstanceName() {
- return "gridCommandHandlerTest";
- }
-
- /** {@inheritDoc} */
- @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
- IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
-
- if (atomicConfiguration != null)
- cfg.setAtomicConfiguration(atomicConfiguration);
-
- cfg.setCommunicationSpi(new TestRecordingCommunicationSpi());
-
- cfg.setConnectorConfiguration(new ConnectorConfiguration());
-
- DataStorageConfiguration memCfg = new DataStorageConfiguration()
- .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
- .setMaxSize(50L * 1024 * 1024));
-
- if (dataRegionConfiguration != null)
- memCfg.setDataRegionConfigurations(dataRegionConfiguration);
-
- cfg.setDataStorageConfiguration(memCfg);
-
- DataStorageConfiguration dsCfg = cfg.getDataStorageConfiguration();
- dsCfg.setWalMode(WALMode.LOG_ONLY);
- dsCfg.getDefaultDataRegionConfiguration().setPersistenceEnabled(true);
-
- cfg.setConsistentId(igniteInstanceName);
-
- cfg.setClientMode(igniteInstanceName.startsWith("client"));
-
- return cfg;
- }
/**
* Test activation works via control.sh
@@ -309,53 +195,6 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
}
/**
- * @param args Arguments.
- * @return Result of execution.
- */
- protected int execute(String... args) {
- return execute(new ArrayList<>(asList(args)));
- }
-
- /**
- * @param args Arguments.
- * @return Result of execution
- */
- protected int execute(List<String> args) {
- if (!F.isEmpty(args) && !"--help".equalsIgnoreCase(args.get(0))) {
- // Add force to avoid interactive confirmation.
- args.add(CMD_AUTO_CONFIRMATION);
- }
-
- return new CommandHandler().execute(args);
- }
-
- /**
- * @param hnd Handler.
- * @param args Arguments.
- * @return Result of execution
- */
- protected int execute(CommandHandler hnd, ArrayList<String> args) {
- // Add force to avoid interactive confirmation
- args.add(CMD_AUTO_CONFIRMATION);
-
- return hnd.execute(args);
- }
-
- /**
- * @param hnd Handler.
- * @param args Arguments.
- * @return Result of execution
- */
- protected int execute(CommandHandler hnd, String... args) {
- ArrayList<String> args0 = new ArrayList<>(asList(args));
-
- // Add force to avoid interactive confirmation
- args0.add(CMD_AUTO_CONFIRMATION);
-
- return hnd.execute(args0);
- }
-
- /**
* Test deactivation works via control.sh
*
* @throws Exception If failed.
@@ -487,21 +326,21 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
assertEquals(EXIT_CODE_OK, execute("--cache", "find_garbage", "--port", "11212"));
- assertTrue(testOut.toString().contains("garbage not found"));
+ assertContains(log, testOut.toString(), "garbage not found");
testOut.reset();
assertEquals(EXIT_CODE_OK, execute("--cache", "find_garbage",
ignite(0).localNode().id().toString(), "--port", "11212"));
- assertTrue(testOut.toString().contains("garbage not found"));
+ assertContains(log, testOut.toString(), "garbage not found");
testOut.reset();
assertEquals(EXIT_CODE_OK, execute("--cache", "find_garbage",
"groupGarbage", "--port", "11212"));
- assertTrue(testOut.toString().contains("garbage not found"));
+ assertContains(log, testOut.toString(), "garbage not found");
}
/**
@@ -613,7 +452,7 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute("--baseline", "remove", offlineNodeConsId));
- assertTrue(testOut.toString().contains("Changing BaselineTopology on inactive cluster is not allowed."));
+ assertContains(log, testOut.toString(), "Changing BaselineTopology on inactive cluster is not allowed.");
}
/**
@@ -989,7 +828,7 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
String out = testOut.toString();
for (GridCacheVersion nearXid : nearXids)
- assertTrue(nearXid.toString(), out.contains(nearXid.toString()));
+ assertContains(log, out, nearXid.toString());
}
finally {
unlockLatch.countDown();
@@ -1053,18 +892,18 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
testOut.reset();
- assertTrue(out.contains("Transaction was found in completed versions history of the following nodes:"));
+ assertContains(log, out, "Transaction was found in completed versions history of the following nodes:");
if (out.contains(TransactionState.COMMITTED.name())) {
commitMatched = true;
- assertFalse(out.contains(TransactionState.ROLLED_BACK.name()));
+ assertNotContains(log, out, TransactionState.ROLLED_BACK.name());
}
if (out.contains(TransactionState.ROLLED_BACK.name())) {
rollbackMatched = true;
- assertFalse(out.contains(TransactionState.COMMITTED.name()));
+ assertNotContains(log, out, TransactionState.COMMITTED.name());
}
}
@@ -1336,7 +1175,7 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute("--baseline", "add", consistentIDs));
- assertTrue(testOut.toString().contains("Changing BaselineTopology on inactive cluster is not allowed."));
+ assertContains(log, testOut.toString(), "Changing BaselineTopology on inactive cluster is not allowed.");
consistentIDs =
getTestIgniteInstanceName(1) + ", " +
@@ -1345,8 +1184,10 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute("--baseline", "add", consistentIDs));
- assertTrue(testOut.toString(), testOut.toString().contains("Node not found for consistent ID:"));
- assertFalse(testOut.toString(), testOut.toString().contains(getTestIgniteInstanceName() + "1"));
+ String out = testOut.toString();
+
+ assertContains(log, out, "Node not found for consistent ID:");
+ assertNotContains(log, out, getTestIgniteInstanceName() + "1");
}
/**
@@ -1361,7 +1202,7 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
for (CacheSubcommands cmd : CacheSubcommands.values()) {
if (cmd != HELP) {
- assertTrue(cmd.text(), output.contains(cmd.toString()));
+ assertContains(log, output, cmd.toString());
Class<? extends Enum<? extends CommandArg>> args = cmd.getCommandArgs();
@@ -1396,8 +1237,10 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
assertEquals(EXIT_CODE_OK, execute("--help"));
+ String testOutStr = testOut.toString();
+
for (CommandList cmd : CommandList.values())
- assertTrue(cmd.text(), testOut.toString().contains(cmd.toString()));
+ assertContains(log, testOutStr, cmd.toString());
}
/**
@@ -1415,7 +1258,7 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
assertEquals(EXIT_CODE_OK, execute("--cache", "idle_verify"));
- assertContains(testOut.toString(), "no conflicts have been found");
+ assertContains(log, testOut.toString(), "no conflicts have been found");
HashSet<Integer> clearKeys = new HashSet<>(asList(1, 2, 3, 4, 5, 6));
@@ -1423,7 +1266,7 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
assertEquals(EXIT_CODE_OK, execute("--cache", "idle_verify"));
- assertContains(testOut.toString(), "conflict partitions");
+ assertContains(log, testOut.toString(), "conflict partitions");
}
/**
@@ -1451,7 +1294,7 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
assertEquals(EXIT_CODE_OK, execute("--cache", "idle_verify", DEFAULT_CACHE_NAME));
- assertContains(testOut.toString(), "no conflicts have been found");
+ assertContains(log, testOut.toString(), "no conflicts have been found");
}
/**
@@ -1471,7 +1314,7 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
assertEquals(EXIT_CODE_OK, execute("--cache", "idle_verify"));
- assertTrue(testOut.toString().contains("no conflicts have been found"));
+ assertContains(log, testOut.toString(), "no conflicts have been found");
GridCacheContext<Object, Object> cacheCtx = ignite.cachex(DEFAULT_CACHE_NAME).context();
@@ -1481,7 +1324,7 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
assertEquals(EXIT_CODE_OK, execute("--cache", "idle_verify"));
- assertTrue(testOut.toString().contains("found 2 conflict partitions"));
+ assertContains(log, testOut.toString(), "found 2 conflict partitions");
}
/**
@@ -1510,9 +1353,9 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
String zeroUpdateCntrs = new String(Files.readAllBytes(Paths.get(fileNameMatcher.group(1))));
- assertTrue(zeroUpdateCntrs.contains("idle_verify check has finished, found " + emptyPartId + " partitions"));
- assertTrue(zeroUpdateCntrs.contains("1 partitions was skipped"));
- assertTrue(zeroUpdateCntrs.contains("idle_verify check has finished, no conflicts have been found."));
+ assertContains(log, zeroUpdateCntrs, "idle_verify check has finished, found " + emptyPartId + " partitions");
+ assertContains(log, zeroUpdateCntrs, "1 partitions was skipped");
+ assertContains(log, zeroUpdateCntrs, "idle_verify check has finished, no conflicts have been found.");
assertSort(emptyPartId, zeroUpdateCntrs);
@@ -1532,9 +1375,9 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
String nonZeroUpdateCntrs = new String(Files.readAllBytes(Paths.get(fileNameMatcher.group(1))));
- assertTrue(nonZeroUpdateCntrs.contains("idle_verify check has finished, found " + 31 + " partitions"));
- assertTrue(nonZeroUpdateCntrs.contains("1 partitions was skipped"));
- assertTrue(nonZeroUpdateCntrs.contains("idle_verify check has finished, no conflicts have been found."));
+ assertContains(log, nonZeroUpdateCntrs, "idle_verify check has finished, found " + 31 + " partitions");
+ assertContains(log, nonZeroUpdateCntrs, "1 partitions was skipped");
+ assertContains(log, nonZeroUpdateCntrs, "idle_verify check has finished, no conflicts have been found.");
assertSort(31, zeroUpdateCntrs);
@@ -1574,10 +1417,10 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
if (fileNameMatcher.find()) {
String dumpWithZeros = new String(Files.readAllBytes(Paths.get(fileNameMatcher.group(1))));
- assertTrue(dumpWithZeros.contains("idle_verify check has finished, found " + parts + " partitions"));
- assertTrue(dumpWithZeros.contains("Partition: PartitionKeyV2 [grpId=1544803905, grpName=default, partId=0]"));
- assertTrue(dumpWithZeros.contains("updateCntr=0, size=0, partHash=0"));
- assertTrue(dumpWithZeros.contains("no conflicts have been found"));
+ assertContains(log, dumpWithZeros, "idle_verify check has finished, found " + parts + " partitions");
+ assertContains(log, dumpWithZeros, "Partition: PartitionKeyV2 [grpId=1544803905, grpName=default, partId=0]");
+ assertContains(log, dumpWithZeros, "updateCntr=0, size=0, partHash=0");
+ assertContains(log, dumpWithZeros, "no conflicts have been found");
assertSort(parts, dumpWithZeros);
}
@@ -1585,13 +1428,13 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
if (fileNameMatcher.find()) {
String dumpWithoutZeros = new String(Files.readAllBytes(Paths.get(fileNameMatcher.group(1))));
- assertTrue(dumpWithoutZeros.contains("idle_verify check has finished, found " + keysCount + " partitions"));
- assertTrue(dumpWithoutZeros.contains((parts - keysCount) + " partitions was skipped"));
- assertTrue(dumpWithoutZeros.contains("Partition: PartitionKeyV2 [grpId=1544803905, grpName=default, partId="));
+ assertContains(log, dumpWithoutZeros, "idle_verify check has finished, found " + keysCount + " partitions");
+ assertContains(log, dumpWithoutZeros, (parts - keysCount) + " partitions was skipped");
+ assertContains(log, dumpWithoutZeros, "Partition: PartitionKeyV2 [grpId=1544803905, grpName=default, partId=");
- assertFalse(dumpWithoutZeros.contains("updateCntr=0, size=0, partHash=0"));
+ assertNotContains(log, dumpWithoutZeros, "updateCntr=0, size=0, partHash=0");
- assertTrue(dumpWithoutZeros.contains("no conflicts have been found"));
+ assertContains(log, dumpWithoutZeros, "no conflicts have been found");
assertSort(keysCount, dumpWithoutZeros);
}
@@ -1605,8 +1448,7 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
* @throws Exception if failed
*/
@Test
- public void testCacheIdleVerifyMultipleCacheFilterOptions()
- throws Exception {
+ public void testCacheIdleVerifyMultipleCacheFilterOptions() throws Exception {
IgniteEx ignite = startGrids(2);
ignite.cluster().active(true);
@@ -1697,6 +1539,61 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
);
}
+ /** */
+ @Test
+ public void testIdleVerifyCheckCrcFailsOnNotIdleCluster() throws Exception {
+ checkpointFreq = 100L;
+
+ IgniteEx node = startGrids(2);
+
+ node.cluster().active(true);
+
+ IgniteCache cache = node.createCache(new CacheConfiguration<>()
+ .setAffinity(new RendezvousAffinityFunction(false, 32))
+ .setBackups(1)
+ .setName(DEFAULT_CACHE_NAME)
+ );
+
+ AtomicBoolean stopFlag = new AtomicBoolean();
+
+ Thread loadThread = new Thread(() -> {
+ ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+ while (!stopFlag.get()) {
+ cache.put(rnd.nextInt(), rnd.nextInt());
+
+ if (Thread.interrupted())
+ break;
+ }
+ });
+
+ try {
+ loadThread.start();
+
+ doSleep(checkpointFreq);
+
+ injectTestSystemOut();
+
+ assertEquals(EXIT_CODE_OK, execute("--cache", "idle_verify", "--check-crc"));
+ }
+ finally {
+ stopFlag.set(true);
+
+ loadThread.join();
+ }
+
+ String out = testOut.toString();
+
+ assertContains(log, out, "idle_verify failed");
+ assertContains(log, out, "See log for additional information.");
+
+ String logFileName = (out.split("See log for additional information. ")[1]).split(".txt")[0];
+
+ String logFile = new String(Files.readAllBytes(new File(logFileName + ".txt").toPath()));
+
+ assertContains(log, logFile, "Checkpoint with dirty pages started! Cluster not idle!");
+ }
+
/**
* Runs idle_verify with specified arguments and checks the dump if dump option was present.
*
@@ -1724,7 +1621,7 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
Matcher fileNameMatcher = dumpFileNameMatcher();
if (fileNameMatcher.find()) {
- assertTrue(argsSet.contains("--dump"));
+ assertContains(log, argsSet, "--dump");
Path filePath = Paths.get(fileNameMatcher.group(1));
@@ -1732,38 +1629,18 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
Files.delete(filePath);
- assertContains(dump, outputExp);
+ assertContains(log, dump, outputExp);
if (cmdExp != null)
- assertContains(dump, cmdExp);
+ assertContains(log, dump, cmdExp);
}
else {
- assertFalse(argsSet.contains("--dump"));
+ assertNotContains(log, argsSet, "--dump");
- assertContains(testOut.toString(), outputExp);
+ assertContains(log, testOut.toString(), outputExp);
}
- }
- else
- assertContains(testOut.toString(), outputExp);
- }
-
- /**
- * Checks that string {@param str} contains substring {@param substr}. Logs both strings and throws {@link
- * java.lang.AssertionError}, if not.
- *
- * @param str string
- * @param substr substring
- */
- private void assertContains(String str, String substr) {
- try {
- assertTrue(str.contains(substr));
- }
- catch (AssertionError e) {
- log.warning(String.format("String does not contain substring: '%s':", substr));
- log.warning("String:");
- log.warning(str);
- throw e;
- }
+ } else
+ assertContains(log, testOut.toString(), outputExp);
}
/**
@@ -1829,7 +1706,7 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
log.info(dumpWithConflicts);
- assertTrue(dumpWithConflicts.contains("found 2 conflict partitions: [counterConflicts=1, hashConflicts=1]"));
+ assertContains(log, dumpWithConflicts, "found 2 conflict partitions: [counterConflicts=1, hashConflicts=1]");
}
else
fail("Should be found dump with conflicts");
@@ -1929,8 +1806,8 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
String out = testOut.toString();
- assertTrue(out.contains("idle_verify failed on 1 node."));
- assertTrue(out.contains("See log for additional information."));
+ assertContains(log, out, "idle_verify failed on 1 node.");
+ assertContains(log, out, "See log for additional information.");
}
/** */
@@ -1949,8 +1826,8 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
String outputStr = testOut.toString();
- assertTrue(outputStr, outputStr.contains("idle_verify failed on 1 node."));
- assertTrue(outputStr, outputStr.contains("idle_verify check has finished, no conflicts have been found."));
+ assertContains(log, outputStr, "idle_verify failed on 1 node.");
+ assertContains(log, outputStr, "idle_verify check has finished, no conflicts have been found.");
}
/** */
@@ -2027,9 +1904,9 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
if (fileNameMatcher.find()) {
String dumpWithConflicts = new String(Files.readAllBytes(Paths.get(fileNameMatcher.group(1))));
- assertTrue(dumpWithConflicts.contains("Idle verify failed on nodes:"));
+ assertContains(log, dumpWithConflicts, "Idle verify failed on nodes:");
- assertTrue(dumpWithConflicts.contains("Node ID: " + unstableNodeId));
+ assertContains(log, dumpWithConflicts, "Node ID: " + unstableNodeId);
}
else
fail("Should be found dump with conflicts");
@@ -2089,8 +1966,11 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
if (fileNameMatcher.find()) {
String dumpWithConflicts = new String(Files.readAllBytes(Paths.get(fileNameMatcher.group(1))));
- assertTrue(dumpWithConflicts.contains("found 4 conflict partitions: [counterConflicts=2, " +
- "hashConflicts=2]"));
+ assertContains(
+ log,
+ dumpWithConflicts,
+ "found 4 conflict partitions: [counterConflicts=2, hashConflicts=2]"
+ );
}
else
fail("Should be found dump with conflicts");
@@ -2156,8 +2036,11 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
if (fileNameMatcher.find()) {
String dumpWithConflicts = new String(Files.readAllBytes(Paths.get(fileNameMatcher.group(1))));
- assertTrue(dumpWithConflicts.contains("found 1 conflict partitions: [counterConflicts=0, " +
- "hashConflicts=1]"));
+ assertContains(
+ log,
+ dumpWithConflicts,
+ "found 1 conflict partitions: [counterConflicts=0, hashConflicts=1]"
+ );
}
else
fail("Should be found dump with conflicts");
@@ -2197,7 +2080,7 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
if (fileNameMatcher.find()) {
String dumpWithConflicts = new String(Files.readAllBytes(Paths.get(fileNameMatcher.group(1))));
- assertTrue(dumpWithConflicts, dumpWithConflicts.contains("There are no caches matching given filter options."));
+ assertContains(log, dumpWithConflicts, "There are no caches matching given filter options.");
}
else
fail("Should be found dump with conflicts");
@@ -2243,9 +2126,9 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
if (fileNameMatcher.find()) {
String dumpWithConflicts = new String(Files.readAllBytes(Paths.get(fileNameMatcher.group(1))));
- assertTrue(dumpWithConflicts, dumpWithConflicts.contains("idle_verify check has finished, found 32 partitions"));
- assertTrue(dumpWithConflicts, dumpWithConflicts.contains("default_third"));
- assertTrue(!dumpWithConflicts.contains("shared_grp"));
+ assertContains(log, dumpWithConflicts, "idle_verify check has finished, found 32 partitions");
+ assertContains(log, dumpWithConflicts, "default_third");
+ assertNotContains(log, dumpWithConflicts, "shared_grp");
}
else
fail("Should be found dump with conflicts");
@@ -2284,7 +2167,7 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
assertEquals(EXIT_CODE_OK, execute("--cache", "idle_verify"));
- assertContains(testOut.toString(), "no conflicts have been found");
+ assertContains(log, testOut.toString(), "no conflicts have been found");
startGrid(2);
@@ -2292,7 +2175,7 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
assertEquals(EXIT_CODE_OK, execute("--cache", "idle_verify"));
- assertContains(testOut.toString(), "MOVING partitions");
+ assertContains(log, testOut.toString(), "MOVING partitions");
}
/**
@@ -2357,11 +2240,13 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
l2.countDown();
- assertTrue(testOut.toString().contains("TxEntry"));
- assertTrue(testOut.toString().contains("op=READ"));
- assertTrue(testOut.toString().contains("op=CREATE"));
- assertTrue(testOut.toString().contains("id=" + ignite(0).cluster().localNode().id()));
- assertTrue(testOut.toString().contains("id=" + ignite(1).cluster().localNode().id()));
+ String out = testOut.toString();
+
+ assertContains(log, out, "TxEntry");
+ assertContains(log, out, "op=READ");
+ assertContains(log, out, "op=CREATE");
+ assertContains(log, out, "id=" + ignite(0).cluster().localNode().id());
+ assertContains(log, out, "id=" + ignite(1).cluster().localNode().id());
}
finally {
svc.shutdown();
@@ -2390,8 +2275,10 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
assertEquals(EXIT_CODE_OK, execute("--cache", "list", "testSeq.*", "--seq"));
- assertTrue(testOut.toString().contains("testSeq"));
- assertTrue(testOut.toString().contains("testSeq2"));
+ String out = testOut.toString();
+
+ assertContains(log, out, "testSeq");
+ assertContains(log, out, "testSeq2");
}
/**
@@ -2416,7 +2303,7 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
assertEquals(EXIT_CODE_OK, execute("--cache", "list", ".*", "--groups"));
- assertTrue(testOut.toString().contains("G100"));
+ assertContains(log, testOut.toString(), "G100");
}
/**
@@ -2440,10 +2327,12 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
assertEquals(EXIT_CODE_OK, execute("--cache", "list", ".*"));
- assertTrue(testOut.toString().contains("cacheName=" + DEFAULT_CACHE_NAME));
- assertTrue(testOut.toString().contains("prim=32"));
- assertTrue(testOut.toString().contains("mapped=32"));
- assertTrue(testOut.toString().contains("affCls=RendezvousAffinityFunction"));
+ String out = testOut.toString();
+
+ assertContains(log, out, "cacheName=" + DEFAULT_CACHE_NAME);
+ assertContains(log, out, "prim=32");
+ assertContains(log, out, "mapped=32");
+ assertContains(log, out, "affCls=RendezvousAffinityFunction");
}
/** */
@@ -2539,17 +2428,17 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
if (outputFormat == null || SINGLE_LINE.text().equals(outputFormat)) {
for (int i = 0; i < cachesCnt; i++)
- assertTrue(outStr.contains("name=" + DEFAULT_CACHE_NAME + i));
+ assertContains(log, outStr, "name=" + DEFAULT_CACHE_NAME + i);
- assertTrue(outStr.contains("partitions=32"));
- assertTrue(outStr.contains("function=o.a.i.cache.affinity.rendezvous.RendezvousAffinityFunction"));
+ assertContains(log, outStr, "partitions=32");
+ assertContains(log, outStr, "function=o.a.i.cache.affinity.rendezvous.RendezvousAffinityFunction");
}
else if (MULTI_LINE.text().equals(outputFormat)) {
for (int i = 0; i < cachesCnt; i++)
- assertTrue(outStr.contains("[cache = '" + DEFAULT_CACHE_NAME + i + "']"));
+ assertContains(log, outStr, "[cache = '" + DEFAULT_CACHE_NAME + i + "']");
- assertTrue(outStr.contains("Affinity Partitions: 32"));
- assertTrue(outStr.contains("Affinity Function: o.a.i.cache.affinity.rendezvous.RendezvousAffinityFunction"));
+ assertContains(log, outStr, "Affinity Partitions: 32");
+ assertContains(log, outStr, "Affinity Function: o.a.i.cache.affinity.rendezvous.RendezvousAffinityFunction");
}
else
fail("Unknown output format: " + outputFormat);
@@ -2571,30 +2460,30 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
// Run distribution for all node and all cache
assertEquals(EXIT_CODE_OK, execute("--cache", "distribution", "null"));
- String log = testOut.toString();
+ String out = testOut.toString();
// Result include info by cache "default"
- assertTrue(log.contains("[next group: id=1544803905, name=default]"));
+ assertContains(log ,out, "[next group: id=1544803905, name=default]");
// Result include info by cache "ignite-sys-cache"
- assertTrue(log.contains("[next group: id=-2100569601, name=ignite-sys-cache]"));
+ assertContains(log ,out, "[next group: id=-2100569601, name=ignite-sys-cache]");
// Run distribution for all node and all cache and include additional user attribute
assertEquals(EXIT_CODE_OK, execute("--cache", "distribution", "null", "--user-attributes", "ZONE,CELL,DC"));
- log = testOut.toString();
+ out = testOut.toString();
// Find last row
- int lastRowIndex = log.lastIndexOf('\n');
+ int lastRowIndex = out.lastIndexOf('\n');
assertTrue(lastRowIndex > 0);
// Last row is empty, but the previous line contains data
- lastRowIndex = log.lastIndexOf('\n', lastRowIndex - 1);
+ lastRowIndex = out.lastIndexOf('\n', lastRowIndex - 1);
assertTrue(lastRowIndex > 0);
- String lastRow = log.substring(lastRowIndex);
+ String lastRow = out.substring(lastRowIndex);
// Since 3 user attributes have been added, the total number of columns in response should be 12 (separators 11)
assertEquals(11, lastRow.split(",").length);
@@ -2615,12 +2504,11 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
assertEquals(EXIT_CODE_OK, execute("--cache", "reset_lost_partitions", "ignite-sys-cache,default"));
- final String log = testOut.toString();
-
- assertTrue(log.contains("Reset LOST-partitions performed successfully. Cache group (name = 'ignite-sys-cache'"));
+ final String out = testOut.toString();
- assertTrue(log.contains("Reset LOST-partitions performed successfully. Cache group (name = 'default'"));
+ assertContains(log, out, "Reset LOST-partitions performed successfully. Cache group (name = 'ignite-sys-cache'");
+ assertContains(log, out, "Reset LOST-partitions performed successfully. Cache group (name = 'default'");
}
/**
@@ -2668,18 +2556,22 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
assertEquals(EXIT_CODE_OK, execute("--wal", "print"));
+ String out = testOut.toString();
+
for (String id : nodes)
- assertTrue(testOut.toString().contains(id));
+ assertContains(log, out, id);
- assertTrue(!testOut.toString().contains("error"));
+ assertNotContains(log, out, "error");
testOut.reset();
assertEquals(EXIT_CODE_OK, execute("--wal", "print", nodes.get(0)));
- assertTrue(!testOut.toString().contains(nodes.get(1)));
+ out = testOut.toString();
- assertTrue(!testOut.toString().contains("error"));
+ assertNotContains(log, out, nodes.get(1));
+
+ assertNotContains(log, out, "error");
}
/**
@@ -2702,18 +2594,22 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
assertEquals(EXIT_CODE_OK, execute("--wal", "delete"));
+ String out = testOut.toString();
+
for (String id : nodes)
- assertTrue(testOut.toString().contains(id));
+ assertContains(log, out, id);
- assertTrue(!testOut.toString().contains("error"));
+ assertNotContains(log, out, "error");
testOut.reset();
assertEquals(EXIT_CODE_OK, execute("--wal", "delete", nodes.get(0)));
- assertTrue(!testOut.toString().contains(nodes.get(1)));
+ out = testOut.toString();
+
+ assertNotContains(log, out, nodes.get(1));
- assertTrue(!testOut.toString().contains("error"));
+ assertNotContains(log, out, "error");
}
/**
@@ -2927,8 +2823,10 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
/** */
private static class IncrementClosure implements EntryProcessor<Long, Long, Void> {
/** {@inheritDoc} */
- @Override public Void process(MutableEntry<Long, Long> entry,
- Object... arguments) throws EntryProcessorException {
+ @Override public Void process(
+ MutableEntry<Long, Long> entry,
+ Object... arguments
+ ) throws EntryProcessorException {
entry.setValue(entry.exists() ? entry.getValue() + 1 : 0);
return null;
diff --git a/modules/indexing/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingTest.java b/modules/indexing/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingTest.java
index 938b682..1062100 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingTest.java
@@ -25,8 +25,10 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicBoolean;
import javax.cache.Cache;
import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteDataStreamer;
import org.apache.ignite.cache.CacheAtomicityMode;
@@ -54,13 +56,14 @@ import org.junit.Test;
import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK;
import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.INDEX_FILE_NAME;
+import static org.apache.ignite.testframework.GridTestUtils.assertContains;
/**
*
*/
-public class GridCommandHandlerIndexingTest extends GridCommandHandlerTest {
+public class GridCommandHandlerIndexingTest extends GridCommandHandlerAbstractTest {
/** Test cache name. */
- private static final String CACHE_NAME = "persons-cache-vi";
+ protected static final String CACHE_NAME = "persons-cache-vi";
/**
* Tests that validation doesn't fail if nothing is broken.
@@ -73,7 +76,7 @@ public class GridCommandHandlerIndexingTest extends GridCommandHandlerTest {
assertEquals(EXIT_CODE_OK, execute("--cache", "validate_indexes", CACHE_NAME));
- assertTrue(testOut.toString().contains("no issues found"));
+ assertContains(log, testOut.toString(), "no issues found");
}
/**
@@ -95,10 +98,11 @@ public class GridCommandHandlerIndexingTest extends GridCommandHandlerTest {
"--check-first", "10000",
"--check-through", "10"));
- assertTrue(testOut.toString().contains("issues found (listed above)"));
+ String out = testOut.toString();
- assertTrue(testOut.toString().contains(
- "Key is present in SQL index, but is missing in corresponding data page."));
+ assertContains(log, out, "issues found (listed above)");
+
+ assertContains(log, out, "Key is present in SQL index, but is missing in corresponding data page.");
}
/**
@@ -114,7 +118,52 @@ public class GridCommandHandlerIndexingTest extends GridCommandHandlerTest {
assertEquals(EXIT_CODE_OK, execute("--cache", "validate_indexes", CACHE_NAME));
- assertTrue(testOut.toString().contains("issues found (listed above)"));
+ assertContains(log, testOut.toString(), "issues found (listed above)");
+ }
+
+ /** */
+ @Test
+ public void testValidateIndexesFailedOnNotIdleCluster() throws Exception {
+ checkpointFreq = 100L;
+
+ Ignite ignite = prepareGridForTest();
+
+ AtomicBoolean stopFlag = new AtomicBoolean();
+
+ IgniteCache<Integer, Person> cache = ignite.cache(CACHE_NAME);
+
+ Thread loadThread = new Thread(() -> {
+ ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+ while (!stopFlag.get()) {
+ int id = rnd.nextInt();
+
+ cache.put(id, new Person(id, "name" + id));
+
+ if (Thread.interrupted())
+ break;
+ }
+ });
+
+ try {
+ loadThread.start();
+
+ doSleep(checkpointFreq);
+
+ injectTestSystemOut();
+
+ assertEquals(EXIT_CODE_OK, execute("--cache", "validate_indexes", CACHE_NAME));
+ }
+ finally {
+ stopFlag.set(true);
+
+ loadThread.join();
+ }
+
+ String out = testOut.toString();
+
+ assertContains(log, out, "Index validation failed");
+ assertContains(log, out, "Checkpoint with dirty pages started! Cluster not idle!");
}
/**
@@ -140,7 +189,7 @@ public class GridCommandHandlerIndexingTest extends GridCommandHandlerTest {
assertEquals(EXIT_CODE_OK, execute("--cache", "validate_indexes", CACHE_NAME));
- assertTrue(testOut.toString().contains("issues found (listed above)"));
+ assertContains(log, testOut.toString(), "issues found (listed above)");
}
/**
@@ -153,10 +202,8 @@ public class GridCommandHandlerIndexingTest extends GridCommandHandlerTest {
Ignite client = startGrid("client");
- String cacheName = "persons-cache-vi";
-
client.getOrCreateCache(new CacheConfiguration<Integer, Person>()
- .setName(cacheName)
+ .setName(CACHE_NAME)
.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC)
.setAtomicityMode(CacheAtomicityMode.ATOMIC)
.setBackups(1)