use of org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK in project ignite by apache.
the class GridCommandHandlerTest method testConnectivityCommandWithNodeExit.
/**
* Test that if node exits topology during connectivity check, the command will not fail.
*
* Description:
* 1. Start three nodes.
* 2. Execute connectivity check.
* 3. When 3-rd node receives connectivity check compute task, it must stop itself.
* 4. The command should exit with code OK.
*
* @throws Exception If failed.
*/
@Test
public void testConnectivityCommandWithNodeExit() throws Exception {
IgniteEx[] node3 = new IgniteEx[1];
/**
*/
class KillNode3CommunicationSpi extends TcpCommunicationSpi {
/**
* Fail check connection request and stop third node
*/
boolean fail;
/**
*/
public KillNode3CommunicationSpi(boolean fail) {
this.fail = fail;
}
/**
* {@inheritDoc}
*/
@Override
public IgniteFuture<BitSet> checkConnection(List<ClusterNode> nodes) {
if (fail) {
runAsync(node3[0]::close);
return null;
}
return super.checkConnection(nodes);
}
}
IgniteEx node1 = startGrid(1, (UnaryOperator<IgniteConfiguration>) configuration -> {
configuration.setCommunicationSpi(new KillNode3CommunicationSpi(false));
return configuration;
});
IgniteEx node2 = startGrid(2, (UnaryOperator<IgniteConfiguration>) configuration -> {
configuration.setCommunicationSpi(new KillNode3CommunicationSpi(false));
return configuration;
});
node3[0] = startGrid(3, (UnaryOperator<IgniteConfiguration>) configuration -> {
configuration.setCommunicationSpi(new KillNode3CommunicationSpi(true));
return configuration;
});
assertFalse(node1.cluster().state().active());
node1.cluster().state(ACTIVE);
assertEquals(3, node1.cluster().nodes().size());
injectTestSystemOut();
final IgniteInternalFuture<?> connectivity = runAsync(() -> {
final int result = execute("--diagnostic", "connectivity");
assertEquals(EXIT_CODE_OK, result);
});
connectivity.get();
}
use of org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK in project ignite by apache.
the class GridCommandHandlerTest method testConnectivityCommandWithFailedNodes.
/**
* Test connectivity command works via control.sh with one node failing.
*/
@Test
public void testConnectivityCommandWithFailedNodes() throws Exception {
UUID okId = UUID.randomUUID();
UUID failingId = UUID.randomUUID();
UnaryOperator<IgniteConfiguration> operator = configuration -> {
configuration.setCommunicationSpi(new TcpCommunicationSpi() {
/**
* {inheritDoc}
*/
@Override
public IgniteFuture<BitSet> checkConnection(List<ClusterNode> nodes) {
BitSet bitSet = new BitSet();
int idx = 0;
for (ClusterNode remoteNode : nodes) {
if (!remoteNode.id().equals(failingId))
bitSet.set(idx);
idx++;
}
return new IgniteFinishedFutureImpl<>(bitSet);
}
});
return configuration;
};
IgniteEx ignite = startGrid("normal", configuration -> {
operator.apply(configuration);
configuration.setConsistentId(okId);
configuration.setNodeId(okId);
return configuration;
});
IgniteEx failure = startGrid("failure", configuration -> {
operator.apply(configuration);
configuration.setConsistentId(failingId);
configuration.setNodeId(failingId);
return configuration;
});
ignite.cluster().state(ACTIVE);
failure.cluster().state(ACTIVE);
injectTestSystemOut();
int connectivity = execute("--diagnostic", "connectivity");
assertEquals(EXIT_CODE_OK, connectivity);
String out = testOut.toString();
String what = "There is no connectivity between the following nodes";
assertContains(log, out.replaceAll("[\\W_]+", "").trim(), what.replaceAll("[\\W_]+", "").trim());
}
use of org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK in project ignite by apache.
the class GridCommandHandlerTest method testDiagnosticPageLocksTracker.
/**
* Test execution of --diagnostic command.
*
* @throws Exception if failed.
*/
@Test
public void testDiagnosticPageLocksTracker() throws Exception {
Ignite ignite = startGrid(0, (UnaryOperator<IgniteConfiguration>) cfg -> cfg.setConsistentId("node0/dump"));
startGrid(1, (UnaryOperator<IgniteConfiguration>) cfg -> cfg.setConsistentId("node1/dump"));
startGrid(2, (UnaryOperator<IgniteConfiguration>) cfg -> cfg.setConsistentId("node2/dump"));
startGrid(3, (UnaryOperator<IgniteConfiguration>) cfg -> cfg.setConsistentId("node3/dump"));
Collection<ClusterNode> nodes = ignite.cluster().nodes();
List<ClusterNode> nodes0 = new ArrayList<>(nodes);
ClusterNode node0 = nodes0.get(0);
ClusterNode node1 = nodes0.get(1);
ClusterNode node2 = nodes0.get(2);
ClusterNode node3 = nodes0.get(3);
ignite.cluster().active(true);
assertEquals(EXIT_CODE_OK, execute("--diagnostic"));
assertEquals(EXIT_CODE_OK, execute("--diagnostic", "help"));
// Dump locks only on connected node to default path.
assertEquals(EXIT_CODE_OK, execute("--diagnostic", "pageLocks", "dump"));
// Check file dump in default path.
checkNumberFiles(defaultDiagnosticDir, 1);
assertEquals(EXIT_CODE_OK, execute("--diagnostic", "pageLocks", "dump_log"));
// Dump locks only on connected node to specific path.
assertEquals(EXIT_CODE_OK, execute("--diagnostic", "pageLocks", "dump", "--path", customDiagnosticDir.getAbsolutePath()));
// Check file dump in specific path.
checkNumberFiles(customDiagnosticDir, 1);
// Dump locks only all nodes.
assertEquals(EXIT_CODE_OK, execute("--diagnostic", "pageLocks", "dump", "--all"));
// Current cluster 4 nodes -> 4 files + 1 from previous operation.
checkNumberFiles(defaultDiagnosticDir, 5);
assertEquals(EXIT_CODE_OK, execute("--diagnostic", "pageLocks", "dump_log", "--all"));
assertEquals(EXIT_CODE_OK, execute("--diagnostic", "pageLocks", "dump", "--path", customDiagnosticDir.getAbsolutePath(), "--all"));
// Current cluster 4 nodes -> 4 files + 1 from previous operation.
checkNumberFiles(customDiagnosticDir, 5);
// Dump locks only 2 nodes use nodeIds as arg.
assertEquals(EXIT_CODE_OK, execute("--diagnostic", "pageLocks", "dump", "--nodes", node0.id().toString() + "," + node2.id().toString()));
// Dump locks only for 2 nodes -> 2 files + 5 from previous operation.
checkNumberFiles(defaultDiagnosticDir, 7);
// Dump locks only for 2 nodes use constIds as arg.
assertEquals(EXIT_CODE_OK, execute("--diagnostic", "pageLocks", "dump", "--nodes", node0.consistentId().toString() + "," + node2.consistentId().toString()));
assertEquals(EXIT_CODE_OK, execute("--diagnostic", "pageLocks", "dump_log", "--nodes", node1.id().toString() + "," + node3.id().toString()));
assertEquals(EXIT_CODE_OK, execute("--diagnostic", "pageLocks", "dump", "--path", customDiagnosticDir.getAbsolutePath(), "--nodes", node1.consistentId().toString() + "," + node3.consistentId().toString()));
// Dump locks only for 2 nodes -> 2 files + 5 from previous operation.
checkNumberFiles(customDiagnosticDir, 7);
}
use of org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK in project ignite by apache.
the class GridCommandHandlerTest method testPersistenceBackupCorruptedCachesCommand.
/**
* Test verifies that persistence backup command copies all corrupted caches content to backup directory
* but does not touch other directories.
*
* @throws Exception If failed.
*/
@Test
public void testPersistenceBackupCorruptedCachesCommand() 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", "backup", "corrupted", "--host", "localhost", "--port", port));
long backedUpCachesCnt = Arrays.stream(mntcNodeWorkDir.listFiles()).filter(File::isDirectory).filter(f -> f.getName().startsWith("backup_")).filter(f -> f.getName().contains(cacheName0)).count();
assertEquals(1, backedUpCachesCnt);
checkCacheAndBackupDirsContent(mntcNodeWorkDir);
}
use of org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK in project ignite by apache.
the class GridCommandHandlerTest method testPersistenceCleanCorruptedCachesCommand.
/**
* Test verifies persistence clean command cleaning only corrupted caches and not touching others.
*
* @throws Exception If failed.
*/
@Test
public void testPersistenceCleanCorruptedCachesCommand() throws Exception {
String cacheName0 = DEFAULT_CACHE_NAME + "0";
String cacheName1 = DEFAULT_CACHE_NAME + "1";
String cacheName2 = DEFAULT_CACHE_NAME + "2";
String cacheName3 = DEFAULT_CACHE_NAME + "3";
File mntcNodeWorkDir = startGridAndPutNodeToMaintenance(new CacheConfiguration[] { cacheConfiguration(cacheName0), cacheConfiguration(cacheName1), cacheConfiguration(cacheName2), cacheConfiguration(cacheName3) }, s -> !s.equals(cacheName3));
IgniteEx ig1 = startGrid(1);
String port = ig1.localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString();
assertEquals(EXIT_CODE_OK, execute("--persistence", "clean", "corrupted", "--host", "localhost", "--port", port));
boolean cleanedEmpty = Arrays.stream(mntcNodeWorkDir.listFiles()).filter(f -> f.getName().contains(cacheName0) || f.getName().contains(cacheName1) || f.getName().contains(cacheName2)).map(f -> f.listFiles().length == 1).reduce(true, (t, u) -> t && u);
assertTrue(cleanedEmpty);
stopGrid(1);
ig1 = startGrid(1);
assertFalse(ig1.context().maintenanceRegistry().isMaintenanceMode());
}
Aggregations