use of org.apache.ignite.testframework.junits.WithSystemProperty in project ignite by apache.
the class CheckpointReadLockFailureTest method testReentrance.
/**
* @throws Exception If failed.
*/
@Test
@WithSystemProperty(key = IGNITE_PDS_LOG_CP_READ_LOCK_HOLDERS, value = "true")
public void testReentrance() throws Exception {
IgniteEx ig = startGrid(0);
ig.cluster().state(ClusterState.ACTIVE);
GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) ig.context().cache().context().database();
CheckpointReadWriteLock checkpointReadWriteLock = U.field(db.checkpointManager.checkpointTimeoutLock(), "checkpointReadWriteLock");
ReentrantReadWriteLockWithTracking rwLock = U.field(checkpointReadWriteLock, "checkpointLock");
CountDownLatch waitFirstRLock = new CountDownLatch(1);
CountDownLatch waitSecondRLock = new CountDownLatch(1);
long timeout = 500L;
IgniteInternalFuture f0 = GridTestUtils.runAsync(() -> {
// noinspection LockAcquiredButNotSafelyReleased
rwLock.readLock().lock();
// noinspection LockAcquiredButNotSafelyReleased
rwLock.readLock().lock();
rwLock.readLock().unlock();
waitFirstRLock.countDown();
try {
waitSecondRLock.await();
} catch (InterruptedException e) {
fail(e.toString());
}
rwLock.readLock().unlock();
}, "async-runnable-runner-1");
IgniteInternalFuture f1 = GridTestUtils.runAsync(() -> {
try {
waitFirstRLock.await();
} catch (InterruptedException e) {
fail(e.toString());
}
try {
rwLock.writeLock().tryLock();
assertFalse(GridTestUtils.waitForCondition(rwLock.writeLock()::isHeldByCurrentThread, timeout));
} catch (IgniteInterruptedCheckedException e) {
e.printStackTrace();
}
waitSecondRLock.countDown();
try {
rwLock.writeLock().tryLock(timeout, TimeUnit.MILLISECONDS);
assertTrue(rwLock.writeLock().isHeldByCurrentThread());
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
rwLock.writeLock().unlock();
}
}, "async-runnable-runner-2");
f1.get(4 * timeout);
f0.get(4 * timeout);
stopGrid(0);
}
use of org.apache.ignite.testframework.junits.WithSystemProperty in project ignite by apache.
the class CheckpointReadLockFailureTest method testPrintCpRLockHolder.
/**
* @throws Exception If failed.
*/
@Test
@WithSystemProperty(key = IGNITE_PDS_LOG_CP_READ_LOCK_HOLDERS, value = "true")
public void testPrintCpRLockHolder() throws Exception {
CountDownLatch canRelease = new CountDownLatch(1);
testLog = new ListeningTestLogger(log);
LogListener lsnr = LogListener.matches(LOCK_HOLD_MESSAGE).build();
testLog.registerListener(lsnr);
IgniteEx ig = startGrid(0);
ig.cluster().state(ClusterState.ACTIVE);
GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) ig.context().cache().context().database();
CheckpointReadWriteLock checkpointReadWriteLock = U.field(db.checkpointManager.checkpointTimeoutLock(), "checkpointReadWriteLock");
ReentrantReadWriteLockWithTracking tracker = U.field(checkpointReadWriteLock, "checkpointLock");
GridTestUtils.runAsync(() -> {
checkpointReadWriteLock.readLock();
try {
canRelease.await(tracker.lockWaitThreshold() + 500, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
checkpointReadWriteLock.readUnlock();
}
}, "async-runnable-runner-1");
assertTrue(GridTestUtils.waitForCondition(lsnr::check, tracker.lockWaitThreshold() + 1000));
stopGrid(0);
}
use of org.apache.ignite.testframework.junits.WithSystemProperty in project ignite by apache.
the class IgnitePdsDiscoDataHandlingInNewClusterTest method testNewDynamicCacheDoesntStartOnOldNode.
/**
* @throws Exception
*/
@Test
@WithSystemProperty(key = IgniteSystemProperties.IGNITE_DUMP_THREADS_ON_FAILURE, value = "false")
public void testNewDynamicCacheDoesntStartOnOldNode() throws Exception {
IgniteEx ig0 = startGrid(NODE_CONS_ID_0);
startGrid(NODE_CONS_ID_1);
ig0.cluster().active(true);
startDynamicCache(ig0, DYNAMIC_CACHE_NAME_0, MIXED_CACHES_GROUP_NAME_0);
stopGrid(NODE_CONS_ID_1);
startDynamicCache(ig0, DYNAMIC_CACHE_NAME_1, MIXED_CACHES_GROUP_NAME_0);
startDynamicCache(ig0, DYNAMIC_CACHE_NAME_2, DYNAMIC_CACHES_GROUP_NAME_1);
SHOULD_FAIL.set(true);
IgniteEx ig1 = startGrid(NODE_CONS_ID_1);
verifyCachesAndGroups(ig1);
}
use of org.apache.ignite.testframework.junits.WithSystemProperty in project ignite by apache.
the class GridTcpCommunicationInverseConnectionEstablishingTest method testClientSkippingInverseConnResponseIsForciblyFailed.
/**
* Forcible node kill functionality is triggered in inverse connection request flow as well
* when a timeout for inverse connection is reached.
*
* @throws Exception If failed.
*/
@Test
@WithSystemProperty(key = IgniteSystemProperties.IGNITE_ENABLE_FORCIBLE_NODE_KILL, value = "true")
public void testClientSkippingInverseConnResponseIsForciblyFailed() throws Exception {
UNREACHABLE_DESTINATION.set(UNRESOLVED_HOST);
RESPOND_TO_INVERSE_REQUEST.set(false);
AtomicBoolean clientFailedEventFlag = new AtomicBoolean(false);
IgniteEx srv = startGrid();
srv.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event event) {
clientFailedEventFlag.set(true);
return false;
}
}, EventType.EVT_NODE_FAILED, EventType.EVT_NODE_LEFT);
forceClientToSrvConnections = false;
IgniteEx client = startClientGrid(1);
ClusterNode clientNode = client.localNode();
interruptCommWorkerThreads(client.name());
TcpCommunicationSpi spi = (TcpCommunicationSpi) srv.configuration().getCommunicationSpi();
GridTestUtils.invoke(spi, "onNodeLeft", clientNode.consistentId(), clientNode.id());
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(() -> srv.context().io().sendIoTest(clientNode, new byte[10], false).get());
assertTrue(GridTestUtils.waitForCondition(clientFailedEventFlag::get, 10_000));
}
use of org.apache.ignite.testframework.junits.WithSystemProperty in project ignite by apache.
the class GridTcpCommunicationSpiConfigSelfTest method testSendToNonInitializedTcpCommSpi.
/**
* Verifies that TcpCommunicationSpi starts messaging protocol only when fully initialized.
*
* @see <a href="https://issues.apache.org/jira/browse/IGNITE-12982">IGNITE-12982</a>
*
* @throws Exception If failed.
*/
@Test
@WithSystemProperty(key = "IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK", value = "true")
public void testSendToNonInitializedTcpCommSpi() throws Exception {
ListeningTestLogger listeningLogger = new ListeningTestLogger(log);
LogListener npeLsnr = LogListener.matches("NullPointerException").andMatches("InboundConnectionHandler.onMessageSent").build();
listeningLogger.registerListener(npeLsnr);
GridTestNode sendingNode = new GridTestNode();
sendingNode.order(0);
GridSpiTestContext sendingCtx = initSpiContext();
TcpCommunicationSpi sendingSpi = initializeSpi(sendingCtx, sendingNode, listeningLogger, false);
spisToStop.add(sendingSpi);
sendingSpi.onContextInitialized(sendingCtx);
GridTestNode receiverNode = new GridTestNode();
receiverNode.order(1);
GridSpiTestContext receiverCtx = initSpiContext();
/*
* This is a dirty hack to intervene into TcpCommunicationSpi#onContextInitialized0 method
* and add a delay before injecting metrics listener into its clients (like InboundConnectionHandler).
* The purpose of the delay is to make race between sending a message and initializing TcpCommSpi visible.
*
* This solution heavily depends on current code structure of onContextInitialized0 method.
* If any modifications are made to it, this logic could break and the test starts failing.
*
* In that case try to rewrite the test or delete it as this race is really hard to test.
*/
receiverCtx.metricsRegistryProducer((name) -> {
try {
Thread.sleep(100);
} catch (Exception ignored) {
// No-op.
}
return new MetricRegistry(name, null, null, new NullLogger());
});
TcpCommunicationSpi receiverSpi = initializeSpi(receiverCtx, receiverNode, listeningLogger, true);
spisToStop.add(receiverSpi);
receiverCtx.remoteNodes().add(sendingNode);
sendingCtx.remoteNodes().add(receiverNode);
IgniteInternalFuture sendFut = GridTestUtils.runAsync(() -> {
Message msg = new GridTestMessage(sendingNode.id(), 0, 0);
sendingSpi.sendMessage(receiverNode, msg);
});
IgniteInternalFuture initFut = GridTestUtils.runAsync(() -> {
try {
receiverSpi.onContextInitialized(receiverCtx);
} catch (Exception ignored) {
// No-op.
}
});
assertFalse("Check test logs, NPE was found", GridTestUtils.waitForCondition(npeLsnr::check, 3_000));
initFut.get();
sendFut.get();
}
Aggregations