Skip to content

Commit

Permalink
Merge pull request apache#2429 from balesh2/GEODE-3778
Browse files Browse the repository at this point in the history
GEODE-3778: Remove test FileWriters
  • Loading branch information
nonbinaryprogrammer authored Sep 6, 2018
2 parents 0ee4f17 + add995b commit 449411a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
import static org.mockito.Mockito.when;

import java.io.File;
import java.nio.charset.Charset;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;

import org.apache.commons.io.FileUtils;
import org.awaitility.Awaitility;
import org.awaitility.core.ConditionFactory;
import org.junit.Before;
Expand All @@ -41,8 +43,6 @@
import org.apache.geode.distributed.LocatorLauncher.Builder;
import org.apache.geode.distributed.LocatorLauncher.LocatorState;
import org.apache.geode.internal.process.io.EmptyFileWriter;
import org.apache.geode.internal.process.io.IntegerFileWriter;
import org.apache.geode.internal.process.io.StringFileWriter;
import org.apache.geode.test.junit.rules.ExecutorServiceRule;

/**
Expand Down Expand Up @@ -110,7 +110,7 @@ public void statusShouldAwaitTimeoutWhileFileIsEmpty() throws Exception {
@Test
public void statusShouldReturnJsonFromStatusFile() throws Exception {
// given: FileProcessController with pidFile containing real pid
new IntegerFileWriter(pidFile).writeToFile(pid);
FileUtils.writeStringToFile(pidFile, String.valueOf(pid), Charset.defaultCharset());
FileProcessController controller = new FileProcessController(params, pid, 2, MINUTES);

// when: status is called in one thread
Expand All @@ -123,7 +123,7 @@ public void statusShouldReturnJsonFromStatusFile() throws Exception {
});

// and: json is written to the status file
new StringFileWriter(statusFile).writeToFile(STATUS_JSON);
FileUtils.writeStringToFile(statusFile, STATUS_JSON, Charset.defaultCharset());

// then: returned status should be the json in the file
await().untilAsserted(() -> assertThat(statusRef.get()).isEqualTo(STATUS_JSON));
Expand All @@ -138,7 +138,7 @@ public void statusShouldReturnJsonFromStatusFile() throws Exception {
@Test
public void emptyStatusFileCausesStatusToHang() throws Exception {
// given: FileProcessController with pidFile containing real pid
new IntegerFileWriter(pidFile).writeToFile(pid);
FileUtils.writeStringToFile(pidFile, String.valueOf(pid), Charset.defaultCharset());
FileProcessController controller = new FileProcessController(params, pid, 2, MINUTES);

// when: status is called in one thread
Expand Down Expand Up @@ -198,7 +198,7 @@ public void status_withStatusRequestFileExists_doesNotFail() throws Exception {
}
});

new StringFileWriter(statusFile).writeToFile(STATUS_JSON);
FileUtils.writeStringToFile(statusFile, STATUS_JSON, Charset.defaultCharset());

// assert
await().untilAsserted(() -> assertThat(statusRequestFile).exists());
Expand All @@ -207,7 +207,7 @@ public void status_withStatusRequestFileExists_doesNotFail() throws Exception {
@Test
public void statusCreatesStatusRequestFile() throws Exception {
// arrange
new IntegerFileWriter(pidFile).writeToFile(pid);
FileUtils.writeStringToFile(pidFile, String.valueOf(pid), Charset.defaultCharset());
FileProcessController controller = new FileProcessController(params, pid, 2, MINUTES);

// act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.io.File;
import java.nio.charset.Charset;

import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
import org.junit.rules.TemporaryFolder;

import org.apache.geode.internal.process.io.EmptyFileWriter;
import org.apache.geode.internal.process.io.IntegerFileWriter;
import org.apache.geode.internal.process.lang.AvailablePid;
import org.apache.geode.test.junit.Retry;
import org.apache.geode.test.junit.rules.RetryRule;
Expand Down Expand Up @@ -80,7 +81,7 @@ public void createsPidFile() throws Exception {
public void existingPidFileThrowsFileAlreadyExistsException() throws Exception {
// arrange
System.setProperty(PROPERTY_IGNORE_IS_PID_ALIVE, "true");
new IntegerFileWriter(pidFile).writeToFile(fakePid);
FileUtils.writeStringToFile(pidFile, String.valueOf(fakePid), Charset.defaultCharset());

// act/assert
assertThatThrownBy(() -> new LocalProcessLauncher(pidFile, false))
Expand All @@ -90,7 +91,7 @@ public void existingPidFileThrowsFileAlreadyExistsException() throws Exception {
@Test
public void overwritesPidFileIfForce() throws Exception {
// arrange
new IntegerFileWriter(pidFile).writeToFile(actualPid);
FileUtils.writeStringToFile(pidFile, String.valueOf(actualPid), Charset.defaultCharset());

// act
new LocalProcessLauncher(pidFile, true);
Expand All @@ -103,7 +104,7 @@ public void overwritesPidFileIfForce() throws Exception {
@Retry(3)
public void overwritesPidFileIfOtherPidIsNotAlive() throws Exception {
// arrange
new IntegerFileWriter(pidFile).writeToFile(fakePid);
FileUtils.writeStringToFile(pidFile, String.valueOf(fakePid), Charset.defaultCharset());

// act
new LocalProcessLauncher(pidFile, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@

import java.io.File;
import java.io.FileNotFoundException;
import java.nio.charset.Charset;

import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import org.apache.geode.internal.process.io.IntegerFileWriter;
import org.apache.geode.internal.process.lang.AvailablePid;

/**
Expand Down Expand Up @@ -56,7 +57,7 @@ public void before() throws Exception {
public void readsIntFromFile() throws Exception {
// arrange
String value = "42";
new IntegerFileWriter(pidFile).writeToFile(value);
FileUtils.writeStringToFile(pidFile, value, Charset.defaultCharset());

// act
int readValue = new PidFile(pidFile).readPid();
Expand All @@ -68,7 +69,7 @@ public void readsIntFromFile() throws Exception {
@Test
public void readingEmptyFileThrowsIllegalArgumentException() throws Exception {
// arrange
new IntegerFileWriter(pidFile).writeToFile("");
FileUtils.writeStringToFile(pidFile, "", Charset.defaultCharset());

// act/assert
assertThatThrownBy(() -> new PidFile(pidFile).readPid())
Expand All @@ -79,7 +80,7 @@ public void readingEmptyFileThrowsIllegalArgumentException() throws Exception {
public void readingFileWithNonIntegerThrowsIllegalArgumentException() throws Exception {
// arrange
String value = "forty two";
new IntegerFileWriter(pidFile).writeToFile(value);
FileUtils.writeStringToFile(pidFile, value, Charset.defaultCharset());

// act/assert
assertThatThrownBy(() -> new PidFile(pidFile).readPid())
Expand All @@ -91,7 +92,7 @@ public void readingFileWithNonIntegerThrowsIllegalArgumentException() throws Exc
public void readingFileWithNegativeIntegerThrowsIllegalArgumentException() throws Exception {
// arrange
String value = "-42";
new IntegerFileWriter(pidFile).writeToFile(value);
FileUtils.writeStringToFile(pidFile, value, Charset.defaultCharset());

// act/assert
assertThatThrownBy(() -> new PidFile(pidFile).readPid())
Expand All @@ -112,10 +113,12 @@ public void readingNullFileThrowsNullPointerException() throws Exception {
@Test
public void findsCorrectFileByName() throws Exception {
// arrange
new IntegerFileWriter(pidFile).writeToFile(pid);
FileUtils.writeStringToFile(pidFile, String.valueOf(pid), Charset.defaultCharset());
int[] pids = new AvailablePid().findAvailablePids(4);
for (int i = 1; i <= pids.length; i++) {
new IntegerFileWriter(new File(directory, "pid" + i + ".txt")).writeToFile(pids[i - 1]);
FileUtils.writeStringToFile(
new File(directory, "pid" + i + ".txt"), String.valueOf(pids[i - 1]),
Charset.defaultCharset());
}
assertThat(directory.listFiles()).hasSize(pids.length + 1);

Expand Down Expand Up @@ -162,7 +165,9 @@ public void missingFileInFullDirectoryThrowsFileNotFoundException() throws Excep
// arrange
int[] pids = new AvailablePid().findAvailablePids(4);
for (int i = 1; i <= pids.length; i++) {
new IntegerFileWriter(new File(directory, "pid" + i + ".txt")).writeToFile(pids[i - 1]);
FileUtils.writeStringToFile(
new File(directory, "pid" + i + ".txt"), String.valueOf(pids[i - 1]),
Charset.defaultCharset());
}
assertThat(directory.listFiles()).hasSameSizeAs(pids);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@

import java.io.File;
import java.io.FileNotFoundException;
import java.nio.charset.Charset;

import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
import org.junit.rules.TemporaryFolder;

import org.apache.geode.internal.process.io.IntegerFileWriter;

/**
* Functional integration tests for {@link ProcessControllerFactory}.
*/
Expand Down Expand Up @@ -73,7 +73,7 @@ public void createProcessController_withoutPidFile_throwsFileNotFoundException()
@Test
public void createProcessController_returnsMBeanProcessController() throws Exception {
// arrange
new IntegerFileWriter(pidFile).writeToFile(pid);
FileUtils.writeStringToFile(pidFile, String.valueOf(pid), Charset.defaultCharset());

// act
ProcessController controller =
Expand All @@ -87,7 +87,7 @@ public void createProcessController_returnsMBeanProcessController() throws Excep
public void createProcessController_withoutAttachAPI_returnsFileProcessController()
throws Exception {
// arrange
new IntegerFileWriter(pidFile).writeToFile(pid);
FileUtils.writeStringToFile(pidFile, String.valueOf(pid), Charset.defaultCharset());
System.setProperty(ProcessControllerFactory.PROPERTY_DISABLE_ATTACH_API, "true");
factory = new ProcessControllerFactory();

Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 449411a

Please sign in to comment.