Search in sources :

Example 76 with LogListener

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

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

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

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

Example 80 with LogListener

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

the class GridCommandHandlerInterruptCommandTest method testCancelValidateIndexesClosure.

/**
 * Test invokes index validation closure and canceling it after started.
 *
 * @throws Exception If failed.
 */
@Test
public void testCancelValidateIndexesClosure() throws Exception {
    IgniteEx ignite0 = startGrid(0);
    ignite0.cluster().active(true);
    preloadeData(ignite0);
    AtomicBoolean cancelled = new AtomicBoolean(false);
    ValidateIndexesClosure clo = new ValidateIndexesClosure(cancelled::get, Collections.singleton(DEFAULT_CACHE_NAME), 0, 0, false, true);
    ListeningTestLogger listeningLogger = new ListeningTestLogger(false, log);
    GridTestUtils.setFieldValue(clo, "ignite", ignite0);
    GridTestUtils.setFieldValue(clo, "log", listeningLogger);
    LogListener lnsrValidationStarted = LogListener.matches("Current progress of ValidateIndexesClosure").build();
    listeningLogger.registerListener(lnsrValidationStarted);
    IgniteInternalFuture fut = GridTestUtils.runAsync(() -> GridTestUtils.assertThrows(log, clo::call, IgniteException.class, ValidateIndexesClosure.CANCELLED_MSG));
    assertTrue(GridTestUtils.waitForCondition(lnsrValidationStarted::check, 10_000));
    assertFalse(fut.isDone());
    cancelled.set(true);
    fut.get(10_000);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LogListener(org.apache.ignite.testframework.LogListener) IgniteException(org.apache.ignite.IgniteException) IgniteEx(org.apache.ignite.internal.IgniteEx) ValidateIndexesClosure(org.apache.ignite.internal.visor.verify.ValidateIndexesClosure) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) 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