summaryrefslogtreecommitdiff
path: root/same/src/test/java
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-18 10:53:03 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-18 10:53:03 +0100
commit52ad0bdcd80b01ab6b40ddc0fca8c1e3ab9d0a00 (patch)
tree92871e86031e2b4ab805ef8dd9aad39b43b6832b /same/src/test/java
parente9773489eb1bc3f13d7b1619e03a33039937fb0a (diff)
Remove clients upon errors.
Add test for removing clients.
Diffstat (limited to 'same/src/test/java')
-rw-r--r--same/src/test/java/com/orbekk/same/MasterServiceImplTest.java36
1 files changed, 35 insertions, 1 deletions
diff --git a/same/src/test/java/com/orbekk/same/MasterServiceImplTest.java b/same/src/test/java/com/orbekk/same/MasterServiceImplTest.java
index 8397744..0782d7f 100644
--- a/same/src/test/java/com/orbekk/same/MasterServiceImplTest.java
+++ b/same/src/test/java/com/orbekk/same/MasterServiceImplTest.java
@@ -14,7 +14,22 @@ public class MasterServiceImplTest {
private TestBroadcaster broadcaster = new TestBroadcaster();
private MasterServiceImpl master = new MasterServiceImpl(state,
connections, broadcaster);
-
+
+ public static class UnreachableClient implements ClientService {
+ @Override
+ public void notifyNetwork(String networkName, String masterUrl)
+ throws Exception {
+ throw new Exception("Unreachable client");
+ }
+
+ @Override
+ public void setState(String component, String data, long revision)
+ throws Exception {
+ throw new Exception("Unreachable client");
+ }
+ }
+
+
@Before
public void setUp() {
connections.masterMap.put("http://master", master);
@@ -97,4 +112,23 @@ public class MasterServiceImplTest {
assertEquals(state, client1.testGetState());
assertEquals(state, client2.testGetState());
}
+
+ @Test
+ public void masterRemovesParticipant() {
+ master.setUrl("http://master/");
+ ClientServiceImpl client = new ClientServiceImpl(
+ new State("ClientNetwork"), connections);
+ client.setUrl("http://client/");
+ connections.clientMap.put("http://client/ClientService.json", client);
+ client.joinNetwork("http://master");
+ assertTrue(master._performWork());
+ assertTrue(state.getList(".participants").contains("http://client/ClientService.json"));
+
+ connections.clientMap.put("http://client/ClientService.json",
+ new UnreachableClient());
+ master.updateStateRequest("NewState", "NewStateData", 0);
+ master._performWork();
+
+ assertEquals("[]", state.getDataOf(".participants"));
+ }
}