Search in sources :

Example 1 with ViewHandler

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();
}
Also used : Protocol(org.jgroups.stack.Protocol) IntStream(java.util.stream.IntStream) java.util(java.util) Util(org.jgroups.util.Util) BeforeMethod(org.testng.annotations.BeforeMethod) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.testng.annotations.Test) GMS(org.jgroups.protocols.pbcast.GMS) Field(java.lang.reflect.Field) DefaultThreadFactory(org.jgroups.util.DefaultThreadFactory) Consumer(java.util.function.Consumer) CountDownLatch(java.util.concurrent.CountDownLatch) BiPredicate(java.util.function.BiPredicate) ThreadFactory(org.jgroups.util.ThreadFactory) Stream(java.util.stream.Stream) ViewHandler(org.jgroups.protocols.pbcast.ViewHandler) Global(org.jgroups.Global) GmsImpl(org.jgroups.protocols.pbcast.GmsImpl) Address(org.jgroups.Address) TimeScheduler3(org.jgroups.util.TimeScheduler3) View(org.jgroups.View) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ViewHandler(org.jgroups.protocols.pbcast.ViewHandler) GmsImpl(org.jgroups.protocols.pbcast.GmsImpl)

Example 2 with ViewHandler

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();
}
Also used : Protocol(org.jgroups.stack.Protocol) IntStream(java.util.stream.IntStream) java.util(java.util) Util(org.jgroups.util.Util) BeforeMethod(org.testng.annotations.BeforeMethod) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.testng.annotations.Test) GMS(org.jgroups.protocols.pbcast.GMS) Field(java.lang.reflect.Field) DefaultThreadFactory(org.jgroups.util.DefaultThreadFactory) Consumer(java.util.function.Consumer) CountDownLatch(java.util.concurrent.CountDownLatch) BiPredicate(java.util.function.BiPredicate) ThreadFactory(org.jgroups.util.ThreadFactory) Stream(java.util.stream.Stream) ViewHandler(org.jgroups.protocols.pbcast.ViewHandler) Global(org.jgroups.Global) GmsImpl(org.jgroups.protocols.pbcast.GmsImpl) Address(org.jgroups.Address) TimeScheduler3(org.jgroups.util.TimeScheduler3) View(org.jgroups.View) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ViewHandler(org.jgroups.protocols.pbcast.ViewHandler) GmsImpl(org.jgroups.protocols.pbcast.GmsImpl)

Example 3 with ViewHandler

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()));
}
Also used : Protocol(org.jgroups.stack.Protocol) IntStream(java.util.stream.IntStream) java.util(java.util) Util(org.jgroups.util.Util) Test(org.testng.annotations.Test) GMS(org.jgroups.protocols.pbcast.GMS) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) BiPredicate(java.util.function.BiPredicate) Stream(java.util.stream.Stream) ViewHandler(org.jgroups.protocols.pbcast.ViewHandler) Global(org.jgroups.Global) GmsImpl(org.jgroups.protocols.pbcast.GmsImpl) JChannel(org.jgroups.JChannel) Address(org.jgroups.Address) org.jgroups.protocols(org.jgroups.protocols) ViewHandler(org.jgroups.protocols.pbcast.ViewHandler) GMS(org.jgroups.protocols.pbcast.GMS) GmsImpl(org.jgroups.protocols.pbcast.GmsImpl)

Example 4 with ViewHandler

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()));
}
Also used : Protocol(org.jgroups.stack.Protocol) IntStream(java.util.stream.IntStream) java.util(java.util) Util(org.jgroups.util.Util) Test(org.testng.annotations.Test) GMS(org.jgroups.protocols.pbcast.GMS) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) BiPredicate(java.util.function.BiPredicate) Stream(java.util.stream.Stream) ViewHandler(org.jgroups.protocols.pbcast.ViewHandler) Global(org.jgroups.Global) GmsImpl(org.jgroups.protocols.pbcast.GmsImpl) JChannel(org.jgroups.JChannel) Address(org.jgroups.Address) org.jgroups.protocols(org.jgroups.protocols) JChannel(org.jgroups.JChannel) ViewHandler(org.jgroups.protocols.pbcast.ViewHandler) GMS(org.jgroups.protocols.pbcast.GMS) GmsImpl(org.jgroups.protocols.pbcast.GmsImpl)

Aggregations

Field (java.lang.reflect.Field)4 java.util (java.util)4 BiPredicate (java.util.function.BiPredicate)4 Consumer (java.util.function.Consumer)4 IntStream (java.util.stream.IntStream)4 Stream (java.util.stream.Stream)4 Address (org.jgroups.Address)4 Global (org.jgroups.Global)4 GMS (org.jgroups.protocols.pbcast.GMS)4 GmsImpl (org.jgroups.protocols.pbcast.GmsImpl)4 ViewHandler (org.jgroups.protocols.pbcast.ViewHandler)4 Protocol (org.jgroups.stack.Protocol)4 Util (org.jgroups.util.Util)4 Test (org.testng.annotations.Test)4 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Collectors (java.util.stream.Collectors)2 JChannel (org.jgroups.JChannel)2 View (org.jgroups.View)2 org.jgroups.protocols (org.jgroups.protocols)2