You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by sa...@apache.org on 2018/08/01 17:58:49 UTC

[geode] branch develop updated: GEODE-5212: Convert ExportLogsIntegrationTest to DistributedTest (#2155)

This is an automated email from the ASF dual-hosted git repository.

sai_boorlagadda pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 18884b8  GEODE-5212: Convert ExportLogsIntegrationTest to DistributedTest (#2155)
18884b8 is described below

commit 18884b820628702e0194844e9e971ed160cfac7b
Author: Sai Boorlagadda <sa...@gmail.com>
AuthorDate: Wed Aug 1 10:58:44 2018 -0700

    GEODE-5212: Convert ExportLogsIntegrationTest to DistributedTest (#2155)
    
      Due to differences on how defaultDirectory is initialized between
      Windows and Unix, this test fails if its integration test.
      So converted it to be a DistributedTest.
    
    Signed-off-by: Jens Deppe <jd...@pivotal.io>
---
 .../internal/cli/commands/ExportLogsDUnitTest.java | 68 +++++++++++++--
 .../cli/commands/ExportLogsIntegrationTest.java    | 97 ----------------------
 .../ExportLogsOverHttpDistributedTest.java}        |  6 +-
 3 files changed, 65 insertions(+), 106 deletions(-)

diff --git a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTest.java
index d21d395..c6ffb97 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTest.java
@@ -19,6 +19,7 @@ package org.apache.geode.management.internal.cli.commands;
 import static java.util.stream.Collectors.joining;
 import static java.util.stream.Collectors.toList;
 import static java.util.stream.Collectors.toSet;
+import static org.apache.commons.io.FileUtils.listFiles;
 import static org.apache.geode.management.internal.cli.commands.ExportLogsCommand.FORMAT;
 import static org.apache.geode.management.internal.cli.commands.ExportLogsCommand.ONLY_DATE_FORMAT;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -27,6 +28,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.Serializable;
 import java.nio.charset.Charset;
+import java.nio.file.Path;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.time.ZonedDateTime;
@@ -41,10 +43,12 @@ import java.util.stream.Stream;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.logging.log4j.Logger;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
 
 import org.apache.geode.cache.Cache;
 import org.apache.geode.distributed.ConfigurationProperties;
@@ -70,12 +74,18 @@ public class ExportLogsDUnitTest {
   @Rule
   public GfshCommandRule gfshConnector = new GfshCommandRule();
 
-  private MemberVM locator;
+  @Rule
+  public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+  protected MemberVM locator;
   private MemberVM server1;
   private MemberVM server2;
 
   private Map<MemberVM, List<LogLine>> expectedMessages;
 
+  public File getWorkingDirectory() throws Exception {
+    return locator.getWorkingDir();
+  }
 
   @Before
   public void setup() throws Exception {
@@ -103,9 +113,53 @@ public class ExportLogsDUnitTest {
       });
     }
 
+    connect();
+  }
+
+  public void connect() throws Exception {
     gfshConnector.connectAndVerify(locator);
   }
 
+  @After
+  public void after() throws Exception {
+    Stream.of(getWorkingDirectory().listFiles())
+        .filter(f -> f.getName().endsWith(".zip")).forEach(file -> file.delete());
+  }
+
+  @Test
+  public void withFiles_savedToLocatorWorkingDir() throws Exception {
+    String[] extensions = {"zip"};
+    // Expects locator to produce file in own working directory when connected via JMX
+    gfshConnector.executeCommand("export logs");
+    assertThat(listFiles(getWorkingDirectory(), extensions, false)).isNotEmpty();
+  }
+
+  @Test
+  public void withFiles_savedToLocatorSpecifiedRelativeDir() throws Exception {
+    String[] extensions = {"zip"};
+    Path workingDirPath = getWorkingDirectory().toPath();
+    Path subdirPath = workingDirPath.resolve("some").resolve("test").resolve("directory");
+    Path relativeDir = workingDirPath.relativize(subdirPath);
+    // Expects locator to produce file in own working directory when connected via JMX
+    gfshConnector.executeCommand("export logs --dir=" + relativeDir.toString());
+    assertThat(listFiles(getWorkingDirectory(), extensions, false)).isEmpty();
+    assertThat(listFiles(getWorkingDirectory(), extensions, true)).isNotEmpty();
+    assertThat(listFiles(subdirPath.toFile(), extensions, false)).isNotEmpty();
+  }
+
+  @Test
+  public void withFiles_savedToLocatorSpecifiedAbsoluteDir() throws Exception {
+    String[] extensions = {"zip"};
+    Path workingDirPath = getWorkingDirectory().toPath();
+    Path absoluteDirPath =
+        workingDirPath.resolve("some").resolve("test").resolve("directory").toAbsolutePath();
+    // Expects locator to produce file in own working directory when connected via JMX
+    gfshConnector.executeCommand("export logs --dir=" + absoluteDirPath.toString());
+    assertThat(listFiles(getWorkingDirectory(), extensions, false)).isEmpty();
+    assertThat(listFiles(getWorkingDirectory(), extensions, true)).isNotEmpty();
+    assertThat(listFiles(absoluteDirPath.toFile(), extensions, false)).isNotEmpty();
+  }
+
   @Test
   public void startAndEndDateCanIncludeLogs() throws Exception {
     ZonedDateTime now = LocalDateTime.now().atZone(ZoneId.systemDefault());
@@ -219,7 +273,7 @@ public class ExportLogsDUnitTest {
   }
 
 
-  private void verifyZipFileContents(Set<String> acceptedLogLevels) throws IOException {
+  private void verifyZipFileContents(Set<String> acceptedLogLevels) throws Exception {
     File unzippedLogFileDir = unzipExportedLogs();
 
     Set<File> dirsFromZipFile =
@@ -270,19 +324,19 @@ public class ExportLogsDUnitTest {
 
   }
 
-  private File unzipExportedLogs() throws IOException {
-    File locatorWorkingDir = locator.getWorkingDir();
-    List<File> filesInDir = Stream.of(locatorWorkingDir.listFiles()).collect(toList());
+  private File unzipExportedLogs() throws Exception {
+    File locatorWorkingDir = getWorkingDirectory();
+    List<File> filesInDir = Stream.of(getWorkingDirectory().listFiles()).collect(toList());
     assertThat(filesInDir).isNotEmpty();
 
 
-    List<File> zipFilesInDir = Stream.of(locatorWorkingDir.listFiles())
+    List<File> zipFilesInDir = Stream.of(getWorkingDirectory().listFiles())
         .filter(f -> f.getName().endsWith(".zip")).collect(toList());
     assertThat(zipFilesInDir)
         .describedAs(filesInDir.stream().map(File::getAbsolutePath).collect(joining(",")))
         .hasSize(1);
 
-    File unzippedLogFileDir = new File(locatorWorkingDir, "unzippedLogs");
+    File unzippedLogFileDir = temporaryFolder.newFolder("unzippedLogs");
     ZipUtils.unzip(zipFilesInDir.get(0).getCanonicalPath(), unzippedLogFileDir.getCanonicalPath());
     return unzippedLogFileDir;
   }
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsIntegrationTest.java
deleted file mode 100644
index 08d5240..0000000
--- a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsIntegrationTest.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package org.apache.geode.management.internal.cli.commands;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.io.File;
-import java.nio.file.Path;
-
-import org.apache.commons.io.FileUtils;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.test.junit.categories.LoggingTest;
-import org.apache.geode.test.junit.rules.GfshCommandRule;
-import org.apache.geode.test.junit.rules.LocatorStarterRule;
-
-@Category({LoggingTest.class})
-public class ExportLogsIntegrationTest {
-  @ClassRule
-  public static LocatorStarterRule locator =
-      new LocatorStarterRule().withWorkingDir().withLogFile().withAutoStart();
-
-  @Rule
-  public GfshCommandRule gfsh = new GfshCommandRule();
-
-  @Before
-  public void connect() throws Exception {
-    gfsh.connectAndVerify(locator);
-  }
-
-  public File getWorkingDirectory() throws Exception {
-    return locator.getWorkingDir();
-  }
-
-  @Test
-  public void testInvalidMember() throws Exception {
-    gfsh.executeCommand("export logs --member=member1,member2");
-    assertThat(gfsh.getGfshOutput()).contains("No Members Found");
-  }
-
-  @Test
-  public void testNothingToExport() throws Exception {
-    gfsh.executeCommand("export logs --stats-only");
-    assertThat(gfsh.getGfshOutput()).contains("No files to be exported.");
-  }
-
-  @Test
-  public void withFiles_savedToLocatorWorkingDir() throws Exception {
-    String[] extensions = {"zip"};
-    // Expects locator to produce file in own working directory when connected via JMX
-    gfsh.executeCommand("export logs");
-    assertThat(FileUtils.listFiles(getWorkingDirectory(), extensions, false)).isNotEmpty();
-  }
-
-  @Test
-  public void withFiles_savedToLocatorSpecifiedRelativeDir() throws Exception {
-    String[] extensions = {"zip"};
-    Path workingDirPath = getWorkingDirectory().toPath();
-    Path subdirPath = workingDirPath.resolve("some").resolve("test").resolve("directory");
-    Path relativeDir = workingDirPath.relativize(subdirPath);
-    // Expects locator to produce file in own working directory when connected via JMX
-    gfsh.executeCommand("export logs --dir=" + relativeDir.toString());
-    assertThat(FileUtils.listFiles(getWorkingDirectory(), extensions, false)).isEmpty();
-    assertThat(FileUtils.listFiles(getWorkingDirectory(), extensions, true)).isNotEmpty();
-    assertThat(FileUtils.listFiles(subdirPath.toFile(), extensions, false)).isNotEmpty();
-  }
-
-  @Test
-  public void withFiles_savedToLocatorSpecifiedAbsoluteDir() throws Exception {
-    String[] extensions = {"zip"};
-    Path workingDirPath = getWorkingDirectory().toPath();
-    Path absoluteDirPath =
-        workingDirPath.resolve("some").resolve("test").resolve("directory").toAbsolutePath();
-    // Expects locator to produce file in own working directory when connected via JMX
-    gfsh.executeCommand("export logs --dir=" + absoluteDirPath.toString());
-    assertThat(FileUtils.listFiles(getWorkingDirectory(), extensions, false)).isEmpty();
-    assertThat(FileUtils.listFiles(getWorkingDirectory(), extensions, true)).isNotEmpty();
-    assertThat(FileUtils.listFiles(absoluteDirPath.toFile(), extensions, false)).isNotEmpty();
-  }
-}
diff --git a/geode-web/src/integrationTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsOverHttpIntegrationTest.java b/geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsOverHttpDistributedTest.java
similarity index 85%
rename from geode-web/src/integrationTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsOverHttpIntegrationTest.java
rename to geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsOverHttpDistributedTest.java
index 0fb65cc..9325819 100644
--- a/geode-web/src/integrationTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsOverHttpIntegrationTest.java
+++ b/geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsOverHttpDistributedTest.java
@@ -23,11 +23,13 @@ import org.apache.geode.test.junit.categories.GfshTest;
 import org.apache.geode.test.junit.rules.GfshCommandRule;
 
 @Category({GfshTest.class})
-public class ExportLogsOverHttpIntegrationTest extends ExportLogsIntegrationTest {
+public class ExportLogsOverHttpDistributedTest extends ExportLogsDUnitTest {
 
   @Override
   public void connect() throws Exception {
-    gfsh.connectAndVerify(locator.getHttpPort(), GfshCommandRule.PortType.http);
+    if (!gfshConnector.isConnected()) {
+      gfshConnector.connectAndVerify(locator.getHttpPort(), GfshCommandRule.PortType.http);
+    }
   }
 
   public File getWorkingDirectory() throws Exception {