use of org.apache.ignite.testframework.ListeningTestLogger in project ignite by apache.
the class WaitForBackupsOnShutdownSystemPropertyTest method beforeTest.
/**
* {@inheritDoc}
*/
@Override
protected void beforeTest() throws Exception {
super.beforeTest();
listeningLog = new ListeningTestLogger(log);
}
use of org.apache.ignite.testframework.ListeningTestLogger in project ignite by apache.
the class IgniteSecurityProcessorTest method testThrowIllegalStateExceptionIfNodeNotFoundInDiscoCache.
/**
* Checks that {@link IgniteSecurityProcessor#withContext(UUID)} throws exception in case a node ID is unknown.
*/
@Test
public void testThrowIllegalStateExceptionIfNodeNotFoundInDiscoCache() {
GridKernalContext ctx = mock(GridKernalContext.class);
when(ctx.config()).thenReturn(new IgniteConfiguration());
when(ctx.discovery()).thenReturn(mock(GridDiscoveryManager.class));
LogListener logLsnr = LogListener.matches(s -> s.contains("Failed to obtain a security context.")).times(1).build();
ListeningTestLogger log = new ListeningTestLogger(false);
log.registerListener(logLsnr);
when(ctx.log(IgniteSecurityProcessor.class)).thenReturn(log);
GridSecurityProcessor secPrc = mock(GridSecurityProcessor.class);
IgniteSecurityProcessor ignSecPrc = new IgniteSecurityProcessor(ctx, secPrc);
assertThrowsWithCause(() -> ignSecPrc.withContext(UUID.randomUUID()), IllegalStateException.class);
assertTrue(logLsnr.check());
}
use of org.apache.ignite.testframework.ListeningTestLogger in project ignite by apache.
the class PerformanceStatisticsRotateFileTest method beforeTestsStarted.
/**
* {@inheritDoc}
*/
@Override
protected void beforeTestsStarted() throws Exception {
listeningLog = new ListeningTestLogger(log);
startGrids(NODES_CNT - 1);
startClientGrid(NODES_CNT);
}
use of org.apache.ignite.testframework.ListeningTestLogger in project ignite by apache.
the class IgniteSnapshotManagerSelfTest method testSnapshotAlwaysStartsNewCheckpoint.
/**
* @throws Exception If fails.
*/
@Test
public void testSnapshotAlwaysStartsNewCheckpoint() throws Exception {
long testTimeout = 30_000;
listenLog = new ListeningTestLogger(log);
LogListener lsnr = LogListener.matches("Snapshot operation is scheduled on local node").times(1).build();
listenLog.registerListener(lsnr);
IgniteEx ignite = startGridsWithCache(1, 4096, key -> new Account(key, key), new CacheConfiguration<>(DEFAULT_CACHE_NAME));
assertTrue("Test requires that only forced checkpoints were allowed.", ignite.configuration().getDataStorageConfiguration().getCheckpointFrequency() >= TimeUnit.DAYS.toMillis(365));
GridCacheDatabaseSharedManager dbMgr = ((GridCacheDatabaseSharedManager) ignite.context().cache().context().database());
// Ensure that previous checkpoint finished.
dbMgr.getCheckpointer().currentProgress().futureFor(CheckpointState.FINISHED).get(testTimeout);
CountDownLatch beforeCpEnter = new CountDownLatch(1);
CountDownLatch beforeCpExit = new CountDownLatch(1);
// Block checkpointer on start.
dbMgr.addCheckpointListener(new CheckpointListener() {
@Override
public void beforeCheckpointBegin(CheckpointListener.Context ctx) throws IgniteCheckedException {
beforeCpEnter.countDown();
U.await(beforeCpExit, testTimeout, TimeUnit.MILLISECONDS);
}
@Override
public void onMarkCheckpointBegin(CheckpointListener.Context ctx) {
// No-op.
}
@Override
public void onCheckpointBegin(CheckpointListener.Context ctx) {
// No-op.
}
});
dbMgr.forceCheckpoint("snapshot-task-hang-test");
beforeCpEnter.await(testTimeout, TimeUnit.MILLISECONDS);
IgniteFuture<Void> snpFut = ignite.snapshot().createSnapshot(SNAPSHOT_NAME);
// Wait until the snapshot task checkpoint listener is registered.
assertTrue(GridTestUtils.waitForCondition(lsnr::check, testTimeout));
// Unblock checkpointer.
beforeCpExit.countDown();
// Make sure the snapshot has been taken.
snpFut.get(testTimeout);
}
use of org.apache.ignite.testframework.ListeningTestLogger in project ignite by apache.
the class DiagnosticProcessorTest method testOutputDiagnosticCorruptedPagesInfo.
/**
* Check that when an CorruptedTreeException is thrown, a "corruptedPages_TIMESTAMP.txt"
* will be created and a warning will be in the log.
*
* @throws Exception If failed.
*/
@Test
public void testOutputDiagnosticCorruptedPagesInfo() throws Exception {
ListeningTestLogger listeningTestLog = new ListeningTestLogger(GridAbstractTest.log);
IgniteEx n = startGrid(0, cfg -> {
cfg.setGridLogger(listeningTestLog);
});
n.cluster().state(ClusterState.ACTIVE);
awaitPartitionMapExchange();
for (int i = 0; i < 10_000; i++) n.cache(DEFAULT_CACHE_NAME).put(i, "val_" + i);
assertNotNull(n.context().diagnostic());
T2<Integer, Long> anyPageId = findAnyPageId(n);
assertNotNull(anyPageId);
LogListener logLsnr = LogListener.matches("CorruptedTreeException has occurred. " + "To diagnose it, make a backup of the following directories: ").build();
listeningTestLog.registerListener(logLsnr);
n.context().failure().process(new FailureContext(FailureType.CRITICAL_ERROR, new CorruptedTreeException("Test ex", null, DEFAULT_CACHE_NAME, anyPageId.get1(), anyPageId.get2())));
assertTrue(logLsnr.check());
Path diagnosticPath = getFieldValue(n.context().diagnostic(), "diagnosticPath");
List<File> corruptedPagesFiles = Arrays.stream(diagnosticPath.toFile().listFiles()).filter(f -> corruptedPagesFileNamePattern().matcher(f.getName()).matches()).collect(toList());
assertEquals(1, corruptedPagesFiles.size());
assertTrue(corruptedPagesFiles.get(0).length() > 0);
}
Aggregations