use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerDefragmentationTest method createCommandHandler.
/**
*/
private CommandHandler createCommandHandler(ListeningTestLogger testLog) {
Logger log = CommandHandler.initLogger(null);
log.addHandler(new StreamHandler(System.out, new Formatter() {
/**
* {@inheritDoc}
*/
@Override
public String format(LogRecord record) {
String msg = record.getMessage();
testLog.info(msg);
return msg + "\n";
}
}));
return new CommandHandler(log);
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerDefragmentationTest method testDefragmentationCancelInProgress.
/**
* @throws Exception If failed.
*/
@Test
public void testDefragmentationCancelInProgress() throws Exception {
IgniteEx ig = startGrid(0);
ig.cluster().state(ClusterState.ACTIVE);
IgniteCache<Object, Object> cache = ig.getOrCreateCache(DEFAULT_CACHE_NAME);
for (int i = 0; i < 1024; i++) cache.put(i, i);
forceCheckpoint(ig);
String grid0ConsId = ig.configuration().getConsistentId().toString();
ListeningTestLogger testLog = new ListeningTestLogger();
CommandHandler cmd = createCommandHandler(testLog);
assertEquals(EXIT_CODE_OK, execute(cmd, "--defragmentation", "schedule", "--nodes", grid0ConsId));
String port = grid(0).localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString();
stopGrid(0);
blockCdl = new CountDownLatch(128);
UnaryOperator<IgniteConfiguration> cfgOp = cfg -> {
DataStorageConfiguration dsCfg = cfg.getDataStorageConfiguration();
FileIOFactory delegate = dsCfg.getFileIOFactory();
dsCfg.setFileIOFactory((file, modes) -> {
if (file.getName().contains("dfrg")) {
if (blockCdl.getCount() == 0) {
try {
// Slow down defragmentation process.
// This'll be enough for the test since we have, like, 900 partitions left.
Thread.sleep(100);
} catch (InterruptedException ignore) {
// No-op.
}
} else
blockCdl.countDown();
}
return delegate.create(file, modes);
});
return cfg;
};
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(() -> {
try {
startGrid(0, cfgOp);
} catch (Exception e) {
// No-op.
throw new RuntimeException(e);
}
});
blockCdl.await();
LogListener logLsnr = LogListener.matches("Defragmentation cancelled successfully.").build();
testLog.registerListener(logLsnr);
assertEquals(EXIT_CODE_OK, execute(cmd, "--port", port, "--defragmentation", "cancel"));
assertTrue(logLsnr.check());
fut.get();
testLog.clearListeners();
logLsnr = LogListener.matches("Defragmentation is already completed or has been cancelled previously.").build();
testLog.registerListener(logLsnr);
assertEquals(EXIT_CODE_OK, execute(cmd, "--port", port, "--defragmentation", "cancel"));
assertTrue(logLsnr.check());
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerIndexListTest method tesAllArgs.
/**
* Checks that command with all arguments specified works.
*/
@Test
public void tesAllArgs() {
final String idxName = "PERSON_ORGID_ASC_IDX";
injectTestSystemOut();
final CommandHandler handler = new CommandHandler(createTestLogger());
assertEquals(EXIT_CODE_OK, execute(handler, "--cache", "indexes_list", "--node-id", grid(0).localNode().id().toString(), "--group-name", "^" + GROUP_NAME + "$", "--cache-name", CACHE_NAME, "--index-name", idxName));
assertTrue(testOut.toString().contains("grpName=" + GROUP_NAME + ", cacheName=" + CACHE_NAME + ", idxName=PERSON_ORGID_ASC_IDX, colsNames=ArrayList [ORGID, _KEY], tblName=PERSON"));
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerIndexListTest method testListCacheWithoutIndexes.
/**
* Checks that command works for cache without indexes.
*/
@Test
public void testListCacheWithoutIndexes() {
IgniteEx ignite = grid(0);
final String tmpCacheName = "tmpCache";
injectTestSystemOut();
final CommandHandler handler = new CommandHandler(createTestLogger());
try {
ignite.createCache(tmpCacheName);
try (IgniteDataStreamer<Long, Long> streamer = ignite.dataStreamer(tmpCacheName)) {
for (long i = 0; i < 1000; i++) streamer.addData(i * 13, i * 17);
}
assertEquals(EXIT_CODE_OK, execute(handler, "--cache", "indexes_list", "--cache-name", tmpCacheName));
String str = testOut.toString();
String[] lines = str.split("\n");
assertEquals("Unexpected output size", 11, lines.length);
} finally {
ignite.destroyCache(tmpCacheName);
}
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerIndexListTest method checkGroup.
/**
*/
private void checkGroup(String grpRegEx, Predicate<String> predicate, int expectedResNum) {
final CommandHandler handler = new CommandHandler(createTestLogger());
assertEquals(EXIT_CODE_OK, execute(handler, "--cache", "indexes_list", "--group-name", grpRegEx));
Set<IndexListInfoContainer> cmdResult = handler.getLastOperationResult();
assertNotNull(cmdResult);
boolean isResCorrect = cmdResult.stream().map(IndexListInfoContainer::groupName).allMatch(predicate);
assertTrue("Unexpected command result", isResCorrect);
int indexesNum = cmdResult.size();
assertEquals("Unexpected number of indexes: " + indexesNum, indexesNum, expectedResNum);
}
Aggregations