Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2784,19 +2784,17 @@ public void testMasterKeyChange() throws Exception {

createCacheAndPreload(ignite, 10);

CommandHandler h = new CommandHandler();

assertEquals(EXIT_CODE_OK, execute(h, "--encryption", "get_master_key_name"));
assertEquals(EXIT_CODE_OK, execute("--encryption", "get_master_key_name"));

assertContains(log, testOut.toString(), ignite.encryption().getMasterKeyName());

assertEquals(EXIT_CODE_OK, execute(h, "--encryption", "change_master_key", MASTER_KEY_NAME_2));
assertEquals(EXIT_CODE_OK, execute("--encryption", "change_master_key", MASTER_KEY_NAME_2));

assertContains(log, testOut.toString(), "The master key changed.");

assertEquals(MASTER_KEY_NAME_2, ignite.encryption().getMasterKeyName());

assertEquals(EXIT_CODE_OK, execute(h, "--encryption", "get_master_key_name"));
assertEquals(EXIT_CODE_OK, execute("--encryption", "get_master_key_name"));

assertContains(log, testOut.toString(), ignite.encryption().getMasterKeyName());

Expand Down Expand Up @@ -2996,7 +2994,7 @@ public void testMasterKeyChangeOnInactiveCluster() throws Exception {

Ignite ignite = startGrids(1);

CommandHandler h = new CommandHandler();
CommandHandler h = new CommandHandler(createTestLogger());

assertEquals(EXIT_CODE_OK, execute(h, "--encryption", "get_master_key_name"));

Expand Down Expand Up @@ -3111,21 +3109,15 @@ public void testClusterCreateSnapshotWarning() throws Exception {
try {
injectTestSystemOut();

CommandHandler hnd = new CommandHandler();

List<String> args = new ArrayList<>(F.asList("--snapshot", "create", "testDsSnp", "--sync"));

int code = execute(hnd, args);
int code = execute(new ArrayList<>(F.asList("--snapshot", "create", "testDsSnp", "--sync")));

assertEquals(EXIT_CODE_UNEXPECTED_ERROR, code);

LogListener logLsnr = LogListener.matches(DataStreamerUpdatesHandler.WRN_MSG).times(1).build();
logLsnr.accept(testOut.toString());
logLsnr.check();

args = new ArrayList<>(F.asList("--snapshot", "check", "testDsSnp"));

code = execute(hnd, args);
code = execute(new ArrayList<>(F.asList("--snapshot", "check", "testDsSnp")));

assertEquals(EXIT_CODE_OK, code);

Expand Down Expand Up @@ -3159,7 +3151,7 @@ private void doClusterSnapshotCreate(boolean syncMode) throws Exception {

injectTestSystemOut();

CommandHandler h = new CommandHandler();
CommandHandler h = new CommandHandler(createTestLogger());

// Invalid command syntax check.
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "create", snpName, "blah"));
Expand Down Expand Up @@ -3216,8 +3208,7 @@ public void testClusterSnapshotOnInactive() throws Exception {

startGrids(1);

assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute(new CommandHandler(), "--snapshot", "create",
"testSnapshotName"));
assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute("--snapshot", "create", "testSnapshotName"));

assertContains(log, testOut.toString(), "Snapshot operation has been rejected. The cluster is inactive.");
}
Expand Down Expand Up @@ -3292,28 +3283,26 @@ public void testSnapshotRestoreSynchronously() throws Exception {

ig.snapshot().createSnapshot(snpName).get(getTestTimeout());

CommandHandler h = new CommandHandler();

autoConfirmation = false;

// Invalid command syntax checks.
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "restore", snpName, "--cancel", "--sync"));
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute("--snapshot", "restore", snpName, "--cancel", "--sync"));
assertContains(log, testOut.toString(), "Invalid argument: --sync.");

assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "restore", snpName, "blah"));
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute("--snapshot", "restore", snpName, "blah"));
assertContains(
log,
testOut.toString(),
"Invalid argument: blah. Possible options: --groups, --src, --increment, --sync, --check."
);

assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "restore", snpName, "--status", "--sync"));
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute("--snapshot", "restore", snpName, "--status", "--sync"));
assertContains(log, testOut.toString(), "Invalid argument: --sync. Action \"--status\" does not support specified option.");

assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "restore", snpName, "--sync", "--start"));
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute("--snapshot", "restore", snpName, "--sync", "--start"));
assertContains(log, testOut.toString(), "Invalid argument: --start.");

assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "restore", snpName, "--start", "blah"));
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute("--snapshot", "restore", snpName, "--start", "blah"));
assertContains(
log,
testOut.toString(),
Expand All @@ -3323,15 +3312,15 @@ public void testSnapshotRestoreSynchronously() throws Exception {
autoConfirmation = true;

// Cache exists.
assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute(h, "--snapshot", "restore", snpName, "--start", "--sync"));
assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute("--snapshot", "restore", snpName, "--start", "--sync"));
assertContains(log, testOut.toString(), "Command option '--start' is redundant and must be avoided.");
assertContains(log, testOut.toString(), "Unable to restore cache group - directory is not empty. " +
"Cache group should be destroyed manually before perform restore operation [group=" + cacheName);

ig.cache(cacheName).destroy();
awaitPartitionMapExchange();

assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", snpName, "--sync"));
assertEquals(EXIT_CODE_OK, execute("--snapshot", "restore", snpName, "--sync"));
assertNotContains(log, testOut.toString(), "Command option '--start' is redundant and must be avoided.");
assertContains(log, testOut.toString(), "Snapshot cache group restore operation completed successfully");

Expand Down Expand Up @@ -3381,7 +3370,7 @@ public void testSnapshotRestore() throws Exception {
assertNull(ig.cache(cacheName2));
assertNull(ig.cache(cacheName3));

CommandHandler h = new CommandHandler();
CommandHandler h = new CommandHandler(createTestLogger());

assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "restore", snpName, cacheName1));
assertContains(log, testOut.toString(),
Expand Down Expand Up @@ -3516,25 +3505,23 @@ public void testIncrementalSnapshotRestore() throws Exception {

assertNull(ig.cache(cacheName1));

CommandHandler h = new CommandHandler();

// Missed increment index.
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "restore", snpName, "--increment"));
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute("--snapshot", "restore", snpName, "--increment"));
assertContains(log, testOut.toString(), "Expected incremental snapshot index");

// Wrong params.
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "restore", snpName, "--increment", "wrong"));
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute("--snapshot", "restore", snpName, "--increment", "wrong"));
assertContains(log, testOut.toString(), "Invalid value for incremental snapshot index");

// Missed increment index.
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "restore", snpName, "--increment", "1", "--increment", "2"));
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute("--snapshot", "restore", snpName, "--increment", "1", "--increment", "2"));
assertContains(log, testOut.toString(), "increment arg specified twice");

// Non existent increment.
assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute(h, "--snapshot", "restore", snpName, "--increment", "2", "--sync"));
assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute("--snapshot", "restore", snpName, "--increment", "2", "--sync"));

// Succesfull restore.
assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", snpName, "--increment", "1", "--sync"));
assertEquals(EXIT_CODE_OK, execute("--snapshot", "restore", snpName, "--increment", "1", "--sync"));

cache1 = ig.cache(cacheName1);

Expand All @@ -3550,7 +3537,7 @@ public void testIncrementalSnapshotRestore() throws Exception {
assertNull(ig.cache(cacheName1));

// Specify full increment index value.
assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", snpName, "--increment", "0000000000000001", "--sync"));
assertEquals(EXIT_CODE_OK, execute("--snapshot", "restore", snpName, "--increment", "0000000000000001", "--sync"));

cache1 = ig.cache(cacheName1);

Expand All @@ -3576,32 +3563,31 @@ public void testSnapshotCreateCheckAndRestoreCustomDir() throws Exception {
createCacheAndPreload(ignite, keysCnt);

injectTestSystemOut();
CommandHandler h = new CommandHandler();

assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "create", snpName, "--dest", "A", "--dest", "B"));
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute("--snapshot", "create", snpName, "--dest", "A", "--dest", "B"));
assertContains(log, testOut.toString(), "--dest arg specified twice.");

assertEquals(EXIT_CODE_OK,
execute(h, "--snapshot", "create", snpName, "--sync", "--dest", snpDir.getAbsolutePath()));
execute("--snapshot", "create", snpName, "--sync", "--dest", snpDir.getAbsolutePath()));

ignite.destroyCache(DEFAULT_CACHE_NAME);

assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "restore", snpName, "--sync"));
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute("--snapshot", "restore", snpName, "--sync"));
assertContains(log, testOut.toString(), "Snapshot does not exists [snapshot=" + snpName);

assertEquals(EXIT_CODE_INVALID_ARGUMENTS,
execute(h, "--snapshot", "restore", snpName, "--src", "A", "--src", "B"));
execute("--snapshot", "restore", snpName, "--src", "A", "--src", "B"));
assertContains(log, testOut.toString(), "--src arg specified twice.");

// The check command simply prints the results of the check, it always ends with a zero exit code.
assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "check", snpName));
assertEquals(EXIT_CODE_OK, execute("--snapshot", "check", snpName));
assertContains(log, testOut.toString(), "Snapshot does not exists [snapshot=" + snpName);

assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "check", snpName, "--src", snpDir.getAbsolutePath()));
assertEquals(EXIT_CODE_OK, execute("--snapshot", "check", snpName, "--src", snpDir.getAbsolutePath()));
assertContains(log, testOut.toString(), "The check procedure has finished, no conflicts have been found.");

assertEquals(EXIT_CODE_OK,
execute(h, "--snapshot", "restore", snpName, "--sync", "--src", snpDir.getAbsolutePath()));
execute("--snapshot", "restore", snpName, "--sync", "--src", snpDir.getAbsolutePath()));

IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);

Expand Down Expand Up @@ -3636,7 +3622,6 @@ public void testSnapshotRestoreCancelAndStatus() throws Exception {
ig.destroyCache(DEFAULT_CACHE_NAME);
awaitPartitionMapExchange();

CommandHandler h = new CommandHandler();
CountDownLatch ioStartLatch = new CountDownLatch(1);
IgniteSnapshotManager snpMgr = ig.context().cache().context().snapshotMgr();

Expand All @@ -3650,7 +3635,7 @@ public void testSnapshotRestoreCancelAndStatus() throws Exception {
assertFalse(restoreFut.isDone());

// Check the status with a control command.
assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "status"));
assertEquals(EXIT_CODE_OK, execute("--snapshot", "status"));

Pattern operIdPtrn = Pattern.compile("Operation request ID: (?<id>[-\\w]{36})");
Matcher matcher = operIdPtrn.matcher(testOut.toString());
Expand All @@ -3660,17 +3645,17 @@ public void testSnapshotRestoreCancelAndStatus() throws Exception {
assertNotNull(operIdStr);

// Check "status" with the wrong snapshot name.
assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", missingSnpName, "--status"));
assertEquals(EXIT_CODE_OK, execute("--snapshot", "restore", missingSnpName, "--status"));
assertContains(log, testOut.toString(),
"Snapshot cache group restore operation is NOT running [snapshot=" + missingSnpName + ']');

// Check "cancel" with the wrong snapshot name.
assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", missingSnpName, "--cancel"));
assertEquals(EXIT_CODE_OK, execute("--snapshot", "restore", missingSnpName, "--cancel"));
assertContains(log, testOut.toString(),
"Snapshot cache group restore operation is NOT running [snapshot=" + missingSnpName + ']');

// Cancel operation using control command.
assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "cancel", "--id", operIdStr));
assertEquals(EXIT_CODE_OK, execute("--snapshot", "cancel", "--id", operIdStr));
assertContains(log, testOut.toString(),
"Snapshot operation cancelled [id=" + operIdStr + ']');

Expand All @@ -3683,7 +3668,7 @@ public void testSnapshotRestoreCancelAndStatus() throws Exception {

assertTrue(ctxDisposed);

assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "status"));
assertEquals(EXIT_CODE_OK, execute("--snapshot", "status"));
assertContains(log, testOut.toString(), "There is no create or restore snapshot operation in progress.");

assertNull(ig.cache(DEFAULT_CACHE_NAME));
Expand Down