Search in sources :

Example 31 with CommandHandler

use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.

the class BaselineEventsTest method testChangeAutoAdjustTimeout.

/**
 */
@Test
public void testChangeAutoAdjustTimeout() throws Exception {
    IgniteClusterEx cluster = startGrids(2).cluster();
    cluster.active(true);
    AtomicLong autoAdjustTimeout = new AtomicLong();
    listen(grid(0), event -> {
        BaselineConfigurationChangedEvent bltCfgChangedEvt = (BaselineConfigurationChangedEvent) event;
        autoAdjustTimeout.set(bltCfgChangedEvt.autoAdjustTimeout());
        return true;
    }, EventType.EVT_BASELINE_AUTO_ADJUST_AWAITING_TIME_CHANGED);
    assertEquals(CommandHandler.EXIT_CODE_OK, new CommandHandler().execute(Arrays.asList("--baseline", "auto_adjust", "enable", "timeout", "10", "--yes")));
    assertTrue(GridTestUtils.waitForCondition(() -> autoAdjustTimeout.get() == 10L, 3_000));
    cluster.baselineAutoAdjustTimeout(50);
    assertTrue(GridTestUtils.waitForCondition(() -> autoAdjustTimeout.get() == 50L, 3_000));
}
Also used : IgniteClusterEx(org.apache.ignite.internal.cluster.IgniteClusterEx) AtomicLong(java.util.concurrent.atomic.AtomicLong) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 32 with CommandHandler

use of org.apache.ignite.internal.commandline.CommandHandler 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 33 with CommandHandler

use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.

the class GridCommandHandlerIndexListTest method testCacheIndexList.

/**
 * Tests --index name option and output correctness.
 */
@Test
public void testCacheIndexList() {
    final String idxName = "PERSON_ORGID_ASC_IDX";
    final int expectedLinesNum = 15;
    final int expectedIndexDescrLinesNum = 2;
    injectTestSystemOut();
    final CommandHandler handler = new CommandHandler(createTestLogger());
    assertEquals(EXIT_CODE_OK, execute(handler, "--cache", "indexes_list", "--index-name", idxName));
    String outStr = testOut.toString();
    assertTrue(outStr.contains("grpName=" + GROUP_NAME + ", cacheName=" + CACHE_NAME + ", idxName=PERSON_ORGID_ASC_IDX, " + "colsNames=ArrayList [ORGID, _KEY], tblName=PERSON"));
    assertTrue(outStr.contains("grpName=" + GROUP_NAME_SECOND + ", cacheName=" + CACHE_NAME_SECOND + ", idxName=PERSON_ORGID_ASC_IDX, colsNames=ArrayList [ORGID, _KEY], tblName=PERSON"));
    final String[] outputLines = outStr.split("\n");
    int outputLinesNum = outputLines.length;
    assertEquals("Unexpected number of lines: " + outputLinesNum, outputLinesNum, expectedLinesNum);
    long indexDescrLinesNum = Arrays.stream(outputLines).filter(s -> s.contains("grpName=")).count();
    assertEquals("Unexpected number of index description lines: " + indexDescrLinesNum, indexDescrLinesNum, expectedIndexDescrLinesNum);
    Set<IndexListInfoContainer> cmdResult = handler.getLastOperationResult();
    assertNotNull(cmdResult);
    final int resSetSize = cmdResult.size();
    assertEquals("Unexpected result set size: " + resSetSize, resSetSize, 2);
    boolean isResSetCorrect = cmdResult.stream().map(IndexListInfoContainer::indexName).allMatch((name) -> name.equals(idxName));
    assertTrue("Unexpected result set", isResSetCorrect);
}
Also used : Arrays(java.util.Arrays) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) Predicate(java.util.function.Predicate) Set(java.util.Set) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) CACHE_NAME_SECOND(org.apache.ignite.util.GridCommandHandlerIndexingUtils.CACHE_NAME_SECOND) EXIT_CODE_OK(org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK) GROUP_NAME_SECOND(org.apache.ignite.util.GridCommandHandlerIndexingUtils.GROUP_NAME_SECOND) CacheCommands(org.apache.ignite.internal.commandline.cache.CacheCommands) CACHE_NAME(org.apache.ignite.util.GridCommandHandlerIndexingUtils.CACHE_NAME) THREE_ENTRIES_CACHE_NAME_COMMON_PART(org.apache.ignite.util.GridCommandHandlerIndexingUtils.THREE_ENTRIES_CACHE_NAME_COMMON_PART) GridCommandHandlerIndexingUtils.createAndFillSeveralCaches(org.apache.ignite.util.GridCommandHandlerIndexingUtils.createAndFillSeveralCaches) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) GROUP_NAME(org.apache.ignite.util.GridCommandHandlerIndexingUtils.GROUP_NAME) IndexListInfoContainer(org.apache.ignite.internal.visor.cache.index.IndexListInfoContainer) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) IndexListInfoContainer(org.apache.ignite.internal.visor.cache.index.IndexListInfoContainer) Test(org.junit.Test)

Example 34 with CommandHandler

use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.

the class GridCommandHandlerIndexRebuildStatusTest method testCommandOutput.

/**
 * Basic check.
 */
@Test
public void testCommandOutput() throws Exception {
    injectTestSystemOut();
    idxRebuildsStartedNum.set(0);
    final CommandHandler handler = new CommandHandler(createTestLogger());
    stopGrid(GRIDS_NUM - 1);
    stopGrid(GRIDS_NUM - 2);
    deleteIndexBin(getTestIgniteInstanceName(GRIDS_NUM - 1));
    deleteIndexBin(getTestIgniteInstanceName(GRIDS_NUM - 2));
    IndexProcessor.idxRebuildCls = BlockingIndexesRebuildTask.class;
    IgniteEx ignite1 = startGrid(GRIDS_NUM - 1);
    IndexProcessor.idxRebuildCls = BlockingIndexesRebuildTask.class;
    IgniteEx ignite2 = startGrid(GRIDS_NUM - 2);
    final UUID id1 = ignite1.localNode().id();
    final UUID id2 = ignite2.localNode().id();
    boolean allRebuildsStarted = GridTestUtils.waitForCondition(() -> idxRebuildsStartedNum.get() == 6, 30_000);
    assertTrue("Failed to wait for all indexes to start being rebuilt", allRebuildsStarted);
    assertEquals(EXIT_CODE_OK, execute(handler, "--cache", "indexes_rebuild_status"));
    statusRequestingFinished.set(true);
    checkResult(handler, id1, id2);
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) UUID(java.util.UUID) Test(org.junit.Test)

Example 35 with CommandHandler

use of org.apache.ignite.internal.commandline.CommandHandler in project ignite by apache.

the class GridCommandHandlerIndexRebuildStatusTest method testNodeIdOption.

/**
 * Check --node-id option.
 */
@Test
public void testNodeIdOption() throws Exception {
    injectTestSystemOut();
    idxRebuildsStartedNum.set(0);
    final CommandHandler handler = new CommandHandler(createTestLogger());
    stopGrid(GRIDS_NUM - 1);
    stopGrid(GRIDS_NUM - 2);
    deleteIndexBin(getTestIgniteInstanceName(GRIDS_NUM - 1));
    deleteIndexBin(getTestIgniteInstanceName(GRIDS_NUM - 2));
    IndexProcessor.idxRebuildCls = BlockingIndexesRebuildTask.class;
    IgniteEx ignite1 = startGrid(GRIDS_NUM - 1);
    IndexProcessor.idxRebuildCls = BlockingIndexesRebuildTask.class;
    startGrid(GRIDS_NUM - 2);
    final UUID id1 = ignite1.localNode().id();
    boolean allRebuildsStarted = GridTestUtils.waitForCondition(() -> idxRebuildsStartedNum.get() == 6, 30_000);
    assertTrue("Failed to wait for all indexes to start being rebuilt", allRebuildsStarted);
    assertEquals(EXIT_CODE_OK, execute(handler, "--cache", "indexes_rebuild_status", "--node-id", id1.toString()));
    statusRequestingFinished.set(true);
    checkResult(handler, id1);
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

CommandHandler (org.apache.ignite.internal.commandline.CommandHandler)35 Test (org.junit.Test)26 IgniteEx (org.apache.ignite.internal.IgniteEx)16 Ignite (org.apache.ignite.Ignite)12 IgniteCacheGroupsWithRestartsTest (org.apache.ignite.internal.processors.cache.persistence.db.IgniteCacheGroupsWithRestartsTest)10 AbstractSnapshotSelfTest.doSnapshotCancellationTest (org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.doSnapshotCancellationTest)10 Logger (java.util.logging.Logger)6 ArrayList (java.util.ArrayList)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 ListeningTestLogger (org.apache.ignite.testframework.ListeningTestLogger)5 Arrays (java.util.Arrays)4 Formatter (java.util.logging.Formatter)4 LogRecord (java.util.logging.LogRecord)4 StreamHandler (java.util.logging.StreamHandler)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)4 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)4 IOException (java.io.IOException)3 Collections (java.util.Collections)3 List (java.util.List)3