mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-02 03:36:24 -04:00
Wait for preliminary data and bootstrap while setting up network stress tests
This should be common for the different tests.
This commit is contained in:
parent
ad6c0599f6
commit
c67f724e0f
1 changed files with 16 additions and 13 deletions
|
@ -80,11 +80,6 @@ public class NetworkStressTest {
|
||||||
/** A list of peer node's public key rings. */
|
/** A list of peer node's public key rings. */
|
||||||
private List<PubKeyRing> peerPKRings = new ArrayList<>();
|
private List<PubKeyRing> peerPKRings = new ArrayList<>();
|
||||||
|
|
||||||
/** A barrier to wait for concurrent reception of preliminary data in peers. */
|
|
||||||
private CountDownLatch prelimDataLatch;
|
|
||||||
/** A barrier to wait for concurrent bootstrap of peers. */
|
|
||||||
private CountDownLatch bootstrapLatch;
|
|
||||||
|
|
||||||
/** Number of direct messages to be sent by each peer. */
|
/** Number of direct messages to be sent by each peer. */
|
||||||
private int directCount = DIRECT_COUNT_DEFAULT;
|
private int directCount = DIRECT_COUNT_DEFAULT;
|
||||||
|
|
||||||
|
@ -109,14 +104,15 @@ public class NetworkStressTest {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
String.format("Direct messages sent per peer must not be negative: %d", directCount)
|
String.format("Direct messages sent per peer must not be negative: %d", directCount)
|
||||||
);
|
);
|
||||||
|
|
||||||
prelimDataLatch = new CountDownLatch(nPeers);
|
|
||||||
bootstrapLatch = new CountDownLatch(nPeers);
|
|
||||||
|
|
||||||
/** A property where threads can indicate setup failure of local services (Tor node, hidden service). */
|
/** A property where threads can indicate setup failure of local services (Tor node, hidden service). */
|
||||||
final BooleanProperty localServicesFailed = new SimpleBooleanProperty(false);
|
final BooleanProperty localServicesFailed = new SimpleBooleanProperty(false);
|
||||||
/** A barrier to wait for concurrent setup of local services (Tor node, hidden service). */
|
/** A barrier to wait for concurrent setup of local services (Tor node, hidden service). */
|
||||||
final CountDownLatch localServicesLatch = new CountDownLatch(1 /*seed node*/ + nPeers);
|
final CountDownLatch localServicesLatch = new CountDownLatch(1 /*seed node*/ + nPeers);
|
||||||
|
/* A barrier to wait for concurrent reception of preliminary data in peers. */
|
||||||
|
final CountDownLatch prelimDataLatch = new CountDownLatch(nPeers);
|
||||||
|
/* A barrier to wait for concurrent bootstrap of peers. */
|
||||||
|
final CountDownLatch bootstrapLatch = new CountDownLatch(nPeers);
|
||||||
|
|
||||||
|
|
||||||
// Set a security provider to allow key generation.
|
// Set a security provider to allow key generation.
|
||||||
Security.addProvider(new BouncyCastleProvider());
|
Security.addProvider(new BouncyCastleProvider());
|
||||||
|
@ -151,7 +147,8 @@ public class NetworkStressTest {
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
peerPKRings.add(peer.getKeyRing().getPubKeyRing());
|
peerPKRings.add(peer.getKeyRing().getPubKeyRing());
|
||||||
peerNodes.add(peer);
|
peerNodes.add(peer);
|
||||||
peer.start(new PeerServiceListener(localServicesLatch, localServicesFailed));
|
peer.start(new PeerServiceListener(
|
||||||
|
localServicesLatch, localServicesFailed, prelimDataLatch, bootstrapLatch));
|
||||||
}
|
}
|
||||||
print("created peer nodes");
|
print("created peer nodes");
|
||||||
|
|
||||||
|
@ -492,14 +489,20 @@ public class NetworkStressTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PeerServiceListener extends TestSetupListener implements P2PServiceListener {
|
private class PeerServiceListener extends TestSetupListener implements P2PServiceListener {
|
||||||
PeerServiceListener(CountDownLatch localServicesLatch, BooleanProperty localServicesFailed) {
|
private final CountDownLatch prelimDataLatch;
|
||||||
|
private final CountDownLatch bootstrapLatch;
|
||||||
|
|
||||||
|
PeerServiceListener(CountDownLatch localServicesLatch, BooleanProperty localServicesFailed,
|
||||||
|
CountDownLatch prelimDataLatch, CountDownLatch bootstrapLatch) {
|
||||||
super(localServicesLatch, localServicesFailed);
|
super(localServicesLatch, localServicesFailed);
|
||||||
|
this.prelimDataLatch = prelimDataLatch;
|
||||||
|
this.bootstrapLatch = bootstrapLatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRequestingDataCompleted() {
|
public void onRequestingDataCompleted() {
|
||||||
// preliminary data received
|
// preliminary data received
|
||||||
NetworkStressTest.this.prelimDataLatch.countDown();
|
prelimDataLatch.countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -515,7 +518,7 @@ public class NetworkStressTest {
|
||||||
@Override
|
@Override
|
||||||
public void onBootstrapComplete() {
|
public void onBootstrapComplete() {
|
||||||
// peer bootstrapped
|
// peer bootstrapped
|
||||||
NetworkStressTest.this.bootstrapLatch.countDown();
|
bootstrapLatch.countDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue