use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class UNICAST_ConnectionTests method testMultipleConcurrentResets.
/**
* Tests concurrent reception of multiple messages with a different conn_id (https://issues.jboss.org/browse/JGRP-1347)
*/
@Test(dataProvider = "configProvider")
public void testMultipleConcurrentResets(Class<? extends UNICAST3> unicast) throws Exception {
setup(unicast);
sendAndCheck(a, b_addr, 1, r2);
// now close connection on A unilaterally
System.out.println("==== Closing the connection on A");
removeConnection(u1, b_addr);
r2.clear();
final Protocol ucast = b.getProtocolStack().findProtocol(Util.getUnicastProtocols());
int NUM = 10;
final List<Message> msgs = new ArrayList<>(NUM);
for (int i = 1; i <= NUM; i++) {
Message msg = new BytesMessage(b_addr, i).setSrc(a_addr);
Header hdr = createDataHeader(ucast, 1, (short) 2, true);
msg.putHeader(ucast.getId(), hdr);
msgs.add(msg);
}
Thread[] threads = new Thread[NUM];
final CyclicBarrier barrier = new CyclicBarrier(NUM + 1);
for (int i = 0; i < NUM; i++) {
final int index = i;
threads[i] = new Thread(() -> {
try {
barrier.await();
ucast.up(msgs.get(index));
} catch (Exception e) {
e.printStackTrace();
}
});
threads[i].start();
}
barrier.await();
for (Thread thread : threads) thread.join();
List<Integer> list = r2.getMessages();
System.out.println("list = " + print(list));
assert list.size() == 1 : "list must have 1 element but has " + list.size() + ": " + print(list);
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class UNICAST_DropFirstAndLastTest method testFirstMessageDropped.
/**
* A sends unicast message 1 to B, but we drop message 1. The code in
* https://issues.jboss.org/browse/JGRP-1563 now needs to make sure message 1 is retransmitted to B
* within a short time period, and we don't have to rely on the stable task to kick in.
*/
@Test(dataProvider = "configProvider")
public void testFirstMessageDropped(Class<? extends UNICAST3> unicast_class) throws Exception {
setup(unicast_class);
System.out.println("**** closing all connections ****");
// close all connections, so we can start from scratch and send message A1 to B
for (JChannel ch : Arrays.asList(a, b)) {
Protocol unicast = ch.getProtocolStack().findProtocol(Util.getUnicastProtocols());
removeAllConnections(unicast);
}
setLevel("trace", a, b);
System.out.println("--> A sending first message to B (dropped before it reaches B)");
// drops the next unicast
discard.dropDownUnicasts(1);
a.send(new BytesMessage(b.getAddress(), 1));
List<Integer> msgs = rb.list();
try {
Util.waitUntilListHasSize(msgs, 1, 500000, 500);
} catch (AssertionError err) {
printConnectionTables(a, b);
throw err;
}
System.out.println("list=" + msgs);
printConnectionTables(a, b);
// assert ((UNICAST2)a.getProtocolStack().findProtocol(UNICAST2.class)).connectionEstablished(b.getAddress());
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class UNICAST_RetransmitTest method setLevel.
protected static void setLevel(String level, JChannel... channels) {
for (JChannel ch : channels) {
Protocol prot = ch.getProtocolStack().findProtocol(UNICAST3.class);
prot.level(level);
}
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class DNSDiscoveryTester method runTestAndCheckIfViewWasReceived.
public boolean runTestAndCheckIfViewWasReceived(String dnsQuery, String recordType) throws Exception {
List<JChannel> channels = new ArrayList<>();
CountDownLatch waitForViewToForm = new CountDownLatch(1);
for (int i = 0; i < numberOfTestedInstances; ++i) {
DNS_PING ping = new DNS_PING();
ping.dns_resolver = dnsResolverBuilder.build();
ping.dns_query = dnsQuery;
ping.dns_record_type = recordType;
ping.dns_address = "fake.com";
Protocol[] protocols = { new TCP().setBindAddress(InetAddress.getLoopbackAddress()).setBindPort(portStart).setPortRange(1), ping, new NAKACK2(), new UNICAST3(), new STABLE(), new GMS().setJoinTimeout(timeout) };
JChannel c = new JChannel(protocols).name(String.valueOf(i + 1));
channels.add(c);
c.setReceiver(new Receiver() {
@Override
public void viewAccepted(View view) {
if (view.getMembers().size() == numberOfTestedInstances) {
waitForViewToForm.countDown();
}
}
});
c.connect("TEST");
}
boolean viewReceived = waitForViewToForm.await(timeout, unit);
channels.forEach(JChannel::close);
return viewReceived;
}
use of org.jgroups.stack.Protocol in project JGroups by belaban.
the class ConfiguratorTest method testRemovalOfBottom.
public void testRemovalOfBottom() throws Exception {
Protocol prot = stack.removeProtocol("UDP");
assert prot != null;
List<Protocol> protocols = stack.getProtocols();
Assert.assertEquals(5, protocols.size());
assert protocols.get(protocols.size() - 1).getName().endsWith("PING");
}
Aggregations