Fixed issues with PING for local tests
This commit is contained in:
parent
b48886376b
commit
5e8e475747
|
@ -78,12 +78,10 @@ class PingPongLocalTest extends BaseTest {
|
||||||
|
|
||||||
// ----
|
// ----
|
||||||
|
|
||||||
Client client = new Client();
|
Client client = new Client(configuration);
|
||||||
addEndPoint(client);
|
addEndPoint(client);
|
||||||
final Listeners listeners1 = client.listeners();
|
final Listeners listeners1 = client.listeners();
|
||||||
listeners1.add(new Listener.OnConnected<Connection>() {
|
listeners1.add(new Listener.OnConnected<Connection>() {
|
||||||
AtomicInteger check = new AtomicInteger(0);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
void connected(Connection connection) {
|
void connected(Connection connection) {
|
||||||
|
@ -95,8 +93,6 @@ class PingPongLocalTest extends BaseTest {
|
||||||
});
|
});
|
||||||
|
|
||||||
listeners1.add(new Listener.OnError<Connection>() {
|
listeners1.add(new Listener.OnError<Connection>() {
|
||||||
AtomicInteger check = new AtomicInteger(0);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
void error(Connection connection, Throwable throwable) {
|
void error(Connection connection, Throwable throwable) {
|
||||||
|
|
|
@ -18,6 +18,7 @@ package dorkbox.network;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -31,6 +32,36 @@ class PingTest extends BaseTest {
|
||||||
|
|
||||||
private volatile int response = -1;
|
private volatile int response = -1;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public
|
||||||
|
void pingLocal() throws SecurityException, IOException {
|
||||||
|
this.response = -1;
|
||||||
|
|
||||||
|
Server server = new Server();
|
||||||
|
addEndPoint(server);
|
||||||
|
server.bind(false);
|
||||||
|
|
||||||
|
// ----
|
||||||
|
|
||||||
|
Client client = new Client();
|
||||||
|
addEndPoint(client);
|
||||||
|
|
||||||
|
client.connect(5000);
|
||||||
|
|
||||||
|
System.err.println("Testing LOCAL ping");
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
this.response = client.send()
|
||||||
|
.ping()
|
||||||
|
.getResponse();
|
||||||
|
System.err.println("Ping: " + this.response);
|
||||||
|
}
|
||||||
|
|
||||||
|
stopEndPoints();
|
||||||
|
if (this.response == -1) {
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ping prefers the following order: UDP, TCP
|
// ping prefers the following order: UDP, TCP
|
||||||
@Test
|
@Test
|
||||||
public
|
public
|
||||||
|
@ -66,6 +97,57 @@ class PingTest extends BaseTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public
|
||||||
|
void pingLocal_testListeners1() throws SecurityException, IOException {
|
||||||
|
this.response = -1;
|
||||||
|
|
||||||
|
Server server = new Server();
|
||||||
|
addEndPoint(server);
|
||||||
|
server.bind(false);
|
||||||
|
|
||||||
|
// ----
|
||||||
|
|
||||||
|
Client client = new Client();
|
||||||
|
addEndPoint(client);
|
||||||
|
|
||||||
|
client.connect(5000);
|
||||||
|
|
||||||
|
System.err.println("Testing LOCAL ping with multi callback");
|
||||||
|
|
||||||
|
final PingListener<Connection> pingListener = new PingListener<Connection>() {
|
||||||
|
AtomicInteger count = new AtomicInteger();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public
|
||||||
|
void response(Connection connection, int pingResponseTime) {
|
||||||
|
System.err.println("Ping: " + pingResponseTime);
|
||||||
|
|
||||||
|
if (this.count.incrementAndGet() < 10) {
|
||||||
|
connection.send()
|
||||||
|
.ping()
|
||||||
|
.add(this);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PingTest.this.response = pingResponseTime;
|
||||||
|
stopEndPoints();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// alternate way to register for the receipt of a one-off ping response
|
||||||
|
// doesn't matter how many times this is called. If there is a PING waiting, then it's overwritten
|
||||||
|
Ping ping = client.send()
|
||||||
|
.ping();
|
||||||
|
ping.add(pingListener);
|
||||||
|
|
||||||
|
waitForThreads();
|
||||||
|
|
||||||
|
if (this.response == -1) {
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public
|
public
|
||||||
void pingTCP_testListeners1() throws SecurityException, IOException {
|
void pingTCP_testListeners1() throws SecurityException, IOException {
|
||||||
|
@ -89,14 +171,14 @@ class PingTest extends BaseTest {
|
||||||
System.err.println("Testing TCP ping with multi callback");
|
System.err.println("Testing TCP ping with multi callback");
|
||||||
|
|
||||||
final PingListener<Connection> pingListener = new PingListener<Connection>() {
|
final PingListener<Connection> pingListener = new PingListener<Connection>() {
|
||||||
volatile int count = 0;
|
AtomicInteger count = new AtomicInteger();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
void response(Connection connection, int pingResponseTime) {
|
void response(Connection connection, int pingResponseTime) {
|
||||||
System.err.println("Ping: " + pingResponseTime);
|
System.err.println("Ping: " + pingResponseTime);
|
||||||
|
|
||||||
if (this.count++ < 10) {
|
if (this.count.incrementAndGet() < 10) {
|
||||||
connection.send()
|
connection.send()
|
||||||
.ping()
|
.ping()
|
||||||
.add(this);
|
.add(this);
|
||||||
|
@ -121,6 +203,47 @@ class PingTest extends BaseTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public
|
||||||
|
void pingLocal_testListeners2() throws SecurityException, IOException {
|
||||||
|
this.response = -1;
|
||||||
|
|
||||||
|
Server server = new Server();
|
||||||
|
addEndPoint(server);
|
||||||
|
server.bind(false);
|
||||||
|
|
||||||
|
// ----
|
||||||
|
|
||||||
|
Client client = new Client();
|
||||||
|
addEndPoint(client);
|
||||||
|
|
||||||
|
client.connect(5000);
|
||||||
|
|
||||||
|
System.err.println("Testing TCP ping with single callback");
|
||||||
|
|
||||||
|
final PingListener<Connection> pingListener = new PingListener<Connection>() {
|
||||||
|
@Override
|
||||||
|
public
|
||||||
|
void response(Connection connection, int pingResponseTime) {
|
||||||
|
System.err.println("Ping: " + pingResponseTime);
|
||||||
|
PingTest.this.response = pingResponseTime;
|
||||||
|
stopEndPoints();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// alternate way to register for the receipt of a one-off ping response
|
||||||
|
// doesn't matter how many times this is called. If there is a PING waiting, then it's overwritten
|
||||||
|
Ping ping = client.send()
|
||||||
|
.ping();
|
||||||
|
ping.add(pingListener);
|
||||||
|
|
||||||
|
waitForThreads();
|
||||||
|
if (this.response == -1) {
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public
|
public
|
||||||
void pingTCP_testListeners2() throws SecurityException, IOException {
|
void pingTCP_testListeners2() throws SecurityException, IOException {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user