use of org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK in project ignite by apache.
the class GridCommandHandlerTest method testPersistenceCleanAllCachesCommand.
/**
* Test verifies persistence clean all command that cleans all cache directories.
*
* @throws Exception
*/
@Test
public void testPersistenceCleanAllCachesCommand() throws Exception {
String cacheName0 = DEFAULT_CACHE_NAME + "0";
String cacheName1 = DEFAULT_CACHE_NAME + "1";
File mntcNodeWorkDir = startGridAndPutNodeToMaintenance(new CacheConfiguration[] { cacheConfiguration(cacheName0), cacheConfiguration(cacheName1) }, s -> s.equals(cacheName0));
IgniteEx ig1 = startGrid(1);
String port = ig1.localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString();
assertEquals(EXIT_CODE_OK, execute("--persistence", "clean", "all", "--host", "localhost", "--port", port));
boolean allEmpty = Arrays.stream(mntcNodeWorkDir.listFiles()).filter(File::isDirectory).filter(f -> f.getName().startsWith("cache-")).map(f -> f.listFiles().length == 1).reduce(true, (t, u) -> t && u);
assertTrue(allEmpty);
stopGrid(1);
ig1 = startGrid(1);
assertFalse(ig1.context().maintenanceRegistry().isMaintenanceMode());
}
use of org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK in project ignite by apache.
the class GridCommandHandlerTest method testPersistenceBackupSpecifiedCachesCommand.
/**
* Test verifies that persistence backup command with specified caches copied only content of that caches and
* doesn't touch other directories.
*
* @throws Exception If failed.
*/
@Test
public void testPersistenceBackupSpecifiedCachesCommand() throws Exception {
String cacheName0 = DEFAULT_CACHE_NAME + "0";
String cacheName1 = DEFAULT_CACHE_NAME + "1";
String cacheName2 = DEFAULT_CACHE_NAME + "2";
String nonExistingCacheName = "nonExistingCache";
File mntcNodeWorkDir = startGridAndPutNodeToMaintenance(new CacheConfiguration[] { cacheConfiguration(cacheName0), cacheConfiguration(cacheName1), cacheConfiguration(cacheName2) }, s -> s.equals(cacheName0) || s.equals(cacheName2));
IgniteEx ig1 = startGrid(1);
String port = ig1.localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString();
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute("--persistence", "backup", "caches", nonExistingCacheName, "--host", "localhost", "--port", port));
assertEquals(EXIT_CODE_OK, execute("--persistence", "backup", "caches", cacheName0 + "," + cacheName2, "--host", "localhost", "--port", port));
long backedUpCachesCnt = Arrays.stream(mntcNodeWorkDir.listFiles()).filter(File::isDirectory).filter(f -> f.getName().startsWith("backup_")).count();
assertEquals(2, backedUpCachesCnt);
checkCacheAndBackupDirsContent(mntcNodeWorkDir);
}
use of org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK in project ignite by apache.
the class GridCommandHandlerClusterByClassTest method testCacheDistribution.
/**
*/
@Test
public void testCacheDistribution() {
Ignite ignite = crd;
createCacheAndPreload(ignite, 100);
injectTestSystemOut();
// Run distribution for all node and all cache
assertEquals(EXIT_CODE_OK, execute("--cache", "distribution", "null"));
String out = testOut.toString();
// Result include info by cache "default"
assertContains(log, out, "[next group: id=1544803905, name=default]");
// Result include info by cache "ignite-sys-cache"
assertContains(log, out, "[next group: id=-2100569601, name=ignite-sys-cache]");
// Run distribution for all node and all cache and include additional user attribute
assertEquals(EXIT_CODE_OK, execute("--cache", "distribution", "null", "--user-attributes", "ZONE,CELL,DC"));
out += "\n" + testOut.toString();
List<String> outLines = Arrays.stream(out.split("\n")).map(String::trim).collect(toList());
int firstIndex = outLines.indexOf("[next group: id=1544803905, name=default]");
int lastIndex = outLines.lastIndexOf("[next group: id=1544803905, name=default]");
String dataLine = outLines.get(firstIndex + 1);
String userArrtDataLine = outLines.get(lastIndex + 1);
long commaNum = dataLine.chars().filter(i -> i == ',').count();
long userArrtCommaNum = userArrtDataLine.chars().filter(i -> i == ',').count();
// Check that number of columns increased by 3
assertEquals(3, userArrtCommaNum - commaNum);
}
use of org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK 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.EXIT_CODE_OK 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);
}
Aggregations