summaryrefslogtreecommitdiff
path: root/same/src/test
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-03-13 14:05:38 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-03-13 14:05:38 +0100
commitb256d125695da6b2a8eedd6f59ad07e94bd2b0bc (patch)
tree042074790f5d34775e528cc1ef164056bbf94849 /same/src/test
parentaf836cf8e577d2dabeb6450066bcc7ff55bf70e8 (diff)
Clients can control their master.
Add failing test.
Diffstat (limited to 'same/src/test')
-rw-r--r--same/src/test/java/com/orbekk/same/FunctionalTest.java24
1 files changed, 24 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 3707581..215efd9 100644
--- a/same/src/test/java/com/orbekk/same/FunctionalTest.java
+++ b/same/src/test/java/com/orbekk/same/FunctionalTest.java
@@ -1,6 +1,8 @@
package com.orbekk.same;
import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
@@ -95,4 +97,26 @@ public class FunctionalTest {
assertThat(x1.get(), is("TestValue1"));
assertThat(x2.get(), is("TestValue1"));
}
+
+ @Test public void clientBecomesMaster() {
+ 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 void enableMaster(State lastKnownState) {
+ newMaster.resumeFrom(lastKnownState);
+ }
+ @Override
+ public void disableMaster() {
+ }
+ };
+ client1.setMasterController(controller);
+ client1.startMasterElection();
+ newMaster.performWork();
+ assertThat(client1.masterUrl, is(newMasterUrl));
+ assertThat(client2.masterUrl, is(newMasterUrl));
+ }
}