mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-22 05:29:33 -04:00
Keep network stress test data if environment variable `STRESS_TEST_DIR
` is specified
This commit is contained in:
parent
3a7359247b
commit
e12d61d026
1 changed files with 20 additions and 7 deletions
|
@ -20,10 +20,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.FileVisitResult;
|
import java.nio.file.*;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.SimpleFileVisitor;
|
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -37,12 +34,14 @@ public class NetworkStressTest {
|
||||||
// Test parameters
|
// Test parameters
|
||||||
|
|
||||||
/** Number of peer nodes to create. */
|
/** Number of peer nodes to create. */
|
||||||
private static final int NPEERS = 1;
|
private static final int NPEERS = 4;
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
|
|
||||||
/** Numeric identifier of the regtest Bitcoin network. */
|
/** Numeric identifier of the regtest Bitcoin network. */
|
||||||
private static final int REGTEST_NETWORK_ID = 2;
|
private static final int REGTEST_NETWORK_ID = 2;
|
||||||
|
/** Environment variable to specify a persistent test data directory. */
|
||||||
|
private static final String TEST_DIR_ENVVAR = "STRESS_TEST_DIR";
|
||||||
|
|
||||||
// Instance fields
|
// Instance fields
|
||||||
|
|
||||||
|
@ -141,7 +140,8 @@ public class NetworkStressTest {
|
||||||
// Wait for concurrent tasks to finish.
|
// Wait for concurrent tasks to finish.
|
||||||
shutdownLatch.await();
|
shutdownLatch.await();
|
||||||
|
|
||||||
if (tempDir != null) {
|
// Cleanup directory if not given explicitly.
|
||||||
|
if (tempDir != null && System.getenv(TEST_DIR_ENVVAR) == null) {
|
||||||
deleteRecursively(tempDir);
|
deleteRecursively(tempDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,20 @@ public class NetworkStressTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Path createTempDirectory() throws IOException {
|
private Path createTempDirectory() throws IOException {
|
||||||
return Files.createTempDirectory("bsq" + this.getClass().getSimpleName());
|
Path stressTestDirPath;
|
||||||
|
|
||||||
|
String stressTestDir = System.getenv(TEST_DIR_ENVVAR);
|
||||||
|
if (stressTestDir != null) {
|
||||||
|
// Test directory specified, use and create if missing.
|
||||||
|
stressTestDirPath = Paths.get(stressTestDir);
|
||||||
|
if (!Files.isDirectory(stressTestDirPath)) {
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
|
stressTestDirPath.toFile().mkdirs();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
stressTestDirPath = Files.createTempDirectory("bsq" + this.getClass().getSimpleName());
|
||||||
|
}
|
||||||
|
return stressTestDirPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void deleteRecursively(@NotNull final Path path) throws IOException {
|
private static void deleteRecursively(@NotNull final Path path) throws IOException {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue