mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-09-20 21:14:44 -04:00
Send direct messages from all peers to random ones in network stress test
This commit is contained in:
parent
97722a6ecd
commit
b8d49e44b6
1 changed files with 35 additions and 35 deletions
|
@ -29,10 +29,7 @@ import java.io.IOException;
|
||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@ -182,43 +179,46 @@ public class NetworkStressTest {
|
||||||
org.junit.Assert.assertTrue("timed out while waiting for bootstrap",
|
org.junit.Assert.assertTrue("timed out while waiting for bootstrap",
|
||||||
bootstrapLatch.await(30, TimeUnit.SECONDS));
|
bootstrapLatch.await(30, TimeUnit.SECONDS));
|
||||||
|
|
||||||
// Test sending a direct message from peer #0 to peer #1.
|
// Test each peer sending a direct message to another random peer.
|
||||||
|
final int nPeers = peerNodes.size();
|
||||||
BooleanProperty sentDirectFailed = new SimpleBooleanProperty(false);
|
BooleanProperty sentDirectFailed = new SimpleBooleanProperty(false);
|
||||||
final CountDownLatch sentDirectLatch = new CountDownLatch(1);
|
final CountDownLatch sentDirectLatch = new CountDownLatch(nPeers);
|
||||||
final CountDownLatch receivedDirectLatch = new CountDownLatch(1);
|
final CountDownLatch receivedDirectLatch = new CountDownLatch(nPeers);
|
||||||
final int srcPeerIdx = 0;
|
for (final P2PService srcPeer : peerNodes) {
|
||||||
final int dstPeerIdx = 1;
|
final int dstPeerIdx = (int) (Math.random() * nPeers);
|
||||||
final P2PService srcPeer = peerNodes.get(srcPeerIdx);
|
final P2PService dstPeer = peerNodes.get(dstPeerIdx);
|
||||||
final P2PService dstPeer = peerNodes.get(dstPeerIdx);
|
/*System.out.println(
|
||||||
srcPeer.sendEncryptedDirectMessage(dstPeer.getAddress(), peerPKRings.get(dstPeerIdx),
|
"Sending direct message from peer " + srcPeer.getAddress() + " to " + dstPeer.getAddress());*/
|
||||||
new StressTestDirectMessage("test/" + dstPeer.getAddress()), new SendDirectMessageListener() {
|
srcPeer.sendEncryptedDirectMessage(dstPeer.getAddress(), peerPKRings.get(dstPeerIdx),
|
||||||
@Override
|
new StressTestDirectMessage("test/" + dstPeer.getAddress()), new SendDirectMessageListener() {
|
||||||
public void onArrived() {
|
@Override
|
||||||
sentDirectLatch.countDown();
|
public void onArrived() {
|
||||||
}
|
sentDirectLatch.countDown();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFault() {
|
public void onFault() {
|
||||||
sentDirectFailed.set(true);
|
sentDirectFailed.set(true);
|
||||||
sentDirectLatch.countDown();
|
sentDirectLatch.countDown();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
dstPeer.addDecryptedDirectMessageListener((decryptedMsgWithPubKey, peerNodeAddress) -> {
|
dstPeer.addDecryptedDirectMessageListener((decryptedMsgWithPubKey, peerNodeAddress) -> {
|
||||||
if (!(decryptedMsgWithPubKey.message instanceof StressTestDirectMessage))
|
if (!(decryptedMsgWithPubKey.message instanceof StressTestDirectMessage))
|
||||||
return;
|
return;
|
||||||
StressTestDirectMessage directMessage = (StressTestDirectMessage)(decryptedMsgWithPubKey.message);
|
StressTestDirectMessage directMessage = (StressTestDirectMessage) (decryptedMsgWithPubKey.message);
|
||||||
if ((directMessage.getData().equals("test/" + dstPeer.getAddress())))
|
if ((directMessage.getData().equals("test/" + dstPeer.getAddress())))
|
||||||
receivedDirectLatch.countDown();
|
receivedDirectLatch.countDown();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
// Since receiving is completed before sending is reported to be complete,
|
// Since receiving is completed before sending is reported to be complete,
|
||||||
// all receiving checks should end before all sending checks to avoid deadlocking.
|
// all receiving checks should end before all sending checks to avoid deadlocking.
|
||||||
// Wait for peer #1 to complete receiving.
|
// Wait for peers to complete receiving.
|
||||||
org.junit.Assert.assertTrue("timed out while receiving direct message",
|
org.junit.Assert.assertTrue("timed out while receiving direct messages",
|
||||||
receivedDirectLatch.await(30, TimeUnit.SECONDS));
|
receivedDirectLatch.await(30, TimeUnit.SECONDS));
|
||||||
// Wait for peer #0 to complete sending.
|
// Wait for peers to complete sending.
|
||||||
org.junit.Assert.assertTrue("timed out while sending direct message",
|
org.junit.Assert.assertTrue("timed out while sending direct messages",
|
||||||
sentDirectLatch.await(30, TimeUnit.SECONDS));
|
sentDirectLatch.await(30, TimeUnit.SECONDS));
|
||||||
org.junit.Assert.assertFalse("peer failed to send message", sentDirectFailed.get());
|
org.junit.Assert.assertFalse("some peer(s) failed to send a direct message", sentDirectFailed.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Path createTestDataDirectory() throws IOException {
|
private Path createTestDataDirectory() throws IOException {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue