Search in sources :

Example 96 with LogListener

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

the class IgniteTopologyPrintFormatSelfTest method doServerLogTest.

/**
 * @throws Exception If failed.
 */
private void doServerLogTest() throws Exception {
    String nodeId8;
    testLog = new ListeningTestLogger(log);
    Pattern ptrn = Pattern.compile(String.format(ALIVE_NODES_MSG, 1, 2));
    LogListener aliveNodesLsnr = LogListener.matches(ptrn).times(log.isDebugEnabled() ? 0 : 4).build();
    testLog.registerListener(aliveNodesLsnr);
    LogListener lsnr;
    LogListener lsnr2;
    try {
        Ignite srv = startGrid("server");
        nodeId8 = U.id8(srv.cluster().localNode().id());
        lsnr = LogListener.matches(String.format(TOPOLOGY_MSG, 2, nodeId8, 2, 0)).build();
        lsnr2 = LogListener.matches(s -> s.contains(String.format(NUMBER_SRV_NODES, 2)) && s.contains(String.format(CLIENT_NODES_COUNT, 0))).build();
        testLog.registerAllListeners(lsnr, lsnr2);
        Ignite srv1 = startGrid("server1");
        waitForDiscovery(srv, srv1);
    } finally {
        stopAllGrids();
    }
    checkLogMessages(aliveNodesLsnr, lsnr, lsnr2);
}
Also used : Pattern(java.util.regex.Pattern) LogListener(org.apache.ignite.testframework.LogListener) Ignite(org.apache.ignite.Ignite) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger)

Example 97 with LogListener

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

the class GracefulShutdownTest method testNotIdealOwners.

/**
 * Try to stop node when not all backups are matching of ideal assignment.
 *
 * @throws Exception If failed.
 */
@Test
public void testNotIdealOwners() throws Exception {
    backups = 1;
    Ignite ignite0 = startGrid(0);
    ignite0.cluster().active(true);
    for (int i = 1; i <= 3; i++) {
        IgniteCache cache = ignite0.cache("cache" + i);
        assertNotNull(cache);
        try (IgniteDataStreamer streamer = ignite0.dataStreamer("cache" + i)) {
            for (int j = 0; j < 100; j++) streamer.addData(j, j);
        }
    }
    TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(ignite0);
    spi.blockMessages((node, msg) -> {
        String nodeName = (String) node.attributes().get(ATTR_IGNITE_INSTANCE_NAME);
        if (msg instanceof GridDhtPartitionSupplyMessage) {
            GridDhtPartitionSupplyMessage supplyMsg = (GridDhtPartitionSupplyMessage) msg;
            if (supplyMsg.groupId() != CU.cacheId(GridCacheUtils.UTILITY_CACHE_NAME) && getTestIgniteInstanceName(1).equals(nodeName))
                return true;
        }
        return false;
    });
    startGrid(1);
    Ignite ignite2 = startGrid(2);
    resetBaselineTopology();
    spi.waitForBlocked();
    for (CacheGroupContext grp : ((IgniteEx) ignite2).context().cache().cacheGroups()) {
        GridTestUtils.waitForCondition(() -> !grp.topology().partitionMap(false).get(((IgniteEx) ignite2).localNode().id()).hasMovingPartitions(), 30_000);
    }
    LogListener lnsr = LogListener.matches("This node is waiting for backups of local partitions for group").build();
    listeningLog.registerListener(lnsr);
    IgniteInternalFuture fut = GridTestUtils.runAsync(() -> {
        ignite2.close();
    });
    assertTrue(GridTestUtils.waitForCondition(lnsr::check, 30_000));
    assertFalse(fut.isDone());
    spi.stopBlock();
    assertTrue(GridTestUtils.waitForCondition(fut::isDone, 30_000));
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) LogListener(org.apache.ignite.testframework.LogListener) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteCache(org.apache.ignite.IgniteCache) Ignite(org.apache.ignite.Ignite) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) Test(org.junit.Test)

Example 98 with LogListener

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

the class GracefulShutdownTest method tesStartCacheWhenNodeStopping.

/**
 * Stopping node and start cache which does not allow it.
 *
 * @throws Exception If failed.
 */
@Test
public void tesStartCacheWhenNodeStopping() throws Exception {
    backups = 2;
    Ignite ignite0 = startGrid(0);
    ignite0.cluster().active(true);
    for (int i = 1; i <= 3; i++) {
        IgniteCache cache = ignite0.cache("cache" + i);
        assertNotNull(cache);
        try (IgniteDataStreamer streamer = ignite0.dataStreamer("cache" + i)) {
            for (int j = 0; j < 100; j++) streamer.addData(j, j);
        }
    }
    TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(ignite0);
    spi.blockMessages((node, msg) -> {
        String nodeName = (String) node.attributes().get(ATTR_IGNITE_INSTANCE_NAME);
        if (msg instanceof GridDhtPartitionSupplyMessage) {
            GridDhtPartitionSupplyMessage supplyMsg = (GridDhtPartitionSupplyMessage) msg;
            if (supplyMsg.groupId() != CU.cacheId(GridCacheUtils.UTILITY_CACHE_NAME) && getTestIgniteInstanceName(1).equals(nodeName))
                return true;
        }
        return false;
    });
    Ignite ignite1 = startGrid(1);
    Ignite ignite2 = startGrid(2);
    resetBaselineTopology();
    spi.waitForBlocked();
    for (CacheGroupContext grp : ((IgniteEx) ignite2).context().cache().cacheGroups()) {
        grp.preloader().rebalanceFuture().get();
    }
    ignite2.close();
    LogListener lnsr = LogListener.matches("This node is waiting for completion of rebalance for group").build();
    listeningLog.registerListener(lnsr);
    IgniteInternalFuture fut = GridTestUtils.runAsync(() -> {
        ignite1.close();
    });
    assertTrue(GridTestUtils.waitForCondition(lnsr::check, 30_000));
    listeningLog.unregisterListener(lnsr);
    assertFalse(fut.isDone());
    ignite0.getOrCreateCache(new CacheConfiguration(DEFAULT_CACHE_NAME).setBackups(1));
    spi.stopBlock();
    lnsr = LogListener.matches("This node is waiting for backups of local partitions for group").build();
    listeningLog.registerListener(lnsr);
    assertTrue(GridTestUtils.waitForCondition(lnsr::check, 30_000));
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) LogListener(org.apache.ignite.testframework.LogListener) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteCache(org.apache.ignite.IgniteCache) Ignite(org.apache.ignite.Ignite) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.Test)

Example 99 with LogListener

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

the class ExpiryPolicyInfoLoggingTest method checkLoggingExpiryInfoForStaticallyCreatedCacheStartedInRecoveryMode.

/**
 * Checking logging of expiry policy info for statically created cache wich started in recovery mode.
 */
@Test
public void checkLoggingExpiryInfoForStaticallyCreatedCacheStartedInRecoveryMode() throws Exception {
    persistenceEnabled = true;
    LogListener lsnr = LogListener.matches(s -> s.startsWith(String.format(STARTED_CACHE_IN_RECOVERY_MODE_MSG, CACHE_1_NAME)) && s.contains(String.format(EXPRITY_POLICY_MSG, ModifiedExpiryPolicy.class.getName(), true))).times(1).build();
    log.registerListener(lsnr);
    startGrid(0);
    assertTrue(lsnr.check());
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 100 with LogListener

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

the class ReadMetricsOnNodeStartupTest method testReadMetricsOnNodeStartup.

/**
 * @throws Exception If failed.
 */
@Test
public void testReadMetricsOnNodeStartup() throws Exception {
    LogListener lsnr = LogListener.matches(s -> s.contains("Exception")).atLeast(1).build();
    listeningLog.registerListener(lsnr);
    startGrid(0);
    exportLatch.await();
    stopGrid(0);
    assertFalse("There was an exception during metric read. See log for details.", lsnr.check());
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

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