mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-03 04:06:23 -04:00
Some comments and better names in network stress test
This commit is contained in:
parent
dc149f30e3
commit
718c935fef
1 changed files with 15 additions and 10 deletions
|
@ -19,21 +19,26 @@ import java.util.Set;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
public class NetworkStressTest {
|
public class NetworkStressTest {
|
||||||
|
/** A directory to temporarily hold seed and normal nodes' configuration and state files. */
|
||||||
private Path tempDir;
|
private Path tempDir;
|
||||||
|
/** A single seed node that other nodes will contact to request initial data. */
|
||||||
private SeedNode seedNode;
|
private SeedNode seedNode;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws IOException, InterruptedException {
|
public void setup() throws IOException, InterruptedException {
|
||||||
|
/** A barrier to wait for concurrent tasks. */
|
||||||
|
final CountDownLatch pendingTasks = new CountDownLatch(1 /*seed node*/);
|
||||||
|
|
||||||
|
// Create the temporary directory.
|
||||||
tempDir = createTempDirectory();
|
tempDir = createTempDirectory();
|
||||||
|
|
||||||
|
// 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 = new NodeAddress("localhost:8002");
|
||||||
final boolean useLocalhost = true;
|
final boolean useLocalhost = true;
|
||||||
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
|
||||||
|
boolean seedNodeSetupFailed = false;
|
||||||
// Use as a barrier to wait for concurrent tasks.
|
|
||||||
final CountDownLatch latch = new CountDownLatch(1 /*seed node*/);
|
|
||||||
// Start the seed node.
|
|
||||||
seedNode.createAndStartP2PService(seedNodeAddress, useLocalhost,
|
seedNode.createAndStartP2PService(seedNodeAddress, useLocalhost,
|
||||||
2 /*regtest*/, true /*detailed logging*/, seedNodes,
|
2 /*regtest*/, true /*detailed logging*/, seedNodes,
|
||||||
new P2PServiceListener() {
|
new P2PServiceListener() {
|
||||||
|
@ -64,7 +69,7 @@ public class NetworkStressTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHiddenServicePublished() {
|
public void onHiddenServicePublished() {
|
||||||
latch.countDown(); // one less task to wait on
|
pendingTasks.countDown(); // one less task to wait on
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -75,19 +80,19 @@ public class NetworkStressTest {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Wait for concurrent tasks to finish.
|
// Wait for concurrent tasks to finish.
|
||||||
latch.await();
|
pendingTasks.await();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws InterruptedException, IOException {
|
public void tearDown() throws InterruptedException, IOException {
|
||||||
// Use as a barrier to wait for concurrent tasks.
|
/** A barrier to wait for concurrent tasks. */
|
||||||
final CountDownLatch latch = new CountDownLatch(1 /*seed node*/);
|
final CountDownLatch pendingTasks = new CountDownLatch(1 /*seed node*/);
|
||||||
// Stop the seed node.
|
// Stop the seed node.
|
||||||
if (seedNode != null) {
|
if (seedNode != null) {
|
||||||
seedNode.shutDown(latch::countDown);
|
seedNode.shutDown(pendingTasks::countDown);
|
||||||
}
|
}
|
||||||
// Wait for concurrent tasks to finish.
|
// Wait for concurrent tasks to finish.
|
||||||
latch.await();
|
pendingTasks.await();
|
||||||
|
|
||||||
if (tempDir != null) {
|
if (tempDir != null) {
|
||||||
deleteRecursively(tempDir);
|
deleteRecursively(tempDir);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue