use of org.jgroups.blocks.cs.BaseServer in project JGroups by belaban.
the class ServerUnitTest method testSendNullData.
public void testSendNullData() throws Exception {
for (boolean nio : new boolean[] { false, true }) {
try (BaseServer a = create(nio, 0)) {
Address myself = a.localAddress();
// the test passes if send() doesn't throw an exception
a.send(myself, null, 0, 0);
}
}
}
use of org.jgroups.blocks.cs.BaseServer in project JGroups by belaban.
the class ServerTest method waitForOpenConns.
protected static void waitForOpenConns(int expected, BaseServer... servers) {
for (int i = 0; i < 10; i++) {
boolean all_ok = true;
for (BaseServer server : servers) {
if (server.getNumOpenConnections() != expected) {
all_ok = false;
break;
}
}
if (all_ok)
return;
Util.sleep(500);
}
}
use of org.jgroups.blocks.cs.BaseServer in project JGroups by belaban.
the class ServerUnitTest method testSendToSelf.
public void testSendToSelf() throws Exception {
for (boolean nio : new boolean[] { false, true }) {
try (BaseServer a = create(nio, 0)) {
long NUM = 1000, total_time;
Address myself = a.localAddress();
MyReceiver r = new MyReceiver(a, NUM, false);
byte[] data = "hello world".getBytes();
a.receiver(r);
for (int i = 0; i < NUM; i++) send(data, a, myself);
log("sent " + NUM + " msgs");
r.waitForCompletion(20000);
total_time = r.stop_time - r.start_time;
log("number expected=" + r.getNumExpected() + ", number received=" + r.getNumReceived() + ", total time=" + total_time + " (" + (double) total_time / r.getNumReceived() + " ms/msg)");
Assert.assertEquals(r.getNumExpected(), r.getNumReceived());
}
}
}
use of org.jgroups.blocks.cs.BaseServer in project JGroups by belaban.
the class ServerUnitTest method testSendToOtherGetResponse.
// @Test(invocationCount=100)
public void testSendToOtherGetResponse() throws Exception {
final byte[] data = "hello world".getBytes();
for (boolean nio : new boolean[] { false, true }) {
try (BaseServer a = create(nio, 0);
BaseServer b = create(nio, 0)) {
long NUM = 1000, total_time;
Address other = b.localAddress();
MyReceiver r1 = new MyReceiver(a, NUM, false);
// send response
MyReceiver r2 = new MyReceiver(b, NUM, true);
a.receiver(r1);
b.receiver(r2);
for (int i = 0; i < NUM; i++) send(data, a, other);
System.out.printf("\n\n%s sent %d msgs to %s\n", "A", NUM, "B");
a.flushAll();
// now wait until B has received NUM messages from A
Util.waitUntilTrue(10000, 100, () -> r2.getNumReceived() >= r2.getNumExpected());
// this causes pending responses at B to be sent from B to A
b.flushAll();
Util.waitUntil(10000, 100, () -> r1.getNumReceived() == r1.getNumExpected());
total_time = r1.stop_time - r1.start_time;
System.out.printf("A: expected=%d, received=%d\nB: expected=%d, received=%d, sent=%d\ntotal time=%d (%.2f ms/msg)", r1.getNumExpected(), r1.getNumReceived(), r1.getNumExpected(), r2.getNumReceived(), r2.num_sent.get(), total_time, (double) total_time / r1.getNumReceived());
Assert.assertEquals(r1.getNumReceived(), r1.getNumExpected());
}
}
}
use of org.jgroups.blocks.cs.BaseServer in project JGroups by belaban.
the class ServerUnitTest method testSendToOther.
public void testSendToOther() throws Exception {
for (boolean nio : new boolean[] { false, true }) {
try (BaseServer a = create(nio, 0);
BaseServer b = create(nio, 0)) {
long NUM = 1000, total_time;
Address other = b.localAddress();
MyReceiver r = new MyReceiver(b, NUM, false);
byte[] data = "hello world".getBytes();
b.receiver(r);
for (int i = 0; i < NUM; i++) send(data, a, other);
log("sent " + NUM + " msgs");
r.waitForCompletion(20000);
total_time = r.stop_time - r.start_time;
log("number expected=" + r.getNumExpected() + ", number received=" + r.getNumReceived() + ", total time=" + total_time + " (" + (double) total_time / r.getNumReceived() + " ms/msg)");
Assert.assertEquals(r.getNumExpected(), r.getNumReceived());
}
}
}
Aggregations