From 409dfe838e8ae30e2512256852c1fef31f3255b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Tue, 20 Mar 2012 12:45:26 +0100 Subject: Make sure there is only one valid new master. This is done using the paxos proposal number as a certificate. --- .../test/java/com/orbekk/same/FunctionalTest.java | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'same/src/test') 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)); + } } -- cgit v1.2.3