diff options
author | Martin <marcin.j.chrzanowski@gmail.com> | 2020-01-12 23:58:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-12 23:58:24 +0100 |
commit | 50924560e8829914a4b8d315752c693890210c88 (patch) | |
tree | 2f7003cec915d94859081c7712362e7d1317554f | |
parent | 0f31d1f5c267f893d765ccd848b95fc111009de5 (diff) | |
parent | ec0971201f2b2c90513321a33896390252a43f3d (diff) |
Merge pull request #119 from m-chrzan/use-gtp
Use GTP when deciding which zones to send
-rw-r--r-- | src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java | 13 | ||||
-rw-r--r-- | src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlStateTest.java | 45 |
2 files changed, 53 insertions, 5 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java index 0525f41..cfaf560 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java @@ -3,7 +3,6 @@ package pl.edu.mimuw.cloudatlas.agent.modules; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -170,12 +169,16 @@ public class GossipGirlState { System.out.println("INFO: GossipGirlState calculated offset: " + offset.toString()); } - public AttributesMap modifyAttributes(AttributesMap attributes) { + public ValueDuration delta() { ValueDuration delta = offset; if (!initiating) { delta = delta.negate(); } - attributes.addOrChange("timestamp", attributes.getOrNull("timestamp").subtract(delta)); + return delta; + } + + public AttributesMap modifyAttributes(AttributesMap attributes) { + attributes.addOrChange("timestamp", attributes.getOrNull("timestamp").subtract(delta())); return attributes; } @@ -220,7 +223,7 @@ public class GossipGirlState { System.out.println("DEBUG: timestamps to send: " + getZoneTimestampsToSend().toString()); for (Entry<PathName, ValueTime> timestampedPath : getZoneTimestampsToSend().entrySet()) { ValueTime theirTimestamp = theirZoneTimestamps.get(timestampedPath.getKey()); - if (theirTimestamp == null || ValueUtils.valueLower(theirTimestamp, timestampedPath.getValue())) { + if (theirTimestamp == null || ValueUtils.valueLower(theirTimestamp.subtract(delta()), timestampedPath.getValue())) { zonesToSend.add(timestampedPath.getKey()); } } @@ -310,10 +313,10 @@ public class GossipGirlState { break; case WAIT_FOR_FIRST_INFO: // TODO: use offset to setup GTP + offset = message.getOffset(); setZonesToSend(); setQueriesToSend(); setWaitingFor(); - offset = message.getOffset(); state = State.SEND_INFO; if (!waitingForZones.remove(message.getPath())) { diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlStateTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlStateTest.java new file mode 100644 index 0000000..b9162b8 --- /dev/null +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlStateTest.java @@ -0,0 +1,45 @@ +package pl.edu.mimuw.cloudatlas.agent.modules; + +import org.junit.Test; +import static org.junit.Assert.*; + +import pl.edu.mimuw.cloudatlas.model.PathName; +import pl.edu.mimuw.cloudatlas.model.ValueContact; +import pl.edu.mimuw.cloudatlas.model.ValueDuration; +import pl.edu.mimuw.cloudatlas.model.ValueInt; +import pl.edu.mimuw.cloudatlas.model.ValueTime; + +public class GossipGirlStateTest { + @Test + public void gtpTest1() throws Exception { + GossipGirlState state = new GossipGirlState(0, new PathName("/"), new ValueContact(null, null), true); + state.hejkaSendTimestamp = new ValueTime(100l); + state.hejkaReceiveTimestamp = new ValueTime(110l); + state.noCoTamSendTimestamp = new ValueTime(120l); + state.noCoTamReceiveTimestamp = new ValueTime(130l); + state.computeOffset(); + assertEquals(new ValueDuration(0l), state.offset); + } + + @Test + public void gtpTest2() throws Exception { + GossipGirlState state = new GossipGirlState(0, new PathName("/"), new ValueContact(null, null), true); + state.hejkaSendTimestamp = new ValueTime(100l); + state.hejkaReceiveTimestamp = new ValueTime(60l); + state.noCoTamSendTimestamp = new ValueTime(70l); + state.noCoTamReceiveTimestamp = new ValueTime(130l); + state.computeOffset(); + assertEquals(new ValueDuration(-50l), state.offset); + } + + @Test + public void gtpTest3() throws Exception { + GossipGirlState state = new GossipGirlState(0, new PathName("/"), new ValueContact(null, null), true); + state.hejkaSendTimestamp = new ValueTime(100l); + state.hejkaReceiveTimestamp = new ValueTime(160l); + state.noCoTamSendTimestamp = new ValueTime(170l); + state.noCoTamReceiveTimestamp = new ValueTime(130l); + state.computeOffset(); + assertEquals(new ValueDuration(50l), state.offset); + } +} |