GEODE-2420: Resolve conflicts with recent checkin

Use InternalCache instead of GemnFireCachImpl.

Refactored product and tests
- Combined LogExporter and LogSizer.
- Remove classes no longer needed


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

Branch: refs/heads/feature/GEODE-2632-17
Commit: c5962aa9308764bb964e4b4160e969f2dfae062d
Parents: 3ce3437
Author: Ken Howe <kh...@pivotal.io>
Authored: Mon May 15 15:00:00 2017 -0700
Committer: Ken Howe <kh...@pivotal.io>
Committed: Tue May 23 08:16:17 2017 -0700

----------------------------------------------------------------------
 .../cli/commands/ExportLogsCommand.java         | 199 ++++++++-----------
 .../cli/functions/ExportLogsFunction.java       |   3 +-
 .../cli/functions/ExportedLogsSizeInfo.java     | 105 ----------
 .../cli/functions/SizeExportLogsFunction.java   |  29 ++-
 .../internal/cli/i18n/CliStrings.java           |   2 +-
 .../internal/cli/util/LogExporter.java          |  63 +++++-
 .../management/internal/cli/util/LogSizer.java  | 118 -----------
 .../cli/commands/ExportLogsCommandTest.java     | 121 ++---------
 .../cli/commands/ExportLogsDUnitTest.java       |  21 +-
 .../commands/ExportLogsFileSizeLimitTest.java   |   4 +-
 .../cli/commands/ExportLogsTestSuite.java       |  10 +-
 .../cli/functions/ExportedLogsSizeInfoTest.java | 133 -------------
 .../SizeExportLogsFunctionCacheTest.java        | 174 ----------------
 .../functions/SizeExportLogsFunctionTest.java   | 178 +++++++++++++++++
 .../cli/functions/SizeExportLogsTestSuite.java  |  29 ---
 .../internal/cli/util/LogExporterTest.java      |   6 +-
 .../internal/cli/util/LogSizerTest.java         |  17 +-
 17 files changed, 376 insertions(+), 836 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/c5962aa9/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 af681da..ab93f94 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
@@ -44,7 +44,6 @@ import org.apache.geode.management.cli.ConverterHint;
 import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.internal.cli.CliUtil;
 import org.apache.geode.management.internal.cli.functions.ExportLogsFunction;
-import org.apache.geode.management.internal.cli.functions.ExportedLogsSizeInfo;
 import 
org.apache.geode.management.internal.cli.functions.SizeExportLogsFunction;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
 import org.apache.geode.management.internal.cli.result.ResultBuilder;
@@ -65,7 +64,7 @@ public class ExportLogsCommand implements CommandMarker {
 
   private static final Pattern DISK_SPACE_LIMIT_PATTERN = 
Pattern.compile("(\\d+)([kmgtKMGT]?)");
 
-  private InternalCache getCache() {
+  InternalCache getCache() {
     return (InternalCache) CacheFactory.getAnyInstance();
   }
 
@@ -129,106 +128,88 @@ public class ExportLogsCommand implements CommandMarker {
 
           List<Object> results = (List<Object>) estimateLogSize(args, 
server).getResult();
           long estimatedSize = 0;
-          long diskAvailable = 0;
-          long diskSize = 0;
           if (!results.isEmpty()) {
             List<?> res = (List<?>) results.get(0);
-            if (res.get(0) instanceof ExportedLogsSizeInfo) {
-              ExportedLogsSizeInfo sizeInfo = (ExportedLogsSizeInfo) 
res.get(0);
-              estimatedSize = sizeInfo.getLogsSize();
-              diskAvailable = sizeInfo.getDiskAvailable();
-              diskSize = sizeInfo.getDiskSize();
+            if (res.get(0) instanceof Long) {
+              estimatedSize = (Long) res.get(0);
             }
           }
           logger.info("Received estimated export size from member {}: {}", 
server.getId(),
               estimatedSize);
           totalEstimatedExportSize += estimatedSize;
-
-          // If export size checking is enabled, then estimated size on each 
member shouldn't exceed
-          // the available disk on that member
-          try {
-            isSizeCheckEnabledAndWithinDiskSpaceOfMember(server.getName(),
-                parseFileSizeLimit(fileSizeLimit), estimatedSize, 
diskAvailable, diskSize);
-          } catch (ManagementException e) {
-            return ResultBuilder.createUserErrorResult(e.getMessage());
-          }
         }
 
         // The sum of the estimated export sizes from each member should not 
exceed the
-        // disk availble on the locator
+        // disk available on the locator
         try {
-          isSizeCheckEnabledAndWithinDiskSpaceOfMember("locator", 
parseFileSizeLimit(fileSizeLimit),
-              totalEstimatedExportSize, getLocalDiskAvailable(), 
getLocalDiskSize());
+          sizeCheckIsEnabledAndWithinDiskSpaceOfMember("locator", 
parseFileSizeLimit(fileSizeLimit),
+              totalEstimatedExportSize, getLocalDiskAvailable());
         } catch (ManagementException e) {
           return ResultBuilder.createUserErrorResult(e.getMessage());
         }
       }
 
-      if (testhookSkipExports()) {
-        result = ResultBuilder.createInfoResult("Estimated size of exported 
logs is "
-            + new BytesToString().of(totalEstimatedExportSize));
-      } else {
-        // get zipped files from all servers next
-        Map<String, Path> zipFilesFromMembers = new HashMap<>();
-        for (DistributedMember server : targetMembers) {
-          Region region = 
ExportLogsFunction.createOrGetExistingExportLogsRegion(true, cache);
+      // get zipped files from all servers next
+      Map<String, Path> zipFilesFromMembers = new HashMap<>();
+      for (DistributedMember server : targetMembers) {
+        Region region = 
ExportLogsFunction.createOrGetExistingExportLogsRegion(true, cache);
 
-          ExportLogsCacheWriter cacheWriter =
-              (ExportLogsCacheWriter) region.getAttributes().getCacheWriter();
+        ExportLogsCacheWriter cacheWriter =
+            (ExportLogsCacheWriter) region.getAttributes().getCacheWriter();
 
-          cacheWriter.startFile(server.getName());
+        cacheWriter.startFile(server.getName());
 
-          CliUtil.executeFunction(new ExportLogsFunction(),
-              new ExportLogsFunction.Args(start, end, logLevel, onlyLogLevel, 
logsOnly, statsOnly),
-              server).getResult();
-          Path zipFile = cacheWriter.endFile();
-          ExportLogsFunction.destroyExportLogsRegion(cache);
-
-          // only put the zipfile in the map if it is not null
-          if (zipFile != null) {
-            logger.info("Received zip file from member {}: {}", 
server.getId(), zipFile);
-            zipFilesFromMembers.put(server.getId(), zipFile);
-          }
-        }
+        CliUtil.executeFunction(new ExportLogsFunction(),
+            new ExportLogsFunction.Args(start, end, logLevel, onlyLogLevel, 
logsOnly, statsOnly),
+            server).getResult();
+        Path zipFile = cacheWriter.endFile();
+        ExportLogsFunction.destroyExportLogsRegion(cache);
 
-        if (zipFilesFromMembers.isEmpty()) {
-          return ResultBuilder.createUserErrorResult("No files to be 
exported.");
+        // only put the zipfile in the map if it is not null
+        if (zipFile != null) {
+          logger.info("Received zip file from member {}: {}", server.getId(), 
zipFile);
+          zipFilesFromMembers.put(server.getId(), zipFile);
         }
+      }
 
-        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
-        Path exportedLogsDir = tempDir.resolve("exportedLogs");
-        FileUtils.forceMkdir(exportedLogsDir.toFile());
-
-        for (Path zipFile : zipFilesFromMembers.values()) {
-          Path unzippedMemberDir =
-              
exportedLogsDir.resolve(zipFile.getFileName().toString().replace(".zip", ""));
-          ZipUtils.unzip(zipFile.toAbsolutePath().toString(), 
unzippedMemberDir.toString());
-          FileUtils.deleteQuietly(zipFile.toFile());
-        }
+      if (zipFilesFromMembers.isEmpty()) {
+        return ResultBuilder.createUserErrorResult("No files to be exported.");
+      }
 
-        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();
+      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
+      Path exportedLogsDir = tempDir.resolve("exportedLogs");
+      FileUtils.forceMkdir(exportedLogsDir.toFile());
+
+      for (Path zipFile : zipFilesFromMembers.values()) {
+        Path unzippedMemberDir =
+            
exportedLogsDir.resolve(zipFile.getFileName().toString().replace(".zip", ""));
+        ZipUtils.unzip(zipFile.toAbsolutePath().toString(), 
unzippedMemberDir.toString());
+        FileUtils.deleteQuietly(zipFile.toFile());
+      }
 
-        logger.info("Zipping into: " + exportedLogsZipFile.toString());
-        ZipUtils.zipDirectory(exportedLogsDir, exportedLogsZipFile);
-        try {
-          
isFileSizeCheckEnabledAndWithinLimit(parseFileSizeLimit(fileSizeLimit),
-              exportedLogsZipFile.toFile());
-        } catch (ManagementException e) {
-          return ResultBuilder.createUserErrorResult(e.getMessage());
-        } finally {
-          FileUtils.deleteDirectory(tempDir.toFile());
-        }
-        result = 
ResultBuilder.createInfoResult(exportedLogsZipFile.toString());
+      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);
+      try {
+        isFileSizeCheckEnabledAndWithinLimit(parseFileSizeLimit(fileSizeLimit),
+            exportedLogsZipFile.toFile());
+      } catch (ManagementException e) {
+        FileUtils.deleteQuietly(exportedLogsZipFile.toFile());
+        return ResultBuilder.createUserErrorResult(e.getMessage());
+      } finally {
+        FileUtils.deleteDirectory(tempDir.toFile());
       }
+      result = ResultBuilder.createInfoResult(exportedLogsZipFile.toString());
     } catch (Exception ex) {
       logger.error(ex.getMessage(), ex);
       result = ResultBuilder.createGemFireErrorResult(ex.getMessage());
@@ -240,15 +221,6 @@ public class ExportLogsCommand implements CommandMarker {
   }
 
   /**
-   * Test hook for unit testing. To limit scope of test to only estimate size 
of exports (i.e. skip
-   * the filtering and exporting logs & stats from cluster members), stub this 
method to return true
-   * to skip exporting.
-   */
-  boolean testhookSkipExports() {
-    return false;
-  }
-
-  /**
    * Wrapper to enable stubbing of static method call for unit testing
    */
   Set<DistributedMember> getMembers(String[] groups, String[] memberIds) {
@@ -292,47 +264,38 @@ public class ExportLogsCommand implements CommandMarker {
 
   /**
    * Throws ManagementException if file size is over fileSizeLimit bytes
-   *
-   * @return false == limit is zero (checking disabled)<br>
-   *         true == file size is less than limit<br>
-   *         exception == file size is over limit
    */
-  boolean isFileSizeCheckEnabledAndWithinLimit(long fileSizeLimitBytes, File 
file) {
-    if (fileSizeLimitBytes < 1) {
-      // size checks disabled
-      return false;
-    }
-    if (FileUtils.sizeOf(file) < fileSizeLimitBytes) {
-      return true;
+  void isFileSizeCheckEnabledAndWithinLimit(long fileSizeLimitBytes, File 
file) {
+    if (fileSizeLimitBytes > 0) {
+      if (FileUtils.sizeOf(file) > fileSizeLimitBytes) {
+        StringBuilder sb = new StringBuilder();
+        sb.append("Exported logs zip file size = 
").append(FileUtils.sizeOf(file)).append(", ")
+            .append(CliStrings.EXPORT_LOGS__FILESIZELIMIT).append(" = 
").append(fileSizeLimitBytes)
+            .append(
+                ". To disable exported logs file size check use option 
\"--file-size-limit=0\".");
+        throw new ManagementException(sb.toString()); // FileTooBigException
+      }
     }
-    StringBuilder sb = new StringBuilder();
-    sb.append("Exported logs zip file size = 
").append(FileUtils.sizeOf(file)).append(", ")
-        .append(CliStrings.EXPORT_LOGS__FILESIZELIMIT).append(" = 
").append(fileSizeLimitBytes)
-        .append(". To disable exported logs file size check use option 
\"--file-size-limit=0\".");
-    throw new ManagementException(sb.toString()); // FileTooBigException
   }
 
+
   /**
    * Throws ManagementException if export file size checking is enabled and 
the space required on a
    * cluster member to filter and zip up files to be exported exceeds the disk 
space available
    */
-  boolean isSizeCheckEnabledAndWithinDiskSpaceOfMember(String memberName, long 
fileSizeLimitBytes,
-      long estimatedSize, long diskAvailable, long diskSize) {
-    // TODO:GEODE-2420: warn user if exportedLogs filtering will exceed disk 
available
-    if (fileSizeLimitBytes < 1) {
-      // size checks disabled
-      return false;
-    }
-    StringBuilder sb = new StringBuilder();
-    BytesToString bytesToString = new BytesToString();
-    if (estimatedSize > diskAvailable) {
-      sb.append("Estimated disk space required 
(").append(bytesToString.of(estimatedSize))
-          .append(") to consolidate logs on member ").append(memberName)
-          .append(" will exceed available disk space 
(").append(bytesToString.of(diskAvailable))
-          .append(")");
-      throw new ManagementException(sb.toString()); // FileTooBigException
+  void sizeCheckIsEnabledAndWithinDiskSpaceOfMember(String memberName, long 
fileSizeLimitBytes,
+      long estimatedSize, long diskAvailable) {
+    if (fileSizeLimitBytes > 0) {
+      StringBuilder sb = new StringBuilder();
+      BytesToString bytesToString = new BytesToString();
+      if (estimatedSize > diskAvailable) {
+        sb.append("Estimated disk space required 
(").append(bytesToString.of(estimatedSize))
+            .append(") to consolidate logs on member ").append(memberName)
+            .append(" will exceed available disk space 
(").append(bytesToString.of(diskAvailable))
+            .append(")");
+        throw new ManagementException(sb.toString()); // FileTooBigException
+      }
     }
-    return true;
   }
 
   static int parseSize(String diskSpaceLimit) {

http://git-wip-us.apache.org/repos/asf/geode/blob/c5962aa9/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ExportLogsFunction.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ExportLogsFunction.java
 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ExportLogsFunction.java
index 663a08e..86b506e 100644
--- 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ExportLogsFunction.java
+++ 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ExportLogsFunction.java
@@ -125,8 +125,7 @@ public class ExportLogsFunction implements Function, 
InternalEntity {
 
     Region exportLogsRegion = cache.getRegion(EXPORT_LOGS_REGION);
     if (exportLogsRegion == null) {
-      AttributesFactory<String, Configuration> regionAttrsFactory =
-          new AttributesFactory<String, Configuration>();
+      AttributesFactory<String, Configuration> regionAttrsFactory = new 
AttributesFactory<>();
       regionAttrsFactory.setDataPolicy(DataPolicy.EMPTY);
       regionAttrsFactory.setScope(Scope.DISTRIBUTED_ACK);
 

http://git-wip-us.apache.org/repos/asf/geode/blob/c5962aa9/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ExportedLogsSizeInfo.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ExportedLogsSizeInfo.java
 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ExportedLogsSizeInfo.java
deleted file mode 100644
index c175e1a..0000000
--- 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ExportedLogsSizeInfo.java
+++ /dev/null
@@ -1,105 +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.functions;
-
-import org.apache.geode.DataSerializable;
-import org.apache.geode.DataSerializer;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.Objects;
-
-public class ExportedLogsSizeInfo implements DataSerializable {
-  private long logsSize;
-  private long diskAvailable;
-  private long diskSize;
-
-  // Used for deserialization only
-  public ExportedLogsSizeInfo() {
-    logsSize = 0;
-    diskAvailable = 0;
-    diskSize = 0;
-  }
-
-  public ExportedLogsSizeInfo(long logsSize, long diskAvailable, long 
diskSize) {
-    this.logsSize = logsSize;
-    this.diskAvailable = diskAvailable;
-    this.diskSize = diskSize;
-  }
-
-  public long getDiskSize() {
-    return diskSize;
-  }
-
-  public long getDiskAvailable() {
-    return diskAvailable;
-  }
-
-  public long getLogsSize() {
-
-    return logsSize;
-  }
-
-  @Override
-  public boolean equals(Object o) {
-    if (this == o) {
-      return true;
-    }
-    if (o == null || getClass() != o.getClass()) {
-      return false;
-    }
-
-    ExportedLogsSizeInfo that = (ExportedLogsSizeInfo) o;
-
-    if (logsSize != that.logsSize) {
-      return false;
-    }
-    if (diskAvailable != that.diskAvailable) {
-      return false;
-    }
-    return diskSize == that.diskSize;
-  }
-
-  @Override
-  public int hashCode() {
-    return Objects.hash(logsSize, diskAvailable, diskSize);
-  }
-
-  @Override
-  public void toData(DataOutput out) throws IOException {
-    DataSerializer.writeLong(logsSize, out);
-    DataSerializer.writeLong(diskAvailable, out);
-    DataSerializer.writeLong(diskSize, out);
-  }
-
-  @Override
-  public void fromData(DataInput in) throws IOException, 
ClassNotFoundException {
-    logsSize = DataSerializer.readLong(in);
-    diskAvailable = DataSerializer.readLong(in);
-    diskSize = DataSerializer.readLong(in);
-  }
-
-  @Override
-  public String toString() {
-    StringBuilder result = new StringBuilder();
-    result.append("[");
-    result.append("logsSize: " + logsSize);
-    result.append(", diskAvailable: " + diskAvailable);
-    result.append(", diskSize: " + diskSize);
-    result.append("]");
-    return result.toString();
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/c5962aa9/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunction.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunction.java
 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunction.java
index 3d98fe9..57355c0 100644
--- 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunction.java
+++ 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunction.java
@@ -16,9 +16,11 @@ package org.apache.geode.management.internal.cli.functions;
 
 import java.io.File;
 import java.io.IOException;
-import java.text.ParseException;
 import java.util.Arrays;
 
+import org.apache.geode.management.ManagementException;
+import org.apache.geode.management.internal.cli.util.BytesToString;
+import org.apache.geode.management.internal.cli.util.LogExporter;
 import org.apache.logging.log4j.Logger;
 
 import org.apache.geode.cache.execute.Function;
@@ -30,7 +32,6 @@ import org.apache.geode.internal.cache.GemFireCacheImpl;
 import org.apache.geode.internal.cache.InternalCache;
 import org.apache.geode.internal.logging.LogService;
 import org.apache.geode.management.internal.cli.util.LogFilter;
-import org.apache.geode.management.internal.cli.util.LogSizer;
 
 public class SizeExportLogsFunction extends ExportLogsFunction implements 
Function, InternalEntity {
   private static final Logger LOGGER = LogService.getLogger();
@@ -42,13 +43,20 @@ public class SizeExportLogsFunction extends 
ExportLogsFunction implements Functi
       InternalCache cache = GemFireCacheImpl.getInstance();
       DistributionConfig config = 
cache.getInternalDistributedSystem().getConfig();
       Args args = (Args) context.getArguments();
-      long diskAvailable = config.getLogFile().getUsableSpace();
-      long diskSize = config.getLogFile().getTotalSpace();
+      long diskAvailable = getDiskAvailable(config);
       long estimatedSize = estimateLogFileSize(cache.getMyId(), 
config.getLogFile(),
           config.getStatisticArchiveFile(), args);
 
-      context.getResultSender().lastResult(
-          Arrays.asList(new ExportedLogsSizeInfo(estimatedSize, diskAvailable, 
diskSize)));
+      BytesToString bytesToString = new BytesToString();
+      if (estimatedSize == 0 || estimatedSize < diskAvailable) {
+        context.getResultSender().lastResult(Arrays.asList(estimatedSize));
+      } else {
+        StringBuilder sb = new StringBuilder().append("Estimated disk space 
required (")
+            .append(bytesToString.of(estimatedSize)).append(") to consolidate 
logs on member ")
+            .append(cache.getName()).append(" will exceed available disk space 
(")
+            .append(bytesToString.of(diskAvailable)).append(")");
+        context.getResultSender().sendException(new 
ManagementException(sb.toString())); // FileTooBigException
+      }
 
     } catch (Exception e) {
       e.printStackTrace();
@@ -57,8 +65,12 @@ public class SizeExportLogsFunction extends 
ExportLogsFunction implements Functi
     }
   }
 
+  long getDiskAvailable(DistributionConfig config) {
+    return config.getLogFile().getUsableSpace();
+  }
+
   long estimateLogFileSize(final DistributedMember member, final File logFile,
-      final File statArchive, final Args args) throws ParseException, 
IOException {
+      final File statArchive, final Args args) throws IOException {
     if (LOGGER.isDebugEnabled()) {
       LOGGER.debug("SizeExportLogsFunction started for member {}", member);
     }
@@ -76,7 +88,8 @@ public class SizeExportLogsFunction extends 
ExportLogsFunction implements Functi
     LogFilter logFilter = new LogFilter(args.getLogLevel(), 
args.isThisLogLevelOnly(),
         args.getStartTime(), args.getEndTime());
 
-    long estimatedSize = new LogSizer(logFilter, baseLogFile, 
baseStatsFile).getFilteredSize();
+    long estimatedSize =
+        new LogExporter(logFilter, baseLogFile, 
baseStatsFile).estimateFilteredSize();
 
     LOGGER.info("Estimated log file size: " + estimatedSize);
 

http://git-wip-us.apache.org/repos/asf/geode/blob/c5962aa9/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
index 68d055c..cbeee99 100644
--- 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
+++ 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
@@ -1441,7 +1441,7 @@ public class CliStrings {
   public static final String EXPORT_LOGS__STATSONLY__HELP = "Whether to only 
export statistics";
   public static final String EXPORT_LOGS__FILESIZELIMIT = "file-size-limit";
   public static final String EXPORT_LOGS__FILESIZELIMIT__HELP =
-      "Limits size of the file that can be exported. Specify zero for no 
limit. Value is in megabytes by default or [m|g|t] may be specified.";
+      "Limits size of the file that can be exported. Specify zero for no 
limit. Value is in megabytes by default or [k|m|g|t] may be specified.";
   public static final String EXPORT_LOGS__FILESIZELIMIT__SPECIFIED_DEFAULT = 
"0";
   public static final String EXPORT_LOGS__FILESIZELIMIT__UNSPECIFIED_DEFAULT = 
"100m";
 

http://git-wip-us.apache.org/repos/asf/geode/blob/c5962aa9/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/LogExporter.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/LogExporter.java
 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/LogExporter.java
index a0be7fb..5802f79 100644
--- 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/LogExporter.java
+++ 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/LogExporter.java
@@ -31,7 +31,7 @@ import java.io.FileWriter;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.text.ParseException;
+import java.util.Collections;
 import java.util.List;
 import java.util.function.Predicate;
 import java.util.stream.Stream;
@@ -51,10 +51,8 @@ public class LogExporter {
    * @param logFilter the filter that's used to check if we need to accept the 
file or the logLine
    * @param baseLogFile if not null, we will export the logs in that directory
    * @param baseStatsFile if not null, we will export stats in that directory
-   * @throws ParseException
    */
-  public LogExporter(LogFilter logFilter, File baseLogFile, File baseStatsFile)
-      throws ParseException {
+  public LogExporter(LogFilter logFilter, File baseLogFile, File 
baseStatsFile) {
     assert logFilter != null;
     this.logFilter = logFilter;
     this.baseLogFile = baseLogFile;
@@ -65,7 +63,6 @@ public class LogExporter {
    *
    * @return Path to the zip file that has all the filtered files, null if no 
files are selected to
    *         export.
-   * @throws IOException
    */
   public Path export() throws IOException {
     Path tempDirectory = Files.createTempDirectory("exportLogs");
@@ -127,24 +124,68 @@ public class LogExporter {
     }
   }
 
-  protected List<Path> findLogFiles(Path workingDir) throws IOException {
+  /**
+   * @return combined size of stat archives and filtered log files in bytes
+   */
+  public long estimateFilteredSize() throws IOException {
+    long filteredSize = 0;
+    if (baseLogFile != null) {
+      for (Path logFile : findLogFiles(baseLogFile.toPath().getParent())) {
+        filteredSize += filterAndSize(logFile);
+      }
+    }
+
+    if (baseStatsFile != null) {
+      for (Path statFile : findStatFiles(baseStatsFile.toPath().getParent())) {
+        filteredSize += statFile.toFile().length();
+      }
+    }
+
+    return filteredSize;
+  }
+
+  /**
+   * @return size of file in bytes
+   */
+  private long filterAndSize(Path originalLogFile) throws IOException {
+    long size = 0;
+    this.logFilter.startNewFile();
+
+    try (BufferedReader reader = new BufferedReader(new 
FileReader(originalLogFile.toFile()))) {
+      String line;
+      while ((line = reader.readLine()) != null) {
+        LogFilter.LineFilterResult result = this.logFilter.acceptsLine(line);
+
+        if (result == LogFilter.LineFilterResult.REMAINDER_OF_FILE_REJECTED) {
+          break;
+        }
+        if (result == LogFilter.LineFilterResult.LINE_ACCEPTED) {
+          size += line.length() + File.separator.length();
+        }
+      }
+    }
+    return size;
+  }
+
+  List<Path> findLogFiles(Path workingDir) throws IOException {
     Predicate<Path> logFileSelector = (Path file) -> 
file.toString().toLowerCase().endsWith(".log");
     return findFiles(workingDir, logFileSelector);
   }
 
 
-  protected List<Path> findStatFiles(Path workingDir) throws IOException {
+  List<Path> findStatFiles(Path workingDir) throws IOException {
     Predicate<Path> statFileSelector =
         (Path file) -> file.toString().toLowerCase().endsWith(".gfs");
     return findFiles(workingDir, statFileSelector);
   }
 
   private List<Path> findFiles(Path workingDir, Predicate<Path> fileSelector) 
throws IOException {
-    Stream<Path> selectedFiles =
-        
Files.list(workingDir).filter(fileSelector).filter(this.logFilter::acceptsFile);
+    Stream<Path> selectedFiles/* = null */;
+    if (!workingDir.toFile().isDirectory()) {
+      return Collections.emptyList();
+    }
+    selectedFiles = 
Files.list(workingDir).filter(fileSelector).filter(this.logFilter::acceptsFile);
 
     return selectedFiles.collect(toList());
   }
-
-
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/c5962aa9/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/LogSizer.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/LogSizer.java
 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/LogSizer.java
deleted file mode 100644
index f1adae6..0000000
--- 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/LogSizer.java
+++ /dev/null
@@ -1,118 +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.util;
-
-import static java.util.stream.Collectors.toList;
-
-import org.apache.geode.internal.logging.LogService;
-import org.apache.logging.log4j.Logger;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.text.ParseException;
-import java.util.Collections;
-import java.util.List;
-import java.util.Scanner;
-import java.util.function.Predicate;
-import java.util.stream.Stream;
-
-public class LogSizer {
-  private static final Logger LOGGER = LogService.getLogger();
-
-  private final LogFilter logFilter;
-  private final File baseLogFile;
-  private final File baseStatsFile;
-
-  private long filteredSize;
-
-  /**
-   * @param logFilter the filter that's used to check if we need to accept the 
file or the logLine
-   * @param baseLogFile if not null, we will estimate the additional disk 
space required to filter
-   *        and export the logs in that directory
-   * @param baseStatsFile if not null, we will estimate the additional disk 
space required to filter
-   *        and export the stats in that directory
-   */
-  public LogSizer(LogFilter logFilter, File baseLogFile, File baseStatsFile) 
throws ParseException {
-    assert logFilter != null;
-    this.logFilter = logFilter;
-    this.baseLogFile = baseLogFile;
-    this.baseStatsFile = baseStatsFile;
-    filteredSize = 0;
-  }
-
-  /**
-   * @return combined size of stat archives and filtered log files in bytes
-   */
-  public long getFilteredSize() throws IOException {
-
-    if (baseLogFile != null) {
-      for (Path logFile : findLogFiles(baseLogFile.toPath().getParent())) {
-        filteredSize += filterAndSize(logFile);
-      }
-    }
-
-    if (baseStatsFile != null) {
-      for (Path statFile : findStatFiles(baseStatsFile.toPath().getParent())) {
-        filteredSize += statFile.toFile().length();
-      }
-    }
-
-    return filteredSize;
-  }
-
-  /**
-   * @return size of file in bytes
-   */
-  protected long filterAndSize(Path originalLogFile) throws 
FileNotFoundException {
-    long size = 0;
-    Scanner in = new Scanner(originalLogFile.toFile());
-    while (in.hasNextLine()) {
-      String line = in.nextLine();
-
-      LogFilter.LineFilterResult result = this.logFilter.acceptsLine(line);
-
-      if (result == LogFilter.LineFilterResult.REMAINDER_OF_FILE_REJECTED) {
-        break;
-      }
-      size += line.length() + File.separator.length();
-    }
-    return size;
-  }
-
-  protected List<Path> findLogFiles(Path workingDir) throws IOException {
-    Predicate<Path> logFileSelector = (Path file) -> 
file.toString().toLowerCase().endsWith(".log");
-    return findFiles(workingDir, logFileSelector);
-  }
-
-
-  protected List<Path> findStatFiles(Path workingDir) throws IOException {
-    Predicate<Path> statFileSelector =
-        (Path file) -> file.toString().toLowerCase().endsWith(".gfs");
-    return findFiles(workingDir, statFileSelector);
-  }
-
-  private List<Path> findFiles(Path workingDir, Predicate<Path> fileSelector) 
throws IOException {
-    Stream<Path> selectedFiles = null;
-    if (!workingDir.toFile().isDirectory()) {
-      return Collections.emptyList();
-    }
-    selectedFiles = 
Files.list(workingDir).filter(fileSelector).filter(this.logFilter::acceptsFile);
-
-    return selectedFiles.collect(toList());
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/c5962aa9/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommandTest.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommandTest.java
 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommandTest.java
index 2b7839a..8888a91 100644
--- 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommandTest.java
+++ 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommandTest.java
@@ -28,10 +28,9 @@ import org.apache.geode.cache.execute.FunctionException;
 import org.apache.geode.cache.execute.ResultCollector;
 import org.apache.geode.distributed.DistributedMember;
 import 
org.apache.geode.distributed.internal.membership.InternalDistributedMember;
-import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.internal.cache.InternalCache;
 import org.apache.geode.management.ManagementException;
 import org.apache.geode.management.cli.Result;
-import org.apache.geode.management.internal.cli.functions.ExportedLogsSizeInfo;
 import 
org.apache.geode.management.internal.cli.functions.SizeExportLogsFunction;
 import org.apache.geode.test.junit.categories.UnitTest;
 import org.junit.Test;
@@ -125,122 +124,38 @@ public class ExportLogsCommandTest {
   public void sizeTooBigOnMember_sizeChecksDisabled_returnsFalse() throws 
Exception {
     final Cache mockCache = mock(Cache.class);
     final DistributedMember mockDistributedMember = 
mock(DistributedMember.class);
-    final Execution mockFuntionExecutor = mock(Execution.class);
+    final Execution mockFunctionExecutor = mock(Execution.class);
     final ExportLogsCommand cmd =
-        createExportLogsCommand(mockCache, mockDistributedMember, 
mockFuntionExecutor);
-    
assertThat(cmd.isSizeCheckEnabledAndWithinDiskSpaceOfMember("clusterMember", 0, 
MEGABYTE + 1024,
-        MEGABYTE, TERABYTE)).isFalse();
+        createExportLogsCommand(mockCache, mockDistributedMember, 
mockFunctionExecutor);
+    cmd.sizeCheckIsEnabledAndWithinDiskSpaceOfMember("clusterMember", 0, 
MEGABYTE + 1024, MEGABYTE);
   }
 
   @Test
-  public void sizeOKOnMember_sizeChecksEnabled_returnsTrue() throws Exception {
+  public void sizeOKOnMember_sizeChecksEnabled_doesNotThrow() throws Exception 
{
     final Cache mockCache = mock(Cache.class);
     final DistributedMember mockDistributedMember = 
mock(DistributedMember.class);
-    final Execution mockFuntionExecutor = mock(Execution.class);
+    final Execution mockFunctionExecutor = mock(Execution.class);
     final ExportLogsCommand cmd =
-        createExportLogsCommand(mockCache, mockDistributedMember, 
mockFuntionExecutor);
-    
assertThat(cmd.isSizeCheckEnabledAndWithinDiskSpaceOfMember("clusterMember", 10 
* MEGABYTE,
-        MEGABYTE - 1024, MEGABYTE, TERABYTE)).isTrue();
+        createExportLogsCommand(mockCache, mockDistributedMember, 
mockFunctionExecutor);
+    cmd.sizeCheckIsEnabledAndWithinDiskSpaceOfMember("clusterMember", 10 * 
MEGABYTE,
+        MEGABYTE - 1024, MEGABYTE);
   }
 
   @Test
   public void sizeTooBigOnMember_sizeChecksEnabled_shouldThrow() throws 
Exception {
     final Cache mockCache = mock(Cache.class);
     final DistributedMember mockDistributedMember = 
mock(DistributedMember.class);
-    final Execution mockFuntionExecutor = mock(Execution.class);
+    final Execution mockFunctionExecutor = mock(Execution.class);
     final ExportLogsCommand cmd =
-        createExportLogsCommand(mockCache, mockDistributedMember, 
mockFuntionExecutor);
-    assertThatThrownBy(() -> 
cmd.isSizeCheckEnabledAndWithinDiskSpaceOfMember("clusterMember",
-        10 * MEGABYTE, MEGABYTE + 1024, MEGABYTE, TERABYTE))
-            .isInstanceOf(ManagementException.class);
-  }
-
-  @Test
-  public void sizeFromMember_withinLimits() throws Exception {
-    final GemFireCacheImpl mockCache = mock(GemFireCacheImpl.class);
-    final ExportLogsCommand realCmd = new ExportLogsCommand();
-
-    ExportLogsCommand spyCmd = spy(realCmd);
-    String start = null;
-    String end = null;
-    String logLevel = null;
-    boolean onlyLogLevel = false;
-    boolean logsOnly = false;
-    boolean statsOnly = false;
-
-    InternalDistributedMember member1 = new 
InternalDistributedMember("member1", 12345);
-    InternalDistributedMember member2 = new 
InternalDistributedMember("member2", 98765);
-    member1.getNetMember().setName("member1");
-    member2.getNetMember().setName("member2");
-    Set<DistributedMember> testMembers = new HashSet<>();
-    testMembers.add(member1);
-    testMembers.add(member2);
-
-    ResultCollector testResults1 = new CustomCollector();
-    testResults1.addResult(member1,
-        Arrays.asList(new ExportedLogsSizeInfo(MEGABYTE, 2 * MEGABYTE, 
TERABYTE)));
-    ResultCollector testResults2 = new CustomCollector();
-    testResults2.addResult(member2,
-        Arrays.asList(new ExportedLogsSizeInfo(2 * MEGABYTE, 2 * MEGABYTE, 
TERABYTE)));
-
-    doReturn(mockCache).when(spyCmd).getCache();
-    doReturn(testMembers).when(spyCmd).getMembers(null, null);
-    doReturn(testResults1).when(spyCmd)
-        .estimateLogSize(Matchers.any(SizeExportLogsFunction.Args.class), 
eq(member1));
-    doReturn(testResults2).when(spyCmd)
-        .estimateLogSize(Matchers.any(SizeExportLogsFunction.Args.class), 
eq(member2));
-    doReturn(true).when(spyCmd).testhookSkipExports();
-
-    Result res = spyCmd.exportLogs("working dir", null, null, logLevel, 
onlyLogLevel, false, start,
-        end, logsOnly, statsOnly, "1g");
-    assertThat(res.getStatus()).isEqualTo(Result.Status.OK);
-  }
-
-  @Test
-  public void 
sizeFromMember_greaterThanDiskAvailable_shouldReturnErrorResult() throws 
Exception {
-    final GemFireCacheImpl mockCache = mock(GemFireCacheImpl.class);
-    final ExportLogsCommand realCmd = new ExportLogsCommand();
-    ExportLogsCommand spyCmd = spy(realCmd);
-
-    String start = null;
-    String end = null;
-    String logLevel = null;
-    boolean onlyLogLevel = false;
-    boolean logsOnly = false;
-    boolean statsOnly = false;
-
-    InternalDistributedMember member1 = new 
InternalDistributedMember("member1", 12345);
-    InternalDistributedMember member2 = new 
InternalDistributedMember("member2", 98765);
-    member1.getNetMember().setName("member1");
-    member2.getNetMember().setName("member2");
-    Set<DistributedMember> testMembers = new HashSet<>();
-    testMembers.add(member1);
-    testMembers.add(member2);
-
-    ResultCollector testResults1 = new CustomCollector();
-    testResults1.addResult(member1,
-        Arrays.asList(new ExportedLogsSizeInfo(2 * MEGABYTE, MEGABYTE, 
TERABYTE)));
-    ResultCollector testResults2 = new CustomCollector();
-    testResults2.addResult(member2,
-        Arrays.asList(new ExportedLogsSizeInfo(2 * MEGABYTE, 2 * MEGABYTE, 
TERABYTE)));
-
-    doReturn(mockCache).when(spyCmd).getCache();
-    doReturn(testMembers).when(spyCmd).getMembers(null, null);
-    doReturn(testResults1).when(spyCmd)
-        .estimateLogSize(Matchers.any(SizeExportLogsFunction.Args.class), 
eq(member1));
-    doReturn(testResults2).when(spyCmd)
-        .estimateLogSize(Matchers.any(SizeExportLogsFunction.Args.class), 
eq(member2));
-    doReturn(true).when(spyCmd).testhookSkipExports();
-
-    Result res = spyCmd.exportLogs("working dir", null, null, logLevel, 
onlyLogLevel, false, start,
-        end, logsOnly, statsOnly, "1g");
-    assertThat(res.getStatus()).isEqualTo(Result.Status.ERROR);
+        createExportLogsCommand(mockCache, mockDistributedMember, 
mockFunctionExecutor);
+    assertThatThrownBy(() -> 
cmd.sizeCheckIsEnabledAndWithinDiskSpaceOfMember("clusterMember",
+        10 * MEGABYTE, MEGABYTE + 1024, 
MEGABYTE)).isInstanceOf(ManagementException.class);
   }
 
   @Test
   public void 
sizeFromAllMembers_greaterThanLocalDiskAvailable_shouldReturnErrorResult()
       throws Exception {
-    final GemFireCacheImpl mockCache = mock(GemFireCacheImpl.class);
+    final InternalCache mockCache = mock(InternalCache.class);
     final ExportLogsCommand realCmd = new ExportLogsCommand();
     ExportLogsCommand spyCmd = spy(realCmd);
 
@@ -260,11 +175,9 @@ public class ExportLogsCommandTest {
     testMembers.add(member2);
 
     ResultCollector testResults1 = new CustomCollector();
-    testResults1.addResult(member1,
-        Arrays.asList(new ExportedLogsSizeInfo(75 * MEGABYTE, GIGABYTE, 
TERABYTE)));
+    testResults1.addResult(member1, Arrays.asList(75 * MEGABYTE));
     ResultCollector testResults2 = new CustomCollector();
-    testResults2.addResult(member2,
-        Arrays.asList(new ExportedLogsSizeInfo(60 * MEGABYTE, GIGABYTE, 
TERABYTE)));
+    testResults2.addResult(member2, Arrays.asList(60 * MEGABYTE));
 
     doReturn(mockCache).when(spyCmd).getCache();
     doReturn(testMembers).when(spyCmd).getMembers(null, null);
@@ -275,8 +188,6 @@ public class ExportLogsCommandTest {
     doReturn(125 * MEGABYTE).when(spyCmd).getLocalDiskAvailable();
     doReturn(GIGABYTE).when(spyCmd).getLocalDiskSize();
 
-    doReturn(true).when(spyCmd).testhookSkipExports();
-
     Result res = spyCmd.exportLogs("working dir", null, null, logLevel, 
onlyLogLevel, false, start,
         end, logsOnly, statsOnly, "125m");
     assertThat(res.getStatus()).isEqualTo(Result.Status.ERROR);

http://git-wip-us.apache.org/repos/asf/geode/blob/c5962aa9/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 0e0f6aa..8609b3a 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
@@ -39,7 +39,6 @@ import 
org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
 import org.apache.geode.test.dunit.rules.Member;
 import org.apache.geode.test.dunit.rules.MemberVM;
 import org.apache.geode.test.junit.categories.DistributedTest;
-import org.apache.geode.test.junit.categories.FlakyTest;
 import org.apache.logging.log4j.Logger;
 import org.junit.Before;
 import org.junit.Rule;
@@ -157,8 +156,7 @@ public class ExportLogsDUnitTest {
   @Test
   public void testExportWithThresholdLogLevelFilter() throws Exception {
 
-    CommandResult result = gfshConnector
-        .executeAndVerifyCommand("export logs --log-level=info 
--only-log-level=false");
+    gfshConnector.executeAndVerifyCommand("export logs --log-level=info 
--only-log-level=false");
 
     Set<String> acceptedLogLevels = Stream.of("info", 
"error").collect(toSet());
     verifyZipFileContents(acceptedLogLevels);
@@ -167,8 +165,7 @@ public class ExportLogsDUnitTest {
 
   @Test
   public void testExportWithExactLogLevelFilter() throws Exception {
-    CommandResult result =
-        gfshConnector.executeAndVerifyCommand("export logs --log-level=info 
--only-log-level=true");
+    gfshConnector.executeAndVerifyCommand("export logs --log-level=info 
--only-log-level=true");
 
 
     Set<String> acceptedLogLevels = Stream.of("info").collect(toSet());
@@ -177,7 +174,7 @@ public class ExportLogsDUnitTest {
 
   @Test
   public void testExportWithNoOptionsGiven() throws Exception {
-    CommandResult result = gfshConnector.executeAndVerifyCommand("export 
logs");
+    gfshConnector.executeAndVerifyCommand("export logs");
     Set<String> acceptedLogLevels = Stream.of("info", "error", 
"debug").collect(toSet());
     verifyZipFileContents(acceptedLogLevels);
   }
@@ -229,7 +226,7 @@ public class ExportLogsDUnitTest {
   }
 
 
-  public void verifyZipFileContents(Set<String> acceptedLogLevels) throws 
IOException {
+  private void verifyZipFileContents(Set<String> acceptedLogLevels) throws 
IOException {
     File unzippedLogFileDir = unzipExportedLogs();
 
     Set<File> dirsFromZipFile =
@@ -247,7 +244,7 @@ public class ExportLogsDUnitTest {
     }
   }
 
-  public void verifyLogFileContents(Set<String> acceptedLogLevels, File 
dirForMember)
+  private void verifyLogFileContents(Set<String> acceptedLogLevels, File 
dirForMember)
       throws IOException {
 
     String memberName = dirForMember.getName();
@@ -312,13 +309,13 @@ public class ExportLogsDUnitTest {
     String message;
     boolean shouldBeIgnoredDueToTimestamp;
 
-    public LogLine(String message, String level, boolean 
shouldBeIgnoredDueToTimestamp) {
+    LogLine(String message, String level, boolean 
shouldBeIgnoredDueToTimestamp) {
       this.message = message;
       this.level = level;
       this.shouldBeIgnoredDueToTimestamp = shouldBeIgnoredDueToTimestamp;
     }
 
-    public LogLine(Member member, String level) {
+    LogLine(Member member, String level) {
       this.level = level;
       this.message = buildMessage(member.getName());
     }
@@ -332,13 +329,13 @@ public class ExportLogsDUnitTest {
       if (Objects.equals(level, "error")) {
         stringBuilder.append(ERROR_LOG_PREFIX + "-");
       }
-      stringBuilder.append(level + "-");
+      stringBuilder.append(level).append("-");
 
       return stringBuilder.append(memberName).toString();
     }
 
 
-    public void writeLog(Logger logger) {
+    void writeLog(Logger logger) {
       switch (this.level) {
         case "info":
           logger.info(getMessage());

http://git-wip-us.apache.org/repos/asf/geode/blob/c5962aa9/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsFileSizeLimitTest.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsFileSizeLimitTest.java
 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsFileSizeLimitTest.java
index 1058053..4ab88b6 100644
--- 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsFileSizeLimitTest.java
+++ 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsFileSizeLimitTest.java
@@ -64,7 +64,7 @@ public class ExportLogsFileSizeLimitTest {
 
     ExportLogsCommand exportLogsCommand = new ExportLogsCommand();
 
-    
assertThat(exportLogsCommand.isFileSizeCheckEnabledAndWithinLimit(MEGABYTE, 
file)).isTrue();
+    exportLogsCommand.isFileSizeCheckEnabledAndWithinLimit(MEGABYTE, file);
   }
 
   @Test
@@ -74,7 +74,7 @@ public class ExportLogsFileSizeLimitTest {
 
     ExportLogsCommand exportLogsCommand = new ExportLogsCommand();
 
-    assertThat(exportLogsCommand.isFileSizeCheckEnabledAndWithinLimit(0, 
file)).isFalse();
+    exportLogsCommand.isFileSizeCheckEnabledAndWithinLimit(0, file);
   }
 
   private void fillUpFile(File file, long sizeInBytes) throws IOException {

http://git-wip-us.apache.org/repos/asf/geode/blob/c5962aa9/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsTestSuite.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsTestSuite.java
 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsTestSuite.java
index 8f8c532..4e1dac0 100644
--- 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsTestSuite.java
+++ 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsTestSuite.java
@@ -14,8 +14,10 @@
  */
 package org.apache.geode.management.internal.cli.commands;
 
-import 
org.apache.geode.management.internal.cli.functions.SizeExportLogsFunctionCacheTest;
+import 
org.apache.geode.management.internal.cli.functions.SizeExportLogsFunctionTest;
 import 
org.apache.geode.management.internal.cli.functions.SizeExportLogsFunctionFileTest;
+import 
org.apache.geode.management.internal.cli.util.LogExporterIntegrationTest;
+import org.apache.geode.management.internal.cli.util.LogExporterTest;
 import org.apache.geode.management.internal.cli.util.LogSizerTest;
 import org.junit.Ignore;
 import org.junit.runner.RunWith;
@@ -27,9 +29,9 @@ import org.junit.runners.Suite;
 
 @Ignore
 @Suite.SuiteClasses({ExportLogsCommandTest.class, 
ExportLogsFileSizeLimitTest.class,
-    ExportLogsIntegrationTest.class, ExportLogsDUnitTest.class,
-    SizeExportLogsFunctionCacheTest.class, 
SizeExportLogsFunctionFileTest.class,
-    LogSizerTest.class})
+    ExportLogsIntegrationTest.class, ExportLogsDUnitTest.class, 
SizeExportLogsFunctionTest.class,
+    SizeExportLogsFunctionFileTest.class, LogSizerTest.class, 
LogExporterTest.class,
+    LogExporterIntegrationTest.class})
 @RunWith(Suite.class)
 public class ExportLogsTestSuite {
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/c5962aa9/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/ExportedLogsSizeInfoTest.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/ExportedLogsSizeInfoTest.java
 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/ExportedLogsSizeInfoTest.java
deleted file mode 100644
index 0bfbefa..0000000
--- 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/ExportedLogsSizeInfoTest.java
+++ /dev/null
@@ -1,133 +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.functions;
-
-import static org.assertj.core.api.Assertions.*;
-
-import org.apache.geode.test.junit.categories.UnitTest;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutput;
-import java.io.DataOutputStream;
-
-@Category(UnitTest.class)
-public class ExportedLogsSizeInfoTest {
-
-  @Test
-  public void testExportedLogsSizeInfoConstructor() {
-    ExportedLogsSizeInfo sizeDetail = new ExportedLogsSizeInfo(1L, 11L, 111L);
-    assertThat(sizeDetail).isNotNull();
-    assertThat(sizeDetail.getLogsSize()).isEqualTo(1L);
-    assertThat(sizeDetail.getDiskAvailable()).isEqualTo(11L);
-    assertThat(sizeDetail.getDiskSize()).isEqualTo(111L);
-  }
-
-  @Test
-  public void testExportedLogsSizeInfoZeroArgConstructor() {
-    ExportedLogsSizeInfo sizeDetail = new ExportedLogsSizeInfo();
-    assertThat(sizeDetail).isNotNull();
-    assertThat(sizeDetail.getLogsSize()).isEqualTo(0L);
-    assertThat(sizeDetail.getDiskAvailable()).isEqualTo(0L);
-    assertThat(sizeDetail.getDiskSize()).isEqualTo(0L);
-  }
-
-  @Test
-  public void equals_returnsTrueForTwoInstancesWithTheSameFieldValues() throws 
Exception {
-    ExportedLogsSizeInfo sizeDetail1 = new ExportedLogsSizeInfo(2L, 22L, 222L);
-    ExportedLogsSizeInfo sizeDetail2 = new ExportedLogsSizeInfo(2L, 22L, 222L);
-    assertThat(sizeDetail1.equals(sizeDetail1)).isTrue();
-    assertThat(sizeDetail1.equals(sizeDetail2)).isTrue();
-    assertThat(sizeDetail2.equals(sizeDetail1)).isTrue();
-  }
-
-  @Test
-  public void equals_returnsFalseWhenLogsSizeDiffers() throws Exception {
-    ExportedLogsSizeInfo sizeDetail1 = new ExportedLogsSizeInfo(3L, 33L, 333L);
-    ExportedLogsSizeInfo sizeDetail2 = new ExportedLogsSizeInfo(33L, 33L, 
333L);
-    assertThat(sizeDetail1.equals(sizeDetail2)).isFalse();
-    assertThat(sizeDetail2.equals(sizeDetail1)).isFalse();
-  }
-
-  @Test
-  public void equals_returnsFalseWhenAvailableDiskDiffers() throws Exception {
-    ExportedLogsSizeInfo sizeDetail1 = new ExportedLogsSizeInfo(4L, 44L, 444L);
-    ExportedLogsSizeInfo sizeDetail2 = new ExportedLogsSizeInfo(4L, 4L, 444L);
-    assertThat(sizeDetail1.equals(sizeDetail2)).isFalse();
-    assertThat(sizeDetail2.equals(sizeDetail1)).isFalse();
-  }
-
-  @Test
-  public void equals_returnsFalseWheneDiskSizeDiffers() throws Exception {
-    ExportedLogsSizeInfo sizeDetail1 = new ExportedLogsSizeInfo(5L, 55L, 555L);
-    ExportedLogsSizeInfo sizeDetail2 = new ExportedLogsSizeInfo(5L, 55L, 55L);
-    assertThat(sizeDetail1.equals(sizeDetail2)).isFalse();
-    assertThat(sizeDetail2.equals(sizeDetail1)).isFalse();
-  }
-
-  @Test
-  public void equals_returnsFalseForComparisonWithNullObject() throws 
Exception {
-    ExportedLogsSizeInfo sizeDetail1 = new ExportedLogsSizeInfo(6L, 66L, 666L);
-    ExportedLogsSizeInfo sizeDetail2 = null;
-    assertThat(sizeDetail1.equals(sizeDetail2)).isFalse();
-  }
-
-  @Test
-  public void testClassInequality() {
-    ExportedLogsSizeInfo sizeDeatai1 = new ExportedLogsSizeInfo(7L, 77L, 777L);
-    String sizeDetail2 = sizeDeatai1.toString();
-    assertThat(sizeDeatai1.equals(sizeDetail2)).isFalse();
-    assertThat(sizeDetail2.equals(sizeDeatai1)).isFalse();
-  }
-
-  @Test
-  public void testHashCode() throws Exception {
-    ExportedLogsSizeInfo sizeDetail1 = new ExportedLogsSizeInfo();
-    ExportedLogsSizeInfo sizeDetail2 = new ExportedLogsSizeInfo(8L, 88L, 888L);
-    ExportedLogsSizeInfo sizeDetail3 = new ExportedLogsSizeInfo(88L, 8L, 888L);
-
-    assertThat(sizeDetail1.hashCode()).isNotEqualTo(sizeDetail2.hashCode());
-    assertThat(sizeDetail1.hashCode()).isNotEqualTo(sizeDetail3.hashCode());
-    assertThat(sizeDetail2.hashCode()).isNotEqualTo(sizeDetail3.hashCode());
-
-    assertThat(sizeDetail1.hashCode()).isEqualTo(29791);
-    assertThat(sizeDetail2.hashCode()).isEqualTo(41095);
-    assertThat(sizeDetail3.hashCode()).isEqualTo(115495);
-  }
-
-  @Test
-  public void deserialization_setsFieldsToOriginalUnserializedValues() throws 
Exception {
-    ExportedLogsSizeInfo sizeDetail = new ExportedLogsSizeInfo(9L, 99L, 999L);
-    ByteArrayOutputStream baos = new ByteArrayOutputStream();
-    DataOutput out = new DataOutputStream(baos);
-    sizeDetail.toData(out);
-    ExportedLogsSizeInfo sizeDetailIn = new ExportedLogsSizeInfo();
-    sizeDetailIn.fromData(new DataInputStream(new 
ByteArrayInputStream(baos.toByteArray())));
-
-    assertThat(sizeDetailIn).isEqualTo(sizeDetail);
-  }
-
-  @Test
-  public void testToString() throws Exception {
-    ExportedLogsSizeInfo sizeDetail = new ExportedLogsSizeInfo(10L, 100L, 
1000L);
-    assertThat(sizeDetail.toString())
-        .isEqualTo("[logsSize: 10, diskAvailable: 100, diskSize: 1000]");
-
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/c5962aa9/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunctionCacheTest.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunctionCacheTest.java
 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunctionCacheTest.java
deleted file mode 100644
index 0e8348d..0000000
--- 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunctionCacheTest.java
+++ /dev/null
@@ -1,174 +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.functions;
-
-import static org.assertj.core.api.Assertions.*;
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.execute.FunctionContext;
-import org.apache.geode.cache.execute.ResultSender;
-import org.apache.geode.distributed.DistributedMember;
-import org.apache.geode.internal.cache.execute.FunctionContextImpl;
-import org.apache.geode.test.dunit.rules.ServerStarterRule;
-import org.apache.geode.test.junit.categories.IntegrationTest;
-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.junit.rules.TestName;
-
-import java.io.File;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Properties;
-
-@Category(IntegrationTest.class)
-public class SizeExportLogsFunctionCacheTest {
-
-  private Cache cache;
-
-  private SizeExportLogsFunction.Args nonFilteringArgs;
-  private TestResultSender resultSender;
-  private FunctionContext functionContext;
-  private File dir;
-  private DistributedMember member;
-  private File logFile;
-  private File statFile;
-  private String name;
-
-  @Rule
-  public TemporaryFolder temporaryFolder = new TemporaryFolder();
-
-  @Rule
-  public TestName testName = new TestName();
-
-  @Rule
-  public ServerStarterRule server = new ServerStarterRule();
-
-  @Before
-  public void before() throws Throwable {
-    name = testName.getMethodName();
-
-    this.dir = this.temporaryFolder.getRoot();
-    logFile = new File(dir, name + ".log");
-    statFile = new File(dir, name + ".gfs");
-
-    this.nonFilteringArgs = new ExportLogsFunction.Args(null, null, null, 
false, false, false);
-    functionContext = new FunctionContextImpl("functionId", nonFilteringArgs, 
resultSender);
-
-  }
-
-  @Test
-  public void withFiles_returnsCombinedSizeResult() throws Throwable {
-    Properties config = new Properties();
-    config.setProperty(NAME, name);
-    config.setProperty(LOG_FILE, logFile.getAbsolutePath());
-    config.setProperty(STATISTIC_ARCHIVE_FILE, statFile.getAbsolutePath());
-
-    server.withProperties(config).startServer();
-    TestResultSender resultSender = new TestResultSender();
-    FunctionContext context = new FunctionContextImpl("functionId", 
nonFilteringArgs, resultSender);
-
-    // log and stat files sizes are not constant with a real cache running, so 
check for the sizer
-    // estimate within a range
-    long initalFileSizes = FileUtils.sizeOf(logFile) + 
FileUtils.sizeOf(statFile);
-    new SizeExportLogsFunction().execute(context);
-    long finalFileSizes = FileUtils.sizeOf(logFile) + 
FileUtils.sizeOf(statFile);
-    getAndVerifySizeEstimate(resultSender, initalFileSizes, finalFileSizes);
-  }
-
-  @Test
-  public void noFiles_returnsZeroResult() throws Throwable {
-    Properties config = new Properties();
-    config.setProperty(NAME, name);
-    config.setProperty(LOG_FILE, "");
-    config.setProperty(STATISTIC_ARCHIVE_FILE, "");
-
-    server.withProperties(config).startServer();
-
-    TestResultSender resultSender = new TestResultSender();
-    FunctionContext context = new FunctionContextImpl("functionId", 
nonFilteringArgs, resultSender);
-
-    new SizeExportLogsFunction().execute(context);
-    getAndVerifySizeEstimate(resultSender, 0L);
-  }
-
-  private void getAndVerifySizeEstimate(TestResultSender resultSender, long 
expectedSize)
-      throws Throwable {
-    getAndVerifySizeEstimate(resultSender, expectedSize, expectedSize);
-  }
-
-  private void getAndVerifySizeEstimate(TestResultSender resultSender, long 
minExpected,
-      long maxExpected) throws Throwable {
-    List<?> results = resultSender.getResults();
-
-    assertThat(results).isNotNull();
-    assertThat(results.size()).isEqualTo(1);
-    List<?> result = (List<?>) results.get(0);
-    assertThat(result).isNotNull();
-    if (minExpected == maxExpected) {
-      assertThat(((ExportedLogsSizeInfo) 
result.get(0)).getLogsSize()).isEqualTo(minExpected);
-    }
-    assertThat(((ExportedLogsSizeInfo) result.get(0)).getLogsSize())
-        .isGreaterThanOrEqualTo(minExpected).isLessThanOrEqualTo(maxExpected);
-  }
-
-  @Test
-  public void withFunctionError_shouldThrow() throws Throwable {
-    Properties config = new Properties();
-    config.setProperty(NAME, name);
-
-    server.withProperties(config).startServer();
-
-    TestResultSender resultSender = new TestResultSender();
-    FunctionContext context = new FunctionContextImpl("functionId", null, 
resultSender);
-
-    new SizeExportLogsFunction().execute(context);
-    
assertThatThrownBy(resultSender::getResults).isInstanceOf(NullPointerException.class);
-  }
-
-  private static class TestResultSender implements ResultSender {
-
-    private final List<Object> results = new LinkedList<>();
-
-    private Throwable t;
-
-    protected List<Object> getResults() throws Throwable {
-      if (t != null) {
-        throw t;
-      }
-      return Collections.unmodifiableList(results);
-    }
-
-    @Override
-    public void lastResult(final Object lastResult) {
-      results.add(lastResult);
-    }
-
-    @Override
-    public void sendResult(final Object oneResult) {
-      results.add(oneResult);
-    }
-
-    @Override
-    public void sendException(final Throwable t) {
-      this.t = t;
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/c5962aa9/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunctionTest.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunctionTest.java
 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunctionTest.java
new file mode 100644
index 0000000..cc5e7d5
--- /dev/null
+++ 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunctionTest.java
@@ -0,0 +1,178 @@
+/*
+ * 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.functions;
+
+import static org.assertj.core.api.Assertions.*;
+import static org.apache.geode.distributed.ConfigurationProperties.*;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.geode.cache.execute.FunctionContext;
+import org.apache.geode.cache.execute.ResultSender;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.internal.cache.execute.FunctionContextImpl;
+import org.apache.geode.management.ManagementException;
+import org.apache.geode.test.dunit.rules.ServerStarterRule;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+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.junit.rules.TestName;
+import org.mockito.Matchers;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Properties;
+
+@Category(IntegrationTest.class)
+public class SizeExportLogsFunctionTest {
+
+
+  private SizeExportLogsFunction.Args nonFilteringArgs;
+  private File logFile;
+  private File statFile;
+  private Properties config;
+  private TestResultSender resultSender;
+
+  @Rule
+  public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+  @Rule
+  public TestName testName = new TestName();
+
+  @Rule
+  public ServerStarterRule server = new ServerStarterRule();
+
+  @Before
+  public void before() throws Throwable {
+    String name = testName.getMethodName();
+    config = new Properties();
+    config.setProperty(NAME, name);
+
+    File dir = this.temporaryFolder.getRoot();
+    logFile = new File(dir, name + ".log");
+    statFile = new File(dir, name + ".gfs");
+
+    resultSender = new TestResultSender();
+    this.nonFilteringArgs = new SizeExportLogsFunction.Args(null, null, null, 
false, false, false);
+
+  }
+
+  @Test
+  public void withFiles_returnsCombinedSizeResult() throws Throwable {
+    config.setProperty(LOG_FILE, logFile.getAbsolutePath());
+    config.setProperty(STATISTIC_ARCHIVE_FILE, statFile.getAbsolutePath());
+
+    server.withProperties(config).startServer();
+    FunctionContext context = new FunctionContextImpl("functionId", 
nonFilteringArgs, resultSender);
+
+    // log and stat files sizes are not constant with a real cache running, so 
check for the sizer
+    // estimate within a range
+    long initialFileSizes = FileUtils.sizeOf(logFile) + 
FileUtils.sizeOf(statFile);
+    new SizeExportLogsFunction().execute(context);
+    long finalFileSizes = FileUtils.sizeOf(logFile) + 
FileUtils.sizeOf(statFile);
+    getAndVerifySizeEstimate(resultSender, initialFileSizes, finalFileSizes);
+  }
+
+  @Test
+  public void noFiles_returnsZeroResult() throws Throwable {
+    config.setProperty(LOG_FILE, "");
+    config.setProperty(STATISTIC_ARCHIVE_FILE, "");
+
+    server.withProperties(config).startServer();
+
+    FunctionContext context = new FunctionContextImpl("functionId", 
nonFilteringArgs, resultSender);
+    new SizeExportLogsFunction().execute(context);
+    getAndVerifySizeEstimate(resultSender, 0L);
+  }
+
+  @Test
+  public void withFunctionError_shouldThrow() throws Throwable {
+    server.withProperties(config).startServer();
+
+    FunctionContext context = new FunctionContextImpl("functionId", null, 
resultSender);
+    new SizeExportLogsFunction().execute(context);
+    
assertThatThrownBy(resultSender::getResults).isInstanceOf(NullPointerException.class);
+  }
+
+  @Test
+  public void sizeGreaterThanDiskAvailable_sendsErrorResult() throws Throwable 
{
+    server.withProperties(config).startServer();
+
+    FunctionContext context = new FunctionContextImpl("functionId", 
nonFilteringArgs, resultSender);
+    SizeExportLogsFunction testFunction = new SizeExportLogsFunction();
+    SizeExportLogsFunction spyFunction = spy(testFunction);
+    long fakeDiskAvailable = 1024;
+    doReturn(fakeDiskAvailable).when(spyFunction)
+        .getDiskAvailable(Matchers.any(DistributionConfig.class));
+
+    spyFunction.execute(context);
+    
assertThatThrownBy(resultSender::getResults).isInstanceOf(ManagementException.class);
+  }
+
+  private void getAndVerifySizeEstimate(TestResultSender resultSender, long 
expectedSize)
+      throws Throwable {
+    getAndVerifySizeEstimate(resultSender, expectedSize, expectedSize);
+  }
+
+  private void getAndVerifySizeEstimate(TestResultSender resultSender, long 
minExpected,
+      long maxExpected) throws Throwable {
+    List<?> results = resultSender.getResults();
+
+    assertThat(results).isNotNull();
+    assertThat(results.size()).isEqualTo(1);
+    List<?> result = (List<?>) results.get(0);
+    assertThat(result).isNotNull();
+    if (minExpected == maxExpected) {
+      assertThat(((Long) result.get(0))).isEqualTo(minExpected);
+    }
+    assertThat(((Long) result.get(0))).isGreaterThanOrEqualTo(minExpected)
+        .isLessThanOrEqualTo(maxExpected);
+  }
+
+  private static class TestResultSender implements ResultSender {
+
+    private final List<Object> results = new LinkedList<>();
+
+    private Throwable t;
+
+    List<Object> getResults() throws Throwable {
+      if (t != null) {
+        throw t;
+      }
+      return Collections.unmodifiableList(results);
+    }
+
+    @Override
+    public void lastResult(final Object lastResult) {
+      results.add(lastResult);
+    }
+
+    @Override
+    public void sendResult(final Object oneResult) {
+      results.add(oneResult);
+    }
+
+    @Override
+    public void sendException(final Throwable t) {
+      this.t = t;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/c5962aa9/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsTestSuite.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsTestSuite.java
 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsTestSuite.java
deleted file mode 100644
index e70a750..0000000
--- 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsTestSuite.java
+++ /dev/null
@@ -1,29 +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.functions;
-
-import org.apache.geode.management.internal.cli.util.LogSizerTest;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * JUnit, DUnit and Integration tests for SizeExportLogsFunction.
- */
-@Suite.SuiteClasses({SizeExportLogsFunctionCacheTest.class, 
SizeExportLogsFunctionFileTest.class,
-    LogSizerTest.class, ExportedLogsSizeInfoTest.class})
-@RunWith(Suite.class)
-public class SizeExportLogsTestSuite {
-
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/c5962aa9/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogExporterTest.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogExporterTest.java
 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogExporterTest.java
index a387af3..83f0b44 100644
--- 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogExporterTest.java
+++ 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogExporterTest.java
@@ -50,7 +50,7 @@ public class LogExporterTest {
   public TemporaryFolder temporaryFolder = new TemporaryFolder();
 
   private LogExporter logExporter;
-  LogFilter logFilter;
+  private LogFilter logFilter;
   private File workingDir;
 
   @Before
@@ -71,7 +71,7 @@ public class LogExporterTest {
   }
 
   @Test
-  public void exporterShouldStillReturnFilefNoAcceptableLogs() throws 
Exception {
+  public void exporterShouldStillReturnFileIfNoAcceptableLogs() throws 
Exception {
     File logFile1 = new File(workingDir, "server1.log");
     FileUtils.writeStringToFile(logFile1, "some log for server1 \n some other 
log line");
     
when(logFilter.acceptsLine(any())).thenReturn(LogFilter.LineFilterResult.LINE_REJECTED);
@@ -138,7 +138,7 @@ public class LogExporterTest {
     
assertThat(logExporter.findStatFiles(workingDir.toPath())).doesNotContain(notALogFile.toPath());
   }
 
-  public static Set<String> getZipEntries(String zipFilePath) throws 
IOException {
+  static Set<String> getZipEntries(String zipFilePath) throws IOException {
     return new 
ZipFile(zipFilePath).stream().map(ZipEntry::getName).collect(Collectors.toSet());
   }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/c5962aa9/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogSizerTest.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogSizerTest.java
 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogSizerTest.java
index c7b3ab9..f0b7f96 100644
--- 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogSizerTest.java
+++ 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogSizerTest.java
@@ -32,7 +32,6 @@ import org.junit.rules.TestName;
 
 import java.io.File;
 import java.io.IOException;
-import java.nio.file.Path;
 import java.text.ParseException;
 
 @Category(UnitTest.class)
@@ -40,8 +39,6 @@ public class LogSizerTest {
   private LogFilter logFilter;
   private SizeExportLogsFunction.Args nonFilteringArgs;
 
-  private File dir;
-
   @Rule
   public TemporaryFolder temporaryFolder = new TemporaryFolder();
   @Rule
@@ -50,9 +47,7 @@ public class LogSizerTest {
   @Before
   public void setUp() throws Exception {
     logFilter = mock(LogFilter.class);
-    dir = temporaryFolder.getRoot();
     nonFilteringArgs = new ExportLogsFunction.Args(null, null, null, false, 
false, false);
-
   }
 
   @After
@@ -62,8 +57,8 @@ public class LogSizerTest {
 
   @Test
   public void nullFileArgs_returnsZeroSize() throws ParseException, 
IOException {
-    LogSizer sizer = new LogSizer(logFilter, null, null);
-    assertThat(sizer.getFilteredSize()).isEqualTo(0L);
+    LogExporter sizer = new LogExporter(logFilter, null, null);
+    assertThat(sizer.estimateFilteredSize()).isEqualTo(0L);
   }
 
   @Test
@@ -75,8 +70,8 @@ public class LogSizerTest {
         new File("root" + separator + "parent" + separator + testName + 
".log").toPath());
     when(mockStatFile.toPath()).thenReturn(
         new File("root" + separator + "parent" + separator + testName + 
".gfs").toPath());
-    LogSizer sizer = new LogSizer(logFilter, mockLogFile, mockStatFile);
-    assertThat(sizer.getFilteredSize()).isEqualTo(0L);
+    LogExporter sizer = new LogExporter(logFilter, mockLogFile, mockStatFile);
+    assertThat(sizer.estimateFilteredSize()).isEqualTo(0L);
   }
 
   @Test
@@ -92,8 +87,8 @@ public class LogSizerTest {
         new LogFilter(nonFilteringArgs.getLogLevel(), 
nonFilteringArgs.isThisLogLevelOnly(),
             nonFilteringArgs.getStartTime(), nonFilteringArgs.getEndTime());
 
-    LogSizer sizer = new LogSizer(logFilter, mockLogFile, mockStatFile);
-    assertThat(sizer.getFilteredSize()).isEqualTo(0L);
+    LogExporter sizer = new LogExporter(logFilter, mockLogFile, mockStatFile);
+    assertThat(sizer.estimateFilteredSize()).isEqualTo(0L);
   }
 
 }

Reply via email to