use of org.apache.ignite.testframework.LogListener in project ignite by apache.
the class EvictionPolicyFailureHandlerTest method testCacheMapDoesNotContainsWrongEntityAfterTransaction.
/**
* We expect that localPeek produces an exception, but the entry evict returns false because the transaction locks
* this entry. After transaction commit, the entry will be evicted.
*/
@Test
public void testCacheMapDoesNotContainsWrongEntityAfterTransaction() throws Exception {
LogListener lsnr = LogListener.matches(s -> s.contains("The cache entry cannot be touched")).times(1).build();
log.registerListener(lsnr);
IgniteEx node = startGrid(0);
IgniteEx client = startClientGrid(1);
GridCacheAdapter<Object, Object> cache = ((IgniteKernal) node).internalCache(DEFAULT_CACHE_NAME);
cache.put(1, 1);
CountDownLatch locPeekFinished = new CountDownLatch(1);
CountDownLatch txStarted = new CountDownLatch(1);
CountDownLatch txFinished = new CountDownLatch(1);
GridTestUtils.runAsync(() -> {
IgniteCache<Object, Object> cache1 = client.cache(DEFAULT_CACHE_NAME);
IgniteTransactions transactions = client.transactions();
try (Transaction tx = transactions.txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache1.put(2.1, 2.4);
txStarted.countDown();
locPeekFinished.await();
tx.commit();
} catch (Exception ignore) {
}
txFinished.countDown();
}, "tx-thread");
txStarted.await();
try {
cache.localPeek(2.1, new CachePeekMode[] { CachePeekMode.ONHEAP });
} catch (Exception ignore) {
}
locPeekFinished.countDown();
assertTrue(lsnr.check(10_000));
txFinished.await();
assertFalse(cache.map().entrySet(cache.context().cacheId()).stream().anyMatch(e -> new Double(2.1).equals(e.key().value(null, false))));
assertEquals(ACTIVE, node.cluster().state());
}
use of org.apache.ignite.testframework.LogListener in project ignite by apache.
the class ExpiryPolicyInfoLoggingTest method checkLoggingExpiryInfoForDynamicallyCreatedCache.
/**
* Checking logging of expiry policy info for dynamically created cache.
*/
@Test
public void checkLoggingExpiryInfoForDynamicallyCreatedCache() throws Exception {
LogListener lsnr = LogListener.matches(s -> s.startsWith(String.format(STARTED_CACHE_MSG, CACHE_2_NAME)) && s.contains(String.format(EXPRITY_POLICY_MSG, AccessedExpiryPolicy.class.getName(), false))).times(1).build();
log.registerListener(lsnr);
IgniteEx srv = startGrid(0);
srv.createCache(new CacheConfiguration<>(CACHE_2_NAME).setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 5))).setEagerTtl(false));
assertTrue(lsnr.check());
}
use of org.apache.ignite.testframework.LogListener in project ignite by apache.
the class ExpiryPolicyInfoLoggingTest method checkLoggingExpiryInfoForStaticallyCreatedCache.
/**
* Checking logging of expiry policy info for statically created cache.
*/
@Test
public void checkLoggingExpiryInfoForStaticallyCreatedCache() throws Exception {
LogListener lsnr = LogListener.matches(s -> s.startsWith(String.format(STARTED_CACHE_MSG, CACHE_1_NAME)) && s.contains(String.format(EXPRITY_POLICY_MSG, ModifiedExpiryPolicy.class.getName(), true))).times(1).build();
log.registerListener(lsnr);
startGrid(0);
assertTrue(lsnr.check());
}
use of org.apache.ignite.testframework.LogListener 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.LogListener 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