Search in sources :

Example 26 with WithSystemProperty

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);
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteEx(org.apache.ignite.internal.IgniteEx) CheckpointReadWriteLock(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointReadWriteLock) ReentrantReadWriteLockWithTracking(org.apache.ignite.internal.util.ReentrantReadWriteLockWithTracking) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 27 with WithSystemProperty

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);
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) IgniteEx(org.apache.ignite.internal.IgniteEx) CheckpointReadWriteLock(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointReadWriteLock) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) CountDownLatch(java.util.concurrent.CountDownLatch) ReentrantReadWriteLockWithTracking(org.apache.ignite.internal.util.ReentrantReadWriteLockWithTracking) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 28 with WithSystemProperty

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);
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 29 with WithSystemProperty

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));
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteEx(org.apache.ignite.internal.IgniteEx) Event(org.apache.ignite.events.Event) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 30 with WithSystemProperty

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();
}
Also used : GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) NullLogger(org.apache.ignite.logger.NullLogger) LogListener(org.apache.ignite.testframework.LogListener) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridTestNode(org.apache.ignite.testframework.GridTestNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridSpiTest(org.apache.ignite.testframework.junits.spi.GridSpiTest) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) Test(org.junit.Test) GridSpiAbstractConfigTest(org.apache.ignite.testframework.junits.spi.GridSpiAbstractConfigTest) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Aggregations

WithSystemProperty (org.apache.ignite.testframework.junits.WithSystemProperty)71 Test (org.junit.Test)71 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)59 IgniteEx (org.apache.ignite.internal.IgniteEx)46 Ignite (org.apache.ignite.Ignite)20 LogListener (org.apache.ignite.testframework.LogListener)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)12 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)11 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)10 File (java.io.File)9 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)9 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)8 ListeningTestLogger (org.apache.ignite.testframework.ListeningTestLogger)8 List (java.util.List)7 IgniteCache (org.apache.ignite.IgniteCache)7 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)7 ClusterNode (org.apache.ignite.cluster.ClusterNode)7 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)7