summaryrefslogtreecommitdiff
path: root/same/src
diff options
context:
space:
mode:
Diffstat (limited to 'same/src')
-rw-r--r--same/src/main/java/com/orbekk/same/MasterServiceImpl.java10
-rw-r--r--same/src/test/java/com/orbekk/same/MasterServiceImplTest.java44
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());
+ }
}