use of org.jgroups.protocols.pbcast.ViewHandler in project JGroups by belaban.
the class ViewHandlerTest method testCoordLeave.
public void testCoordLeave() {
final AtomicBoolean result = new AtomicBoolean(true);
Consumer<Collection<GmsImpl.Request>> req_processor = l -> {
System.out.printf("setting result to %b: list: %s\n", l.size() < 2, l);
if (l.size() >= 2)
result.set(false);
};
ViewHandler<GmsImpl.Request> handler = new ViewHandler<>(gms, req_processor, GmsImpl.Request::canBeProcessedTogether);
handler.add(new GmsImpl.Request(GmsImpl.Request.COORD_LEAVE), new GmsImpl.Request(GmsImpl.Request.COORD_LEAVE));
assert result.get();
}
use of org.jgroups.protocols.pbcast.ViewHandler in project JGroups by belaban.
the class ViewHandlerTest method testCoordLeave2.
public void testCoordLeave2() {
final AtomicBoolean result = new AtomicBoolean(true);
Consumer<Collection<GmsImpl.Request>> req_processor = l -> {
int num_coord_leave_req = (int) l.stream().filter(req -> req.getType() == GmsImpl.Request.COORD_LEAVE).count();
System.out.printf("setting result to %b: list: %s\n", num_coord_leave_req < 2, l);
if (num_coord_leave_req >= 2)
result.set(false);
};
ViewHandler<GmsImpl.Request> handler = new ViewHandler<>(gms, req_processor, GmsImpl.Request::canBeProcessedTogether);
handler.add(new GmsImpl.Request(GmsImpl.Request.LEAVE, a), new GmsImpl.Request(GmsImpl.Request.JOIN, b), new GmsImpl.Request(GmsImpl.Request.COORD_LEAVE), new GmsImpl.Request(GmsImpl.Request.COORD_LEAVE));
assert result.get();
}
use of org.jgroups.protocols.pbcast.ViewHandler in project JGroups by belaban.
the class BaseLeaveTest method testLeaveOfFirstNMembers.
/**
* Sorts and delivers requests LEAVE and COORD_LEAVE according to parameter 'comp'
*/
protected void testLeaveOfFirstNMembers(Comparator<GmsImpl.Request> comp, int leavers) throws Exception {
GMS gms = channels[0].getProtocolStack().findProtocol(GMS.class);
ViewHandler vh = gms.getViewHandler();
MyViewHandler my_vh = new MyViewHandler(gms, vh.reqProcessor(), GmsImpl.Request::canBeProcessedTogether, comp, leavers).processing(true);
setViewHandler(my_vh, gms);
testConcurrentLeaves(leavers);
my_vh.processing(false);
setViewHandler(vh, gms);
assert Arrays.stream(channels, 0, leavers).allMatch(ch -> ch.getView() == null) : "views are:\n" + Arrays.stream(channels, 0, leavers).map(ch -> ch.getAddress() + ": " + ch.getView()).collect(Collectors.joining("\n"));
assert leavers >= channels.length || Arrays.stream(channels, leavers, channels.length - 1).allMatch(ch -> ch.getView().size() == channels.length - leavers && ch.getView().getCoord().equals(channels[leavers].getAddress()));
}
use of org.jgroups.protocols.pbcast.ViewHandler in project JGroups by belaban.
the class BaseLeaveTest method testLeaveOfSecondHalfWithCoordLeaving.
/**
* The second half of the cluster (6,7,8,9,10) sends LEAVE requests to 1, but 1 leaves before they get a response.
* Requires them to resend their LEAVE requests to 2 on the view change when 2 takes over as coord.
*/
public void testLeaveOfSecondHalfWithCoordLeaving() throws Exception {
setup(NUM);
Stream.of(channels).forEach(ch -> ch.getProtocolStack().removeProtocols(FailureDetection.class, FD_SOCK.class));
Comparator<GmsImpl.Request> comp = Comparator.comparingInt(GmsImpl.Request::getType).reversed();
GMS gms = channels[0].getProtocolStack().findProtocol(GMS.class);
ViewHandler vh = gms.getViewHandler();
MyViewHandler my_vh = new MyViewHandler(gms, vh.reqProcessor(), GmsImpl.Request::canBeProcessedTogether, comp, 6).processing(true);
setViewHandler(my_vh, gms);
testConcurrentLeaves(0, 5, 6, 7, 8, 9);
my_vh.processing(false);
setViewHandler(vh, gms);
assert Stream.of(0, 5, 6, 7, 8, 9).map(i -> channels[i]).allMatch(JChannel::isClosed);
assert Stream.of(1, 2, 3, 4).map(i -> channels[i]).allMatch(JChannel::isConnected);
assert Stream.of(1, 2, 3, 4).map(i -> channels[i]).allMatch(ch -> ch.getView().getCoord().equals(channels[1].getAddress()));
}
Aggregations