use of org.jgroups.util.MergeId in project JGroups by belaban.
the class GMS_MergeTest method _testMergeRequestTimeout.
/**
* Simulates the death of a merge leader after having sent a MERGE_REQ. Because there is no MergeView or CANCEL_MERGE
* message, the MergeCanceller has to null merge_id after a timeout
*/
static void _testMergeRequestTimeout(boolean use_flush_props, String cluster_name) throws Exception {
try (JChannel c1 = new JChannel(use_flush_props ? getFlushProps() : getProps()).name("A")) {
c1.connect(cluster_name);
Message merge_request = new EmptyMessage().putHeader(GMS_ID, new GMS.GmsHeader(GMS.GmsHeader.MERGE_REQ).mergeId(MergeId.create(c1.getAddress())));
GMS gms = c1.getProtocolStack().findProtocol(GMS.class);
gms.setMergeTimeout(2000);
MergeId merge_id = gms._getMergeId();
assert merge_id == null;
System.out.println("starting merge");
gms.up(merge_request);
long timeout = gms.getMergeTimeout() * 10;
System.out.println("sleeping for " + timeout + " ms, then fetching merge_id: should be null (cancelled by the MergeCanceller)");
long target_time = System.currentTimeMillis() + timeout;
while (System.currentTimeMillis() < target_time) {
merge_id = gms._getMergeId();
if (merge_id == null)
break;
Util.sleep(500);
}
merge_id = gms._getMergeId();
System.out.println("merge_id = " + merge_id);
assert merge_id == null : "MergeCanceller didn't kick in";
}
}
use of org.jgroups.util.MergeId in project JGroups by belaban.
the class MergeTest3 method testMergeWithMissingMergeResponse.
public void testMergeWithMissingMergeResponse() throws TimeoutException {
createPartition(a, b, c);
createPartition(d, e, f);
System.out.println("Views are:");
for (JChannel ch : Arrays.asList(a, b, c, d, e, f)) System.out.println(ch.getAddress() + ": " + ch.getView());
JChannel merge_leader = findMergeLeader(a, b, c, d, e, f);
List<Address> first_partition = getMembers(a, b, c);
List<Address> second_partition = getMembers(d, e, f);
Collections.sort(first_partition);
// remove the coord
Address first_coord = first_partition.remove(0);
Address busy_first = first_partition.get(0);
Collections.sort(second_partition);
Address second_coord = second_partition.remove(0);
Address busy_second = second_partition.get(second_partition.size() - 1);
System.out.println("\nMerge leader: " + merge_leader.getAddress() + "\nBusy members: " + Arrays.asList(busy_first, busy_second));
MergeId busy_merge_id = MergeId.create(a.getAddress());
setMergeIdIn(busy_first, busy_merge_id);
setMergeIdIn(busy_second, busy_merge_id);
for (JChannel ch : channels) {
// excluding faulty member, as it still discards messages
assert ch.getView().size() == 3;
GMS gms = ch.getProtocolStack().findProtocol(GMS.class);
gms.setJoinTimeout(3000);
DISCARD discard = ch.getProtocolStack().findProtocol(DISCARD.class);
discard.discardAll(false);
}
System.out.println("Injecting MERGE event into merge leader " + merge_leader.getAddress());
GMS gms = merge_leader.getProtocolStack().findProtocol(GMS.class);
int i = 10;
do {
Map<Address, View> merge_views = new HashMap<>(6);
merge_views.put(first_coord, findChannel(first_coord).getView());
merge_views.put(second_coord, findChannel(second_coord).getView());
gms.up(new Event(Event.MERGE, merge_views));
boolean done = true;
System.out.println();
for (JChannel ch : channels) {
System.out.println("==> " + ch.getAddress() + ": " + ch.getView());
Address addr = ch.getAddress();
if (addr.equals(busy_first) || addr.equals(busy_second)) {
if (ch.getView().size() != 3)
done = false;
} else if (ch.getView().size() != 4)
done = false;
}
if (done)
break;
Util.sleep(2000);
} while (--i >= 0);
for (JChannel ch : channels) {
if (ch.getAddress().equals(busy_first) || ch.getAddress().equals(busy_second))
assert ch.getView().size() == 3;
else
assert ch.getView().size() == 4 : ch.getAddress() + "'s view: " + ch.getView();
}
System.out.println("\n************************ Now merging the entire cluster ****************");
cancelMerge(busy_first);
cancelMerge(busy_second);
System.out.println("Injecting MERGE event into merge leader " + merge_leader.getAddress());
Map<Address, View> merge_views = new HashMap<>(6);
i = 10;
do {
merge_views = new HashMap<>(6);
merge_views.put(merge_leader.getAddress(), merge_leader.getView());
merge_views.put(busy_first, findChannel(busy_first).getView());
merge_views.put(busy_second, findChannel(busy_second).getView());
gms.up(new Event(Event.MERGE, merge_views));
if (Stream.of(channels).allMatch(c -> c.getView().size() == 6))
break;
Util.sleep(2000);
} while (--i >= 0);
System.out.printf("channels:\n%s\n", Stream.of(channels).map(c -> String.format("%s: %s", c.getAddress(), c.getView())).collect(Collectors.joining("\n")));
assert Stream.of(channels).allMatch(c -> c.getView().size() == channels.length);
}