Search in sources :

Example 1 with MutableDigest

use of org.jgroups.util.MutableDigest in project JGroups by belaban.

the class MergeTest4 method testMergeWithAsymetricViewsCoordIsolated.

public void testMergeWithAsymetricViewsCoordIsolated() throws Exception {
    // Isolate the coord
    Address coord = a.getView().getCreator();
    System.out.println("Isolating coord: " + coord);
    List<Address> members = new ArrayList<>();
    members.add(coord);
    View coord_view = new View(coord, 4, members);
    System.out.println("coord_view: " + coord_view);
    JChannel coord_channel = findChannel(coord);
    System.out.println("coord_channel: " + coord_channel.getAddress());
    MutableDigest digest = new MutableDigest(coord_view.getMembersRaw());
    NAKACK2 nakack = coord_channel.getProtocolStack().findProtocol(NAKACK2.class);
    digest.merge(nakack.getDigest(coord));
    GMS gms = coord_channel.getProtocolStack().findProtocol(GMS.class);
    gms.installView(coord_view, digest);
    System.out.println("gms.getView() " + gms.getView());
    System.out.println("Views are:");
    for (JChannel ch : Arrays.asList(a, b, c, d)) System.out.println(ch.getAddress() + ": " + ch.getView());
    JChannel merge_leader = findChannel(coord);
    MyReceiver receiver = new MyReceiver();
    merge_leader.setReceiver(receiver);
    System.out.println("merge_leader: " + merge_leader.getAddressAsString());
    System.out.println("Injecting MERGE event into merge leader " + merge_leader.getAddress());
    Map<Address, View> merge_views = new HashMap<>(4);
    merge_views.put(a.getAddress(), a.getView());
    merge_views.put(b.getAddress(), b.getView());
    merge_views.put(c.getAddress(), c.getView());
    merge_views.put(d.getAddress(), d.getView());
    gms = merge_leader.getProtocolStack().findProtocol(GMS.class);
    gms.up(new Event(Event.MERGE, merge_views));
    Util.waitUntilAllChannelsHaveSameView(10000, 1000, a, b, c, d);
    System.out.println("Views are:");
    for (JChannel ch : Arrays.asList(a, b, c, d)) {
        View view = ch.getView();
        System.out.println(ch.getAddress() + ": " + view);
        assert view.size() == 4;
    }
    MergeView merge_view = receiver.getView();
    System.out.println("merge_view = " + merge_view);
    assert merge_view.size() == 4;
    assert merge_view.getSubgroups().size() == 2;
    for (View view : merge_view.getSubgroups()) assert contains(view, a.getAddress()) || contains(view, b.getAddress(), c.getAddress(), d.getAddress());
}
Also used : GMS(org.jgroups.protocols.pbcast.GMS) NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) MutableDigest(org.jgroups.util.MutableDigest)

Example 2 with MutableDigest

use of org.jgroups.util.MutableDigest in project JGroups by belaban.

the class DigestTest method testAllSet.

public void testAllSet() {
    Address[] mbrs = Util.createRandomAddresses(5);
    MutableDigest dig = new MutableDigest(mbrs);
    assert !dig.allSet();
    for (int index : Arrays.asList(1, 3, 4)) dig.set(mbrs[index], index, index + 1);
    System.out.println("dig = " + dig);
    assert !dig.allSet();
    Address[] non_set = dig.getNonSetMembers();
    System.out.println("non_set = " + Arrays.toString(non_set));
    assert non_set != null && non_set.length == 2;
    Assert.assertEquals(non_set, new Address[] { mbrs[0], mbrs[2] });
    for (int index : Arrays.asList(0, 2)) dig.set(mbrs[index], index, index + 1);
    System.out.println("dig = " + dig);
    assert dig.allSet();
    non_set = dig.getNonSetMembers();
    assert non_set.length == 0;
    dig = new MutableDigest(members);
    assert !dig.allSet();
    non_set = dig.getNonSetMembers();
    Assert.assertEquals(non_set, members);
    dig.set(d);
    System.out.println("dig = " + dig);
    assert dig.allSet();
    non_set = dig.getNonSetMembers();
    assert non_set.length == 0;
}
Also used : Address(org.jgroups.Address) MutableDigest(org.jgroups.util.MutableDigest)

Example 3 with MutableDigest

use of org.jgroups.util.MutableDigest in project JGroups by belaban.

the class DigestTest method testContainsAll.

public void testContainsAll() {
    MutableDigest digest = new MutableDigest(members);
    digest.set(a1, 1, 1);
    digest.set(a2, 1, 1);
    assert digest.containsAll(a1, a2, a3);
    digest.set(a3, 1, 1);
    assert digest.containsAll(a1, a2, a3);
    assert d.containsAll(a1, a2, a3);
}
Also used : MutableDigest(org.jgroups.util.MutableDigest)

Example 4 with MutableDigest

use of org.jgroups.util.MutableDigest in project JGroups by belaban.

the class DigestTest method testSetDigest2.

public void testSetDigest2() {
    MutableDigest tmp = new MutableDigest(members);
    // ignored as view doesn't include this member
    tmp.set(Util.createRandomAddress(), 2, 3);
    // ditto
    tmp.set(Util.createRandomAddress(), 2, 3);
    tmp.set(a2, 2, 3);
    tmp.set(a3, 2, 3);
    md.set(tmp);
    Assert.assertEquals(md.capacity(), 3);
}
Also used : MutableDigest(org.jgroups.util.MutableDigest)

Example 5 with MutableDigest

use of org.jgroups.util.MutableDigest in project JGroups by belaban.

the class DigestTest method testReplace.

public void testReplace() {
    MutableDigest digest = new MutableDigest(members);
    digest.set(a1, 1, 1);
    digest.set(a2, 2, 2);
    md.set(digest);
    assert digest.equals(md);
}
Also used : MutableDigest(org.jgroups.util.MutableDigest)

Aggregations

MutableDigest (org.jgroups.util.MutableDigest)18 Digest (org.jgroups.util.Digest)4 NAKACK2 (org.jgroups.protocols.pbcast.NAKACK2)3 Address (org.jgroups.Address)2 GMS (org.jgroups.protocols.pbcast.GMS)2 Protocol (org.jgroups.stack.Protocol)2 ArrayList (java.util.ArrayList)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Condition (java.util.concurrent.locks.Condition)1 Lock (java.util.concurrent.locks.Lock)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 View (org.jgroups.View)1 NakAckHeader2 (org.jgroups.protocols.pbcast.NakAckHeader2)1 MessageBatch (org.jgroups.util.MessageBatch)1 BeforeMethod (org.testng.annotations.BeforeMethod)1