summaryrefslogtreecommitdiff
path: root/same/src/test/java/com
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-03-20 12:45:26 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-03-20 12:45:35 +0100
commit409dfe838e8ae30e2512256852c1fef31f3255b4 (patch)
tree002c0011d3549fb0da3ec3067e8376c84151a947 /same/src/test/java/com
parent6299172d3b9ba0b98b77583c0c3c5fc90d1b7db5 (diff)
Make sure there is only one valid new master.
This is done using the paxos proposal number as a certificate.
Diffstat (limited to 'same/src/test/java/com')
-rw-r--r--same/src/test/java/com/orbekk/same/FunctionalTest.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/same/src/test/java/com/orbekk/same/FunctionalTest.java b/same/src/test/java/com/orbekk/same/FunctionalTest.java
index 0da38a6..ea920c4 100644
--- a/same/src/test/java/com/orbekk/same/FunctionalTest.java
+++ b/same/src/test/java/com/orbekk/same/FunctionalTest.java
@@ -127,4 +127,32 @@ public class FunctionalTest {
assertThat(client1.masterUrl, is(newMasterUrl));
assertThat(client2.masterUrl, is(newMasterUrl));
}
+
+ @Test public void onlyOneNewMaster() {
+ String newMasterUrl = "http://newMaster/MasterService.json";
+ final Master newMaster = Master.create(connections,
+ broadcaster, newMasterUrl, "TestMaster");
+ connections.masterMap.put(newMasterUrl, newMaster.getService());
+ joinClients();
+ MasterController controller = new MasterController() {
+ boolean firstMaster = true;
+ @Override
+ public synchronized void enableMaster(State lastKnownState,
+ int masterId) {
+ assertThat(firstMaster, is(true));
+ newMaster.resumeFrom(lastKnownState, masterId);
+ firstMaster = false;
+ }
+ @Override
+ public void disableMaster() {
+ }
+ };
+ client1.setMasterController(controller);
+ client2.setMasterController(controller);
+ client3.setMasterController(controller);
+ client1.startMasterElection();
+ newMaster.performWork();
+ assertThat(client1.masterUrl, is(newMasterUrl));
+ assertThat(client2.masterUrl, is(newMasterUrl));
+ }
}