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/src/test | |
parent | 080bad3ea5707021c1ae3c33abc0b0e3aca6b908 (diff) |
Implement updateStateRequest().
– Verify that states are synchronized to all clients.
Diffstat (limited to 'same/src/test')
-rw-r--r-- | same/src/test/java/com/orbekk/same/MasterServiceImplTest.java | 44 |
1 files changed, 39 insertions, 5 deletions
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()); + } } |