Search in sources :

Example 56 with ListeningTestLogger

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

the class GridCommandHandlerBrokenIndexTest method getConfiguration.

/**
 * Adds error message listeners to server nodes.
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    if (cfg.isClientMode())
        return cfg;
    ListeningTestLogger testLog = new ListeningTestLogger(false, log);
    Pattern logErrMsgPattern = Pattern.compile("Failed to lookup key: " + IDX_ISSUE_STR);
    LogListener lsnr = LogListener.matches(logErrMsgPattern).build();
    testLog.registerListener(lsnr);
    lsnrs.add(lsnr);
    cfg.setGridLogger(testLog);
    return cfg;
}
Also used : Pattern(java.util.regex.Pattern) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) LogListener(org.apache.ignite.testframework.LogListener) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger)

Example 57 with ListeningTestLogger

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

the class GridCommandHandlerDefragmentationTest method testDefragmentationSchedule.

/**
 * @throws Exception If failed.
 */
@Test
public void testDefragmentationSchedule() throws Exception {
    Ignite ignite = startGrids(2);
    ignite.cluster().state(ACTIVE);
    assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute("--defragmentation", "schedule"));
    String grid0ConsId = grid(0).configuration().getConsistentId().toString();
    String grid1ConsId = grid(1).configuration().getConsistentId().toString();
    ListeningTestLogger testLog = new ListeningTestLogger();
    CommandHandler cmd = createCommandHandler(testLog);
    LogListener logLsnr = LogListener.matches("Scheduling completed successfully.").build();
    testLog.registerListener(logLsnr);
    assertEquals(EXIT_CODE_OK, execute(cmd, "--defragmentation", "schedule", "--nodes", grid0ConsId));
    assertTrue(logLsnr.check());
    MaintenanceTask mntcTask = DefragmentationParameters.toStore(Collections.emptyList());
    assertNotNull(grid(0).context().maintenanceRegistry().registerMaintenanceTask(mntcTask));
    assertNull(grid(1).context().maintenanceRegistry().registerMaintenanceTask(mntcTask));
    stopGrid(0);
    startGrid(0);
    logLsnr = LogListener.matches("Node is already in Maintenance Mode").build();
    testLog.clearListeners();
    testLog.registerListener(logLsnr);
    assertEquals(EXIT_CODE_OK, execute(cmd, "--defragmentation", "schedule", "--nodes", grid0ConsId));
    assertTrue(logLsnr.check());
    stopGrid(0);
    startGrid(0);
    stopGrid(1);
    startGrid(1);
    stopAllGrids();
    startGrids(2);
    logLsnr = LogListener.matches("Scheduling completed successfully.").times(2).build();
    testLog.clearListeners();
    testLog.registerListener(logLsnr);
    assertEquals(EXIT_CODE_OK, execute(cmd, "--defragmentation", "schedule", "--nodes", String.join(",", grid0ConsId, grid1ConsId)));
    assertTrue(logLsnr.check());
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) Ignite(org.apache.ignite.Ignite) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) MaintenanceTask(org.apache.ignite.maintenance.MaintenanceTask) Test(org.junit.Test)

Example 58 with ListeningTestLogger

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

the class GridCommandHandlerDefragmentationTest method testDefragmentationCancel.

/**
 * @throws Exception If failed.
 */
@Test
public void testDefragmentationCancel() throws Exception {
    Ignite ignite = startGrids(2);
    ignite.cluster().state(ACTIVE);
    String grid0ConsId = grid(0).configuration().getConsistentId().toString();
    ListeningTestLogger testLog = new ListeningTestLogger();
    CommandHandler cmd = createCommandHandler(testLog);
    assertEquals(EXIT_CODE_OK, execute(cmd, "--defragmentation", "schedule", "--nodes", grid0ConsId));
    LogListener logLsnr = LogListener.matches("Scheduled defragmentation task cancelled successfully.").atLeast(1).build();
    testLog.registerListener(logLsnr);
    assertEquals(EXIT_CODE_OK, execute(cmd, "--port", grid(0).localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString(), "--defragmentation", "cancel"));
    assertTrue(logLsnr.check());
    testLog.clearListeners();
    logLsnr = LogListener.matches("Scheduled defragmentation task is not found.").build();
    testLog.registerListener(logLsnr);
    assertEquals(EXIT_CODE_OK, execute(cmd, "--port", grid(1).localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString(), "--defragmentation", "cancel"));
    assertTrue(logLsnr.check());
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) Ignite(org.apache.ignite.Ignite) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) Test(org.junit.Test)

Example 59 with ListeningTestLogger

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

the class GridCommandHandlerIndexForceRebuildTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setGridLogger(new ListeningTestLogger(log));
    cfg.setBuildIndexThreadPoolSize(max(2, cfg.getBuildIndexThreadPoolSize()));
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger)

Example 60 with ListeningTestLogger

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

the class GridCommandHandlerDefragmentationTest method testDefragmentationStatus.

/**
 * @throws Exception If failed.
 */
@Test
public void testDefragmentationStatus() throws Exception {
    IgniteEx ig = startGrid(0);
    ig.cluster().state(ClusterState.ACTIVE);
    ig.getOrCreateCache(DEFAULT_CACHE_NAME + "1");
    IgniteCache<Object, Object> cache = ig.getOrCreateCache(DEFAULT_CACHE_NAME + "2");
    ig.getOrCreateCache(DEFAULT_CACHE_NAME + "3");
    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);
    waitCdl = new CountDownLatch(1);
    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 {
                        waitCdl.await();
                    } 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();
    List<LogListener> logLsnrs = Arrays.asList(LogListener.matches("default1 - size before/after: 0MB/0MB").build(), LogListener.matches("default2 - partitions processed/all:").build(), LogListener.matches("Awaiting defragmentation: default3").build());
    for (LogListener logLsnr : logLsnrs) testLog.registerListener(logLsnr);
    assertEquals(EXIT_CODE_OK, execute(cmd, "--port", port, "--defragmentation", "status"));
    waitCdl.countDown();
    for (LogListener logLsnr : logLsnrs) assertTrue(logLsnr.check());
    fut.get();
    ((GridCacheDatabaseSharedManager) grid(0).context().cache().context().database()).defragmentationManager().completionFuture().get();
    testLog.clearListeners();
    logLsnrs = Arrays.asList(LogListener.matches("default1 - size before/after: 0MB/0MB").build(), LogListener.matches(Pattern.compile("default2 - size before/after: (\\S+)/\\1")).build(), LogListener.matches("default3 - size before/after: 0MB/0MB").build());
    for (LogListener logLsnr : logLsnrs) testLog.registerListener(logLsnr);
    assertEquals(EXIT_CODE_OK, execute(cmd, "--port", port, "--defragmentation", "status"));
    for (LogListener logLsnr : logLsnrs) 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) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) 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

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