diff options
Diffstat (limited to 'same/src')
-rw-r--r-- | same/src/main/java/com/orbekk/same/MasterServiceImpl.java | 11 | ||||
-rw-r--r-- | same/src/test/java/com/orbekk/same/MasterServiceImplTest.java | 36 |
2 files changed, 44 insertions, 3 deletions
diff --git a/same/src/main/java/com/orbekk/same/MasterServiceImpl.java b/same/src/main/java/com/orbekk/same/MasterServiceImpl.java index f8044e4..ced0dba 100644 --- a/same/src/main/java/com/orbekk/same/MasterServiceImpl.java +++ b/same/src/main/java/com/orbekk/same/MasterServiceImpl.java @@ -68,7 +68,14 @@ public class MasterServiceImpl implements MasterService, UrlReceiver, Runnable { } private synchronized void removeParticipant(String url) { - logger.error("Remove participant {}: Operation not supported", url); + List<String> participants = participants(); + if (participants.contains(url)) { + logger.warn("RemoveParticipant({})", url); + participants.remove(url); + state.updateFromObject(".participants", participants, + state.getRevision(".participants") + 1); + notifyAll(); + } } private void broadcastNewComponents(List<String> destinations, @@ -82,7 +89,7 @@ public class MasterServiceImpl implements MasterService, UrlReceiver, Runnable { c.getRevision()); } } catch (Exception e) { - logger.warn("Client {} failed to receive state update."); + logger.info("Client {} failed to receive state update.", url); removeParticipant(url); } } 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")); + } } |