use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerTest method testCheckSnapshot.
/**
* @throws Exception If fails.
*/
@Test
public void testCheckSnapshot() throws Exception {
String snpName = "snapshot_02052020";
IgniteEx ig = startGrid(0);
ig.cluster().state(ACTIVE);
createCacheAndPreload(ig, 1000);
snp(ig).createSnapshot(snpName).get();
CommandHandler h = new CommandHandler();
assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "check", snpName));
StringBuilder sb = new StringBuilder();
((IdleVerifyResultV2) h.getLastOperationResult()).print(sb::append, true);
assertContains(log, sb.toString(), "The check procedure has finished, no conflicts have been found");
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerTest method testMasterKeyChange.
/**
* @throws Exception If failed.
*/
@Test
public void testMasterKeyChange() throws Exception {
encryptionEnabled = true;
injectTestSystemOut();
Ignite ignite = startGrids(1);
ignite.cluster().state(ACTIVE);
createCacheAndPreload(ignite, 10);
CommandHandler h = new CommandHandler();
assertEquals(EXIT_CODE_OK, execute(h, "--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));
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"));
assertContains(log, testOut.toString(), ignite.encryption().getMasterKeyName());
testOut.reset();
assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute("--encryption", "change_master_key", "non-existing-master-key-name"));
assertContains(log, testOut.toString(), "Master key change was rejected. Unable to get the master key digest.");
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerTest method testKillHangingLocalTransactions.
/**
*/
@Test
public void testKillHangingLocalTransactions() throws Exception {
Ignite ignite = startGridsMultiThreaded(2);
ignite.cluster().active(true);
Ignite client = startGrid("client");
client.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME).setAtomicityMode(TRANSACTIONAL).setWriteSynchronizationMode(FULL_SYNC).setAffinity(new RendezvousAffinityFunction(false, 64)));
Ignite prim = primaryNode(0L, DEFAULT_CACHE_NAME);
// Blocks lock response to near node.
TestRecordingCommunicationSpi.spi(prim).blockMessages(GridNearLockResponse.class, client.name());
TestRecordingCommunicationSpi.spi(client).blockMessages(GridNearTxFinishRequest.class, prim.name());
GridNearTxLocal clientTx = null;
try (Transaction tx = client.transactions().txStart(PESSIMISTIC, READ_COMMITTED, 2000, 1)) {
clientTx = ((TransactionProxyImpl) tx).tx();
client.cache(DEFAULT_CACHE_NAME).put(0L, 0L);
fail();
} catch (Exception e) {
assertTrue(X.hasCause(e, TransactionTimeoutException.class));
}
assertNotNull(clientTx);
IgniteEx primEx = (IgniteEx) prim;
IgniteInternalTx tx0 = primEx.context().cache().context().tm().activeTransactions().iterator().next();
assertNotNull(tx0);
CommandHandler h = new CommandHandler();
validate(h, map -> {
ClusterNode node = grid(0).cluster().localNode();
VisorTxTaskResult res = map.get(node);
for (VisorTxInfo info : res.getInfos()) assertEquals(tx0.xid(), info.getXid());
assertEquals(1, map.size());
}, "--tx", "--xid", tx0.xid().toString(), "--kill");
tx0.finishFuture().get();
TestRecordingCommunicationSpi.spi(prim).stopBlock();
TestRecordingCommunicationSpi.spi(client).stopBlock();
IgniteInternalFuture<?> nearFinFut = U.field(clientTx, "finishFut");
nearFinFut.get();
checkUserFutures();
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerTest method doClusterSnapshotCreate.
/**
* @param syncMode Execute operation synchrnously.
* @throws Exception If failed.
*/
private void doClusterSnapshotCreate(boolean syncMode) throws Exception {
int keysCnt = 100;
String snpName = "snapshot_02052020";
IgniteEx ig = startGrid(0);
ig.cluster().state(ACTIVE);
createCacheAndPreload(ig, keysCnt);
injectTestSystemOut();
CommandHandler h = new CommandHandler();
// Invalid command syntax check.
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "create", snpName, "blah"));
assertContains(log, testOut.toString(), "Invalid argument: blah. Possible options: --sync.");
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "create", snpName, "--sync", "blah"));
assertContains(log, testOut.toString(), "Invalid argument: blah.");
List<String> args = new ArrayList<>(F.asList("--snapshot", "create", snpName));
if (syncMode)
args.add("--sync");
assertEquals(EXIT_CODE_OK, execute(h, args));
LongMetric opEndTimeMetric = ig.context().metric().registry(SNAPSHOT_METRICS).findMetric("LastSnapshotEndTime");
BooleanSupplier endTimeMetricPredicate = () -> opEndTimeMetric.value() > 0;
if (syncMode)
assertTrue(endTimeMetricPredicate.getAsBoolean());
else {
assertTrue("Waiting for snapshot operation end failed.", waitForCondition(endTimeMetricPredicate::getAsBoolean, getTestTimeout()));
}
assertContains(log, (String) h.getLastOperationResult(), snpName);
stopAllGrids();
IgniteConfiguration cfg = optimize(getConfiguration(getTestIgniteInstanceName(0)));
cfg.setWorkDirectory(Paths.get(resolveSnapshotWorkDirectory(cfg).getAbsolutePath(), snpName).toString());
Ignite snpIg = startGrid(cfg);
snpIg.cluster().state(ACTIVE);
List<Integer> range = IntStream.range(0, keysCnt).boxed().collect(Collectors.toList());
snpIg.cache(DEFAULT_CACHE_NAME).forEach(e -> range.remove((Integer) e.getKey()));
assertTrue("Snapshot must contains cache data [left=" + range + ']', range.isEmpty());
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerAbstractTest method execute.
/**
* Before command executed {@link #testOut} reset.
*/
protected int execute(CommandHandler hnd, List<String> args) {
if (!F.isEmpty(args) && !"--help".equalsIgnoreCase(args.get(0)))
addExtraArguments(args);
testOut.reset();
int exitCode = hnd.execute(args);
lastOperationResult = hnd.getLastOperationResult();
// Flush all Logger handlers to make log data available to test.
Logger logger = U.field(hnd, "logger");
Arrays.stream(logger.getHandlers()).forEach(Handler::flush);
return exitCode;
}
Aggregations