Make methods for seed node address and setup listener creation

This will ease redefining node type (Tor or localhost) and creating more nodes that can report setup result.
This commit is contained in:
Ivan Vilata-i-Balaguer 2016-04-25 11:35:57 +02:00
parent 2c61596871
commit 30e980748d

View file

@ -38,13 +38,33 @@ public class NetworkStressTest {
// Create and start the seed node. // Create and start the seed node.
seedNode = new SeedNode(tempDir.toString()); seedNode = new SeedNode(tempDir.toString());
final NodeAddress seedNodeAddress = new NodeAddress("localhost:8002"); final NodeAddress seedNodeAddress = getSeedNodeAddress();
final boolean useLocalhost = true; final boolean useLocalhost = seedNodeAddress.getFullAddress().startsWith("localhost:");
final Set<NodeAddress> seedNodes = new HashSet<>(1); final Set<NodeAddress> seedNodes = new HashSet<>(1);
seedNodes.add(seedNodeAddress); // the only seed node in tests seedNodes.add(seedNodeAddress); // the only seed node in tests
seedNode.createAndStartP2PService(seedNodeAddress, useLocalhost, seedNode.createAndStartP2PService(seedNodeAddress, useLocalhost,
2 /*regtest*/, true /*detailed logging*/, seedNodes, 2 /*regtest*/, true /*detailed logging*/, seedNodes,
new P2PServiceListener() { getSetupListener(setupFailed, pendingTasks)
);
// Wait for concurrent tasks to finish.
pendingTasks.await();
// Check if any node reported setup failure on start.
if (setupFailed.get())
throw new Exception("nodes failed to start");
}
@NotNull
private static NodeAddress getSeedNodeAddress() {
return new NodeAddress("localhost:8002");
}
@NotNull
private static P2PServiceListener getSetupListener(
final BooleanProperty setupFailed,
final CountDownLatch pendingTasks) {
return new P2PServiceListener() {
@Override @Override
public void onRequestingDataCompleted() { public void onRequestingDataCompleted() {
// do nothing // do nothing
@ -82,15 +102,7 @@ public class NetworkStressTest {
setupFailed.set(true); setupFailed.set(true);
pendingTasks.countDown(); pendingTasks.countDown();
} }
} };
);
// Wait for concurrent tasks to finish.
pendingTasks.await();
// Check if nodes started correctly.
if (setupFailed.get())
throw new Exception("nodes failed to start");
} }
@After @After