Search in sources :

Example 1 with TestRaftProtocolFactory

use of io.atomix.protocols.raft.protocol.TestRaftProtocolFactory in project atomix by atomix.

the class RaftTest method clearTests.

@Before
@After
public void clearTests() throws Exception {
    clients.forEach(c -> {
        try {
            c.close().get(10, TimeUnit.SECONDS);
        } catch (Exception e) {
        }
    });
    servers.forEach(s -> {
        try {
            if (s.isRunning()) {
                s.shutdown().get(10, TimeUnit.SECONDS);
            }
        } catch (Exception e) {
        }
    });
    Path directory = Paths.get("target/test-logs/");
    if (Files.exists(directory)) {
        Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                Files.delete(file);
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                Files.delete(dir);
                return FileVisitResult.CONTINUE;
            }
        });
    }
    if (context != null) {
        context.close();
    }
    members = new ArrayList<>();
    nextId = 0;
    clients = new ArrayList<>();
    servers = new ArrayList<>();
    context = new SingleThreadContext("raft-test-messaging-%d");
    protocolFactory = new TestRaftProtocolFactory(context);
}
Also used : Path(java.nio.file.Path) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) TestRaftProtocolFactory(io.atomix.protocols.raft.protocol.TestRaftProtocolFactory) SingleThreadContext(io.atomix.utils.concurrent.SingleThreadContext) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Before(org.junit.Before) After(org.junit.After)

Aggregations

TestRaftProtocolFactory (io.atomix.protocols.raft.protocol.TestRaftProtocolFactory)1 SingleThreadContext (io.atomix.utils.concurrent.SingleThreadContext)1 IOException (java.io.IOException)1 FileVisitResult (java.nio.file.FileVisitResult)1 Path (java.nio.file.Path)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 After (org.junit.After)1 Before (org.junit.Before)1