Search in sources :

Example 41 with CommandStringBuilder

use of org.apache.geode.management.internal.cli.util.CommandStringBuilder in project geode by apache.

the class ExportLogsStatsDUnitTest method startAndEndDateCanExcludeLogs.

@Test
public void startAndEndDateCanExcludeLogs() throws Exception {
    connectIfNeeded();
    ZonedDateTime now = LocalDateTime.now().atZone(ZoneId.systemDefault());
    ZonedDateTime tomorrow = now.plusDays(1);
    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(ONLY_DATE_FORMAT);
    CommandStringBuilder commandStringBuilder = new CommandStringBuilder("export logs");
    commandStringBuilder.addOption("start-time", dateTimeFormatter.format(tomorrow));
    commandStringBuilder.addOption("log-level", "debug");
    String output = connector.execute(commandStringBuilder.toString());
    assertThat(output).contains("No files to be exported");
}
Also used : ZonedDateTime(java.time.ZonedDateTime) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 42 with CommandStringBuilder

use of org.apache.geode.management.internal.cli.util.CommandStringBuilder in project geode by apache.

the class CreateAlterDestroyRegionCommandsDUnitTest method regionAlterGroupTest.

private void regionAlterGroupTest() {
    CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.ALTER_REGION);
    commandStringBuilder.addOption(CliStrings.ALTER_REGION__REGION, this.alterRegionName);
    commandStringBuilder.addOption(CliStrings.ALTER_REGION__GROUP, "Group1");
    commandStringBuilder.addOption(CliStrings.ALTER_REGION__EVICTIONMAX, "5764");
    CommandResult cmdResult = executeCommand(commandStringBuilder.toString());
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    String stringResult = commandResultToString(cmdResult);
    assertEquals(4, countLinesInString(stringResult, false));
    assertEquals(false, stringResult.contains("ERROR"));
    assertTrue(stringContainsLine(stringResult, this.alterVm1Name + ".*Region \"/" + this.alterRegionName + "\" altered.*"));
    assertTrue(stringContainsLine(stringResult, this.alterVm2Name + ".*Region \"/" + this.alterRegionName + "\" altered.*"));
    this.alterVm1.invoke(() -> {
        RegionAttributes attributes = getCache().getRegion(alterRegionName).getAttributes();
        assertEquals(5764, attributes.getEvictionAttributes().getMaximum());
    });
    this.alterVm2.invoke(() -> {
        RegionAttributes attributes = getCache().getRegion(alterRegionName).getAttributes();
        assertEquals(5764, attributes.getEvictionAttributes().getMaximum());
    });
    commandStringBuilder = new CommandStringBuilder(CliStrings.ALTER_REGION);
    commandStringBuilder.addOption(CliStrings.ALTER_REGION__REGION, "/" + this.alterRegionName);
    commandStringBuilder.addOption(CliStrings.ALTER_REGION__GROUP, "Group2");
    commandStringBuilder.addOption(CliStrings.ALTER_REGION__EVICTIONMAX, "6963");
    cmdResult = executeCommand(commandStringBuilder.toString());
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    stringResult = commandResultToString(cmdResult);
    assertEquals(3, countLinesInString(stringResult, false));
    assertEquals(false, stringResult.contains("ERROR"));
    assertFalse(stringContainsLine(stringResult, this.alterVm1Name + ".*Region \"/" + this.alterRegionName + "\" altered.*"));
    assertTrue(stringContainsLine(stringResult, this.alterVm2Name + ".*Region \"/" + this.alterRegionName + "\" altered.*"));
    this.alterVm1.invoke(() -> {
        RegionAttributes attributes = getCache().getRegion(alterRegionName).getAttributes();
        assertEquals(5764, attributes.getEvictionAttributes().getMaximum());
    });
    this.alterVm2.invoke(() -> {
        RegionAttributes attributes = getCache().getRegion(alterRegionName).getAttributes();
        assertEquals(6963, attributes.getEvictionAttributes().getMaximum());
    });
}
Also used : CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) RegionAttributes(org.apache.geode.cache.RegionAttributes) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult)

Example 43 with CommandStringBuilder

use of org.apache.geode.management.internal.cli.util.CommandStringBuilder in project geode by apache.

the class GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest method testGetOnCacheMiss.

@Test
public void testGetOnCacheMiss() {
    doHousekeeping();
    CommandStringBuilder command = new CommandStringBuilder(CliStrings.GET);
    command.addOption(CliStrings.GET__REGIONNAME, USERS_REGION_NAME);
    command.addOption(CliStrings.GET__KEY, "jonbloom");
    assertResult(true, runCommand(command.toString()));
    command = new CommandStringBuilder(CliStrings.GET);
    command.addOption(CliStrings.GET__REGIONNAME, USERS_REGION_NAME);
    command.addOption(CliStrings.GET__KEY, "jondoe");
    command.addOption(CliStrings.GET__LOAD, "false");
    assertResult(false, runCommand(command.toString()));
    command = new CommandStringBuilder(CliStrings.GET);
    command.addOption(CliStrings.GET__REGIONNAME, USERS_REGION_NAME);
    command.addOption(CliStrings.GET__KEY, "jondoe");
    command.addOption(CliStrings.GET__LOAD, "true");
    assertResult(true, runCommand(command.toString()));
    // NOTE test the unspecified default value for the --load-on-cache-miss
    command = new CommandStringBuilder(CliStrings.GET);
    command.addOption(CliStrings.GET__REGIONNAME, USERS_REGION_NAME);
    command.addOption(CliStrings.GET__KEY, "janedoe");
    assertResult(true, runCommand(command.toString()));
    // NOTE now test an absolute cache miss both for in the Region as well as the CacheLoader
    command = new CommandStringBuilder(CliStrings.GET);
    command.addOption(CliStrings.GET__REGIONNAME, USERS_REGION_NAME);
    command.addOption(CliStrings.GET__KEY, "nonexistinguser");
    command.addOption(CliStrings.GET__LOAD, "true");
    assertResult(false, runCommand(command.toString()));
}
Also used : CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 44 with CommandStringBuilder

use of org.apache.geode.management.internal.cli.util.CommandStringBuilder in project geode by apache.

the class MemberCommandsDUnitTest method testListMemberWithGroups.

/**
   * Tests list member --group=G1
   *
   * @throws IOException
   * @throws ClassNotFoundException
   */
@Test
public void testListMemberWithGroups() throws IOException, ClassNotFoundException {
    setupSystem();
    CommandProcessor commandProcessor = new CommandProcessor();
    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.LIST_MEMBER);
    csb.addOption(CliStrings.LIST_MEMBER__GROUP, "G1");
    Result result = commandProcessor.createCommandStatement(csb.toString(), EMPTY_ENV).process();
    getLogWriter().info("#SB" + getResultAsString(result));
    assertEquals(true, result.getStatus().equals(Status.OK));
}
Also used : CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) CommandProcessor(org.apache.geode.management.internal.cli.remote.CommandProcessor) Result(org.apache.geode.management.cli.Result) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 45 with CommandStringBuilder

use of org.apache.geode.management.internal.cli.util.CommandStringBuilder in project geode by apache.

the class IndexCommandsDUnitTest method testDestroyIndexWithoutIndexName.

// GEODE-1315
@Category(FlakyTest.class)
@Test
public void testDestroyIndexWithoutIndexName() {
    setupSystem();
    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_INDEX);
    csb.addOption(CliStrings.CREATE_INDEX__NAME, indexName);
    csb.addOption(CliStrings.CREATE_INDEX__EXPRESSION, "key");
    csb.addOption(CliStrings.CREATE_INDEX__REGION, "/StocksParReg");
    csb.addOption(CliStrings.CREATE_INDEX__TYPE, "hash");
    String commandString = csb.toString();
    CommandResult commandResult = executeCommand(commandString);
    String resultAsString = commandResultToString(commandResult);
    assertEquals(commandResult.getStatus(), Status.OK);
    csb = new CommandStringBuilder(CliStrings.LIST_INDEX);
    commandString = csb.toString();
    commandResult = executeCommand(commandString);
    resultAsString = commandResultToString(commandResult);
    assertEquals(Status.OK, commandResult.getStatus());
    assertEquals(true, resultAsString.contains(indexName));
    assertEquals(true, resultAsString.contains(VM1Name));
    csb = new CommandStringBuilder(CliStrings.DESTROY_INDEX);
    csb.addOption(CliStrings.DESTROY_INDEX__GROUP, group1);
    commandString = csb.toString();
    commandResult = executeCommand(commandString);
    resultAsString = commandResultToString(commandResult);
    assertEquals(Status.OK, commandResult.getStatus());
    csb = new CommandStringBuilder(CliStrings.LIST_INDEX);
    commandString = csb.toString();
    commandResult = executeCommand(commandString);
    resultAsString = commandResultToString(commandResult);
    assertEquals(Status.OK, commandResult.getStatus());
    csb = new CommandStringBuilder(CliStrings.CREATE_INDEX);
    csb.addOption(CliStrings.CREATE_INDEX__NAME, indexName);
    csb.addOption(CliStrings.CREATE_INDEX__EXPRESSION, "key");
    csb.addOption(CliStrings.CREATE_INDEX__REGION, "/StocksParReg");
    csb.addOption(CliStrings.CREATE_INDEX__TYPE, "hash");
    commandString = csb.toString();
    commandResult = executeCommand(commandString);
    resultAsString = commandResultToString(commandResult);
    assertEquals(Status.OK, commandResult.getStatus());
    csb = new CommandStringBuilder(CliStrings.DESTROY_INDEX);
    csb.addOption(CliStrings.DESTROY_INDEX__REGION, "StocksParReg");
    commandString = csb.toString();
    commandResult = executeCommand(commandString);
    resultAsString = commandResultToString(commandResult);
    assertEquals(Status.OK, commandResult.getStatus());
    csb = new CommandStringBuilder(CliStrings.LIST_INDEX);
    commandString = csb.toString();
    commandResult = executeCommand(commandString);
    resultAsString = commandResultToString(commandResult);
    assertEquals(Status.OK, commandResult.getStatus());
    assertTrue(resultAsString.contains(CliStrings.LIST_INDEX__INDEXES_NOT_FOUND_MESSAGE));
}
Also used : CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Category(org.junit.experimental.categories.Category) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

CommandStringBuilder (org.apache.geode.management.internal.cli.util.CommandStringBuilder)186 Test (org.junit.Test)88 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)87 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)71 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)47 VM (org.apache.geode.test.dunit.VM)41 File (java.io.File)39 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)37 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)36 Properties (java.util.Properties)16 Region (org.apache.geode.cache.Region)14 Category (org.junit.experimental.categories.Category)14 Cache (org.apache.geode.cache.Cache)12 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)12 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)11 IOException (java.io.IOException)10 UnknownHostException (java.net.UnknownHostException)7 HashMap (java.util.HashMap)6 RegionAttributes (org.apache.geode.cache.RegionAttributes)6 ClusterConfigurationService (org.apache.geode.distributed.internal.ClusterConfigurationService)6