mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-26 16:35:18 -04:00
Finished tests for localhost case
This commit is contained in:
parent
afe7ec295b
commit
25be5bdbe1
1 changed files with 78 additions and 79 deletions
|
@ -64,7 +64,7 @@ import static org.junit.Assert.*;
|
||||||
* In the configure method and the connectionType you can define your test scenario further.
|
* In the configure method and the connectionType you can define your test scenario further.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//@Ignore
|
@Ignore
|
||||||
public class TomP2PTests {
|
public class TomP2PTests {
|
||||||
private static final Logger log = LoggerFactory.getLogger(TomP2PTests.class);
|
private static final Logger log = LoggerFactory.getLogger(TomP2PTests.class);
|
||||||
|
|
||||||
|
@ -87,13 +87,14 @@ public class TomP2PTests {
|
||||||
private final static int CLIENT_2_PORT = new Ports().tcpPort();
|
private final static int CLIENT_2_PORT = new Ports().tcpPort();
|
||||||
|
|
||||||
// If you want to test in one specific connection mode define it directly, otherwise use UNKNOWN
|
// If you want to test in one specific connection mode define it directly, otherwise use UNKNOWN
|
||||||
private final ConnectionType connectionType = ConnectionType.DIRECT;
|
private final ConnectionType forcedConnectionType = ConnectionType.DIRECT;
|
||||||
|
private ConnectionType resolvedConnectionType;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void configure() {
|
public void configure() {
|
||||||
// Typically you run the seed node in localhost to test direct connection.
|
// Typically you run the seed node in localhost to test direct connection.
|
||||||
// If you have a setup where you are not behind a router you can also use a WAN side seed node.
|
// If you have a setup where you are not behind a router you can also use a WAN side seed node.
|
||||||
if (connectionType == ConnectionType.DIRECT) {
|
if (forcedConnectionType == ConnectionType.DIRECT) {
|
||||||
seedId = "localhost";
|
seedId = "localhost";
|
||||||
seedIP = "127.0.0.1";
|
seedIP = "127.0.0.1";
|
||||||
seedPort = 5000;
|
seedPort = 5000;
|
||||||
|
@ -188,30 +189,29 @@ public class TomP2PTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bootstrapInUnknownMode() throws Exception {
|
public void bootstrapInUnknownMode() throws Exception {
|
||||||
if (connectionType == ConnectionType.UNKNOWN)
|
if (forcedConnectionType == ConnectionType.UNKNOWN)
|
||||||
assertNotNull(bootstrapInUnknownMode("node_1", CLIENT_1_PORT));
|
assertNotNull(bootstrapInUnknownMode("node_1", CLIENT_1_PORT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBootstrapDirectConnection() throws Exception {
|
public void testBootstrapDirectConnection() throws Exception {
|
||||||
if (connectionType == ConnectionType.DIRECT)
|
if (forcedConnectionType == ConnectionType.DIRECT)
|
||||||
assertNotNull(bootstrapDirectConnection("node_1", CLIENT_1_PORT));
|
assertNotNull(bootstrapDirectConnection("node_1", CLIENT_1_PORT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBootstrapWithPortForwarding() throws Exception {
|
public void testBootstrapWithPortForwarding() throws Exception {
|
||||||
if (connectionType == ConnectionType.NAT)
|
if (forcedConnectionType == ConnectionType.NAT)
|
||||||
assertNotNull(bootstrapWithPortForwarding("node_1", CLIENT_1_PORT));
|
assertNotNull(bootstrapWithPortForwarding("node_1", CLIENT_1_PORT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBootstrapInRelayMode() throws Exception {
|
public void testBootstrapInRelayMode() throws Exception {
|
||||||
if (connectionType == ConnectionType.RELAY)
|
if (forcedConnectionType == ConnectionType.RELAY)
|
||||||
assertNotNull(bootstrapInRelayMode("node_1", CLIENT_1_PORT));
|
assertNotNull(bootstrapInRelayMode("node_1", CLIENT_1_PORT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
// @Ignore
|
|
||||||
public void testPut() throws Exception {
|
public void testPut() throws Exception {
|
||||||
peer1DHT = getDHTPeer("node_1", CLIENT_1_PORT);
|
peer1DHT = getDHTPeer("node_1", CLIENT_1_PORT);
|
||||||
FuturePut futurePut = peer1DHT.put(Number160.createHash("key")).data(new Data("hallo")).start();
|
FuturePut futurePut = peer1DHT.put(Number160.createHash("key")).data(new Data("hallo")).start();
|
||||||
|
@ -221,7 +221,6 @@ public class TomP2PTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
// @Ignore
|
|
||||||
public void testPutGet() throws Exception {
|
public void testPutGet() throws Exception {
|
||||||
peer1DHT = getDHTPeer("node_1", CLIENT_1_PORT);
|
peer1DHT = getDHTPeer("node_1", CLIENT_1_PORT);
|
||||||
FuturePut futurePut = peer1DHT.put(Number160.createHash("key")).data(new Data("hallo")).start();
|
FuturePut futurePut = peer1DHT.put(Number160.createHash("key")).data(new Data("hallo")).start();
|
||||||
|
@ -229,6 +228,7 @@ public class TomP2PTests {
|
||||||
if (!ignoreSuccessTests)
|
if (!ignoreSuccessTests)
|
||||||
assertTrue(futurePut.isSuccess());
|
assertTrue(futurePut.isSuccess());
|
||||||
|
|
||||||
|
|
||||||
peer2DHT = getDHTPeer("node_2", CLIENT_2_PORT);
|
peer2DHT = getDHTPeer("node_2", CLIENT_2_PORT);
|
||||||
FutureGet futureGet = peer2DHT.get(Number160.createHash("key")).start();
|
FutureGet futureGet = peer2DHT.get(Number160.createHash("key")).start();
|
||||||
futureGet.awaitUninterruptibly();
|
futureGet.awaitUninterruptibly();
|
||||||
|
@ -238,11 +238,22 @@ public class TomP2PTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
//@Ignore
|
public void testAdd() throws Exception {
|
||||||
|
peer1DHT = getDHTPeer("node_1", CLIENT_1_PORT);
|
||||||
|
FuturePut futurePut1 = peer1DHT.add(Number160.createHash("locationKey")).data(new Data("hallo1")).start();
|
||||||
|
futurePut1.awaitUninterruptibly();
|
||||||
|
if (!ignoreSuccessTests)
|
||||||
|
assertTrue(futurePut1.isSuccess());
|
||||||
|
|
||||||
|
FuturePut futurePut2 = peer1DHT.add(Number160.createHash("locationKey")).data(new Data("hallo2")).start();
|
||||||
|
futurePut2.awaitUninterruptibly();
|
||||||
|
if (!ignoreSuccessTests)
|
||||||
|
assertTrue(futurePut2.isSuccess());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAddGet() throws Exception {
|
public void testAddGet() throws Exception {
|
||||||
peer1DHT = getDHTPeer("node_1", CLIENT_1_PORT);
|
peer1DHT = getDHTPeer("node_1", CLIENT_1_PORT);
|
||||||
peer2DHT = getDHTPeer("node_2", CLIENT_2_PORT);
|
|
||||||
|
|
||||||
FuturePut futurePut1 = peer1DHT.add(Number160.createHash("locationKey")).data(new Data("hallo1")).start();
|
FuturePut futurePut1 = peer1DHT.add(Number160.createHash("locationKey")).data(new Data("hallo1")).start();
|
||||||
futurePut1.awaitUninterruptibly();
|
futurePut1.awaitUninterruptibly();
|
||||||
if (!ignoreSuccessTests)
|
if (!ignoreSuccessTests)
|
||||||
|
@ -253,6 +264,8 @@ public class TomP2PTests {
|
||||||
if (!ignoreSuccessTests)
|
if (!ignoreSuccessTests)
|
||||||
assertTrue(futurePut2.isSuccess());
|
assertTrue(futurePut2.isSuccess());
|
||||||
|
|
||||||
|
|
||||||
|
peer2DHT = getDHTPeer("node_2", CLIENT_2_PORT);
|
||||||
FutureGet futureGet = peer2DHT.get(Number160.createHash("locationKey")).all().start();
|
FutureGet futureGet = peer2DHT.get(Number160.createHash("locationKey")).all().start();
|
||||||
futureGet.awaitUninterruptibly();
|
futureGet.awaitUninterruptibly();
|
||||||
if (!ignoreSuccessTests)
|
if (!ignoreSuccessTests)
|
||||||
|
@ -264,11 +277,8 @@ public class TomP2PTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void testAddRemove() throws Exception {
|
public void testAddRemove() throws Exception {
|
||||||
peer1DHT = getDHTPeer("node_1", CLIENT_1_PORT);
|
peer1DHT = getDHTPeer("node_1", CLIENT_1_PORT);
|
||||||
peer2DHT = getDHTPeer("node_2", CLIENT_2_PORT);
|
|
||||||
|
|
||||||
FuturePut futurePut1 = peer1DHT.add(Number160.createHash("locationKey")).data(new Data("hallo1")).start();
|
FuturePut futurePut1 = peer1DHT.add(Number160.createHash("locationKey")).data(new Data("hallo1")).start();
|
||||||
futurePut1.awaitUninterruptibly();
|
futurePut1.awaitUninterruptibly();
|
||||||
if (!ignoreSuccessTests)
|
if (!ignoreSuccessTests)
|
||||||
|
@ -279,10 +289,11 @@ public class TomP2PTests {
|
||||||
if (!ignoreSuccessTests)
|
if (!ignoreSuccessTests)
|
||||||
assertTrue(futurePut2.isSuccess());
|
assertTrue(futurePut2.isSuccess());
|
||||||
|
|
||||||
|
|
||||||
|
peer2DHT = getDHTPeer("node_2", CLIENT_2_PORT);
|
||||||
Number160 contentKey = new Data("hallo1").hash();
|
Number160 contentKey = new Data("hallo1").hash();
|
||||||
FutureRemove futureRemove = peer2DHT.remove(Number160.createHash("locationKey")).contentKey(contentKey).start();
|
FutureRemove futureRemove = peer2DHT.remove(Number160.createHash("locationKey")).contentKey(contentKey).start();
|
||||||
futureRemove.awaitUninterruptibly();
|
futureRemove.awaitUninterruptibly();
|
||||||
|
|
||||||
if (!ignoreSuccessTests)
|
if (!ignoreSuccessTests)
|
||||||
assertTrue(futureRemove.isSuccess());
|
assertTrue(futureRemove.isSuccess());
|
||||||
|
|
||||||
|
@ -295,31 +306,14 @@ public class TomP2PTests {
|
||||||
assertTrue(futureGet.dataMap().values().size() == 1);
|
assertTrue(futureGet.dataMap().values().size() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Ignore
|
|
||||||
public void testDHT2Servers() throws Exception {
|
|
||||||
peer1DHT = getDHTPeer("node_1", CLIENT_1_PORT, SEED_ID_WAN_1, SEED_IP_WAN_1, SEED_PORT_WAN_1);
|
|
||||||
peer2DHT = getDHTPeer("node_2", CLIENT_2_PORT, SEED_ID_WAN_2, SEED_IP_WAN_2, SEED_PORT_WAN_2);
|
|
||||||
|
|
||||||
FuturePut futurePut = peer1DHT.put(Number160.createHash("key")).data(new Data("hallo")).start();
|
// The sendDirect operation fails in port forwarding mode because most routers does not support NAT reflections.
|
||||||
futurePut.awaitUninterruptibly();
|
// So if both clients are behind NAT they cannot send direct message to each other.
|
||||||
if (!ignoreSuccessTests)
|
|
||||||
assertTrue(futurePut.isSuccess());
|
|
||||||
|
|
||||||
FutureGet futureGet = peer2DHT.get(Number160.createHash("key")).start();
|
|
||||||
futureGet.awaitUninterruptibly();
|
|
||||||
if (!ignoreSuccessTests)
|
|
||||||
assertTrue(futureGet.isSuccess());
|
|
||||||
assertEquals("hallo", futureGet.data().object());
|
|
||||||
}
|
|
||||||
|
|
||||||
// That test fails in port forwarding mode because most routers does not support NAT reflections.
|
|
||||||
// So if both clients are behind NAT they cannot send direct message to the other.
|
|
||||||
// That will probably be fixed in a future version of TomP2P
|
// That will probably be fixed in a future version of TomP2P
|
||||||
// In relay mode the test should succeed
|
// In relay mode the test succeeds
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void testSendDirectRelay() throws Exception {
|
public void testSendDirectRelay() throws Exception {
|
||||||
|
if (forcedConnectionType == ConnectionType.RELAY || resolvedConnectionType == ConnectionType.RELAY) {
|
||||||
peer1DHT = getDHTPeer("node_1", CLIENT_1_PORT);
|
peer1DHT = getDHTPeer("node_1", CLIENT_1_PORT);
|
||||||
peer2DHT = getDHTPeer("node_2", CLIENT_2_PORT);
|
peer2DHT = getDHTPeer("node_2", CLIENT_2_PORT);
|
||||||
|
|
||||||
|
@ -331,7 +325,8 @@ public class TomP2PTests {
|
||||||
result.append(String.valueOf(request));
|
result.append(String.valueOf(request));
|
||||||
return "world";
|
return "world";
|
||||||
});
|
});
|
||||||
FuturePeerConnection futurePeerConnection = peer1DHT.peer().createPeerConnection(peer2DHT.peer().peerAddress(),
|
FuturePeerConnection futurePeerConnection = peer1DHT.peer().createPeerConnection(peer2DHT.peer()
|
||||||
|
.peerAddress(),
|
||||||
500);
|
500);
|
||||||
FutureDirect futureDirect = peer1DHT.peer().sendDirect(futurePeerConnection).object("hallo").start();
|
FutureDirect futureDirect = peer1DHT.peer().sendDirect(futurePeerConnection).object("hallo").start();
|
||||||
futureDirect.awaitUninterruptibly();
|
futureDirect.awaitUninterruptibly();
|
||||||
|
@ -345,11 +340,13 @@ public class TomP2PTests {
|
||||||
assertTrue(futureDirect.isSuccess());
|
assertTrue(futureDirect.isSuccess());
|
||||||
//assertEquals("pong", futureDirect.object());
|
//assertEquals("pong", futureDirect.object());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// That test should succeed in port forwarding as we use the server seed node as receiver
|
// That test should succeed in port forwarding as we use the server seed node as receiver.
|
||||||
|
// A node can send a message to another peer which is not in the same LAN.
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void testSendDirectPortForwarding() throws Exception {
|
public void testSendDirectPortForwarding() throws Exception {
|
||||||
|
if (forcedConnectionType == ConnectionType.NAT || resolvedConnectionType == ConnectionType.NAT) {
|
||||||
peer1DHT = getDHTPeer("node_1", CLIENT_1_PORT);
|
peer1DHT = getDHTPeer("node_1", CLIENT_1_PORT);
|
||||||
PeerAddress reachablePeerAddress = new PeerAddress(Number160.createHash(seedId), seedIP, seedPort,
|
PeerAddress reachablePeerAddress = new PeerAddress(Number160.createHash(seedId), seedIP, seedPort,
|
||||||
seedPort);
|
seedPort);
|
||||||
|
@ -360,6 +357,7 @@ public class TomP2PTests {
|
||||||
assertTrue(futureDirect.isSuccess());
|
assertTrue(futureDirect.isSuccess());
|
||||||
//assertEquals("pong", futureDirect.object());
|
//assertEquals("pong", futureDirect.object());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -505,14 +503,17 @@ public class TomP2PTests {
|
||||||
|
|
||||||
private Peer bootstrapInUnknownMode(String clientId, int clientPort, String seedNodeId,
|
private Peer bootstrapInUnknownMode(String clientId, int clientPort, String seedNodeId,
|
||||||
String seedNodeIP, int seedNodePort) {
|
String seedNodeIP, int seedNodePort) {
|
||||||
|
resolvedConnectionType = ConnectionType.DIRECT;
|
||||||
Peer peer = bootstrapDirectConnection(clientId, clientPort, seedNodeId, seedNodeIP, seedNodePort);
|
Peer peer = bootstrapDirectConnection(clientId, clientPort, seedNodeId, seedNodeIP, seedNodePort);
|
||||||
if (peer != null)
|
if (peer != null)
|
||||||
return peer;
|
return peer;
|
||||||
|
|
||||||
|
resolvedConnectionType = ConnectionType.NAT;
|
||||||
peer = bootstrapWithPortForwarding(clientId, clientPort, seedNodeId, seedNodeIP, seedNodePort);
|
peer = bootstrapWithPortForwarding(clientId, clientPort, seedNodeId, seedNodeIP, seedNodePort);
|
||||||
if (peer != null)
|
if (peer != null)
|
||||||
return peer;
|
return peer;
|
||||||
|
|
||||||
|
resolvedConnectionType = ConnectionType.RELAY;
|
||||||
peer = bootstrapInRelayMode(clientId, clientPort, seedNodeId, seedNodeIP, seedNodePort);
|
peer = bootstrapInRelayMode(clientId, clientPort, seedNodeId, seedNodeIP, seedNodePort);
|
||||||
if (peer != null)
|
if (peer != null)
|
||||||
return peer;
|
return peer;
|
||||||
|
@ -522,6 +523,7 @@ public class TomP2PTests {
|
||||||
"seedNodeIP= " + seedNodeIP +
|
"seedNodeIP= " + seedNodeIP +
|
||||||
"seedNodePort= " + seedNodePort);
|
"seedNodePort= " + seedNodePort);
|
||||||
|
|
||||||
|
resolvedConnectionType = null;
|
||||||
return peer;
|
return peer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -532,27 +534,24 @@ public class TomP2PTests {
|
||||||
private PeerDHT getDHTPeer(String clientId, int clientPort, String seedNodeId,
|
private PeerDHT getDHTPeer(String clientId, int clientPort, String seedNodeId,
|
||||||
String seedNodeIP, int seedNodePort) {
|
String seedNodeIP, int seedNodePort) {
|
||||||
Peer peer;
|
Peer peer;
|
||||||
if (connectionType == ConnectionType.DIRECT) {
|
if (forcedConnectionType == ConnectionType.DIRECT) {
|
||||||
peer = bootstrapDirectConnection(clientId, clientPort, seedNodeId, seedNodeIP, seedNodePort);
|
peer = bootstrapDirectConnection(clientId, clientPort, seedNodeId, seedNodeIP, seedNodePort);
|
||||||
}
|
}
|
||||||
else if (connectionType == ConnectionType.NAT) {
|
else if (forcedConnectionType == ConnectionType.NAT) {
|
||||||
peer = bootstrapWithPortForwarding(clientId, clientPort, seedNodeId, seedNodeIP, seedNodePort);
|
peer = bootstrapWithPortForwarding(clientId, clientPort, seedNodeId, seedNodeIP, seedNodePort);
|
||||||
}
|
}
|
||||||
else if (connectionType == ConnectionType.RELAY) {
|
else if (forcedConnectionType == ConnectionType.RELAY) {
|
||||||
peer = bootstrapInRelayMode(clientId, clientPort, seedNodeId, seedNodeIP, seedNodePort);
|
peer = bootstrapInRelayMode(clientId, clientPort, seedNodeId, seedNodeIP, seedNodePort);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
peer = bootstrapDirectConnection(clientId, clientPort, seedNodeId, seedNodeIP, seedNodePort);
|
peer = bootstrapInUnknownMode(clientId, clientPort, seedNodeId, seedNodeIP, seedNodePort);
|
||||||
if (peer == null)
|
}
|
||||||
peer = bootstrapWithPortForwarding(clientId, clientPort, seedNodeId, seedNodeIP, seedNodePort);
|
|
||||||
if (peer == null)
|
|
||||||
peer = bootstrapInRelayMode(clientId, clientPort, seedNodeId, seedNodeIP, seedNodePort);
|
|
||||||
if (peer == null)
|
if (peer == null)
|
||||||
Assert.fail("Bootstrapping in all modes failed. Check if the seed node is running. " +
|
Assert.fail("Bootstrapping in all modes failed. Check if the seed node is running. " +
|
||||||
"seedNodeId= " + seedNodeId +
|
"seedNodeId= " + seedNodeId +
|
||||||
"seedNodeIP= " + seedNodeIP +
|
"seedNodeIP= " + seedNodeIP +
|
||||||
"seedNodePort= " + seedNodePort);
|
"seedNodePort= " + seedNodePort);
|
||||||
}
|
|
||||||
|
|
||||||
return new PeerBuilderDHT(peer).start();
|
return new PeerBuilderDHT(peer).start();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue