use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerTest method executeTaskViaControlConsoleUtil.
/**
* @param ignite Ignite to execute task on.
* @param delFoundGarbage If clearing mode should be used.
* @return Result of task run.
*/
private VisorFindAndDeleteGarbageInPersistenceTaskResult executeTaskViaControlConsoleUtil(IgniteEx ignite, boolean delFoundGarbage) {
CommandHandler hnd = new CommandHandler();
List<String> args = new ArrayList<>(Arrays.asList("--yes", "--port", "11212", "--cache", "find_garbage", ignite.localNode().id().toString()));
if (delFoundGarbage)
args.add(FindAndDeleteGarbageArg.DELETE.argName());
hnd.execute(args);
return hnd.getLastOperationResult();
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerTest method testCancelSnapshot.
/**
* @throws Exception If fails.
*/
@Test
public void testCancelSnapshot() throws Exception {
IgniteEx srv = startGrid(0);
IgniteEx startCli = startClientGrid(CLIENT_NODE_NAME_PREFIX);
srv.cluster().state(ACTIVE);
createCacheAndPreload(startCli, 100);
CommandHandler h = new CommandHandler();
doSnapshotCancellationTest(startCli, Collections.singletonList(srv), startCli.cache(DEFAULT_CACHE_NAME), snpName -> assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "cancel", snpName)));
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerTest method testActiveTransactions.
/**
* Test active transactions.
*
* @throws Exception If failed.
*/
@Test
public void testActiveTransactions() 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));
for (Ignite ig : G.allGrids()) assertNotNull(ig.cache(DEFAULT_CACHE_NAME));
CountDownLatch lockLatch = new CountDownLatch(1);
CountDownLatch unlockLatch = new CountDownLatch(1);
IgniteInternalFuture<?> fut = startTransactions("testActiveTransactions", lockLatch, unlockLatch, true);
U.awaitQuiet(lockLatch);
doSleep(5000);
CommandHandler h = new CommandHandler();
final VisorTxInfo[] toKill = { null };
// Basic test.
validate(h, map -> {
VisorTxTaskResult res = map.get(grid(0).cluster().localNode());
for (VisorTxInfo info : res.getInfos()) {
if (info.getSize() == 100) {
// Store for further use.
toKill[0] = info;
break;
}
}
assertEquals(3, map.size());
}, "--tx");
assertNotNull(toKill[0]);
// Test filter by label.
validate(h, map -> {
ClusterNode node = grid(0).cluster().localNode();
for (Map.Entry<ClusterNode, VisorTxTaskResult> entry : map.entrySet()) assertEquals(entry.getKey().equals(node) ? 1 : 0, entry.getValue().getInfos().size());
}, "--tx", "--label", "label1");
// Test filter by label regex.
validate(h, map -> {
ClusterNode node1 = grid(0).cluster().localNode();
ClusterNode node2 = grid("client").cluster().localNode();
for (Map.Entry<ClusterNode, VisorTxTaskResult> entry : map.entrySet()) {
if (entry.getKey().equals(node1)) {
assertEquals(1, entry.getValue().getInfos().size());
assertEquals("label1", entry.getValue().getInfos().get(0).getLabel());
} else if (entry.getKey().equals(node2)) {
assertEquals(1, entry.getValue().getInfos().size());
assertEquals("label2", entry.getValue().getInfos().get(0).getLabel());
} else
assertTrue(entry.getValue().getInfos().isEmpty());
}
}, "--tx", "--label", "^label[0-9]");
// Test filter by empty label.
validate(h, map -> {
VisorTxTaskResult res = map.get(grid(0).localNode());
for (VisorTxInfo info : res.getInfos()) assertNull(info.getLabel());
}, "--tx", "--label", "null");
// test check minSize
int minSize = 10;
validate(h, map -> {
VisorTxTaskResult res = map.get(grid(0).localNode());
assertNotNull(res);
for (VisorTxInfo txInfo : res.getInfos()) assertTrue(txInfo.getSize() >= minSize);
}, "--tx", "--min-size", Integer.toString(minSize));
// test order by size.
validate(h, map -> {
VisorTxTaskResult res = map.get(grid(0).localNode());
assertTrue(res.getInfos().get(0).getSize() >= res.getInfos().get(1).getSize());
}, "--tx", "--order", "SIZE");
// test order by duration.
validate(h, map -> {
VisorTxTaskResult res = map.get(grid(0).localNode());
assertTrue(res.getInfos().get(0).getDuration() >= res.getInfos().get(1).getDuration());
}, "--tx", "--order", "DURATION");
// test order by start_time.
validate(h, map -> {
VisorTxTaskResult res = map.get(grid(0).localNode());
for (int i = res.getInfos().size() - 1; i > 1; i--) assertTrue(res.getInfos().get(i - 1).getStartTime() >= res.getInfos().get(i).getStartTime());
}, "--tx", "--order", "START_TIME");
// Trigger topology change and test connection.
IgniteInternalFuture<?> startFut = multithreadedAsync(() -> {
try {
startGrid(2);
} catch (Exception e) {
fail();
}
}, 1, "start-node-thread");
// Give enough time to reach exchange future.
doSleep(5000);
assertEquals(EXIT_CODE_OK, execute(h, "--tx"));
// Test kill by xid.
validate(h, map -> {
assertEquals(1, map.size());
Map.Entry<ClusterNode, VisorTxTaskResult> killedEntry = map.entrySet().iterator().next();
VisorTxInfo info = killedEntry.getValue().getInfos().get(0);
assertEquals(toKill[0].getXid(), info.getXid());
}, "--tx", "--kill", // Use saved on first run value.
"--xid", // Use saved on first run value.
toKill[0].getXid().toString(), "--nodes", grid(0).localNode().consistentId().toString());
unlockLatch.countDown();
startFut.get();
fut.get();
awaitPartitionMapExchange();
checkUserFutures();
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerClusterByClassTest method testErrUnexpectedWithWithoutVerbose.
/**
* Test checks that stack trace for unexpected error will be output with or
* without {@link CommonArgParser#CMD_VERBOSE} flag.
*/
@Test
public void testErrUnexpectedWithWithoutVerbose() {
injectTestSystemOut();
Logger log = CommandHandler.initLogger(null);
log.addHandler(new StreamHandler(System.out, new Formatter() {
/**
* {@inheritDoc}
*/
@Override
public String format(LogRecord record) {
String msg = record.getMessage();
if (msg.contains("Cluster state:"))
throw new Error();
return msg + "\n";
}
}));
int resCode = EXIT_CODE_UNEXPECTED_ERROR;
CommandHandler cmd = new CommandHandler(log);
assertEquals(resCode, execute(cmd, BASELINE.text()));
assertContains(GridAbstractTest.log, testOut.toString(), ERROR_STACK_TRACE_PREFIX);
assertEquals(resCode, execute(cmd, BASELINE.text(), CMD_VERBOSE));
assertContains(GridAbstractTest.log, testOut.toString(), ERROR_STACK_TRACE_PREFIX);
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class BaselineEventsTest method testChangeBltWithControlUtility.
/**
*/
@Test
public void testChangeBltWithControlUtility() throws Exception {
startGrid(0).cluster().active(true);
AtomicBoolean baselineChanged = new AtomicBoolean();
startGrid(1);
String consistentIds = grid(0).localNode().consistentId() + "," + grid(1).localNode().consistentId();
listen(grid(1), event -> {
baselineChanged.set(true);
BaselineChangedEvent baselineChangedEvt = (BaselineChangedEvent) event;
assertEquals(2, baselineChangedEvt.baselineNodes().size());
return true;
}, EventType.EVT_BASELINE_CHANGED);
assertEquals(CommandHandler.EXIT_CODE_OK, new CommandHandler().execute(Arrays.asList("--baseline", "set", consistentIds, "--yes")));
assertTrue(GridTestUtils.waitForCondition(baselineChanged::get, 3_000));
}
Aggregations