use of org.apache.ignite.testframework.LogListener in project ignite by apache.
the class CheckpointBufferDeadlockTest method runDeadlockScenario.
/**
*/
private void runDeadlockScenario() throws Exception {
LogListener lsnr = LogListener.matches(s -> s.contains("AssertionError")).build();
log.registerListener(lsnr);
IgniteEx ig = startGrid(0);
ig.cluster().active(true);
GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) ig.context().cache().context().database();
FilePageStoreManager pageStoreMgr = (FilePageStoreManager) ig.context().cache().context().pageStore();
final String cacheName = "single-part";
CacheConfiguration<Object, Object> cacheCfg = new CacheConfiguration<>().setName(cacheName).setAffinity(new RendezvousAffinityFunction(false, 1));
IgniteCache<Object, Object> singlePartCache = ig.getOrCreateCache(cacheCfg);
db.enableCheckpoints(false).get();
Thread.sleep(1_000);
try (IgniteDataStreamer<Object, Object> streamer = ig.dataStreamer(singlePartCache.getName())) {
int entries = MAX_SIZE / ENTRY_BYTE_CHUNK_SIZE / 4;
for (int i = 0; i < entries; i++) streamer.addData(i, new byte[ENTRY_BYTE_CHUNK_SIZE]);
streamer.flush();
}
slowCheckpointEnabled.set(true);
log.info(">>> Slow checkpoints enabled");
db.enableCheckpoints(true).get();
AtomicBoolean fail = new AtomicBoolean(false);
IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(new Runnable() {
@Override
public void run() {
int loops = 0;
while (!stop.get()) {
if (loops % 10 == 0 && loops > 0 && loops < 500 || loops % 500 == 0 && loops >= 500)
log.info("Successfully completed " + loops + " loops");
db.checkpointReadLock();
try {
Set<FullPageId> pickedPagesSet = new HashSet<>();
PageStore store = pageStoreMgr.getStore(CU.cacheId(cacheName), 0);
int pages = store.pages();
DataRegion region = db.dataRegion(DataStorageConfiguration.DFLT_DATA_REG_DEFAULT_NAME);
PageMemoryImpl pageMem = (PageMemoryImpl) region.pageMemory();
while (pickedPagesSet.size() < PAGES_TOUCHED_UNDER_CP_LOCK) {
int pageIdx = ThreadLocalRandom.current().nextInt(PAGES_TOUCHED_UNDER_CP_LOCK, pages - PAGES_TOUCHED_UNDER_CP_LOCK);
long pageId = PageIdUtils.pageId(0, PageIdAllocator.FLAG_DATA, pageIdx);
long page = pageMem.acquirePage(CU.cacheId(cacheName), pageId);
try {
// We do not know correct flag(FLAG_DATA or FLAG_AUX). Skip page if no luck.
if (pageId != PageIO.getPageId(page + PageMemoryImpl.PAGE_OVERHEAD))
continue;
} finally {
pageMem.releasePage(CU.cacheId(cacheName), pageId, page);
}
pickedPagesSet.add(new FullPageId(pageId, CU.cacheId(cacheName)));
}
List<FullPageId> pickedPages = new ArrayList<>(pickedPagesSet);
assertEquals(PAGES_TOUCHED_UNDER_CP_LOCK, pickedPages.size());
// Sort to avoid deadlocks on pages rw-locks.
pickedPages.sort(new Comparator<FullPageId>() {
@Override
public int compare(FullPageId o1, FullPageId o2) {
int cmp = Long.compare(o1.groupId(), o2.groupId());
if (cmp != 0)
return cmp;
return Long.compare(o1.effectivePageId(), o2.effectivePageId());
}
});
List<Long> readLockedPages = new ArrayList<>();
// Read lock many pages at once intentionally.
for (int i = 0; i < PAGES_TOUCHED_UNDER_CP_LOCK / 2; i++) {
FullPageId fpid = pickedPages.get(i);
long page = pageMem.acquirePage(fpid.groupId(), fpid.pageId());
long abs = pageMem.readLock(fpid.groupId(), fpid.pageId(), page);
assertFalse(fpid.toString(), abs == 0);
readLockedPages.add(page);
}
// Emulate writes to trigger throttling.
for (int i = PAGES_TOUCHED_UNDER_CP_LOCK / 2; i < PAGES_TOUCHED_UNDER_CP_LOCK && !stop.get(); i++) {
FullPageId fpid = pickedPages.get(i);
long page = pageMem.acquirePage(fpid.groupId(), fpid.pageId());
long abs = pageMem.writeLock(fpid.groupId(), fpid.pageId(), page);
assertFalse(fpid.toString(), abs == 0);
pageMem.writeUnlock(fpid.groupId(), fpid.pageId(), page, null, true);
pageMem.releasePage(fpid.groupId(), fpid.pageId(), page);
}
for (int i = 0; i < PAGES_TOUCHED_UNDER_CP_LOCK / 2; i++) {
FullPageId fpid = pickedPages.get(i);
pageMem.readUnlock(fpid.groupId(), fpid.pageId(), readLockedPages.get(i));
pageMem.releasePage(fpid.groupId(), fpid.pageId(), readLockedPages.get(i));
}
} catch (Throwable e) {
log.error("Error in loader thread", e);
fail.set(true);
} finally {
db.checkpointReadUnlock();
}
loops++;
}
}
}, 10, "load-runner");
// Await for the start of throttling.
Thread.sleep(10_000);
slowCheckpointEnabled.set(false);
log.info(">>> Slow checkpoints disabled");
assertFalse(fail.get());
// Previous checkpoint should eventually finish.
forceCheckpoint();
stop.set(true);
fut.get();
db.enableCheckpoints(true).get();
// check that there is no problem with pinned pages
ig.destroyCache(cacheName);
assertFalse(lsnr.check());
log.unregisterListener(lsnr);
}
use of org.apache.ignite.testframework.LogListener 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.LogListener in project ignite by apache.
the class PerformanceStatisticsRotateFileTest method testRotateFile.
/**
* @throws Exception If failed.
*/
@Test
public void testRotateFile() throws Exception {
assertThrows(log, AbstractPerformanceStatisticsTest::rotateCollectStatistics, IgniteException.class, "Performance statistics collection not started.");
startCollectStatistics();
int cnt = 3;
List<File> filesBefore = new ArrayList<>();
for (int i = 0; i < cnt; i++) {
G.allGrids().forEach(ignite -> ignite.cache(DEFAULT_CACHE_NAME).get(0));
LogListener lsnr = matches("Performance statistics writer rotated").times(NODES_CNT).build();
listeningLog.registerListener(lsnr);
List<File> files = statisticsFiles();
files.removeAll(filesBefore);
filesBefore.addAll(files);
rotateCollectStatistics();
assertTrue(waitForCondition(lsnr::check, TIMEOUT));
checkFiles(files, NODES_CNT, NODES_CNT);
}
stopCollectStatistics();
checkFiles(statisticsFiles(), NODES_CNT * (cnt + 1), NODES_CNT * cnt);
}
use of org.apache.ignite.testframework.LogListener in project ignite by apache.
the class RebuildIndexWithHistoricalRebalanceTest method finishIndexRebuildLsnr.
/**
*/
private LogListener finishIndexRebuildLsnr(String cacheName) {
LogListener lsnr = LogListener.matches(s -> s.startsWith("Finished indexes rebuilding for cache [name=" + cacheName)).times(1).build();
log.registerListener(lsnr);
return lsnr;
}
use of org.apache.ignite.testframework.LogListener in project ignite by apache.
the class IgniteQueryDedicatedPoolTest method checkStarvationQryPoolInLog.
/**
* Check messages about starvation query pool in log.
*
* @param checkTimeout Check timeout.
* @param findLogMsg Log message of interest.
* @param contains Expect whether or not messages are in log.
* @throws Exception If failed.
*/
private void checkStarvationQryPoolInLog(long checkTimeout, String findLogMsg, boolean contains) throws Exception {
assertNotNull(findLogMsg);
qryPoolSize = 1;
startGrid("server");
IgniteEx clientNode = startClientGrid("client");
IgniteCache<Integer, Integer> cache = clientNode.cache(CACHE_NAME);
cache.put(0, 0);
int qrySize = 2;
CyclicBarrier barrier = new CyclicBarrier(qrySize);
LogListener logLsnr = LogListener.matches(findLogMsg).build();
testLog.registerListener(logLsnr);
for (int i = 0; i < qrySize; i++) {
runAsync(() -> {
barrier.await();
cache.query(new ScanQuery<>((o, o2) -> {
doSleep(500);
return true;
})).getAll();
return null;
});
}
if (contains)
assertTrue(waitForCondition(logLsnr::check, checkTimeout));
else
assertFalse(waitForCondition(logLsnr::check, checkTimeout));
}
Aggregations