mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-29 17:58:56 -04:00
Move seed note running out of user thread, still locking
This commit is contained in:
parent
a9d0272e88
commit
0977ef398b
1 changed files with 41 additions and 48 deletions
|
@ -16,7 +16,10 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.SimpleFileVisitor;
|
import java.nio.file.SimpleFileVisitor;
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
|
|
||||||
|
@ -26,24 +29,17 @@ public class NetworkStressTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws IOException, InterruptedException {
|
public void setup() throws IOException, InterruptedException {
|
||||||
// Use an executor that uses a single daemon thread.
|
|
||||||
final ThreadFactory threadFactory = new ThreadFactoryBuilder()
|
|
||||||
.setNameFormat(this.getClass().getSimpleName())
|
|
||||||
.setDaemon(true)
|
|
||||||
.build();
|
|
||||||
UserThread.setExecutor(Executors.newSingleThreadExecutor(threadFactory));
|
|
||||||
|
|
||||||
tempDir = createTempDirectory();
|
tempDir = createTempDirectory();
|
||||||
seedNode = new SeedNode(tempDir.toString());
|
seedNode = new SeedNode(tempDir.toString());
|
||||||
|
final NodeAddress seedNodeAddress = new NodeAddress("localhost:8002");
|
||||||
|
final Set<NodeAddress> seedNodes = new HashSet<>(1);
|
||||||
|
seedNodes.add(seedNodeAddress); // the only seed node in tests
|
||||||
|
|
||||||
// Use as a barrier to wait for concurrent tasks.
|
// Use as a barrier to wait for concurrent tasks.
|
||||||
final CountDownLatch latch = new CountDownLatch(1 /*seed node*/);
|
final CountDownLatch latch = new CountDownLatch(1 /*seed node*/);
|
||||||
// Start the seed node.
|
// Start the seed node.
|
||||||
final NodeAddress seedNodeAddress = new NodeAddress("localhost:8002");
|
|
||||||
UserThread.execute(() -> {
|
|
||||||
try {
|
|
||||||
seedNode.createAndStartP2PService(seedNodeAddress, true /*localhost*/,
|
seedNode.createAndStartP2PService(seedNodeAddress, true /*localhost*/,
|
||||||
2 /*regtest*/, false /*detailed logging*/, null /*seed nodes*/,
|
2 /*regtest*/, true /*detailed logging*/, seedNodes,
|
||||||
new P2PServiceListener() {
|
new P2PServiceListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onRequestingDataCompleted() {
|
public void onRequestingDataCompleted() {
|
||||||
|
@ -62,29 +58,26 @@ public class NetworkStressTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBootstrapComplete() {
|
public void onBootstrapComplete() {
|
||||||
latch.countDown(); // one less task to wait on
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTorNodeReady() {
|
public void onTorNodeReady() {
|
||||||
// do nothing
|
// do nothing
|
||||||
|
System.out.println("TOR NODE READY");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHiddenServicePublished() {
|
public void onHiddenServicePublished() {
|
||||||
// do nothing
|
latch.countDown(); // one less task to wait on
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSetupFailed(Throwable throwable) {
|
public void onSetupFailed(Throwable throwable) {
|
||||||
//XXXX
|
//XXXX
|
||||||
}
|
}
|
||||||
});
|
|
||||||
} catch (Throwable t) {
|
|
||||||
//log.error("Executing task failed. " + t.getMessage());
|
|
||||||
t.printStackTrace();
|
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
// Wait for concurrent tasks to finish.
|
// Wait for concurrent tasks to finish.
|
||||||
latch.await();
|
latch.await();
|
||||||
|
@ -96,7 +89,7 @@ public class NetworkStressTest {
|
||||||
final CountDownLatch latch = new CountDownLatch(1 /*seed node*/);
|
final CountDownLatch latch = 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(latch::countDown);
|
||||||
}
|
}
|
||||||
// Wait for concurrent tasks to finish.
|
// Wait for concurrent tasks to finish.
|
||||||
latch.await();
|
latch.await();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue