Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
yfei-z authored and jabolina committed Oct 24, 2024
1 parent 3711dad commit 6393b08
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jgroups.tests.election;

import org.jgroups.*;
import org.jgroups.conf.ClassConfigurator;
import org.jgroups.protocols.SHARED_LOOPBACK;
import org.jgroups.protocols.pbcast.GMS;
import org.jgroups.protocols.raft.ELECTION2;
Expand Down Expand Up @@ -76,14 +77,18 @@ public void electionAfterMerge(Class<?> ignore) throws Exception {
System.out.println("partition1: " + view(leader));
System.out.println("partition2: " + view(coord));

raft(leader).set("cmd".getBytes(), 0, 3);
for (int i : indexes) {
System.out.println(address(i) + " lastAppended: " + raft(i).lastAppended());
}

// block the new coordinator to advance the term in voting thread
newTerm = new Semaphore(0);

merge(leader, coord);

int finalLeader = leader;
assertThat(eventually(() -> coordIndex(finalLeader) == coord && coordIndex(coord) == coord, 10, TimeUnit.SECONDS))
.isTrue();
Util.waitUntilAllChannelsHaveSameView(30_000, 1000, channels());
assertEquals(coordIndex(leader), coord);
assertEquals(coordIndex(coord), coord);
System.out.println("after merge: " + view(coord));

// since the term is not advanced yet, new coordinator has accepted the existing leader, and stopping the
Expand Down Expand Up @@ -112,6 +117,10 @@ public void electionAfterMerge(Class<?> ignore) throws Exception {
@Override
protected RAFT newRaftInstance() {
return new RAFT() {
{
id = ClassConfigurator.getProtocolId(RAFT.class);
}

@Override
public long createNewTerm() {
Semaphore s = newTerm;
Expand Down

0 comments on commit 6393b08

Please sign in to comment.