Search in sources :

Example 1 with CommandHandler

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

the class GridCommandHandlerTest method testCheckSnapshot.

/**
 * @throws Exception If fails.
 */
@Test
public void testCheckSnapshot() throws Exception {
    String snpName = "snapshot_02052020";
    IgniteEx ig = startGrid(0);
    ig.cluster().state(ACTIVE);
    createCacheAndPreload(ig, 1000);
    snp(ig).createSnapshot(snpName).get();
    CommandHandler h = new CommandHandler();
    assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "check", snpName));
    StringBuilder sb = new StringBuilder();
    ((IdleVerifyResultV2) h.getLastOperationResult()).print(sb::append, true);
    assertContains(log, sb.toString(), "The check procedure has finished, no conflicts have been found");
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) IdleVerifyResultV2(org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2) 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 2 with CommandHandler

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

the class GridCommandHandlerTest method testMasterKeyChange.

/**
 * @throws Exception If failed.
 */
@Test
public void testMasterKeyChange() throws Exception {
    encryptionEnabled = true;
    injectTestSystemOut();
    Ignite ignite = startGrids(1);
    ignite.cluster().state(ACTIVE);
    createCacheAndPreload(ignite, 10);
    CommandHandler h = new CommandHandler();
    assertEquals(EXIT_CODE_OK, execute(h, "--encryption", "get_master_key_name"));
    assertContains(log, testOut.toString(), ignite.encryption().getMasterKeyName());
    assertEquals(EXIT_CODE_OK, execute(h, "--encryption", "change_master_key", MASTER_KEY_NAME_2));
    assertContains(log, testOut.toString(), "The master key changed.");
    assertEquals(MASTER_KEY_NAME_2, ignite.encryption().getMasterKeyName());
    assertEquals(EXIT_CODE_OK, execute(h, "--encryption", "get_master_key_name"));
    assertContains(log, testOut.toString(), ignite.encryption().getMasterKeyName());
    testOut.reset();
    assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute("--encryption", "change_master_key", "non-existing-master-key-name"));
    assertContains(log, testOut.toString(), "Master key change was rejected. Unable to get the master key digest.");
}
Also used : Ignite(org.apache.ignite.Ignite) 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 3 with CommandHandler

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

the class GridCommandHandlerTest method testKillHangingLocalTransactions.

/**
 */
@Test
public void testKillHangingLocalTransactions() 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).setAffinity(new RendezvousAffinityFunction(false, 64)));
    Ignite prim = primaryNode(0L, DEFAULT_CACHE_NAME);
    // Blocks lock response to near node.
    TestRecordingCommunicationSpi.spi(prim).blockMessages(GridNearLockResponse.class, client.name());
    TestRecordingCommunicationSpi.spi(client).blockMessages(GridNearTxFinishRequest.class, prim.name());
    GridNearTxLocal clientTx = null;
    try (Transaction tx = client.transactions().txStart(PESSIMISTIC, READ_COMMITTED, 2000, 1)) {
        clientTx = ((TransactionProxyImpl) tx).tx();
        client.cache(DEFAULT_CACHE_NAME).put(0L, 0L);
        fail();
    } catch (Exception e) {
        assertTrue(X.hasCause(e, TransactionTimeoutException.class));
    }
    assertNotNull(clientTx);
    IgniteEx primEx = (IgniteEx) prim;
    IgniteInternalTx tx0 = primEx.context().cache().context().tm().activeTransactions().iterator().next();
    assertNotNull(tx0);
    CommandHandler h = new CommandHandler();
    validate(h, map -> {
        ClusterNode node = grid(0).cluster().localNode();
        VisorTxTaskResult res = map.get(node);
        for (VisorTxInfo info : res.getInfos()) assertEquals(tx0.xid(), info.getXid());
        assertEquals(1, map.size());
    }, "--tx", "--xid", tx0.xid().toString(), "--kill");
    tx0.finishFuture().get();
    TestRecordingCommunicationSpi.spi(prim).stopBlock();
    TestRecordingCommunicationSpi.spi(client).stopBlock();
    IgniteInternalFuture<?> nearFinFut = U.field(clientTx, "finishFut");
    nearFinFut.get();
    checkUserFutures();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) 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) Transaction(org.apache.ignite.transactions.Transaction) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) VisorTxInfo(org.apache.ignite.internal.visor.tx.VisorTxInfo) VisorTxTaskResult(org.apache.ignite.internal.visor.tx.VisorTxTaskResult) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) 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 4 with CommandHandler

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

the class GridCommandHandlerTest method doClusterSnapshotCreate.

/**
 * @param syncMode Execute operation synchrnously.
 * @throws Exception If failed.
 */
private void doClusterSnapshotCreate(boolean syncMode) throws Exception {
    int keysCnt = 100;
    String snpName = "snapshot_02052020";
    IgniteEx ig = startGrid(0);
    ig.cluster().state(ACTIVE);
    createCacheAndPreload(ig, keysCnt);
    injectTestSystemOut();
    CommandHandler h = new CommandHandler();
    // Invalid command syntax check.
    assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "create", snpName, "blah"));
    assertContains(log, testOut.toString(), "Invalid argument: blah. Possible options: --sync.");
    assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute(h, "--snapshot", "create", snpName, "--sync", "blah"));
    assertContains(log, testOut.toString(), "Invalid argument: blah.");
    List<String> args = new ArrayList<>(F.asList("--snapshot", "create", snpName));
    if (syncMode)
        args.add("--sync");
    assertEquals(EXIT_CODE_OK, execute(h, args));
    LongMetric opEndTimeMetric = ig.context().metric().registry(SNAPSHOT_METRICS).findMetric("LastSnapshotEndTime");
    BooleanSupplier endTimeMetricPredicate = () -> opEndTimeMetric.value() > 0;
    if (syncMode)
        assertTrue(endTimeMetricPredicate.getAsBoolean());
    else {
        assertTrue("Waiting for snapshot operation end failed.", waitForCondition(endTimeMetricPredicate::getAsBoolean, getTestTimeout()));
    }
    assertContains(log, (String) h.getLastOperationResult(), snpName);
    stopAllGrids();
    IgniteConfiguration cfg = optimize(getConfiguration(getTestIgniteInstanceName(0)));
    cfg.setWorkDirectory(Paths.get(resolveSnapshotWorkDirectory(cfg).getAbsolutePath(), snpName).toString());
    Ignite snpIg = startGrid(cfg);
    snpIg.cluster().state(ACTIVE);
    List<Integer> range = IntStream.range(0, keysCnt).boxed().collect(Collectors.toList());
    snpIg.cache(DEFAULT_CACHE_NAME).forEach(e -> range.remove((Integer) e.getKey()));
    assertTrue("Snapshot must contains cache data [left=" + range + ']', range.isEmpty());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) ArrayList(java.util.ArrayList) Ignite(org.apache.ignite.Ignite) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) LongMetric(org.apache.ignite.spi.metric.LongMetric) BooleanSupplier(java.util.function.BooleanSupplier)

Example 5 with CommandHandler

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

the class GridCommandHandlerAbstractTest method execute.

/**
 * Before command executed {@link #testOut} reset.
 */
protected int execute(CommandHandler hnd, List<String> args) {
    if (!F.isEmpty(args) && !"--help".equalsIgnoreCase(args.get(0)))
        addExtraArguments(args);
    testOut.reset();
    int exitCode = hnd.execute(args);
    lastOperationResult = hnd.getLastOperationResult();
    // Flush all Logger handlers to make log data available to test.
    Logger logger = U.field(hnd, "logger");
    Arrays.stream(logger.getHandlers()).forEach(Handler::flush);
    return exitCode;
}
Also used : CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) Handler(java.util.logging.Handler) Logger(java.util.logging.Logger)

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