Skip to content

Commit 18884b8

Browse files
authored
GEODE-5212: Convert ExportLogsIntegrationTest to DistributedTest (apache#2155)
Due to differences on how defaultDirectory is initialized between Windows and Unix, this test fails if its integration test. So converted it to be a DistributedTest. Signed-off-by: Jens Deppe <[email protected]>
1 parent e020888 commit 18884b8

File tree

3 files changed

+65
-106
lines changed

3 files changed

+65
-106
lines changed

geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTest.java

+61-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static java.util.stream.Collectors.joining;
2020
import static java.util.stream.Collectors.toList;
2121
import static java.util.stream.Collectors.toSet;
22+
import static org.apache.commons.io.FileUtils.listFiles;
2223
import static org.apache.geode.management.internal.cli.commands.ExportLogsCommand.FORMAT;
2324
import static org.apache.geode.management.internal.cli.commands.ExportLogsCommand.ONLY_DATE_FORMAT;
2425
import static org.assertj.core.api.Assertions.assertThat;
@@ -27,6 +28,7 @@
2728
import java.io.IOException;
2829
import java.io.Serializable;
2930
import java.nio.charset.Charset;
31+
import java.nio.file.Path;
3032
import java.time.LocalDateTime;
3133
import java.time.ZoneId;
3234
import java.time.ZonedDateTime;
@@ -41,10 +43,12 @@
4143

4244
import org.apache.commons.io.FileUtils;
4345
import org.apache.logging.log4j.Logger;
46+
import org.junit.After;
4447
import org.junit.Before;
4548
import org.junit.Rule;
4649
import org.junit.Test;
4750
import org.junit.experimental.categories.Category;
51+
import org.junit.rules.TemporaryFolder;
4852

4953
import org.apache.geode.cache.Cache;
5054
import org.apache.geode.distributed.ConfigurationProperties;
@@ -70,12 +74,18 @@ public class ExportLogsDUnitTest {
7074
@Rule
7175
public GfshCommandRule gfshConnector = new GfshCommandRule();
7276

73-
private MemberVM locator;
77+
@Rule
78+
public TemporaryFolder temporaryFolder = new TemporaryFolder();
79+
80+
protected MemberVM locator;
7481
private MemberVM server1;
7582
private MemberVM server2;
7683

7784
private Map<MemberVM, List<LogLine>> expectedMessages;
7885

86+
public File getWorkingDirectory() throws Exception {
87+
return locator.getWorkingDir();
88+
}
7989

8090
@Before
8191
public void setup() throws Exception {
@@ -103,9 +113,53 @@ public void setup() throws Exception {
103113
});
104114
}
105115

116+
connect();
117+
}
118+
119+
public void connect() throws Exception {
106120
gfshConnector.connectAndVerify(locator);
107121
}
108122

123+
@After
124+
public void after() throws Exception {
125+
Stream.of(getWorkingDirectory().listFiles())
126+
.filter(f -> f.getName().endsWith(".zip")).forEach(file -> file.delete());
127+
}
128+
129+
@Test
130+
public void withFiles_savedToLocatorWorkingDir() throws Exception {
131+
String[] extensions = {"zip"};
132+
// Expects locator to produce file in own working directory when connected via JMX
133+
gfshConnector.executeCommand("export logs");
134+
assertThat(listFiles(getWorkingDirectory(), extensions, false)).isNotEmpty();
135+
}
136+
137+
@Test
138+
public void withFiles_savedToLocatorSpecifiedRelativeDir() throws Exception {
139+
String[] extensions = {"zip"};
140+
Path workingDirPath = getWorkingDirectory().toPath();
141+
Path subdirPath = workingDirPath.resolve("some").resolve("test").resolve("directory");
142+
Path relativeDir = workingDirPath.relativize(subdirPath);
143+
// Expects locator to produce file in own working directory when connected via JMX
144+
gfshConnector.executeCommand("export logs --dir=" + relativeDir.toString());
145+
assertThat(listFiles(getWorkingDirectory(), extensions, false)).isEmpty();
146+
assertThat(listFiles(getWorkingDirectory(), extensions, true)).isNotEmpty();
147+
assertThat(listFiles(subdirPath.toFile(), extensions, false)).isNotEmpty();
148+
}
149+
150+
@Test
151+
public void withFiles_savedToLocatorSpecifiedAbsoluteDir() throws Exception {
152+
String[] extensions = {"zip"};
153+
Path workingDirPath = getWorkingDirectory().toPath();
154+
Path absoluteDirPath =
155+
workingDirPath.resolve("some").resolve("test").resolve("directory").toAbsolutePath();
156+
// Expects locator to produce file in own working directory when connected via JMX
157+
gfshConnector.executeCommand("export logs --dir=" + absoluteDirPath.toString());
158+
assertThat(listFiles(getWorkingDirectory(), extensions, false)).isEmpty();
159+
assertThat(listFiles(getWorkingDirectory(), extensions, true)).isNotEmpty();
160+
assertThat(listFiles(absoluteDirPath.toFile(), extensions, false)).isNotEmpty();
161+
}
162+
109163
@Test
110164
public void startAndEndDateCanIncludeLogs() throws Exception {
111165
ZonedDateTime now = LocalDateTime.now().atZone(ZoneId.systemDefault());
@@ -219,7 +273,7 @@ public void exportLogsRegionIsCleanedUpProperly() throws IOException, ClassNotFo
219273
}
220274

221275

222-
private void verifyZipFileContents(Set<String> acceptedLogLevels) throws IOException {
276+
private void verifyZipFileContents(Set<String> acceptedLogLevels) throws Exception {
223277
File unzippedLogFileDir = unzipExportedLogs();
224278

225279
Set<File> dirsFromZipFile =
@@ -270,19 +324,19 @@ private void verifyLogFileContents(Set<String> acceptedLogLevels, File dirForMem
270324

271325
}
272326

273-
private File unzipExportedLogs() throws IOException {
274-
File locatorWorkingDir = locator.getWorkingDir();
275-
List<File> filesInDir = Stream.of(locatorWorkingDir.listFiles()).collect(toList());
327+
private File unzipExportedLogs() throws Exception {
328+
File locatorWorkingDir = getWorkingDirectory();
329+
List<File> filesInDir = Stream.of(getWorkingDirectory().listFiles()).collect(toList());
276330
assertThat(filesInDir).isNotEmpty();
277331

278332

279-
List<File> zipFilesInDir = Stream.of(locatorWorkingDir.listFiles())
333+
List<File> zipFilesInDir = Stream.of(getWorkingDirectory().listFiles())
280334
.filter(f -> f.getName().endsWith(".zip")).collect(toList());
281335
assertThat(zipFilesInDir)
282336
.describedAs(filesInDir.stream().map(File::getAbsolutePath).collect(joining(",")))
283337
.hasSize(1);
284338

285-
File unzippedLogFileDir = new File(locatorWorkingDir, "unzippedLogs");
339+
File unzippedLogFileDir = temporaryFolder.newFolder("unzippedLogs");
286340
ZipUtils.unzip(zipFilesInDir.get(0).getCanonicalPath(), unzippedLogFileDir.getCanonicalPath());
287341
return unzippedLogFileDir;
288342
}

geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsIntegrationTest.java

-97
This file was deleted.
+4-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
import org.apache.geode.test.junit.rules.GfshCommandRule;
2424

2525
@Category({GfshTest.class})
26-
public class ExportLogsOverHttpIntegrationTest extends ExportLogsIntegrationTest {
26+
public class ExportLogsOverHttpDistributedTest extends ExportLogsDUnitTest {
2727

2828
@Override
2929
public void connect() throws Exception {
30-
gfsh.connectAndVerify(locator.getHttpPort(), GfshCommandRule.PortType.http);
30+
if (!gfshConnector.isConnected()) {
31+
gfshConnector.connectAndVerify(locator.getHttpPort(), GfshCommandRule.PortType.http);
32+
}
3133
}
3234

3335
public File getWorkingDirectory() throws Exception {

0 commit comments

Comments
 (0)