diff options
author | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-01-16 20:13:07 +0100 |
---|---|---|
committer | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-01-16 20:13:07 +0100 |
commit | 654ac153d6d260ec4cf79e614a93fbcd40dc4659 (patch) | |
tree | d5d1f3bd40a3d8b8cc41fa2d6bcbfa85b20a969a /same | |
parent | 080bad3ea5707021c1ae3c33abc0b0e3aca6b908 (diff) |
Implement updateStateRequest().
– Verify that states are synchronized to all clients.
Diffstat (limited to 'same')
-rw-r--r-- | same/src/main/java/com/orbekk/same/MasterServiceImpl.java | 10 | ||||
-rw-r--r-- | same/src/test/java/com/orbekk/same/MasterServiceImplTest.java | 44 |
2 files changed, 46 insertions, 8 deletions
diff --git a/same/src/main/java/com/orbekk/same/MasterServiceImpl.java b/same/src/main/java/com/orbekk/same/MasterServiceImpl.java index 2101de8..6779702 100644 --- a/same/src/main/java/com/orbekk/same/MasterServiceImpl.java +++ b/same/src/main/java/com/orbekk/same/MasterServiceImpl.java @@ -78,9 +78,13 @@ public class MasterServiceImpl implements MasterService, UrlReceiver, Runnable { @Override - public boolean updateStateRequest(String component, String newData, long revision) { - // TODO Auto-generated method stub - return false; + public synchronized boolean updateStateRequest(String component, + String newData, long revision) { + boolean updated = state.update(component, newData, revision); + if (updated) { + notifyAll(); + } + return updated; } @Override diff --git a/same/src/test/java/com/orbekk/same/MasterServiceImplTest.java b/same/src/test/java/com/orbekk/same/MasterServiceImplTest.java index 25b4073..da45e38 100644 --- a/same/src/test/java/com/orbekk/same/MasterServiceImplTest.java +++ b/same/src/test/java/com/orbekk/same/MasterServiceImplTest.java @@ -48,14 +48,48 @@ public class MasterServiceImplTest { @Test public void clientJoin() { - master.setUrl("http://master"); + master.setUrl("http://master/"); ClientServiceImpl client = new ClientServiceImpl( new State("ClientNetwork"), connections); - client.setUrl("http://client"); - connections.clientMap.put("http://client", client); - master.joinNetworkRequest("TestNetwork", "http://client"); + client.setUrl("http://client/"); + connections.clientMap.put("http://client/ClientService.json", client); + master.joinNetworkRequest("TestNetwork", "http://client/ClientService.json"); assertTrue(master._performWork()); - assertTrue(state.getList(".participants").contains("http://client")); + assertTrue(state.getList(".participants").contains("http://client/ClientService.json")); assertEquals(state, client.testGetState()); } + + @Test + public void validStateRequest() { + master.setUrl("http://master/"); + ClientServiceImpl client1 = new ClientServiceImpl( + new State("ClientNetwork"), connections); + client1.setUrl("http://client/"); + connections.clientMap.put("http://client/ClientService.json", client1); + ClientServiceImpl client2 = new ClientServiceImpl( + new State("ClientNetwork"), connections); + client1.setUrl("http://client2/"); + connections.clientMap.put("http://client2/ClientService.json", client2); + + master.joinNetworkRequest("TestNetwork", "http://client/ClientService.json"); + master.joinNetworkRequest("TestNetwork", "http://client2/ClientService.json"); + + assertTrue(master._performWork()); + assertTrue(state.getList(".participants").contains("http://client/ClientService.json")); + assertTrue(state.getList(".participants").contains("http://client2/ClientService.json")); + assertEquals(state, client1.testGetState()); + + assertTrue(master.updateStateRequest("A", "1", 0)); + assertTrue(master._performWork()); + + assertEquals(state, client1.testGetState()); + assertEquals(state, client2.testGetState()); + + assertFalse(master.updateStateRequest("A", "2", 0)); + assertTrue(master.updateStateRequest("A", "3", 1)); + assertTrue(master._performWork()); + + assertEquals(state, client1.testGetState()); + assertEquals(state, client2.testGetState()); + } } |