Search in sources :

Example 61 with LogListener

use of org.apache.ignite.testframework.LogListener 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 62 with LogListener

use of org.apache.ignite.testframework.LogListener in project ignite by apache.

the class IgnitePdsBinaryMetadataAsyncWritingTest method testPutRequestFromClientIsBlockedIfBinaryMetaWriteIsHanging.

/**
 * Verifies that put(key) method called from client on cache in FULL_SYNC mode returns only when
 * all affinity nodes for this key finished writing binary metadata.
 *
 * @throws Exception If failed.
 */
@Test
public void testPutRequestFromClientIsBlockedIfBinaryMetaWriteIsHanging() throws Exception {
    String cacheName = "testCache";
    CacheConfiguration testCacheCfg = new CacheConfiguration(cacheName).setBackups(2).setAtomicityMode(CacheAtomicityMode.ATOMIC).setCacheMode(CacheMode.PARTITIONED).setWriteSynchronizationMode(FULL_SYNC);
    IgniteEx ig0 = startGrid(0);
    IgniteEx cl0 = startGrid("client0");
    CountDownLatch fileWriteLatch = new CountDownLatch(1);
    IgniteEx ig1 = startGrid(1);
    ig1.context().discovery().setCustomEventListener(MetadataUpdateAcceptedMessage.class, (topVer, snd, msg) -> suppressException(fileWriteLatch::await));
    ListeningTestLogger listeningLog = new ListeningTestLogger(log);
    setRootLoggerDebugLevel();
    LogListener waitingForWriteLsnr = LogListener.matches("Waiting for write completion of").build();
    listeningLog.registerListener(waitingForWriteLsnr);
    startGrid(2);
    ig0.cluster().active(true);
    IgniteCache cache0 = cl0.createCache(testCacheCfg);
    int key0 = findAffinityKeyForNode(ig0.affinity(cacheName), ig0.localNode());
    AtomicBoolean putFinished = new AtomicBoolean(false);
    GridTestUtils.runAsync(() -> {
        cache0.put(key0, new TestAddress(key0, "Russia", "Saint-Petersburg"));
        putFinished.set(true);
    });
    assertFalse(GridTestUtils.waitForCondition(() -> putFinished.get(), 5_000));
    fileWriteLatch.countDown();
    assertTrue(GridTestUtils.waitForCondition(() -> putFinished.get(), 5_000));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LogListener(org.apache.ignite.testframework.LogListener) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteCache(org.apache.ignite.IgniteCache) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) CountDownLatch(java.util.concurrent.CountDownLatch) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 63 with LogListener

use of org.apache.ignite.testframework.LogListener in project ignite by apache.

the class GridTcpCommunicationInverseConnectionEstablishingTest method testClientSkipsInverseConnectionResponse.

/**
 * No server threads hang even if client doesn't respond to inverse connection request.
 *
 * @throws Exception If failed.
 */
@Test
public void testClientSkipsInverseConnectionResponse() throws Exception {
    UNREACHABLE_DESTINATION.set(UNRESOLVED_HOST);
    RESPOND_TO_INVERSE_REQUEST.set(false);
    startGrids(SRVS_NUM - 1);
    LogListener lsnr = LogListener.matches("Failed to wait for establishing inverse communication connection").build();
    startGrid(SRVS_NUM - 1, (UnaryOperator<IgniteConfiguration>) cfg -> {
        ListeningTestLogger log = new ListeningTestLogger(false, cfg.getGridLogger());
        log.registerListener(lsnr);
        return cfg.setGridLogger(log);
    });
    forceClientToSrvConnections = false;
    IgniteEx client = startClientGrid(SRVS_NUM);
    ClusterNode clientNode = client.localNode();
    IgniteEx srv = grid(SRVS_NUM - 1);
    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(fut::isDone, 30_000));
    assertTrue(lsnr.check());
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) LogListener(org.apache.ignite.testframework.LogListener) CoreMatchers.is(org.hamcrest.CoreMatchers.is) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) ClusterState(org.apache.ignite.cluster.ClusterState) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) UnaryOperator(java.util.function.UnaryOperator) IgniteEx(org.apache.ignite.internal.IgniteEx) AtomicReference(java.util.concurrent.atomic.AtomicReference) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) Map(java.util.Map) Assume(org.junit.Assume) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) EventType(org.apache.ignite.events.EventType) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Event(org.apache.ignite.events.Event) TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) FULL_SYNC(org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC) IgniteCache(org.apache.ignite.IgniteCache) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TcpInverseConnectionResponseMessage(org.apache.ignite.spi.communication.tcp.internal.TcpInverseConnectionResponseMessage) GridTopic(org.apache.ignite.internal.GridTopic) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Message(org.apache.ignite.plugin.extensions.communication.Message) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) ATOMIC(org.apache.ignite.cache.CacheAtomicityMode.ATOMIC) GridCommunicationClient(org.apache.ignite.internal.util.nio.GridCommunicationClient) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode) Collections(java.util.Collections) ClusterNode(org.apache.ignite.cluster.ClusterNode) LogListener(org.apache.ignite.testframework.LogListener) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 64 with LogListener

use of org.apache.ignite.testframework.LogListener in project ignite by apache.

the class GridTcpCommunicationSpiSkipWaitHandshakeOnClientTest method startClientAndWaitCommunicationActivation.

/**
 */
private void startClientAndWaitCommunicationActivation() throws IgniteInterruptedCheckedException {
    LogListener lsnr = LogListener.matches(msg -> {
        boolean matched = msg.startsWith(TCP_COMM_START_MSG);
        if (matched)
            fetchedTcpPort = parsePort(msg);
        return matched;
    }).times(1).build();
    log.registerListener(lsnr);
    new Thread(() -> {
        try {
            startGrid(0);
        } catch (Exception ignore) {
        // Noop
        }
    }).start();
    assertTrue(GridTestUtils.waitForCondition(lsnr::check, 20_000));
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException)

Example 65 with LogListener

use of org.apache.ignite.testframework.LogListener 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

LogListener (org.apache.ignite.testframework.LogListener)144 Test (org.junit.Test)116 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)93 ListeningTestLogger (org.apache.ignite.testframework.ListeningTestLogger)68 IgniteEx (org.apache.ignite.internal.IgniteEx)65 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)35 Ignite (org.apache.ignite.Ignite)32 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)31 IgniteCache (org.apache.ignite.IgniteCache)24 WithSystemProperty (org.apache.ignite.testframework.junits.WithSystemProperty)23 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)18 GridTestUtils (org.apache.ignite.testframework.GridTestUtils)16 List (java.util.List)15 CountDownLatch (java.util.concurrent.CountDownLatch)15 Pattern (java.util.regex.Pattern)15 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)14 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)13 UUID (java.util.UUID)12 Collections (java.util.Collections)11