Search in sources :

Example 1 with MemberVM

use of org.apache.geode.test.dunit.rules.MemberVM in project geode by apache.

the class ExportLogsDUnitTest method verifyLogFileContents.

private void verifyLogFileContents(Set<String> acceptedLogLevels, File dirForMember) throws IOException {
    String memberName = dirForMember.getName();
    MemberVM member = expectedMessages.keySet().stream().filter((Member aMember) -> aMember.getName().equals(memberName)).findFirst().get();
    assertThat(member).isNotNull();
    Set<String> fileNamesInDir = Stream.of(dirForMember.listFiles()).map(File::getName).collect(toSet());
    System.out.println(dirForMember.getCanonicalPath() + " : " + fileNamesInDir);
    File logFileForMember = new File(dirForMember, memberName + ".log");
    assertThat(logFileForMember).exists();
    assertThat(fileNamesInDir).hasSize(1);
    String logFileContents = FileUtils.readLines(logFileForMember, Charset.defaultCharset()).stream().collect(joining("\n"));
    for (LogLine logLine : expectedMessages.get(member)) {
        boolean shouldExpectLogLine = acceptedLogLevels.contains(logLine.level) && !logLine.shouldBeIgnoredDueToTimestamp;
        if (shouldExpectLogLine) {
            assertThat(logFileContents).contains(logLine.getMessage());
        } else {
            assertThat(logFileContents).doesNotContain(logLine.getMessage());
        }
    }
}
Also used : MemberVM(org.apache.geode.test.dunit.rules.MemberVM) Member(org.apache.geode.test.dunit.rules.Member) File(java.io.File)

Example 2 with MemberVM

use of org.apache.geode.test.dunit.rules.MemberVM in project geode by apache.

the class ExportLogsDUnitTest method setup.

@Before
public void setup() throws Exception {
    Properties properties = new Properties();
    properties.setProperty(ConfigurationProperties.LOG_LEVEL, "debug");
    locator = lsRule.startLocatorVM(0, properties);
    server1 = lsRule.startServerVM(1, properties, locator.getPort());
    server2 = lsRule.startServerVM(2, properties, locator.getPort());
    IgnoredException.addIgnoredException(ERROR_LOG_PREFIX);
    expectedMessages = new HashMap<>();
    expectedMessages.put(locator, listOfLogLines(locator, "info", "error", "debug"));
    expectedMessages.put(server1, listOfLogLines(server1, "info", "error", "debug"));
    expectedMessages.put(server2, listOfLogLines(server2, "info", "error", "debug"));
    // log the messages in each of the members
    for (MemberVM member : expectedMessages.keySet()) {
        List<LogLine> logLines = expectedMessages.get(member);
        member.invoke(() -> {
            Logger logger = LogService.getLogger();
            logLines.forEach((LogLine logLine) -> logLine.writeLog(logger));
        });
    }
    gfshConnector.connectAndVerify(locator);
}
Also used : MemberVM(org.apache.geode.test.dunit.rules.MemberVM) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Logger(org.apache.logging.log4j.Logger) Before(org.junit.Before)

Example 3 with MemberVM

use of org.apache.geode.test.dunit.rules.MemberVM in project geode by apache.

the class ExportLogsOnServerManagerDUnit method testExportWithOneServer.

@Test
public void testExportWithOneServer() throws Exception {
    MemberVM server0 = lsRule.startServerAsJmxManager(0);
    gfshConnector.connect(server0.getJmxPort(), GfshShellConnectionRule.PortType.jmxManger);
    gfshConnector.executeAndVerifyCommand("export logs");
    String message = gfshConnector.getGfshOutput();
    assertThat(message).contains(server0.getWorkingDir().getAbsolutePath());
    String zipPath = getZipPathFromCommandResult(message);
    Set<String> expectedZipEntries = Sets.newHashSet("server-0/server-0.log");
    Set<String> actualZipEnries = new ZipFile(zipPath).stream().map(ZipEntry::getName).collect(Collectors.toSet());
    assertThat(actualZipEnries).isEqualTo(expectedZipEntries);
}
Also used : ZipFile(java.util.zip.ZipFile) MemberVM(org.apache.geode.test.dunit.rules.MemberVM) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 4 with MemberVM

use of org.apache.geode.test.dunit.rules.MemberVM in project geode by apache.

the class MergeLogsDUnitTest method setup.

@Before
public void setup() throws Exception {
    Properties properties = new Properties();
    properties.setProperty(DistributionConfig.LOG_LEVEL_NAME, "info");
    locator = lsRule.startLocatorVM(0, properties);
    properties.setProperty(DistributionConfig.LOCATORS_NAME, "localhost[" + locator.getPort() + "]");
    MemberVM server = lsRule.startServerVM(1, properties);
    MemberVM server2 = lsRule.startServerVM(2, properties);
    locator.invoke(() -> LogService.getLogger().info(MESSAGE_1));
    server.invoke(() -> LogService.getLogger().info(MESSAGE_2));
    server2.invoke(() -> LogService.getLogger().info(MESSAGE_3));
    locator.invoke(() -> LogService.getLogger().info(MESSAGE_4));
    server.invoke(() -> LogService.getLogger().info(MESSAGE_5));
    server2.invoke(() -> LogService.getLogger().info(MESSAGE_6));
}
Also used : MemberVM(org.apache.geode.test.dunit.rules.MemberVM) Properties(java.util.Properties) Before(org.junit.Before)

Example 5 with MemberVM

use of org.apache.geode.test.dunit.rules.MemberVM in project geode by apache.

the class ClusterConfigDeployJarDUnitTest method testDeployToNoServer.

@Test
public void testDeployToNoServer() throws Exception {
    String clusterJarPath = clusterJar;
    // set up the locator/servers
    MemberVM locator = lsRule.startLocatorVM(0, locatorProps);
    gfshConnector.connect(locator);
    assertThat(gfshConnector.isConnected()).isTrue();
    gfshConnector.executeAndVerifyCommand("deploy --jar=" + clusterJarPath);
    ConfigGroup cluster = new ConfigGroup("cluster").jars("cluster.jar");
    ClusterConfig expectedClusterConfig = new ClusterConfig(cluster);
    expectedClusterConfig.verify(locator);
    // start a server and verify that the server gets the jar
    MemberVM server1 = lsRule.startServerVM(1, locator.getPort());
    expectedClusterConfig.verify(server1);
}
Also used : MemberVM(org.apache.geode.test.dunit.rules.MemberVM) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

MemberVM (org.apache.geode.test.dunit.rules.MemberVM)27 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)19 Test (org.junit.Test)19 Properties (java.util.Properties)8 File (java.io.File)5 ZipFile (java.util.zip.ZipFile)3 Cache (org.apache.geode.cache.Cache)3 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)3 HashSet (java.util.HashSet)2 LuceneIndex (org.apache.geode.cache.lucene.LuceneIndex)2 LuceneService (org.apache.geode.cache.lucene.LuceneService)2 ClusterConfigurationService (org.apache.geode.distributed.internal.ClusterConfigurationService)2 InternalLocator (org.apache.geode.distributed.internal.InternalLocator)2 CommandStringBuilder (org.apache.geode.management.internal.cli.util.CommandStringBuilder)2 Before (org.junit.Before)2 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 Serializable (java.io.Serializable)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1