Search in sources :

Example 41 with ListeningTestLogger

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

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

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

Example 44 with ListeningTestLogger

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

the class GridTcpCommunicationSpiLogTest method beforeTest.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTest() throws Exception {
    super.beforeTest();
    setRootLoggerDebugLevel();
    srvTestLog = new ListeningTestLogger(true, log);
}
Also used : ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger)

Example 45 with ListeningTestLogger

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

the class BasicIndexTest method testCorrectFieldsSequenceInPk.

/**
 *  Checks index usage with correct pk fields enumeration.
 */
@Test
public void testCorrectFieldsSequenceInPk() throws Exception {
    inlineSize = 10;
    srvLog = new ListeningTestLogger(false, log);
    IgniteEx ig0 = startGrid(0);
    GridQueryProcessor qryProc = ig0.context().query();
    populateTable(qryProc, TEST_TBL_NAME, -2, "FIRST_NAME", "LAST_NAME", "ADDRESS", "LANG");
    assertFalse(checkIdxAlreadyExistLog(qryProc, "idx1", TEST_TBL_NAME, "FIRST_NAME", "LAST_NAME"));
    assertTrue(checkIdxAlreadyExistLog(qryProc, "idx2", TEST_TBL_NAME, "LAST_NAME", "FIRST_NAME"));
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) GridQueryProcessor(org.apache.ignite.internal.processors.query.GridQueryProcessor) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) Test(org.junit.Test)

Aggregations

ListeningTestLogger (org.apache.ignite.testframework.ListeningTestLogger)101 Test (org.junit.Test)51 LogListener (org.apache.ignite.testframework.LogListener)48 IgniteEx (org.apache.ignite.internal.IgniteEx)36 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)32 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)30 Ignite (org.apache.ignite.Ignite)21 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)21 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)17 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)14 CountDownLatch (java.util.concurrent.CountDownLatch)9 IgniteCache (org.apache.ignite.IgniteCache)9 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)9 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)9 List (java.util.List)8 Pattern (java.util.regex.Pattern)8 ClusterState (org.apache.ignite.cluster.ClusterState)7 GridQueryProcessor (org.apache.ignite.internal.processors.query.GridQueryProcessor)7 Collections (java.util.Collections)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6