use of org.jgroups.protocols.pbcast.STABLE 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.protocols.pbcast.STABLE in project JGroups by belaban.
the class STABLE_Test method testStableWithDontLoopback.
public void testStableWithDontLoopback() throws Exception {
byte[] payload = new byte[5000];
for (int i = 0; i < 10; i++) {
Message msg = new BytesMessage(null, payload).setFlag(Message.TransientFlag.DONT_LOOPBACK);
b.send(msg);
// prevents batches, which trigger STABLE msgs in non-10000 increments
Util.sleep(200);
}
Util.waitUntil(5000, 500, () -> Stream.of(r1, r3).allMatch(r -> r.size() == 10));
assert r2.size() == 0;
Util.waitUntilTrue(5000, 500, () -> Stream.of(a, b, c).map(c -> ((NAKACK2) c.getProtocolStack().findProtocol(NAKACK2.class)).getWindow(b.getAddress())).allMatch(t -> t.getHighestReceived() == 10 && t.getHighestDelivered() == 10 && t.getLow() == 10));
for (JChannel ch : List.of(a, b, c)) {
NAKACK2 n = ch.getProtocolStack().findProtocol(NAKACK2.class);
Table<Message> t = n.getWindow(b.getAddress());
assert t.getHighestReceived() == 10 && t.getHighestDelivered() == 10 && t.getLow() == 10 : String.format("table for %s is %s (low is probably 0)", ch.getName(), t);
}
}
use of org.jgroups.protocols.pbcast.STABLE in project JGroups by belaban.
the class STABLE_Test method create.
protected static JChannel create(String name) throws Exception {
JChannel ch = new JChannel(Util.getTestStack()).name(name);
STABLE stable = ch.getProtocolStack().findProtocol(STABLE.class);
// disabled periodical stable
stable.setDesiredAverageGossip(0).setMaxBytes(10000);
ch.getProtocolStack().getTransport().getDiagnosticsHandler().setEnabled(true);
return ch;
}
use of org.jgroups.protocols.pbcast.STABLE in project JGroups by belaban.
the class TLSTest method create.
private JChannel create(String name) throws Exception {
TCP transport = new TCP();
transport.setBindAddress(InetAddress.getLoopbackAddress());
transport.setBindPort(9600);
transport.setSocketFactory(sslContexts.containsKey(name) ? new DefaultSocketFactory(sslContexts.get(name)) : new DefaultSocketFactory());
TCPPING ping = new TCPPING();
ping.setInitialHosts2(Collections.singletonList(new IpAddress(transport.getBindAddress(), transport.getBindPort())));
return new JChannel(transport, ping, new NAKACK2(), new UNICAST3(), new STABLE(), new GMS()).name(name);
}
use of org.jgroups.protocols.pbcast.STABLE in project JGroups by belaban.
the class GMS_MergeTest method _testMergeAsymmetricPartitions.
/**
* Tests the merge of the following partitions:
* <ul>
* <li>A: {B, A, C}
* <li>B: {B, C}
* <li>C: {B, C}
* </ol>
* JIRA: https://jira.jboss.org/jira/browse/JGRP-1031
* @throws Exception
*/
static void _testMergeAsymmetricPartitions(boolean use_flush_props, String cluster_name) throws Exception {
JChannel[] channels = null;
MyReceiver[] receivers;
final int NUM = 10;
try {
// use simple IDs for UUIDs, so sorting on merge will NOT change the view order
channels = create(use_flush_props, true, cluster_name, "B", "A", "C");
receivers = new MyReceiver[channels.length];
for (int i = 0; i < channels.length; i++) {
receivers[i] = new MyReceiver(channels[i].getName());
channels[i].setReceiver(receivers[i]);
}
JChannel a = findChannel("A", channels), b = findChannel("B", channels), c = findChannel("C", channels);
print(channels);
View view = channels[channels.length - 1].getView();
assert view.size() == channels.length : "view is " + view;
System.out.println("sending " + NUM + " msgs:");
for (int i = 0; i < NUM; i++) for (JChannel ch : channels) ch.send(null, "Number #" + i + " from " + ch.getAddress());
waitForNumMessages(NUM * channels.length, 10000, 1000, receivers);
checkMessages(NUM * channels.length, receivers);
System.out.println("\ncreating partitions: ");
applyView(channels, "A", "B", "A", "C");
applyView(channels, "B", "B", "C");
applyView(channels, "C", "B", "C");
print(channels);
checkViews(channels, "A", "B", "A", "C");
checkViews(channels, "B", "B", "C");
checkViews(channels, "C", "B", "C");
for (MyReceiver receiver : receivers) receiver.clear();
DISCARD discard = new DISCARD();
discard.addIgnoreMember(b.getAddress());
discard.addIgnoreMember(c.getAddress());
// A should drop all traffic from B or C
a.getProtocolStack().insertProtocol(discard, ProtocolStack.Position.ABOVE, SHARED_LOOPBACK.class);
System.out.println("B and C exchange " + NUM + " messages, A discards them");
for (int i = 0; i < NUM; i++) b.send(null, "message #" + i + " from B");
for (int i = 0; i < NUM; i++) c.send(null, "message #" + i + " from C");
// A *does* receiver B's and C's messages !
waitForNumMessages(NUM * 2, 10000, 500, receivers[0], receivers[2]);
checkMessages(NUM * 2, receivers[0], receivers[2]);
checkMessages(0, receivers[1]);
Digest da = ((NAKACK2) a.getProtocolStack().findProtocol(NAKACK2.class)).getDigest(), db = ((NAKACK2) b.getProtocolStack().findProtocol(NAKACK2.class)).getDigest(), dc = ((NAKACK2) c.getProtocolStack().findProtocol(NAKACK2.class)).getDigest();
System.out.println("Digest A: " + da + "\nDigest B: " + db + "\nDigest C: " + dc);
System.out.println("Running stability protocol on B and C now");
for (int i = 0; i < 3; i++) {
((STABLE) b.getProtocolStack().findProtocol(STABLE.class)).gc();
((STABLE) c.getProtocolStack().findProtocol(STABLE.class)).gc();
Util.sleep(300);
}
db = ((NAKACK2) a.getProtocolStack().findProtocol(NAKACK2.class)).getDigest();
db = ((NAKACK2) b.getProtocolStack().findProtocol(NAKACK2.class)).getDigest();
dc = ((NAKACK2) c.getProtocolStack().findProtocol(NAKACK2.class)).getDigest();
System.out.println("(after purging)\nDigest A: " + da + "\nDigest B: " + db + "\nDigest C: " + dc);
// now enable traffic reception of B and C on A:
discard.removeIgnoredMember(b.getAddress());
discard.removeIgnoredMember(c.getAddress());
Address leader = b.getAddress();
long end_time = System.currentTimeMillis() + 12000;
do {
System.out.println("\n==== injecting merge event into " + leader + " ====");
injectMergeEvent(channels, leader, "B", "A", "C");
Util.sleep(3000);
if (allChannelsHaveView(channels, b.getView()))
break;
} while (end_time > System.currentTimeMillis());
System.out.println("\n");
print(channels);
assertAllChannelsHaveView(channels, b.getView());
} finally {
close(channels);
}
}
Aggregations