This is an automated email from the ASF dual-hosted git repository. av 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 95ba35d2d6b IGNITE-19415 GridCommandHandlerTest should be runnable at other modules (#10698) 95ba35d2d6b is described below commit 95ba35d2d6bafa62b35dde16d137eaad4235fcc6 Author: Anton Vinogradov <a...@apache.org> AuthorDate: Thu May 4 17:10:12 2023 +0300 IGNITE-19415 GridCommandHandlerTest should be runnable at other modules (#10698) --- .../apache/ignite/util/GridCommandHandlerTest.java | 83 +++++++++------------- 1 file changed, 34 insertions(+), 49 deletions(-) diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java index 0e8ab25d3d2..d32bfc244fc 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java @@ -2784,19 +2784,17 @@ public class GridCommandHandlerTest extends GridCommandHandlerClusterPerMethodAb 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()); @@ -2996,7 +2994,7 @@ public class GridCommandHandlerTest extends GridCommandHandlerClusterPerMethodAb Ignite ignite = startGrids(1); - CommandHandler h = new CommandHandler(); + CommandHandler h = new CommandHandler(createTestLogger()); assertEquals(EXIT_CODE_OK, execute(h, "--encryption", "get_master_key_name")); @@ -3111,11 +3109,7 @@ public class GridCommandHandlerTest extends GridCommandHandlerClusterPerMethodAb 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); @@ -3123,9 +3117,7 @@ public class GridCommandHandlerTest extends GridCommandHandlerClusterPerMethodAb 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); @@ -3159,7 +3151,7 @@ public class GridCommandHandlerTest extends GridCommandHandlerClusterPerMethodAb 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")); @@ -3216,8 +3208,7 @@ public class GridCommandHandlerTest extends GridCommandHandlerClusterPerMethodAb 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."); } @@ -3292,28 +3283,26 @@ public class GridCommandHandlerTest extends GridCommandHandlerClusterPerMethodAb 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(), @@ -3323,7 +3312,7 @@ public class GridCommandHandlerTest extends GridCommandHandlerClusterPerMethodAb 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); @@ -3331,7 +3320,7 @@ public class GridCommandHandlerTest extends GridCommandHandlerClusterPerMethodAb 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"); @@ -3381,7 +3370,7 @@ public class GridCommandHandlerTest extends GridCommandHandlerClusterPerMethodAb 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(), @@ -3516,25 +3505,23 @@ public class GridCommandHandlerTest extends GridCommandHandlerClusterPerMethodAb 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); @@ -3550,7 +3537,7 @@ public class GridCommandHandlerTest extends GridCommandHandlerClusterPerMethodAb 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); @@ -3576,32 +3563,31 @@ public class GridCommandHandlerTest extends GridCommandHandlerClusterPerMethodAb 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); @@ -3636,7 +3622,6 @@ public class GridCommandHandlerTest extends GridCommandHandlerClusterPerMethodAb ig.destroyCache(DEFAULT_CACHE_NAME); awaitPartitionMapExchange(); - CommandHandler h = new CommandHandler(); CountDownLatch ioStartLatch = new CountDownLatch(1); IgniteSnapshotManager snpMgr = ig.context().cache().context().snapshotMgr(); @@ -3650,7 +3635,7 @@ public class GridCommandHandlerTest extends GridCommandHandlerClusterPerMethodAb 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()); @@ -3660,17 +3645,17 @@ public class GridCommandHandlerTest extends GridCommandHandlerClusterPerMethodAb 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 + ']'); @@ -3683,7 +3668,7 @@ public class GridCommandHandlerTest extends GridCommandHandlerClusterPerMethodAb 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));