Add skeleton for network stress unit test

This commit is contained in:
Ivan Vilata-i-Balaguer 2016-04-22 09:29:12 +02:00
parent e910233b4c
commit fdc0eafc67

View File

@ -0,0 +1,55 @@
package io.bitsquare.p2p.network;
import org.jetbrains.annotations.NotNull;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
public class NetworkStressTest {
private Path tempDir;
@Before
public void setup() throws IOException {
tempDir = createTempDirectory();
}
@After
public void tearDown() throws IOException {
if (tempDir != null) {
deleteRecursively(tempDir);
}
}
@Test
public void test() {
// do nothing
}
private Path createTempDirectory() throws IOException {
return Files.createTempDirectory("bsq" + this.getClass().getSimpleName());
}
private static void deleteRecursively(@NotNull final Path path) throws IOException {
// Based on <https://stackoverflow.com/a/27917071/6239236> by Tomasz Dzięcielewski.
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(path);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}
});
}
}