Search in sources :

Example 1 with CacheSubcommands

use of org.apache.ignite.internal.commandline.cache.CacheSubcommands in project ignite by apache.

the class GridCommandHandlerClusterByClassTest method testCacheHelp.

/**
 */
@Test
public void testCacheHelp() throws Exception {
    injectTestSystemOut();
    assertEquals(EXIT_CODE_OK, execute("--cache", "help"));
    String output = testOut.toString();
    for (CacheSubcommands cmd : CacheSubcommands.values()) {
        if (cmd != HELP) {
            assertContains(log, output, cmd.toString());
            Class<? extends Enum<? extends CommandArg>> args = cmd.getCommandArgs();
            if (args != null)
                for (Enum<? extends CommandArg> arg : args.getEnumConstants()) assertTrue(cmd + " " + arg, output.contains(arg.toString()));
        } else
            assertContains(log, output, CommandHandler.UTILITY_NAME);
    }
    checkHelp(output, "org.apache.ignite.util/" + getClass().getSimpleName() + "_cache_help.output");
}
Also used : CacheSubcommands(org.apache.ignite.internal.commandline.cache.CacheSubcommands) CommandArg(org.apache.ignite.internal.commandline.argument.CommandArg) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) Test(org.junit.Test)

Example 2 with CacheSubcommands

use of org.apache.ignite.internal.commandline.cache.CacheSubcommands in project ignite by apache.

the class CommandHandlerParsingTest method testFindAndDeleteGarbage.

/**
 */
@Test
public void testFindAndDeleteGarbage() {
    String nodeId = UUID.randomUUID().toString();
    String delete = FindAndDeleteGarbageArg.DELETE.toString();
    String groups = "group1,grpoup2,group3";
    List<List<String>> lists = generateArgumentList(FIND_AND_DELETE_GARBAGE.text(), new T2<>(nodeId, false), new T2<>(delete, false), new T2<>(groups, false));
    for (List<String> list : lists) {
        ConnectionAndSslParameters args = parseArgs(list);
        assertTrue(args.command() instanceof CacheCommands);
        CacheSubcommands subcommand = ((CacheCommands) args.command()).arg();
        FindAndDeleteGarbage.Arguments arg = (FindAndDeleteGarbage.Arguments) subcommand.subcommand().arg();
        if (list.contains(nodeId))
            assertEquals("nodeId parameter unexpected value", nodeId, arg.nodeId().toString());
        else
            assertNull(arg.nodeId());
        assertEquals(list.contains(delete), arg.delete());
        if (list.contains(groups))
            assertEquals(3, arg.groups().size());
        else
            assertNull(arg.groups());
    }
}
Also used : CacheSubcommands(org.apache.ignite.internal.commandline.cache.CacheSubcommands) BaselineArguments(org.apache.ignite.internal.commandline.baseline.BaselineArguments) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) CacheCommands(org.apache.ignite.internal.commandline.cache.CacheCommands) FindAndDeleteGarbage(org.apache.ignite.internal.commandline.cache.FindAndDeleteGarbage) Test(org.junit.Test)

Example 3 with CacheSubcommands

use of org.apache.ignite.internal.commandline.cache.CacheSubcommands in project ignite by apache.

the class CommandHandlerParsingTest method testValidateIndexArguments.

/**
 * validate_indexes command arguments parsing and validation
 */
@Test
public void testValidateIndexArguments() {
    // happy case for all parameters
    try {
        int expectedCheckFirst = 10;
        int expectedCheckThrough = 11;
        UUID nodeId = UUID.randomUUID();
        ConnectionAndSslParameters args = parseArgs(asList(CACHE.text(), VALIDATE_INDEXES.text(), "cache1, cache2", nodeId.toString(), CHECK_FIRST.toString(), Integer.toString(expectedCheckFirst), CHECK_THROUGH.toString(), Integer.toString(expectedCheckThrough)));
        assertTrue(args.command() instanceof CacheCommands);
        CacheSubcommands subcommand = ((CacheCommands) args.command()).arg();
        CacheValidateIndexes.Arguments arg = (CacheValidateIndexes.Arguments) subcommand.subcommand().arg();
        assertEquals("nodeId parameter unexpected value", nodeId, arg.nodeId());
        assertEquals("checkFirst parameter unexpected value", expectedCheckFirst, arg.checkFirst());
        assertEquals("checkThrough parameter unexpected value", expectedCheckThrough, arg.checkThrough());
    } catch (IllegalArgumentException e) {
        fail("Unexpected exception: " + e);
    }
    try {
        int expectedParam = 11;
        UUID nodeId = UUID.randomUUID();
        ConnectionAndSslParameters args = parseArgs(asList(CACHE.text(), VALIDATE_INDEXES.text(), nodeId.toString(), CHECK_THROUGH.toString(), Integer.toString(expectedParam)));
        assertTrue(args.command() instanceof CacheCommands);
        CacheSubcommands subcommand = ((CacheCommands) args.command()).arg();
        CacheValidateIndexes.Arguments arg = (CacheValidateIndexes.Arguments) subcommand.subcommand().arg();
        assertNull("caches weren't specified, null value expected", arg.caches());
        assertEquals("nodeId parameter unexpected value", nodeId, arg.nodeId());
        assertEquals("checkFirst parameter unexpected value", -1, arg.checkFirst());
        assertEquals("checkThrough parameter unexpected value", expectedParam, arg.checkThrough());
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    }
    assertParseArgsThrows("Value for '--check-first' property should be positive.", CACHE.text(), VALIDATE_INDEXES.text(), CHECK_FIRST.toString(), "0");
    assertParseArgsThrows("Numeric value for '--check-through' parameter expected.", CACHE.text(), VALIDATE_INDEXES.text(), CHECK_THROUGH.toString());
}
Also used : CacheSubcommands(org.apache.ignite.internal.commandline.cache.CacheSubcommands) BaselineArguments(org.apache.ignite.internal.commandline.baseline.BaselineArguments) CacheCommands(org.apache.ignite.internal.commandline.cache.CacheCommands) UUID(java.util.UUID) CacheValidateIndexes(org.apache.ignite.internal.commandline.cache.CacheValidateIndexes) Test(org.junit.Test)

Aggregations

CacheSubcommands (org.apache.ignite.internal.commandline.cache.CacheSubcommands)3 Test (org.junit.Test)3 BaselineArguments (org.apache.ignite.internal.commandline.baseline.BaselineArguments)2 CacheCommands (org.apache.ignite.internal.commandline.cache.CacheCommands)2 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 UUID (java.util.UUID)1 CommandArg (org.apache.ignite.internal.commandline.argument.CommandArg)1 CacheValidateIndexes (org.apache.ignite.internal.commandline.cache.CacheValidateIndexes)1 FindAndDeleteGarbage (org.apache.ignite.internal.commandline.cache.FindAndDeleteGarbage)1 GridAbstractTest (org.apache.ignite.testframework.junits.GridAbstractTest)1