Search in sources :

Example 6 with LogListener

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

the class ConsistentIdImplicitlyExplicitlyTest method testConsistentIdConfiguredInIgniteCfgAndJvmProp.

/**
 * Consistent ID is configured in the {@link IgniteConfiguration} and in the JVM property.
 *
 * @throws Exception if failed.
 */
@Test
@WithSystemProperty(key = IGNITE_OVERRIDE_CONSISTENT_ID, value = "JvmProp consistent id")
public void testConsistentIdConfiguredInIgniteCfgAndJvmProp() throws Exception {
    defConsistentId = "IgniteCfg consistent id";
    String specificConsistentId = System.getProperty(IGNITE_OVERRIDE_CONSISTENT_ID);
    ;
    LogListener lsnr = expectLogEvent(WARN_MESSAGE, 0);
    Ignite ignite = startGrid(0);
    assertEquals(specificConsistentId, ignite.configuration().getConsistentId());
    assertEquals(specificConsistentId, ignite.cluster().localNode().consistentId());
    assertTrue(lsnr.check());
    info("Consistent ID: " + ignite.cluster().localNode().consistentId());
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 7 with LogListener

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

the class GridCommandHandlerIndexForceRebuildTest method testComplexIndexRebuild.

/**
 * Checks that index on 2 fields is rebuilt correctly.
 */
@Test
public void testComplexIndexRebuild() throws IgniteInterruptedCheckedException {
    injectTestSystemOut();
    LogListener lsnr = installRebuildCheckListener(grid(LAST_NODE_NUM), CACHE_NAME_NO_GRP);
    assertEquals(EXIT_CODE_OK, execute("--cache", "indexes_force_rebuild", "--node-id", grid(LAST_NODE_NUM).localNode().id().toString(), "--cache-names", CACHE_NAME_NO_GRP));
    assertTrue(waitForIndexesRebuild(grid(LAST_NODE_NUM)));
    assertTrue(lsnr.check());
    removeLogListener(grid(LAST_NODE_NUM), lsnr);
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) MessageOrderLogListener(org.apache.ignite.testframework.MessageOrderLogListener) Test(org.junit.Test)

Example 8 with LogListener

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

the class GridCommandHandlerIndexForceRebuildTest method testGroupNamesArg.

/**
 * Checks --node-id and --group-names options,
 * correctness of utility output and the fact that indexes were actually rebuilt.
 */
@Test
public void testGroupNamesArg() throws Exception {
    blockRebuildIdx.put(CACHE_NAME_1_2, new GridFutureAdapter<>());
    injectTestSystemOut();
    LogListener[] cache1Listeners = new LogListener[GRIDS_NUM];
    LogListener[] cache2Listeners = new LogListener[GRIDS_NUM];
    try {
        triggerIndexRebuild(LAST_NODE_NUM, Collections.singletonList(CACHE_NAME_1_2));
        for (int i = 0; i < GRIDS_NUM; i++) {
            cache1Listeners[i] = installRebuildCheckListener(grid(i), CACHE_NAME_1_1);
            cache2Listeners[i] = installRebuildCheckListener(grid(i), CACHE_NAME_NO_GRP);
        }
        assertEquals(EXIT_CODE_OK, execute("--cache", "indexes_force_rebuild", "--node-id", grid(LAST_NODE_NUM).localNode().id().toString(), "--group-names", GRP_NAME_1 + "," + GRP_NAME_2 + "," + GRP_NAME_NON_EXISTING));
        blockRebuildIdx.remove(CACHE_NAME_1_2);
        waitForIndexesRebuild(grid(LAST_NODE_NUM));
        String outputStr = testOut.toString();
        validateOutputCacheGroupsNotFound(outputStr, GRP_NAME_NON_EXISTING);
        validateOutputIndicesRebuildingInProgress(outputStr, F.asMap(GRP_NAME_1, F.asList(CACHE_NAME_1_2)));
        validateOutputIndicesRebuildWasStarted(outputStr, F.asMap(GRP_NAME_1, F.asList(CACHE_NAME_1_1), GRP_NAME_2, F.asList(CACHE_NAME_2_1)));
        assertEquals("Unexpected number of lines in outputStr.", 20, outputStr.split("\n").length);
        assertFalse(cache1Listeners[0].check());
        assertFalse(cache1Listeners[1].check());
        assertTrue(cache1Listeners[LAST_NODE_NUM].check());
        for (LogListener cache2Lsnr : cache2Listeners) assertFalse(cache2Lsnr.check());
    } finally {
        blockRebuildIdx.remove(CACHE_NAME_1_2);
        for (int i = 0; i < GRIDS_NUM; i++) {
            removeLogListener(grid(i), cache1Listeners[i]);
            removeLogListener(grid(i), cache2Listeners[i]);
        }
        assertTrue(waitForIndexesRebuild(grid(LAST_NODE_NUM)));
    }
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) MessageOrderLogListener(org.apache.ignite.testframework.MessageOrderLogListener) Test(org.junit.Test)

Example 9 with LogListener

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

the class IgniteTopologyPrintFormatSelfTest method doServerAndClientTest.

/**
 * @throws Exception If failed.
 */
private void doServerAndClientTest() throws Exception {
    String nodeId8;
    testLog = new ListeningTestLogger(log);
    Pattern ptrn = Pattern.compile(String.format(ALIVE_NODES_MSG, 1, 4));
    LogListener aliveNodesLsnr = LogListener.matches(ptrn).times(log.isDebugEnabled() ? 0 : 16).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, 4, nodeId8, 2, 2)).build();
        lsnr2 = LogListener.matches(s -> s.contains(String.format(NUMBER_SRV_NODES, 2)) && s.contains(String.format(CLIENT_NODES_COUNT, 2))).build();
        testLog.registerAllListeners(lsnr, lsnr2);
        Ignite srv1 = startGrid("server1");
        Ignite client1 = startClientGrid("first client");
        Ignite client2 = startClientGrid("second client");
        waitForDiscovery(srv, srv1, client1, client2);
    } 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 10 with LogListener

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

the class GridCommandHandlerDefragmentationTest method testDefragmentationCancelInProgress.

/**
 * @throws Exception If failed.
 */
@Test
public void testDefragmentationCancelInProgress() throws Exception {
    IgniteEx ig = startGrid(0);
    ig.cluster().state(ClusterState.ACTIVE);
    IgniteCache<Object, Object> cache = ig.getOrCreateCache(DEFAULT_CACHE_NAME);
    for (int i = 0; i < 1024; i++) cache.put(i, i);
    forceCheckpoint(ig);
    String grid0ConsId = ig.configuration().getConsistentId().toString();
    ListeningTestLogger testLog = new ListeningTestLogger();
    CommandHandler cmd = createCommandHandler(testLog);
    assertEquals(EXIT_CODE_OK, execute(cmd, "--defragmentation", "schedule", "--nodes", grid0ConsId));
    String port = grid(0).localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString();
    stopGrid(0);
    blockCdl = new CountDownLatch(128);
    UnaryOperator<IgniteConfiguration> cfgOp = cfg -> {
        DataStorageConfiguration dsCfg = cfg.getDataStorageConfiguration();
        FileIOFactory delegate = dsCfg.getFileIOFactory();
        dsCfg.setFileIOFactory((file, modes) -> {
            if (file.getName().contains("dfrg")) {
                if (blockCdl.getCount() == 0) {
                    try {
                        // Slow down defragmentation process.
                        // This'll be enough for the test since we have, like, 900 partitions left.
                        Thread.sleep(100);
                    } catch (InterruptedException ignore) {
                    // No-op.
                    }
                } else
                    blockCdl.countDown();
            }
            return delegate.create(file, modes);
        });
        return cfg;
    };
    IgniteInternalFuture<?> fut = GridTestUtils.runAsync(() -> {
        try {
            startGrid(0, cfgOp);
        } catch (Exception e) {
            // No-op.
            throw new RuntimeException(e);
        }
    });
    blockCdl.await();
    LogListener logLsnr = LogListener.matches("Defragmentation cancelled successfully.").build();
    testLog.registerListener(logLsnr);
    assertEquals(EXIT_CODE_OK, execute(cmd, "--port", port, "--defragmentation", "cancel"));
    assertTrue(logLsnr.check());
    fut.get();
    testLog.clearListeners();
    logLsnr = LogListener.matches("Defragmentation is already completed or has been cancelled previously.").build();
    testLog.registerListener(logLsnr);
    assertEquals(EXIT_CODE_OK, execute(cmd, "--port", port, "--defragmentation", "cancel"));
    assertTrue(logLsnr.check());
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) LogListener(org.apache.ignite.testframework.LogListener) Arrays(java.util.Arrays) IgniteNodeAttributes(org.apache.ignite.internal.IgniteNodeAttributes) ClusterState(org.apache.ignite.cluster.ClusterState) UnaryOperator(java.util.function.UnaryOperator) IgniteEx(org.apache.ignite.internal.IgniteEx) Formatter(java.util.logging.Formatter) EXIT_CODE_OK(org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) EXIT_CODE_INVALID_ARGUMENTS(org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_INVALID_ARGUMENTS) FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) StreamHandler(java.util.logging.StreamHandler) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) DefragmentationParameters(org.apache.ignite.internal.processors.cache.persistence.defragmentation.maintenance.DefragmentationParameters) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) LogRecord(java.util.logging.LogRecord) Logger(java.util.logging.Logger) MaintenanceTask(org.apache.ignite.maintenance.MaintenanceTask) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) LogListener(org.apache.ignite.testframework.LogListener) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) CountDownLatch(java.util.concurrent.CountDownLatch) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) 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