Java Code Examples for org.jgroups.util.Util#waitUntilAllChannelsHaveSameView()

The following examples show how to use org.jgroups.util.Util#waitUntilAllChannelsHaveSameView() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppendEntriesTest.java    From jgroups-raft with Apache License 2.0 6 votes vote down vote up
/**
 * Leader A and followers B and C commit entries 1-2. Then C leaves and A and B commit entries 3-5. When C rejoins,
 * it should get log entries 3-5 as well.
 */
public void testCatchingUp() throws Exception {
    init(true);
    // A, B and C commit entries 1-2
    for(int i=1; i <= 2; i++)
        as.put(i,i);
    assertSame(as, bs, cs);

    // Now C leaves
    close(true, true, c);

    // A and B commit entries 3-5
    for(int i=3; i <= 5; i++)
        as.put(i,i);
    assertSame(as, bs);

    // Now start C again: entries 1-5 will have to get resent to C as its log was deleted above (otherwise only 3-5
    // would have to be resent)
    c=create("C", true);  // follower
    cs=new ReplicatedStateMachine<>(c);
    c.connect(CLUSTER);
    Util.waitUntilAllChannelsHaveSameView(10000, 500, a,b,c);

    // Now C should also have the same entries (1-5) as A and B
    assertSame(as, bs, cs);
}
 
Example 2
Source File: AppendEntriesTest.java    From jgroups-raft with Apache License 2.0 6 votes vote down vote up
/**
 * Leader A and follower B commit 5 entries, then snapshot A. Then C comes up and should get the 5 committed entries
 * as well, as a snapshot
 */
public void testInstallSnapshotInC() throws Exception {
    init(true);
    close(true, true, c);
    for(int i=1; i <= 5; i++)
        as.put(i,i);
    assertSame(as, bs);

    // Snapshot A:
    as.snapshot();

    // Now start C
    c=create("C", true);  // follower
    cs=new ReplicatedStateMachine<>(c);
    c.connect(CLUSTER);
    Util.waitUntilAllChannelsHaveSameView(10000, 500, a, b, c);

    assertSame(as, bs, cs);
}
 
Example 3
Source File: ElectionsTest.java    From jgroups-raft with Apache License 2.0 4 votes vote down vote up
@BeforeMethod protected void init() throws Exception {
    a=create("A"); a.connect(CLUSTER);
    b=create("B"); b.connect(CLUSTER);
    c=create("C"); c.connect(CLUSTER);
    Util.waitUntilAllChannelsHaveSameView(10000, 500, a,b,c);
}