use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class BaselineEventsTest method testChangeAutoAdjustTimeout.
/**
*/
@Test
public void testChangeAutoAdjustTimeout() throws Exception {
IgniteClusterEx cluster = startGrids(2).cluster();
cluster.active(true);
AtomicLong autoAdjustTimeout = new AtomicLong();
listen(grid(0), event -> {
BaselineConfigurationChangedEvent bltCfgChangedEvt = (BaselineConfigurationChangedEvent) event;
autoAdjustTimeout.set(bltCfgChangedEvt.autoAdjustTimeout());
return true;
}, EventType.EVT_BASELINE_AUTO_ADJUST_AWAITING_TIME_CHANGED);
assertEquals(CommandHandler.EXIT_CODE_OK, new CommandHandler().execute(Arrays.asList("--baseline", "auto_adjust", "enable", "timeout", "10", "--yes")));
assertTrue(GridTestUtils.waitForCondition(() -> autoAdjustTimeout.get() == 10L, 3_000));
cluster.baselineAutoAdjustTimeout(50);
assertTrue(GridTestUtils.waitForCondition(() -> autoAdjustTimeout.get() == 50L, 3_000));
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerDefragmentationTest method testDefragmentationStatus.
/**
* @throws Exception If failed.
*/
@Test
public void testDefragmentationStatus() throws Exception {
IgniteEx ig = startGrid(0);
ig.cluster().state(ClusterState.ACTIVE);
ig.getOrCreateCache(DEFAULT_CACHE_NAME + "1");
IgniteCache<Object, Object> cache = ig.getOrCreateCache(DEFAULT_CACHE_NAME + "2");
ig.getOrCreateCache(DEFAULT_CACHE_NAME + "3");
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);
waitCdl = new CountDownLatch(1);
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 {
waitCdl.await();
} 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();
List<LogListener> logLsnrs = Arrays.asList(LogListener.matches("default1 - size before/after: 0MB/0MB").build(), LogListener.matches("default2 - partitions processed/all:").build(), LogListener.matches("Awaiting defragmentation: default3").build());
for (LogListener logLsnr : logLsnrs) testLog.registerListener(logLsnr);
assertEquals(EXIT_CODE_OK, execute(cmd, "--port", port, "--defragmentation", "status"));
waitCdl.countDown();
for (LogListener logLsnr : logLsnrs) assertTrue(logLsnr.check());
fut.get();
((GridCacheDatabaseSharedManager) grid(0).context().cache().context().database()).defragmentationManager().completionFuture().get();
testLog.clearListeners();
logLsnrs = Arrays.asList(LogListener.matches("default1 - size before/after: 0MB/0MB").build(), LogListener.matches(Pattern.compile("default2 - size before/after: (\\S+)/\\1")).build(), LogListener.matches("default3 - size before/after: 0MB/0MB").build());
for (LogListener logLsnr : logLsnrs) testLog.registerListener(logLsnr);
assertEquals(EXIT_CODE_OK, execute(cmd, "--port", port, "--defragmentation", "status"));
for (LogListener logLsnr : logLsnrs) assertTrue(logLsnr.check());
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerIndexListTest method testCacheIndexList.
/**
* Tests --index name option and output correctness.
*/
@Test
public void testCacheIndexList() {
final String idxName = "PERSON_ORGID_ASC_IDX";
final int expectedLinesNum = 15;
final int expectedIndexDescrLinesNum = 2;
injectTestSystemOut();
final CommandHandler handler = new CommandHandler(createTestLogger());
assertEquals(EXIT_CODE_OK, execute(handler, "--cache", "indexes_list", "--index-name", idxName));
String outStr = testOut.toString();
assertTrue(outStr.contains("grpName=" + GROUP_NAME + ", cacheName=" + CACHE_NAME + ", idxName=PERSON_ORGID_ASC_IDX, " + "colsNames=ArrayList [ORGID, _KEY], tblName=PERSON"));
assertTrue(outStr.contains("grpName=" + GROUP_NAME_SECOND + ", cacheName=" + CACHE_NAME_SECOND + ", idxName=PERSON_ORGID_ASC_IDX, colsNames=ArrayList [ORGID, _KEY], tblName=PERSON"));
final String[] outputLines = outStr.split("\n");
int outputLinesNum = outputLines.length;
assertEquals("Unexpected number of lines: " + outputLinesNum, outputLinesNum, expectedLinesNum);
long indexDescrLinesNum = Arrays.stream(outputLines).filter(s -> s.contains("grpName=")).count();
assertEquals("Unexpected number of index description lines: " + indexDescrLinesNum, indexDescrLinesNum, expectedIndexDescrLinesNum);
Set<IndexListInfoContainer> cmdResult = handler.getLastOperationResult();
assertNotNull(cmdResult);
final int resSetSize = cmdResult.size();
assertEquals("Unexpected result set size: " + resSetSize, resSetSize, 2);
boolean isResSetCorrect = cmdResult.stream().map(IndexListInfoContainer::indexName).allMatch((name) -> name.equals(idxName));
assertTrue("Unexpected result set", isResSetCorrect);
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerIndexRebuildStatusTest method testCommandOutput.
/**
* Basic check.
*/
@Test
public void testCommandOutput() throws Exception {
injectTestSystemOut();
idxRebuildsStartedNum.set(0);
final CommandHandler handler = new CommandHandler(createTestLogger());
stopGrid(GRIDS_NUM - 1);
stopGrid(GRIDS_NUM - 2);
deleteIndexBin(getTestIgniteInstanceName(GRIDS_NUM - 1));
deleteIndexBin(getTestIgniteInstanceName(GRIDS_NUM - 2));
IndexProcessor.idxRebuildCls = BlockingIndexesRebuildTask.class;
IgniteEx ignite1 = startGrid(GRIDS_NUM - 1);
IndexProcessor.idxRebuildCls = BlockingIndexesRebuildTask.class;
IgniteEx ignite2 = startGrid(GRIDS_NUM - 2);
final UUID id1 = ignite1.localNode().id();
final UUID id2 = ignite2.localNode().id();
boolean allRebuildsStarted = GridTestUtils.waitForCondition(() -> idxRebuildsStartedNum.get() == 6, 30_000);
assertTrue("Failed to wait for all indexes to start being rebuilt", allRebuildsStarted);
assertEquals(EXIT_CODE_OK, execute(handler, "--cache", "indexes_rebuild_status"));
statusRequestingFinished.set(true);
checkResult(handler, id1, id2);
}
use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.
the class GridCommandHandlerIndexRebuildStatusTest method testNodeIdOption.
/**
* Check --node-id option.
*/
@Test
public void testNodeIdOption() throws Exception {
injectTestSystemOut();
idxRebuildsStartedNum.set(0);
final CommandHandler handler = new CommandHandler(createTestLogger());
stopGrid(GRIDS_NUM - 1);
stopGrid(GRIDS_NUM - 2);
deleteIndexBin(getTestIgniteInstanceName(GRIDS_NUM - 1));
deleteIndexBin(getTestIgniteInstanceName(GRIDS_NUM - 2));
IndexProcessor.idxRebuildCls = BlockingIndexesRebuildTask.class;
IgniteEx ignite1 = startGrid(GRIDS_NUM - 1);
IndexProcessor.idxRebuildCls = BlockingIndexesRebuildTask.class;
startGrid(GRIDS_NUM - 2);
final UUID id1 = ignite1.localNode().id();
boolean allRebuildsStarted = GridTestUtils.waitForCondition(() -> idxRebuildsStartedNum.get() == 6, 30_000);
assertTrue("Failed to wait for all indexes to start being rebuilt", allRebuildsStarted);
assertEquals(EXIT_CODE_OK, execute(handler, "--cache", "indexes_rebuild_status", "--node-id", id1.toString()));
statusRequestingFinished.set(true);
checkResult(handler, id1);
}
Aggregations