diff options
author | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-03-20 14:34:26 +0100 |
---|---|---|
committer | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-03-20 14:34:26 +0100 |
commit | 4ad09d6604aa6c2091824a239f9c75a06aef0b24 (patch) | |
tree | 8d2a8fcd1d63efda1314f801e901593b014b3db2 /same/src | |
parent | 409dfe838e8ae30e2512256852c1fef31f3255b4 (diff) |
Start master election when update fails.
Diffstat (limited to 'same/src')
-rw-r--r-- | same/src/main/java/com/orbekk/same/Client.java | 1 | ||||
-rw-r--r-- | same/src/test/java/com/orbekk/same/FunctionalTest.java | 34 |
2 files changed, 34 insertions, 1 deletions
diff --git a/same/src/main/java/com/orbekk/same/Client.java b/same/src/main/java/com/orbekk/same/Client.java index ceacd12..1a9fb7f 100644 --- a/same/src/main/java/com/orbekk/same/Client.java +++ b/same/src/main/java/com/orbekk/same/Client.java @@ -72,6 +72,7 @@ public class Client implements DiscoveryListener { String e_ = throwableToString(e); op.complete(DelayedOperation.Status.createError( "Error contacting master. Update fails: " + e_)); + startMasterElection(); } return op; } diff --git a/same/src/test/java/com/orbekk/same/FunctionalTest.java b/same/src/test/java/com/orbekk/same/FunctionalTest.java index ea920c4..5e0af41 100644 --- a/same/src/test/java/com/orbekk/same/FunctionalTest.java +++ b/same/src/test/java/com/orbekk/same/FunctionalTest.java @@ -14,6 +14,7 @@ import org.junit.Test; import com.orbekk.paxos.PaxosService; import com.orbekk.paxos.PaxosServiceImpl; +import com.orbekk.util.DelayedOperation; /** A functional test that runs with a master and several clients. */ public class FunctionalTest { @@ -28,12 +29,14 @@ public class FunctionalTest { List<Client> clients = new ArrayList<Client>(); TestConnectionManager connections = new TestConnectionManager(); TestBroadcaster broadcaster = new TestBroadcaster(); + MasterServiceProxy masterServiceProxy; @Before public void setUp() { master = Master.create(connections, broadcaster, masterUrl, "TestMaster"); + masterServiceProxy = new MasterServiceProxy(master.getService()); connections.masterMap.put(masterUrl, - master.getService()); + masterServiceProxy); client1 = newClient("TestClient1", "http://client1/ClientService.json"); vf1 = new VariableFactory(client1.getInterface()); client2 = newClient("TestClient2", "http://client2/ClientService.json"); @@ -155,4 +158,33 @@ public class FunctionalTest { assertThat(client1.masterUrl, is(newMasterUrl)); assertThat(client2.masterUrl, is(newMasterUrl)); } + + @Test public void masterFails() { + 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() { + @Override + public synchronized void enableMaster(State lastKnownState, + int masterId) { + newMaster.resumeFrom(lastKnownState, masterId); + } + @Override + public void disableMaster() { + } + }; + client1.setMasterController(controller); + client2.setMasterController(controller); + client3.setMasterController(controller); + Variable<String> x1 = vf1.createString("TestMasterFailure"); + masterServiceProxy.setService(null); + assertThat(x1.set("Woop, woop").getStatus().getStatusCode(), + is(DelayedOperation.Status.ERROR)); + performWork(); + newMaster.performWork(); + assertThat(client1.masterUrl, is(newMasterUrl)); + assertThat(client2.masterUrl, is(newMasterUrl)); + } } |