Search in sources :

Example 26 with CommandHandler

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

the class GridCommandHandlerTest method executeTaskViaControlConsoleUtil.

/**
 * @param ignite Ignite to execute task on.
 * @param delFoundGarbage If clearing mode should be used.
 * @return Result of task run.
 */
private VisorFindAndDeleteGarbageInPersistenceTaskResult executeTaskViaControlConsoleUtil(IgniteEx ignite, boolean delFoundGarbage) {
    CommandHandler hnd = new CommandHandler();
    List<String> args = new ArrayList<>(Arrays.asList("--yes", "--port", "11212", "--cache", "find_garbage", ignite.localNode().id().toString()));
    if (delFoundGarbage)
        args.add(FindAndDeleteGarbageArg.DELETE.argName());
    hnd.execute(args);
    return hnd.getLastOperationResult();
}
Also used : ArrayList(java.util.ArrayList) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler)

Example 27 with CommandHandler

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

the class GridCommandHandlerTest method testCancelSnapshot.

/**
 * @throws Exception If fails.
 */
@Test
public void testCancelSnapshot() throws Exception {
    IgniteEx srv = startGrid(0);
    IgniteEx startCli = startClientGrid(CLIENT_NODE_NAME_PREFIX);
    srv.cluster().state(ACTIVE);
    createCacheAndPreload(startCli, 100);
    CommandHandler h = new CommandHandler();
    doSnapshotCancellationTest(startCli, Collections.singletonList(srv), startCli.cache(DEFAULT_CACHE_NAME), snpName -> assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "cancel", snpName)));
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) IgniteCacheGroupsWithRestartsTest(org.apache.ignite.internal.processors.cache.persistence.db.IgniteCacheGroupsWithRestartsTest) AbstractSnapshotSelfTest.doSnapshotCancellationTest(org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.doSnapshotCancellationTest) Test(org.junit.Test)

Example 28 with CommandHandler

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

the class GridCommandHandlerTest method testActiveTransactions.

/**
 * Test active transactions.
 *
 * @throws Exception If failed.
 */
@Test
public void testActiveTransactions() throws Exception {
    Ignite ignite = startGridsMultiThreaded(2);
    ignite.cluster().active(true);
    Ignite client = startGrid("client");
    client.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME).setAtomicityMode(TRANSACTIONAL).setWriteSynchronizationMode(FULL_SYNC));
    for (Ignite ig : G.allGrids()) assertNotNull(ig.cache(DEFAULT_CACHE_NAME));
    CountDownLatch lockLatch = new CountDownLatch(1);
    CountDownLatch unlockLatch = new CountDownLatch(1);
    IgniteInternalFuture<?> fut = startTransactions("testActiveTransactions", lockLatch, unlockLatch, true);
    U.awaitQuiet(lockLatch);
    doSleep(5000);
    CommandHandler h = new CommandHandler();
    final VisorTxInfo[] toKill = { null };
    // Basic test.
    validate(h, map -> {
        VisorTxTaskResult res = map.get(grid(0).cluster().localNode());
        for (VisorTxInfo info : res.getInfos()) {
            if (info.getSize() == 100) {
                // Store for further use.
                toKill[0] = info;
                break;
            }
        }
        assertEquals(3, map.size());
    }, "--tx");
    assertNotNull(toKill[0]);
    // Test filter by label.
    validate(h, map -> {
        ClusterNode node = grid(0).cluster().localNode();
        for (Map.Entry<ClusterNode, VisorTxTaskResult> entry : map.entrySet()) assertEquals(entry.getKey().equals(node) ? 1 : 0, entry.getValue().getInfos().size());
    }, "--tx", "--label", "label1");
    // Test filter by label regex.
    validate(h, map -> {
        ClusterNode node1 = grid(0).cluster().localNode();
        ClusterNode node2 = grid("client").cluster().localNode();
        for (Map.Entry<ClusterNode, VisorTxTaskResult> entry : map.entrySet()) {
            if (entry.getKey().equals(node1)) {
                assertEquals(1, entry.getValue().getInfos().size());
                assertEquals("label1", entry.getValue().getInfos().get(0).getLabel());
            } else if (entry.getKey().equals(node2)) {
                assertEquals(1, entry.getValue().getInfos().size());
                assertEquals("label2", entry.getValue().getInfos().get(0).getLabel());
            } else
                assertTrue(entry.getValue().getInfos().isEmpty());
        }
    }, "--tx", "--label", "^label[0-9]");
    // Test filter by empty label.
    validate(h, map -> {
        VisorTxTaskResult res = map.get(grid(0).localNode());
        for (VisorTxInfo info : res.getInfos()) assertNull(info.getLabel());
    }, "--tx", "--label", "null");
    // test check minSize
    int minSize = 10;
    validate(h, map -> {
        VisorTxTaskResult res = map.get(grid(0).localNode());
        assertNotNull(res);
        for (VisorTxInfo txInfo : res.getInfos()) assertTrue(txInfo.getSize() >= minSize);
    }, "--tx", "--min-size", Integer.toString(minSize));
    // test order by size.
    validate(h, map -> {
        VisorTxTaskResult res = map.get(grid(0).localNode());
        assertTrue(res.getInfos().get(0).getSize() >= res.getInfos().get(1).getSize());
    }, "--tx", "--order", "SIZE");
    // test order by duration.
    validate(h, map -> {
        VisorTxTaskResult res = map.get(grid(0).localNode());
        assertTrue(res.getInfos().get(0).getDuration() >= res.getInfos().get(1).getDuration());
    }, "--tx", "--order", "DURATION");
    // test order by start_time.
    validate(h, map -> {
        VisorTxTaskResult res = map.get(grid(0).localNode());
        for (int i = res.getInfos().size() - 1; i > 1; i--) assertTrue(res.getInfos().get(i - 1).getStartTime() >= res.getInfos().get(i).getStartTime());
    }, "--tx", "--order", "START_TIME");
    // Trigger topology change and test connection.
    IgniteInternalFuture<?> startFut = multithreadedAsync(() -> {
        try {
            startGrid(2);
        } catch (Exception e) {
            fail();
        }
    }, 1, "start-node-thread");
    // Give enough time to reach exchange future.
    doSleep(5000);
    assertEquals(EXIT_CODE_OK, execute(h, "--tx"));
    // Test kill by xid.
    validate(h, map -> {
        assertEquals(1, map.size());
        Map.Entry<ClusterNode, VisorTxTaskResult> killedEntry = map.entrySet().iterator().next();
        VisorTxInfo info = killedEntry.getValue().getInfos().get(0);
        assertEquals(toKill[0].getXid(), info.getXid());
    }, "--tx", "--kill", // Use saved on first run value.
    "--xid", // Use saved on first run value.
    toKill[0].getXid().toString(), "--nodes", grid(0).localNode().consistentId().toString());
    unlockLatch.countDown();
    startFut.get();
    fut.get();
    awaitPartitionMapExchange();
    checkUserFutures();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) EntryProcessorException(javax.cache.processor.EntryProcessorException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IOException(java.io.IOException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) IgniteException(org.apache.ignite.IgniteException) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) Ignite(org.apache.ignite.Ignite) VisorTxInfo(org.apache.ignite.internal.visor.tx.VisorTxInfo) VisorTxTaskResult(org.apache.ignite.internal.visor.tx.VisorTxTaskResult) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) IgniteCacheGroupsWithRestartsTest(org.apache.ignite.internal.processors.cache.persistence.db.IgniteCacheGroupsWithRestartsTest) AbstractSnapshotSelfTest.doSnapshotCancellationTest(org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.doSnapshotCancellationTest) Test(org.junit.Test)

Example 29 with CommandHandler

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

the class GridCommandHandlerClusterByClassTest method testErrUnexpectedWithWithoutVerbose.

/**
 * Test checks that stack trace for unexpected error will be output with or
 * without {@link CommonArgParser#CMD_VERBOSE} flag.
 */
@Test
public void testErrUnexpectedWithWithoutVerbose() {
    injectTestSystemOut();
    Logger log = CommandHandler.initLogger(null);
    log.addHandler(new StreamHandler(System.out, new Formatter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public String format(LogRecord record) {
            String msg = record.getMessage();
            if (msg.contains("Cluster state:"))
                throw new Error();
            return msg + "\n";
        }
    }));
    int resCode = EXIT_CODE_UNEXPECTED_ERROR;
    CommandHandler cmd = new CommandHandler(log);
    assertEquals(resCode, execute(cmd, BASELINE.text()));
    assertContains(GridAbstractTest.log, testOut.toString(), ERROR_STACK_TRACE_PREFIX);
    assertEquals(resCode, execute(cmd, BASELINE.text(), CMD_VERBOSE));
    assertContains(GridAbstractTest.log, testOut.toString(), ERROR_STACK_TRACE_PREFIX);
}
Also used : LogRecord(java.util.logging.LogRecord) Formatter(java.util.logging.Formatter) StreamHandler(java.util.logging.StreamHandler) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) Logger(java.util.logging.Logger) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) Test(org.junit.Test)

Example 30 with CommandHandler

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

the class BaselineEventsTest method testChangeBltWithControlUtility.

/**
 */
@Test
public void testChangeBltWithControlUtility() throws Exception {
    startGrid(0).cluster().active(true);
    AtomicBoolean baselineChanged = new AtomicBoolean();
    startGrid(1);
    String consistentIds = grid(0).localNode().consistentId() + "," + grid(1).localNode().consistentId();
    listen(grid(1), event -> {
        baselineChanged.set(true);
        BaselineChangedEvent baselineChangedEvt = (BaselineChangedEvent) event;
        assertEquals(2, baselineChangedEvt.baselineNodes().size());
        return true;
    }, EventType.EVT_BASELINE_CHANGED);
    assertEquals(CommandHandler.EXIT_CODE_OK, new CommandHandler().execute(Arrays.asList("--baseline", "set", consistentIds, "--yes")));
    assertTrue(GridTestUtils.waitForCondition(baselineChanged::get, 3_000));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) 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