DBZ-963 Removing hard-coded references to "target" dir;
Also injecting actual build dir via system variable. Making DATA_DIR a simple string.
This commit is contained in:
parent
3401cd23ea
commit
92704ce394
@ -4,6 +4,7 @@ Andreas Bergmeier
|
||||
Andras Istvan Nagy
|
||||
Andrew Tongen
|
||||
Andrey Pustovetov
|
||||
Anton Martynov
|
||||
Attila Szucs
|
||||
Barry LaFond
|
||||
Ben Williams
|
||||
|
@ -5,6 +5,9 @@
|
||||
*/
|
||||
package io.debezium.util;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.fest.assertions.Fail.fail;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -19,10 +22,6 @@
|
||||
import org.fest.assertions.Fail;
|
||||
import org.junit.Before;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
|
||||
import static org.fest.assertions.Fail.fail;
|
||||
|
||||
import io.debezium.util.Stopwatch.Statistics;
|
||||
import io.debezium.util.Stopwatch.StopwatchSet;
|
||||
|
||||
@ -132,6 +131,25 @@ public static int getAvailablePort() {
|
||||
*/
|
||||
public static interface Files {
|
||||
|
||||
public static final String DBZ_TEST_DATA_DIR_ENV_VAR_NAME = "DBZ_TEST_DATA_DIR";
|
||||
public static final String DBZ_TEST_DATA_DIR_SYSTEM_PROPERTY_KEY = "dbz.test.data.dir";
|
||||
|
||||
static final String DATA_DIR = determineTestDataDir();
|
||||
|
||||
static String determineTestDataDir() {
|
||||
String value = System.getProperty(DBZ_TEST_DATA_DIR_SYSTEM_PROPERTY_KEY);
|
||||
if (value != null && (value = value.trim()).length() > 0) {
|
||||
return value;
|
||||
}
|
||||
|
||||
value = System.getenv(DBZ_TEST_DATA_DIR_ENV_VAR_NAME);
|
||||
if (value != null && (value = value.trim()).length() > 0) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return "target/data"; // default value
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain an InputStream to a named resource on the given classpath.
|
||||
*
|
||||
@ -186,24 +204,9 @@ public static File createTestingDirectory(String relativePath) {
|
||||
* This value can be overridden by value of the {@code DBZ_TEST_DATA_DIR} system or environment variable.
|
||||
*/
|
||||
static String dataDir() {
|
||||
if (DATA_DIR[0] != null) {
|
||||
return DATA_DIR[0];
|
||||
return DATA_DIR;
|
||||
}
|
||||
|
||||
String value = System.getProperty("DBZ_TEST_DATA_DIR");
|
||||
if (value != null && (value = value.trim()).length() > 0) {
|
||||
return DATA_DIR[0] = value;
|
||||
}
|
||||
|
||||
value = System.getenv("DBZ_TEST_DATA_DIR");
|
||||
if (value != null && (value = value.trim()).length() > 0) {
|
||||
return DATA_DIR[0] = value;
|
||||
}
|
||||
|
||||
return DATA_DIR[0] = "target/data"; // default value
|
||||
}
|
||||
String[] DATA_DIR = {null};
|
||||
|
||||
/**
|
||||
* Create a randomly-named file within the test data directory.
|
||||
*
|
||||
|
@ -5,31 +5,31 @@
|
||||
*/
|
||||
package io.debezium.util;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
|
||||
public class TestingTest implements Testing {
|
||||
|
||||
@Test
|
||||
public void shouldKnowDirectoriesInsideTestData() {
|
||||
assertThat(Testing.Files.inTestDataDir(new File("target/data/somefile").toPath())).isTrue();
|
||||
assertThat(Testing.Files.inTestDataDir(Paths.get(Testing.Files.dataDir(), "somefile"))).isTrue();
|
||||
assertThat(Testing.Files.inTestDataDir(new File("../debezium").toPath())).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRemoveDirectory() throws Exception {
|
||||
Path path = Paths.get("target/data/test-dir");
|
||||
Path path = Paths.get(Testing.Files.dataDir(), "test-dir");
|
||||
assertThat(path.toFile().mkdirs()).isTrue();
|
||||
|
||||
Path file = Paths.get("target/data/test-dir/file.txt");
|
||||
Path file = path.resolve("file.txt");
|
||||
assertThat(file.toFile().createNewFile()).isTrue();
|
||||
|
||||
Testing.Files.delete(path);
|
||||
// todo: assert that 'target/data/test-dir' is removed
|
||||
assertThat(java.nio.file.Files.exists(path)).isFalse();
|
||||
}
|
||||
}
|
||||
|
6
pom.xml
6
pom.xml
@ -565,12 +565,16 @@
|
||||
<systemProperties combine.children="append">
|
||||
<property>
|
||||
<name>java.io.tmpdir</name>
|
||||
<value>${basedir}/target</value>
|
||||
<value>${project.build.directory}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>skipLongRunningTests</name>
|
||||
<value>${skipLongRunningTests}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>dbz.test.data.dir</name>
|
||||
<value>${project.build.directory}/data</value>
|
||||
</property>
|
||||
</systemProperties>
|
||||
<argLine>-Djava.awt.headless=true ${debug.argline} ${modules.argline}</argLine>
|
||||
<!--runOrder>alphabetical</runOrder-->
|
||||
|
Loading…
Reference in New Issue
Block a user