use of org.apache.ignite.testframework.ListeningTestLogger in project ignite by apache.
the class IgniteBinaryTest method testBinaryWithNotGenericInterceptor.
/**
* Tests that {@code org.apache.ignite.cache.CacheInterceptor#onBeforePut(javax.cache.Cache.Entry, java.lang.Object)}
* throws correct exception in case while cache operations are called from thin client. Only BinaryObject`s are
* acceptable in this case.
*/
@Test
public void testBinaryWithNotGenericInterceptor() throws Exception {
IgniteConfiguration ccfg = Config.getServerConfiguration().setCacheConfiguration(new CacheConfiguration("test").setInterceptor(new ThinBinaryValueInterceptor()));
String castErr = "cannot be cast to";
String treeErr = "B+Tree is corrupted";
ListeningTestLogger srvLog = new ListeningTestLogger(log);
LogListener lsnrCast = LogListener.matches(castErr).andMatches(str -> !str.contains(treeErr)).build();
srvLog.registerListener(lsnrCast);
ccfg.setGridLogger(srvLog);
try (Ignite ign = Ignition.start(ccfg)) {
try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) {
ClientCache<Integer, ThinBinaryValue> cache = client.cache("test");
try {
cache.put(1, new ThinBinaryValue());
fail();
} catch (Exception e) {
assertFalse(X.getFullStackTrace(e).contains(castErr));
}
ClientProcessorMXBean serverMxBean = getMxBean(ign.name(), "Clients", ClientListenerProcessor.class, ClientProcessorMXBean.class);
serverMxBean.showFullStackOnClientSide(true);
try {
cache.put(1, new ThinBinaryValue());
} catch (Exception e) {
assertTrue(X.getFullStackTrace(e).contains(castErr));
}
}
}
assertTrue(lsnrCast.check());
}
use of org.apache.ignite.testframework.ListeningTestLogger in project ignite by apache.
the class IgniteDiagnosticMessagesTest method checkLongRunningTx.
/**
* @param atomicityMode Cache atomicity mode.
* @throws Exception If failed.
*/
public void checkLongRunningTx(CacheAtomicityMode atomicityMode) throws Exception {
final int longOpDumpTimeout = 1000;
System.setProperty(IGNITE_LONG_OPERATIONS_DUMP_TIMEOUT, String.valueOf(longOpDumpTimeout));
try {
final Ignite node0 = startGrid(0);
CacheConfiguration ccfg = cacheConfiguration(atomicityMode);
node0.createCache(ccfg);
UUID id0 = node0.cluster().localNode().id();
ListeningTestLogger testLog = this.testLog = new ListeningTestLogger(false, log);
String msg1 = "Cache entries [cacheId=" + CU.cacheId(DEFAULT_CACHE_NAME) + ", cacheName=" + DEFAULT_CACHE_NAME + "]:";
String msg2 = "General node info [id=" + id0;
LogListener lsnr = LogListener.matches(msg1).andMatches(msg2).build();
testLog.registerListener(lsnr);
final Ignite node1 = startGrid(1);
awaitPartitionMapExchange();
final CountDownLatch l1 = new CountDownLatch(1);
final CountDownLatch l2 = new CountDownLatch(1);
final AtomicReference<Integer> key = new AtomicReference<>();
GridCompoundFuture<Void, Void> fut = new GridCompoundFuture<>();
fut.add(GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
IgniteCache<Object, Object> cache = node0.cache(DEFAULT_CACHE_NAME);
try (Transaction tx = node0.transactions().txStart()) {
key.set(primaryKey(cache));
cache.putIfAbsent(key.get(), "dummy val");
l1.countDown();
l2.await();
tx.commit();
}
return null;
}
}, "tx-1"));
fut.add(GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
IgniteCache<Object, Object> cache = node1.cache(DEFAULT_CACHE_NAME);
try (Transaction tx = node1.transactions().txStart()) {
l1.await();
cache.replace(key.get(), "dummy val2");
tx.commit();
}
return null;
}
}, "tx-2"));
fut.markInitialized();
U.sleep(longOpDumpTimeout);
assertFalse(fut.isDone());
boolean wait = waitForCondition(lsnr::check, longOpDumpTimeout * 2);
l2.countDown();
fut.get();
assertTrue("Unable to found diagnostic messages.", wait);
} finally {
System.clearProperty(IGNITE_LONG_OPERATIONS_DUMP_TIMEOUT);
}
}
use of org.apache.ignite.testframework.ListeningTestLogger in project ignite by apache.
the class IgniteDiagnosticMessagesTest method testTimeOutTxLock.
/**
* Tests that {@link org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLockFuture} timeout object
* dumps debug info to log.
*
* @throws Exception If fails.
*/
@Test
public void testTimeOutTxLock() throws Exception {
final int longOpDumpTimeout = 500;
ListeningTestLogger testLog = new ListeningTestLogger(false, log);
IgniteLogger oldLog = GridTestUtils.getFieldValue(GridDhtLockFuture.class, "log");
GridTestUtils.setFieldValue(GridDhtLockFuture.class, "log", testLog);
try {
IgniteEx grid1 = startGrid(0);
LogListener lsnr = LogListener.matches(Pattern.compile("Transaction tx=GridNearTxLocal \\[.*\\] timed out, can't acquire lock for")).andMatches(Pattern.compile(".*xid=.*, xidVer=.*, nearXid=.*, nearXidVer=.*, label=lock, " + "nearNodeId=" + grid1.cluster().localNode().id() + ".*")).build();
testLog.registerListener(lsnr);
this.testLog = testLog;
IgniteEx grid2 = startGrid(1);
grid2.context().cache().context().tm().longOperationsDumpTimeout(longOpDumpTimeout);
awaitPartitionMapExchange();
emulateTxLockTimeout(grid1, grid2);
assertTrue(lsnr.check());
} finally {
GridTestUtils.setFieldValue(GridDhtLockFuture.class, "log", oldLog);
}
}
use of org.apache.ignite.testframework.ListeningTestLogger in project ignite by apache.
the class EvictPartitionInLogTest method beforeTestsStarted.
/**
* {@inheritDoc}
*/
@Override
protected void beforeTestsStarted() throws Exception {
super.beforeTestsStarted();
clearStaticLog(GridDhtLocalPartition.class);
testLog = new ListeningTestLogger(false, log);
}
use of org.apache.ignite.testframework.ListeningTestLogger in project ignite by apache.
the class WalDeletionArchiveAbstractTest method testSingleCleanWalArchive.
/**
* Checks that the deletion of WAL segments occurs with the maximum number of segments.
*
* @throws Exception If failed.
*/
@Test
@WithSystemProperty(key = IGNITE_CHECKPOINT_TRIGGER_ARCHIVE_SIZE_PERCENTAGE, value = "1000")
public void testSingleCleanWalArchive() throws Exception {
IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(0)).setCacheConfiguration(cacheConfiguration()).setDataStorageConfiguration(new DataStorageConfiguration().setCheckpointFrequency(Long.MAX_VALUE).setMaxWalArchiveSize(5 * MB).setWalSegmentSize((int) MB).setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(true).setMaxSize(GB).setCheckpointPageBufferSize(GB)));
ListeningTestLogger listeningLog = new ListeningTestLogger(cfg.getGridLogger());
cfg.setGridLogger(listeningLog);
IgniteEx n = startGrid(cfg);
n.cluster().state(ClusterState.ACTIVE);
awaitPartitionMapExchange();
for (int i = 0; walArchiveSize(n) < 20L * cfg.getDataStorageConfiguration().getWalSegmentSize(); ) n.cache(DEFAULT_CACHE_NAME).put(i++, new byte[(int) (512 * KB)]);
assertEquals(-1, wal(n).lastTruncatedSegment());
assertEquals(0, gridDatabase(n).lastCheckpointMarkWalPointer().index());
Collection<String> logStrs = new ConcurrentLinkedQueue<>();
listeningLog.registerListener(logStr -> {
if (logStr.contains("Finish clean WAL archive"))
logStrs.add(logStr);
});
forceCheckpoint();
long maxWalArchiveSize = cfg.getDataStorageConfiguration().getMaxWalArchiveSize();
assertTrue(waitForCondition(() -> walArchiveSize(n) < maxWalArchiveSize, getTestTimeout()));
assertEquals(logStrs.toString(), 1, logStrs.size());
}
Aggregations