Search in sources :

Example 16 with CommandHandler

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

the class GridCommandHandlerTracingConfigurationTest method beforeTestsStarted.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTestsStarted() throws Exception {
    super.beforeTestsStarted();
    ignite = startGrids(2);
    hnd = new CommandHandler();
}
Also used : CommandHandler(org.apache.ignite.internal.commandline.CommandHandler)

Example 17 with CommandHandler

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

the class GridCommandHandlerSslWithSecurityTest method flushCommandOutput.

/**
 * Flushes all Logger handlers to make log data available to test.
 * @param hnd Command handler.
 */
private void flushCommandOutput(CommandHandler hnd) {
    Logger log = U.field(hnd, "logger");
    Arrays.stream(log.getHandlers()).forEach(Handler::flush);
}
Also used : CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) Handler(java.util.logging.Handler) Logger(java.util.logging.Logger)

Example 18 with CommandHandler

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

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

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

the class GridCommandHandlerTest method testSnapshotRestoreCancelAndStatus.

/**
 * @throws Exception If fails.
 */
@Test
public void testSnapshotRestoreCancelAndStatus() throws Exception {
    int keysCnt = 2048;
    String snpName = "snapshot_25052021";
    String missingSnpName = "snapshot_MISSING";
    IgniteEx ig = startGrid(getConfiguration(getTestIgniteInstanceName(0)).setSnapshotThreadPoolSize(1));
    startGrid(1).cluster().state(ACTIVE);
    injectTestSystemOut();
    createCacheAndPreload(ig, keysCnt);
    ig.snapshot().createSnapshot(snpName).get(getTestTimeout());
    int locPartsCnt = ig.cachex(DEFAULT_CACHE_NAME).context().topology().localPartitions().size();
    ig.destroyCache(DEFAULT_CACHE_NAME);
    awaitPartitionMapExchange();
    CommandHandler h = new CommandHandler();
    CountDownLatch ioStartLatch = new CountDownLatch(1);
    IgniteSnapshotManager snpMgr = ig.context().cache().context().snapshotMgr();
    // Replace the IO factory in the snapshot manager so we have enough time to test the status command.
    snpMgr.ioFactory(new SlowDownFileIoFactory(snpMgr.ioFactory(), getTestTimeout() / locPartsCnt, ioStartLatch));
    // Restore single cache group.
    IgniteFuture<Void> restoreFut = snpMgr.restoreSnapshot(snpName, Collections.singleton(DEFAULT_CACHE_NAME));
    ioStartLatch.await(getTestTimeout(), TimeUnit.MILLISECONDS);
    assertFalse(restoreFut.isDone());
    // Check the status with a control command.
    assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", snpName, "--status"));
    assertContains(log, testOut.toString(), "Snapshot cache group restore operation is running [snapshot=" + snpName + ']');
    // Check "status" with the wrong snapshot name.
    assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", missingSnpName, "--status"));
    assertContains(log, testOut.toString(), "Snapshot cache group restore operation is NOT running [snapshot=" + missingSnpName + ']');
    // Check "cancel" with the wrong snapshot name.
    assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", missingSnpName, "--cancel"));
    assertContains(log, testOut.toString(), "Snapshot cache group restore operation is NOT running [snapshot=" + missingSnpName + ']');
    // Cancel operation using control command.
    assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", snpName, "--cancel"));
    assertContains(log, testOut.toString(), "Snapshot cache group restore operation canceled [snapshot=" + snpName + ']');
    GridTestUtils.assertThrowsAnyCause(log, () -> restoreFut.get(getTestTimeout()), IgniteCheckedException.class, "Operation has been canceled by the user.");
    // Make sure the context disappeared at node 1.
    boolean ctxDisposed = waitForCondition(() -> !grid(1).context().cache().context().snapshotMgr().isRestoring(), getTestTimeout());
    assertTrue(ctxDisposed);
    assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", snpName, "--status"));
    assertContains(log, testOut.toString(), "Snapshot cache group restore operation is NOT running [snapshot=" + snpName + ']');
    assertNull(ig.cache(DEFAULT_CACHE_NAME));
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteSnapshotManager(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager) 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)

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