Skip to content

Commit

Permalink
Merge pull request #71 from otheng03/master
Browse files Browse the repository at this point in the history
cm: fix masterElection unittest
  • Loading branch information
sanitysoon authored Jun 17, 2016
2 parents 7f5db2c + cee19a3 commit 50c7e06
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -679,5 +679,22 @@ public Boolean call() throws Exception {
return quorum == Integer.valueOf(master.execute("getquorum"));
}
}

public static class MasterGenValidator implements Callable<Boolean> {
final PartitionGroupServer pgs;
final int mGen;

public MasterGenValidator(PartitionGroupServer pgs, int mGen) {
this.pgs = pgs;
this.mGen = mGen;
}

public Boolean call() throws Exception {
if (pgs.getData().getMasterGen() == mGen) {
return true;
}
return false;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -364,21 +364,41 @@ public void masterElection() throws Exception {
masterFinder = new MasterFinder(getPgsList());
await("reconfiguration for master.").atMost(assertionTimeout, SECONDS).until(masterFinder);
validateNormal(masterFinder.getMaster(), pg, PGS_ROLE_MASTER, 2);

masterFinder.getMaster().getName();
doCommand("pgs_leave " + masterFinder.getMaster().getClusterName()
+ " " + masterFinder.getMaster().getName());
doCommand("pgs_lconn " + masterFinder.getMaster().getClusterName()
+ " " + masterFinder.getMaster().getName());

PartitionGroupServer leftPgs = masterFinder.getMaster();
doCommand("pgs_leave " + leftPgs.getClusterName() + " "
+ leftPgs.getName());
doCommand("pgs_lconn " + leftPgs.getClusterName() + " "
+ leftPgs.getName());

// Check mGen
for (PartitionGroupServer pgs : getPgsList()) {
// Skip left PGS
if (pgs == leftPgs) {
continue;
}
await("validate mGen.").atMost(assertionTimeout, SECONDS).until(
new MasterGenValidator(pgs, 4));
}

mimics[0].mSmr.execute("role lconn");
mimics[1].mSmr.execute("role lconn");
mimics[2].mSmr.execute("role lconn");

// Check mGen
for (PartitionGroupServer pgs : getPgsList()) {
// Skip left PGS
if (pgs == leftPgs) {
continue;
}
await("validate mGen.").atMost(assertionTimeout, SECONDS).until(
new MasterGenValidator(pgs, 5));
}

// Check new master
masterFinder = new MasterFinder(getPgsList());
await("reconfiguration for master.").atMost(assertionTimeout, SECONDS).until(masterFinder);
validateNormal(masterFinder.getMaster(), pg, PGS_ROLE_MASTER, 3);
validateNormal(masterFinder.getMaster(), pg, PGS_ROLE_MASTER, 4);

slaveFinder = new SlaveFinder(getPgsList());
await("reconfiguration for slave.").atMost(assertionTimeout, SECONDS).until(slaveFinder);
Expand Down

0 comments on commit 50c7e06

Please sign in to comment.