mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-26 16:35:18 -04:00
Remove caching as it has some side effects for failing tests
This commit is contained in:
parent
d062e1dbbf
commit
c1a645500f
1 changed files with 14 additions and 25 deletions
|
@ -26,8 +26,6 @@ import java.io.IOException;
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@ -39,6 +37,7 @@ import net.tomp2p.dht.FuturePut;
|
||||||
import net.tomp2p.dht.FutureRemove;
|
import net.tomp2p.dht.FutureRemove;
|
||||||
import net.tomp2p.dht.PeerBuilderDHT;
|
import net.tomp2p.dht.PeerBuilderDHT;
|
||||||
import net.tomp2p.dht.PeerDHT;
|
import net.tomp2p.dht.PeerDHT;
|
||||||
|
import net.tomp2p.futures.FutureBootstrap;
|
||||||
import net.tomp2p.futures.FutureDirect;
|
import net.tomp2p.futures.FutureDirect;
|
||||||
import net.tomp2p.futures.FutureDiscover;
|
import net.tomp2p.futures.FutureDiscover;
|
||||||
import net.tomp2p.futures.FuturePeerConnection;
|
import net.tomp2p.futures.FuturePeerConnection;
|
||||||
|
@ -102,17 +101,9 @@ public class TomP2PTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If cache is used tests get faster as it doesn't create and bootstrap a new node at every test.
|
|
||||||
// Need to observe if it can have some side effects.
|
|
||||||
// In cached mode I observed more failures, need investigation why but might be a test setup problem.
|
|
||||||
private static final boolean CACHE_CLIENTS = false;
|
|
||||||
|
|
||||||
// Use to stress tests by repeating them
|
// Use to stress tests by repeating them
|
||||||
private static final int STRESS_TEST_COUNT = 1;
|
private static final int STRESS_TEST_COUNT = 1;
|
||||||
|
|
||||||
// need to be static to keep them during tests
|
|
||||||
private final static Map<String, Peer> cachedPeers = new HashMap<>();
|
|
||||||
|
|
||||||
private PeerDHT peer1DHT;
|
private PeerDHT peer1DHT;
|
||||||
private PeerDHT peer2DHT;
|
private PeerDHT peer2DHT;
|
||||||
private int client1Port;
|
private int client1Port;
|
||||||
|
@ -128,13 +119,11 @@ public class TomP2PTests {
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
if (!CACHE_CLIENTS) {
|
|
||||||
if (peer1DHT != null)
|
if (peer1DHT != null)
|
||||||
peer1DHT.shutdown().awaitUninterruptibly();
|
peer1DHT.shutdown().awaitUninterruptibly();
|
||||||
if (peer2DHT != null)
|
if (peer2DHT != null)
|
||||||
peer2DHT.shutdown().awaitUninterruptibly();
|
peer2DHT.shutdown().awaitUninterruptibly();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Repeat(STRESS_TEST_COUNT)
|
@Repeat(STRESS_TEST_COUNT)
|
||||||
|
@ -242,6 +231,7 @@ public class TomP2PTests {
|
||||||
FutureRemove futureRemove = peer2DHT.remove(Number160.createHash("locationKey")).contentKey(contentKey)
|
FutureRemove futureRemove = peer2DHT.remove(Number160.createHash("locationKey")).contentKey(contentKey)
|
||||||
.start();
|
.start();
|
||||||
futureRemove.awaitUninterruptibly();
|
futureRemove.awaitUninterruptibly();
|
||||||
|
futureRemove.awaitListenersUninterruptibly();
|
||||||
|
|
||||||
// We don't test futureRemove.isSuccess() as this API does not fit well to that operation,
|
// We don't test futureRemove.isSuccess() as this API does not fit well to that operation,
|
||||||
// it might change in future to something like foundAndRemoved and notFound
|
// it might change in future to something like foundAndRemoved and notFound
|
||||||
|
@ -305,9 +295,6 @@ public class TomP2PTests {
|
||||||
|
|
||||||
private Peer bootstrapDirectConnection(String clientId, int clientPort) {
|
private Peer bootstrapDirectConnection(String clientId, int clientPort) {
|
||||||
final String id = clientId + clientPort;
|
final String id = clientId + clientPort;
|
||||||
if (CACHE_CLIENTS && cachedPeers.containsKey(id)) {
|
|
||||||
return cachedPeers.get(id);
|
|
||||||
}
|
|
||||||
Peer peer = null;
|
Peer peer = null;
|
||||||
try {
|
try {
|
||||||
peer = new PeerBuilder(Number160.createHash(clientId)).bindings(getBindings())
|
peer = new PeerBuilder(Number160.createHash(clientId)).bindings(getBindings())
|
||||||
|
@ -316,9 +303,18 @@ public class TomP2PTests {
|
||||||
futureDiscover.awaitUninterruptibly();
|
futureDiscover.awaitUninterruptibly();
|
||||||
if (futureDiscover.isSuccess()) {
|
if (futureDiscover.isSuccess()) {
|
||||||
log.info("Discover with direct connection successful. Address = " + futureDiscover.peerAddress());
|
log.info("Discover with direct connection successful. Address = " + futureDiscover.peerAddress());
|
||||||
cachedPeers.put(id, peer);
|
|
||||||
|
FutureBootstrap futureBootstrap = peer.bootstrap().peerAddress(BOOTSTRAP_NODE_ADDRESS).start();
|
||||||
|
futureBootstrap.awaitUninterruptibly();
|
||||||
|
if (futureBootstrap.isSuccess()) {
|
||||||
return peer;
|
return peer;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
log.warn("Bootstrap failed. Reason = " + futureBootstrap.failedReason());
|
||||||
|
peer.shutdown().awaitUninterruptibly();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
log.warn("Discover with direct connection failed. Reason = " + futureDiscover.failedReason());
|
log.warn("Discover with direct connection failed. Reason = " + futureDiscover.failedReason());
|
||||||
peer.shutdown().awaitUninterruptibly();
|
peer.shutdown().awaitUninterruptibly();
|
||||||
|
@ -336,9 +332,6 @@ public class TomP2PTests {
|
||||||
|
|
||||||
private Peer bootstrapWithPortForwarding(String clientId, int clientPort) {
|
private Peer bootstrapWithPortForwarding(String clientId, int clientPort) {
|
||||||
final String id = clientId + clientPort;
|
final String id = clientId + clientPort;
|
||||||
if (CACHE_CLIENTS && cachedPeers.containsKey(id)) {
|
|
||||||
return cachedPeers.get(id);
|
|
||||||
}
|
|
||||||
Peer peer = null;
|
Peer peer = null;
|
||||||
try {
|
try {
|
||||||
peer = new PeerBuilder(Number160.createHash(clientId)).bindings(getBindings()).behindFirewall()
|
peer = new PeerBuilder(Number160.createHash(clientId)).bindings(getBindings()).behindFirewall()
|
||||||
|
@ -348,6 +341,7 @@ public class TomP2PTests {
|
||||||
FutureDiscover futureDiscover = peer.discover().peerAddress(BOOTSTRAP_NODE_ADDRESS).start();
|
FutureDiscover futureDiscover = peer.discover().peerAddress(BOOTSTRAP_NODE_ADDRESS).start();
|
||||||
FutureNAT futureNAT = peerNAT.startSetupPortforwarding(futureDiscover);
|
FutureNAT futureNAT = peerNAT.startSetupPortforwarding(futureDiscover);
|
||||||
futureNAT.awaitUninterruptibly();
|
futureNAT.awaitUninterruptibly();
|
||||||
|
futureNAT.awaitListenersUninterruptibly();
|
||||||
if (futureNAT.isSuccess()) {
|
if (futureNAT.isSuccess()) {
|
||||||
log.info("Automatic port forwarding is setup. Now we do a futureDiscover again. Address = " +
|
log.info("Automatic port forwarding is setup. Now we do a futureDiscover again. Address = " +
|
||||||
futureNAT.peerAddress());
|
futureNAT.peerAddress());
|
||||||
|
@ -356,7 +350,6 @@ public class TomP2PTests {
|
||||||
if (futureDiscover.isSuccess()) {
|
if (futureDiscover.isSuccess()) {
|
||||||
log.info("Discover with automatic port forwarding was successful. Address = " + futureDiscover
|
log.info("Discover with automatic port forwarding was successful. Address = " + futureDiscover
|
||||||
.peerAddress());
|
.peerAddress());
|
||||||
cachedPeers.put(id, peer);
|
|
||||||
return peer;
|
return peer;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -384,9 +377,6 @@ public class TomP2PTests {
|
||||||
|
|
||||||
private Peer bootstrapInRelayMode(String clientId, int clientPort) {
|
private Peer bootstrapInRelayMode(String clientId, int clientPort) {
|
||||||
final String id = clientId + clientPort;
|
final String id = clientId + clientPort;
|
||||||
if (CACHE_CLIENTS && cachedPeers.containsKey(id)) {
|
|
||||||
return cachedPeers.get(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
Peer peer = null;
|
Peer peer = null;
|
||||||
try {
|
try {
|
||||||
|
@ -400,7 +390,6 @@ public class TomP2PTests {
|
||||||
futureRelayNAT.awaitUninterruptibly();
|
futureRelayNAT.awaitUninterruptibly();
|
||||||
if (futureRelayNAT.isSuccess()) {
|
if (futureRelayNAT.isSuccess()) {
|
||||||
log.info("Bootstrap using relay was successful. Address = " + peer.peerAddress());
|
log.info("Bootstrap using relay was successful. Address = " + peer.peerAddress());
|
||||||
cachedPeers.put(id, peer);
|
|
||||||
return peer;
|
return peer;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue