Message merge_request=new Message();
GMS.GmsHeader hdr=new GMS.GmsHeader(GMS.GmsHeader.MERGE_REQ);
MergeId new_merge_id=MergeId.create(c1.getAddress());
hdr.setMergeId(new_merge_id);
merge_request.putHeader(GMS_ID, hdr);
GMS 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(new Event(Event.MSG, merge_request));
merge_id=gms.getMergeId();
System.out.println("merge_id = " + merge_id);
assert new_merge_id.equals(merge_id);
long timeout=gms.getMergeTimeout() * 2;
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";
}
finally {
Util.close(c1);