summaryrefslogtreecommitdiff
path: root/same
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-17 17:11:12 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-17 17:11:12 +0100
commita2f0a58484bdfc22a8af7b16df051c1e611fc83d (patch)
tree5b3a67d53db242971fdf64e89a4ef5df985363ab /same
parent057ed9266ddfeb4fecd1531f6aa51255a4003b68 (diff)
Fix revision update.
Change State to take the *new* revision when updating.
Diffstat (limited to 'same')
-rw-r--r--same/src/main/java/com/orbekk/same/MasterServiceImpl.java6
-rw-r--r--same/src/main/java/com/orbekk/same/State.java8
-rw-r--r--same/src/test/java/com/orbekk/same/MasterServiceImplTest.java13
3 files changed, 16 insertions, 11 deletions
diff --git a/same/src/main/java/com/orbekk/same/MasterServiceImpl.java b/same/src/main/java/com/orbekk/same/MasterServiceImpl.java
index d7a9e53..a8acc52 100644
--- a/same/src/main/java/com/orbekk/same/MasterServiceImpl.java
+++ b/same/src/main/java/com/orbekk/same/MasterServiceImpl.java
@@ -31,7 +31,7 @@ public class MasterServiceImpl implements MasterService, UrlReceiver, Runnable {
_fullStateReceivers.add(clientUrl);
synchronized(this) {
state.updateFromObject(".participants", participants,
- state.getRevision(".participants"));
+ state.getRevision(".participants") + 1);
notifyAll();
}
} else {
@@ -79,7 +79,7 @@ public class MasterServiceImpl implements MasterService, UrlReceiver, Runnable {
@Override
public synchronized boolean updateStateRequest(String component,
String newData, long revision) {
- boolean updated = state.update(component, newData, revision);
+ boolean updated = state.update(component, newData, revision + 1);
if (updated) {
notifyAll();
}
@@ -90,7 +90,7 @@ public class MasterServiceImpl implements MasterService, UrlReceiver, Runnable {
public void setUrl(String url) {
String myUrl = url + "MasterService.json";
logger.info("Master URL is " + myUrl);
- state.update(".masterUrl", myUrl, 0);
+ state.update(".masterUrl", myUrl, 1);
}
boolean _performWork() {
diff --git a/same/src/main/java/com/orbekk/same/State.java b/same/src/main/java/com/orbekk/same/State.java
index c352990..19b67e5 100644
--- a/same/src/main/java/com/orbekk/same/State.java
+++ b/same/src/main/java/com/orbekk/same/State.java
@@ -26,8 +26,8 @@ public class State {
private Set<String> updatedComponents = new TreeSet<String>();
public State(String networkName) {
- update(".networkName", networkName, 0);
- updateFromObject(".participants", new ArrayList<String>(), 0);
+ update(".networkName", networkName, 1);
+ updateFromObject(".participants", new ArrayList<String>(), 1);
}
public synchronized void clear() {
@@ -54,10 +54,10 @@ public class State {
component = state.get(componentName);
}
- if (revision >= component.getRevision()) {
+ if (revision > component.getRevision()) {
Component oldComponent = new Component(component);
component.setName(componentName);
- component.setRevision(revision + 1);
+ component.setRevision(revision);
component.setData(data);
state.put(componentName, component);
updatedComponents.add(componentName);
diff --git a/same/src/test/java/com/orbekk/same/MasterServiceImplTest.java b/same/src/test/java/com/orbekk/same/MasterServiceImplTest.java
index 583e464..9c72319 100644
--- a/same/src/test/java/com/orbekk/same/MasterServiceImplTest.java
+++ b/same/src/test/java/com/orbekk/same/MasterServiceImplTest.java
@@ -15,6 +15,11 @@ public class MasterServiceImplTest {
private MasterServiceImpl master = new MasterServiceImpl(state,
connections, broadcaster);
+ @Before
+ public void setUp() {
+ connections.masterMap.put("http://master", master);
+ }
+
@Test
public void setsMasterUrl() {
master.setUrl("http://10.0.0.54:10050/");
@@ -53,7 +58,7 @@ public class MasterServiceImplTest {
new State("ClientNetwork"), connections);
client.setUrl("http://client/");
connections.clientMap.put("http://client/ClientService.json", client);
- master.joinNetworkRequest("http://client/ClientService.json");
+ client.joinNetwork("http://master");
assertTrue(master._performWork());
assertTrue(state.getList(".participants").contains("http://client/ClientService.json"));
assertEquals(state, client.testGetState());
@@ -68,11 +73,11 @@ public class MasterServiceImplTest {
connections.clientMap.put("http://client/ClientService.json", client1);
ClientServiceImpl client2 = new ClientServiceImpl(
new State("ClientNetwork"), connections);
- client1.setUrl("http://client2/");
+ client2.setUrl("http://client2/");
connections.clientMap.put("http://client2/ClientService.json", client2);
- master.joinNetworkRequest("http://client/ClientService.json");
- master.joinNetworkRequest("http://client2/ClientService.json");
+ client1.joinNetwork("http://master");
+ client2.joinNetwork("http://master");
assertTrue(master._performWork());
assertTrue(state.getList(".participants").contains("http://client/ClientService.json"));