use of org.apache.ignite.testframework.LogListener in project ignite by apache.
the class GridCommandHandlerBrokenIndexTest method getConfiguration.
/**
* Adds error message listeners to server nodes.
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
if (cfg.isClientMode())
return cfg;
ListeningTestLogger testLog = new ListeningTestLogger(false, log);
Pattern logErrMsgPattern = Pattern.compile("Failed to lookup key: " + IDX_ISSUE_STR);
LogListener lsnr = LogListener.matches(logErrMsgPattern).build();
testLog.registerListener(lsnr);
lsnrs.add(lsnr);
cfg.setGridLogger(testLog);
return cfg;
}
use of org.apache.ignite.testframework.LogListener in project ignite by apache.
the class GridCommandHandlerDefragmentationTest method testDefragmentationSchedule.
/**
* @throws Exception If failed.
*/
@Test
public void testDefragmentationSchedule() throws Exception {
Ignite ignite = startGrids(2);
ignite.cluster().state(ACTIVE);
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute("--defragmentation", "schedule"));
String grid0ConsId = grid(0).configuration().getConsistentId().toString();
String grid1ConsId = grid(1).configuration().getConsistentId().toString();
ListeningTestLogger testLog = new ListeningTestLogger();
CommandHandler cmd = createCommandHandler(testLog);
LogListener logLsnr = LogListener.matches("Scheduling completed successfully.").build();
testLog.registerListener(logLsnr);
assertEquals(EXIT_CODE_OK, execute(cmd, "--defragmentation", "schedule", "--nodes", grid0ConsId));
assertTrue(logLsnr.check());
MaintenanceTask mntcTask = DefragmentationParameters.toStore(Collections.emptyList());
assertNotNull(grid(0).context().maintenanceRegistry().registerMaintenanceTask(mntcTask));
assertNull(grid(1).context().maintenanceRegistry().registerMaintenanceTask(mntcTask));
stopGrid(0);
startGrid(0);
logLsnr = LogListener.matches("Node is already in Maintenance Mode").build();
testLog.clearListeners();
testLog.registerListener(logLsnr);
assertEquals(EXIT_CODE_OK, execute(cmd, "--defragmentation", "schedule", "--nodes", grid0ConsId));
assertTrue(logLsnr.check());
stopGrid(0);
startGrid(0);
stopGrid(1);
startGrid(1);
stopAllGrids();
startGrids(2);
logLsnr = LogListener.matches("Scheduling completed successfully.").times(2).build();
testLog.clearListeners();
testLog.registerListener(logLsnr);
assertEquals(EXIT_CODE_OK, execute(cmd, "--defragmentation", "schedule", "--nodes", String.join(",", grid0ConsId, grid1ConsId)));
assertTrue(logLsnr.check());
}
use of org.apache.ignite.testframework.LogListener in project ignite by apache.
the class GridCommandHandlerDefragmentationTest method testDefragmentationCancel.
/**
* @throws Exception If failed.
*/
@Test
public void testDefragmentationCancel() throws Exception {
Ignite ignite = startGrids(2);
ignite.cluster().state(ACTIVE);
String grid0ConsId = grid(0).configuration().getConsistentId().toString();
ListeningTestLogger testLog = new ListeningTestLogger();
CommandHandler cmd = createCommandHandler(testLog);
assertEquals(EXIT_CODE_OK, execute(cmd, "--defragmentation", "schedule", "--nodes", grid0ConsId));
LogListener logLsnr = LogListener.matches("Scheduled defragmentation task cancelled successfully.").atLeast(1).build();
testLog.registerListener(logLsnr);
assertEquals(EXIT_CODE_OK, execute(cmd, "--port", grid(0).localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString(), "--defragmentation", "cancel"));
assertTrue(logLsnr.check());
testLog.clearListeners();
logLsnr = LogListener.matches("Scheduled defragmentation task is not found.").build();
testLog.registerListener(logLsnr);
assertEquals(EXIT_CODE_OK, execute(cmd, "--port", grid(1).localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString(), "--defragmentation", "cancel"));
assertTrue(logLsnr.check());
}
use of org.apache.ignite.testframework.LogListener 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.testframework.LogListener in project ignite by apache.
the class GridCommandHandlerInterruptCommandTest method testCancelValidateIndexesClosure.
/**
* Test invokes index validation closure and canceling it after started.
*
* @throws Exception If failed.
*/
@Test
public void testCancelValidateIndexesClosure() throws Exception {
IgniteEx ignite0 = startGrid(0);
ignite0.cluster().active(true);
preloadeData(ignite0);
AtomicBoolean cancelled = new AtomicBoolean(false);
ValidateIndexesClosure clo = new ValidateIndexesClosure(cancelled::get, Collections.singleton(DEFAULT_CACHE_NAME), 0, 0, false, true);
ListeningTestLogger listeningLogger = new ListeningTestLogger(false, log);
GridTestUtils.setFieldValue(clo, "ignite", ignite0);
GridTestUtils.setFieldValue(clo, "log", listeningLogger);
LogListener lnsrValidationStarted = LogListener.matches("Current progress of ValidateIndexesClosure").build();
listeningLogger.registerListener(lnsrValidationStarted);
IgniteInternalFuture fut = GridTestUtils.runAsync(() -> GridTestUtils.assertThrows(log, clo::call, IgniteException.class, ValidateIndexesClosure.CANCELLED_MSG));
assertTrue(GridTestUtils.waitForCondition(lnsrValidationStarted::check, 10_000));
assertFalse(fut.isDone());
cancelled.set(true);
fut.get(10_000);
}
Aggregations