Skip to content

Commit

Permalink
GEODE-2576: delete the zip file on locator after it's being streamed …
Browse files Browse the repository at this point in the history
…to client.
  • Loading branch information
jinmeiliao committed Mar 10, 2017
1 parent ab16864 commit 12318c5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package org.apache.geode.management.internal.web.controllers;

import org.apache.commons.io.FileUtils;
import org.apache.geode.internal.lang.StringUtils;
import org.apache.geode.management.internal.cli.i18n.CliStrings;
import org.apache.geode.management.internal.cli.result.ResultBuilder;
Expand Down Expand Up @@ -91,11 +92,14 @@ public ResponseEntity<InputStreamResource> exportLogs(
String filePath = ResultBuilder.fromJson(result).nextLine().trim();

HttpHeaders respHeaders = new HttpHeaders();
File zipFile = new File(filePath);
try {
InputStreamResource isr = new InputStreamResource(new FileInputStream(new File(filePath)));
InputStreamResource isr = new InputStreamResource(new FileInputStream(zipFile));
return new ResponseEntity<InputStreamResource>(isr, respHeaders, HttpStatus.OK);
} catch (Exception ex) {
throw new RuntimeException("IOError writing file to output stream", ex);
} finally {
FileUtils.deleteQuietly(zipFile);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.geode.cache.execute.ResultSender;
import org.apache.geode.internal.cache.GemFireCacheImpl;
import org.apache.geode.internal.cache.execute.FunctionContextImpl;
import org.apache.geode.test.dunit.rules.Server;
import org.apache.geode.test.dunit.rules.ServerStarterRule;
import org.apache.geode.test.junit.categories.IntegrationTest;
import org.apache.logging.log4j.Level;
Expand All @@ -41,15 +40,12 @@
public class ExportLogsFunctionIntegrationTest {

@Rule
public ServerStarterRule serverStarterRule = new ServerStarterRule();

private Server server;
public ServerStarterRule serverStarterRule = new ServerStarterRule().startServer();
private File serverWorkingDir;

@Before
public void setup() throws Exception {
server = serverStarterRule.startServer();
serverWorkingDir = server.getWorkingDir();
serverWorkingDir = serverStarterRule.getWorkingDir();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.junit.rules.TemporaryFolder;

import java.io.File;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
Expand Down Expand Up @@ -58,6 +59,10 @@ public void testExportWithDir() throws Exception {
new ZipFile(zipPath).stream().map(ZipEntry::getName).collect(Collectors.toSet());

assertThat(actualZipEntries).isEqualTo(expectedZipEntries);

// also verify that the zip file on locator is deleted
assertThat(Arrays.stream(locator.getWorkingDir().listFiles())
.filter(file -> file.getName().endsWith(".zip")).collect(Collectors.toSet())).isEmpty();
}

protected String getZipPathFromCommandResult(String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.geode.management.internal.web.shell.RestHttpOperationInvoker;
import org.apache.geode.test.dunit.rules.LocatorStarterRule;
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;
Expand All @@ -48,21 +47,16 @@ public class QueryNamesOverHttpDUnitTest {
protected static int jmxPort = ports[0];
protected static int httpPort = ports[1];

@Rule
public LocatorStarterRule locatorRule = new LocatorStarterRule();

@Before
public void before() throws Exception {
Properties locatorProps = new Properties() {
{
setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost");
setProperty(HTTP_SERVICE_PORT, httpPort + "");
setProperty(JMX_MANAGER_PORT, jmxPort + "");
}
};
locatorRule.startLocator(locatorProps);
}
protected static Properties locatorProps = new Properties() {
{
setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost");
setProperty(HTTP_SERVICE_PORT, httpPort + "");
setProperty(JMX_MANAGER_PORT, jmxPort + "");
}
};

@Rule
public LocatorStarterRule locatorRule = new LocatorStarterRule().startLocator(locatorProps);

@Test
public void testQueryNameOverHttp() throws Exception {
Expand Down

0 comments on commit 12318c5

Please sign in to comment.