use of org.jgroups.blocks.cs.BaseServer in project JGroups by belaban.
the class ServerUnitTest method testReuseOfConnection.
/**
* A connects to B and B connects to A at the same time. This test makes sure we only have <em>one</em> connection,
* not two, e.g. a spurious connection. Tests http://jira.jboss.com/jira/browse/JGRP-549.<p/>
* Turned concurrent test into a simple sequential test. We're going to replace this code with NIO2 soon anyway...
*/
public void testReuseOfConnection() throws Exception {
for (boolean nio : new boolean[] { false, true }) {
try (BaseServer a = create(nio, 0);
BaseServer b = create(nio, 0)) {
int num_conns;
num_conns = a.getNumConnections();
assert num_conns == 0;
num_conns = b.getNumConnections();
assert num_conns == 0;
Address addr1 = a.localAddress(), addr2 = b.localAddress();
byte[] data = "hello world".getBytes();
send(data, a, addr2);
send(data, b, addr1);
String msg = "A: " + a + "\nB: " + b;
System.out.println(msg);
waitForOpenConns(1, a, b);
// done in a loop because connect() might be non-blocking (NioServer)
connectionEstablished(a, addr2);
connectionEstablished(b, addr1);
}
}
}
use of org.jgroups.blocks.cs.BaseServer in project JGroups by belaban.
the class ServerUnitTest method testSendToAll.
public void testSendToAll() 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;
MyReceiver r1 = new MyReceiver(a, NUM, false);
MyReceiver r2 = new MyReceiver(b, NUM, false);
byte[] data = "hello world".getBytes();
// send uncast to establish connection to s2:
// a.send(b.localAddress(), new byte[1000], 0, 1000);
send(data, a, b.localAddress());
Util.sleep(1000);
a.receiver(r1);
b.receiver(r2);
for (int i = 0; i < NUM; i++) send(data, a, null);
log("sent " + NUM + " msgs");
r2.waitForCompletion(20000);
total_time = r2.stop_time - r2.start_time;
log("number expected=" + r2.getNumExpected() + ", number received=" + r2.getNumReceived() + ", total time=" + total_time + " (" + (double) total_time / r2.getNumReceived() + " ms/msg)");
Assert.assertEquals(r2.getNumExpected(), r2.getNumReceived());
assert r1.getNumReceived() == 0 || r1.getNumReceived() > 0;
}
}
}
use of org.jgroups.blocks.cs.BaseServer in project JGroups by belaban.
the class ServerUnitTest method testSendEmptyData.
public void testSendEmptyData() throws Exception {
for (boolean nio : new boolean[] { false, true }) {
try (BaseServer a = create(nio, 0)) {
byte[] data = new byte[0];
Address myself = a.localAddress();
a.receiver(new ReceiverAdapter() {
});
send(data, a, myself);
}
}
}
use of org.jgroups.blocks.cs.BaseServer in project JGroups by belaban.
the class ServerUnitTest method create.
protected static BaseServer create(boolean nio, int port) {
try {
BaseServer retval = nio ? new NioServer(bind_addr, port).maxSendBuffers(1024) : new TcpServer(bind_addr, port);
retval.usePeerConnections(true);
retval.start();
return retval;
} catch (Exception ex) {
return null;
}
}
use of org.jgroups.blocks.cs.BaseServer in project JGroups by belaban.
the class ServerUnitTest method testConnectionCountOnStop.
public void testConnectionCountOnStop() throws Exception {
for (boolean nio : new boolean[] { false, true }) {
try (BaseServer a = create(nio, 0);
BaseServer b = create(nio, 0)) {
Address addr1 = a.localAddress(), addr2 = b.localAddress();
byte[] data = "hello world".getBytes();
// send to self
send(data, a, addr1);
assert a.getNumConnections() == 0;
// send to other
send(data, a, addr2);
// send to self
send(data, b, addr2);
// send to other
send(data, b, addr1);
System.out.println("A:\n" + a + "\nB:\n" + b);
int num_conns_table1 = a.getNumConnections(), num_conns_table2 = b.getNumConnections();
assert num_conns_table1 == 1 : "A should have 1 connection, but has " + num_conns_table1 + ": " + a;
assert num_conns_table2 == 1 : "B should have 1 connection, but has " + num_conns_table2 + ": " + b;
Util.close(b, a);
waitForOpenConns(0, a, b);
}
}
}
Aggregations