geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [11/22] geode git commit: GEODE-2725: export logs now honors --dir when connected via JMX, with respect to the manager filesystem.
Date Thu, 13 Apr 2017 17:18:32 GMT
GEODE-2725: export logs now honors --dir when connected via JMX, with
respect to the manager filesystem.

* Absolute Paths are better.  Test class inheritance is cumbersome.

* Removed --dir usage from ExportLogsDUnitTests:
startAndEndDateCanIncludeLogs and
testExportWithStartAndEndDateTimeFiltering; these tests expected logs
to appear in the locator working directory and the --dir option was
not actually being used.

* Usage of LocalLocatorStarterRules reverted in
ExportLogsIntegrationTest as locator working directory access is
required.

* this closes #438

Corrected mismatched merging of strings against offline help golden file.


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/122e6505
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/122e6505
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/122e6505

Branch: refs/heads/feature/GEODE-2632
Commit: 122e65058f643d8ac862398e5baeba59c2628d8c
Parents: 2bf910a
Author: Patrick Rhomberg <prhomberg@pivotal.io>
Authored: Mon Apr 3 11:24:57 2017 -0700
Committer: Jinmei Liao <jiliao@pivotal.io>
Committed: Wed Apr 12 09:46:36 2017 -0700

----------------------------------------------------------------------
 .../cli/commands/ExportLogsCommand.java         | 14 +++--
 .../cli/commands/ExportLogsInterceptor.java     |  4 +-
 .../cli/commands/ExportLogsDUnitTest.java       |  2 -
 .../cli/commands/ExportLogsIntegrationTest.java | 60 ++++++++++++++++----
 .../dunit/rules/GfshShellConnectionRule.java    |  4 +-
 .../ExportLogsOverHttpIntegrationTest.java      |  8 ++-
 6 files changed, 70 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/122e6505/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java
index 1d5c412..647fff2 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java
@@ -170,8 +170,7 @@ public class ExportLogsCommand implements CommandMarker {
 
       Path tempDir = Files.createTempDirectory("exportedLogs");
       // make sure the directory is created, so that even if there is no files unzipped to
this dir,
-      // we can
-      // still zip it and send an empty zip file back to the client
+      // we can still zip it and send an empty zip file back to the client
       Path exportedLogsDir = tempDir.resolve("exportedLogs");
       FileUtils.forceMkdir(exportedLogsDir.toFile());
 
@@ -182,9 +181,14 @@ public class ExportLogsCommand implements CommandMarker {
         FileUtils.deleteQuietly(zipFile.toFile());
       }
 
-      Path workingDir = Paths.get(System.getProperty("user.dir"));
-      Path exportedLogsZipFile = workingDir
-          .resolve("exportedLogs_" + System.currentTimeMillis() + ".zip").toAbsolutePath();
+      Path dirPath;
+      if (StringUtils.isBlank(dirName)) {
+        dirPath = Paths.get(System.getProperty("user.dir"));
+      } else {
+        dirPath = Paths.get(dirName);
+      }
+      Path exportedLogsZipFile =
+          dirPath.resolve("exportedLogs_" + System.currentTimeMillis() + ".zip").toAbsolutePath();
 
       logger.info("Zipping into: " + exportedLogsZipFile.toString());
       ZipUtils.zipDirectory(exportedLogsDir, exportedLogsZipFile);

http://git-wip-us.apache.org/repos/asf/geode/blob/122e6505/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsInterceptor.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsInterceptor.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsInterceptor.java
index dc20da3..5f21848 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsInterceptor.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsInterceptor.java
@@ -85,9 +85,9 @@ public class ExportLogsInterceptor extends AbstractCliAroundInterceptor
{
       Path dirPath;
       String dirName = parseResult.getParamValueStrings().get("dir");
       if (StringUtils.isBlank(dirName)) {
-        dirPath = Paths.get(System.getProperty("user.dir"));
+        dirPath = Paths.get(System.getProperty("user.dir")).toAbsolutePath();
       } else {
-        dirPath = Paths.get(dirName);
+        dirPath = Paths.get(dirName).toAbsolutePath();
       }
       String fileName = "exportedLogs_" + System.currentTimeMillis() + ".zip";
       File exportedLogFile = dirPath.resolve(fileName).toFile();

http://git-wip-us.apache.org/repos/asf/geode/blob/122e6505/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTest.java
index ef535d8..96ac765 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTest.java
@@ -119,7 +119,6 @@ public class ExportLogsDUnitTest {
     commandStringBuilder.addOption("start-time", dateTimeFormatter.format(yesterday));
     commandStringBuilder.addOption("end-time", dateTimeFormatter.format(tomorrow));
     commandStringBuilder.addOption("log-level", "debug");
-    commandStringBuilder.addOption("dir", "someDir");
 
     gfshConnector.executeAndVerifyCommand(commandStringBuilder.toString());
 
@@ -146,7 +145,6 @@ public class ExportLogsDUnitTest {
     commandStringBuilder.addOption("start-time", dateTimeFormatter.format(cutoffTime.minusDays(1)));
     commandStringBuilder.addOption("end-time", cutoffTimeString);
     commandStringBuilder.addOption("log-level", "debug");
-    commandStringBuilder.addOption("dir", "someDir");
 
     gfshConnector.executeAndVerifyCommand(commandStringBuilder.toString());
 

http://git-wip-us.apache.org/repos/asf/geode/blob/122e6505/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsIntegrationTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsIntegrationTest.java
index 9a39298..3c53dfe 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsIntegrationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsIntegrationTest.java
@@ -15,42 +15,82 @@
 
 package org.apache.geode.management.internal.cli.commands;
 
-import static org.apache.geode.test.dunit.rules.GfshShellConnectionRule.*;
 import static org.assertj.core.api.Assertions.assertThat;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.geode.test.dunit.rules.GfshShellConnectionRule;
-import org.apache.geode.test.dunit.rules.LocatorStarterBuilder;
-import org.apache.geode.test.dunit.rules.LocalLocatorStarterRule;
+import org.apache.geode.test.dunit.rules.LocatorStarterRule;
 import org.apache.geode.test.junit.categories.IntegrationTest;
-import org.junit.ClassRule;
+import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
+import java.nio.file.Path;
+
+import java.io.File;
+
 @Category(IntegrationTest.class)
 public class ExportLogsIntegrationTest {
 
-  @ClassRule
-  public static LocalLocatorStarterRule locator = new LocatorStarterBuilder().buildInThisVM();
+  @Rule
+  public LocatorStarterRule locator = new LocatorStarterRule().withJMXManager().startLocator();
 
   @Rule
   public GfshShellConnectionRule gfsh = new GfshShellConnectionRule();
 
-  protected void connect() throws Exception {
-    gfsh.connectAndVerify(locator.getLocatorPort(), PortType.locator);
+  @Before
+  public void connect() throws Exception {
+    gfsh.connectAndVerify(locator);
+  }
+
+  public File getWorkingDirectory() throws Exception {
+    return locator.getWorkingDir();
   }
 
   @Test
   public void testInvalidMember() throws Exception {
-    connect();
     gfsh.executeCommand("export logs --member=member1,member2");
     assertThat(gfsh.getGfshOutput()).contains("No Members Found");
   }
 
   @Test
   public void testNothingToExport() throws Exception {
-    connect();
     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();
+  }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/122e6505/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java
b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java
index 381b751..02bad30 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java
@@ -92,11 +92,11 @@ public class GfshShellConnectionRule extends DescribedExternalResource
{
 
   }
 
-  public void connect(MemberVM locator, String... options) throws Exception {
+  public void connect(Member locator, String... options) throws Exception {
     connect(locator.getPort(), PortType.locator, options);
   }
 
-  public void connectAndVerify(MemberVM locator, String... options) throws Exception {
+  public void connectAndVerify(Member locator, String... options) throws Exception {
     connect(locator.getPort(), PortType.locator, options);
     assertThat(this.connected).isTrue();
   }

http://git-wip-us.apache.org/repos/asf/geode/blob/122e6505/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsOverHttpIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsOverHttpIntegrationTest.java
b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsOverHttpIntegrationTest.java
index 90f16ea..580ce40 100644
--- a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsOverHttpIntegrationTest.java
+++ b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsOverHttpIntegrationTest.java
@@ -19,12 +19,18 @@ import org.apache.geode.test.dunit.rules.GfshShellConnectionRule;
 import org.apache.geode.test.junit.categories.IntegrationTest;
 import org.junit.experimental.categories.Category;
 
+import java.io.File;
+
 @Category(IntegrationTest.class)
 public class ExportLogsOverHttpIntegrationTest extends ExportLogsIntegrationTest {
 
   @Override
-  protected void connect() throws Exception {
+  public void connect() throws Exception {
     gfsh.connectAndVerify(locator.getHttpPort(), GfshShellConnectionRule.PortType.http);
   }
 
+  public File getWorkingDirectory() throws Exception {
+    return new File(System.getProperty("user.dir"));
+  }
+
 }


Mime
View raw message