m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2020-01-12 17:10:36 +0100
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2020-01-12 17:10:36 +0100
commita07000c6dae6f84dd221454fca24b65e9579afae (patch)
treecd647a463f073840842a7d8283597031322d7c59 /src/test/java/pl/edu/mimuw/cloudatlas/agent/modules
parent9c6a9bb5a8ce6d3282d1fd669214911c302e9aca (diff)
parentf0076abd246bdf40ba4a03c0c894f6f75173eac8 (diff)
Merge branch 'master' into logs-n-stuff
Diffstat (limited to 'src/test/java/pl/edu/mimuw/cloudatlas/agent/modules')
-rw-r--r--src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java57
1 files changed, 50 insertions, 7 deletions
diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java
index 5fac535..d443fad 100644
--- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java
+++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java
@@ -16,6 +16,7 @@ import java.util.Set;
import pl.edu.mimuw.cloudatlas.agent.MockExecutor;
import pl.edu.mimuw.cloudatlas.agent.messages.AgentMessage;
import pl.edu.mimuw.cloudatlas.agent.messages.AttributesMessage;
+import pl.edu.mimuw.cloudatlas.agent.messages.CleanOldGossipsMessage;
import pl.edu.mimuw.cloudatlas.agent.messages.HejkaMessage;
import pl.edu.mimuw.cloudatlas.agent.messages.GetStateMessage;
import pl.edu.mimuw.cloudatlas.agent.messages.GossipGirlMessage;
@@ -83,7 +84,7 @@ public class GossipGirlTest {
Map<PathName, ValueTime> otherZoneTimestamps = makeOtherZoneTimestamps();
Map<Attribute, ValueTime> otherQueryTimestamps = makeOtherQueryTimestamps();
- noCoTamMessage = new NoCoTamMessage("", 0, 42, 0, otherZoneTimestamps, otherQueryTimestamps, TestUtil.addToTime(testTime, 10), TestUtil.addToTime(testTime, 22));
+ noCoTamMessage = new NoCoTamMessage("", 0, 42, 0, otherZoneTimestamps, otherQueryTimestamps, ValueUtils.addToTime(testTime, 10), ValueUtils.addToTime(testTime, 22));
attributesMessage1 = makeAttributesMessage("/son/bro", makeAttributes1());
attributesMessage2 = makeAttributesMessage("/son/whodis", makeAttributes2());
@@ -92,7 +93,7 @@ public class GossipGirlTest {
hejkaMessage = new HejkaMessage("", 0, 123, new PathName("/son/bro"), new PathName("/son/grand"), otherZoneTimestamps, otherQueryTimestamps);
hejkaMessage.setSentTimestamp(testTime);
- hejkaMessage.setReceivedTimestamp(TestUtil.addToTime(testTime, 15));
+ hejkaMessage.setReceivedTimestamp(ValueUtils.addToTime(testTime, 15));
hejkaMessage.setSenderAddress(theirContact.getAddress());
}
@@ -113,7 +114,7 @@ public class GossipGirlTest {
public AttributesMap makeAttributes2() {
AttributesMap attributes = new AttributesMap();
attributes.add("name", new ValueString("whodis"));
- attributes.add("timestamp", TestUtil.addToTime(testTime, -300));
+ attributes.add("timestamp", ValueUtils.addToTime(testTime, -300));
attributes.add("foo", new ValueInt(61l));
attributes.add("bar", new ValueString("nice"));
return attributes;
@@ -141,11 +142,11 @@ public class GossipGirlTest {
}
public void addOtherQueryTimestamp(Map<Attribute, ValueTime> timestamps, String name, long offset) {
- timestamps.put(new Attribute(name), TestUtil.addToTime(testTime, offset));
+ timestamps.put(new Attribute(name), ValueUtils.addToTime(testTime, offset));
}
public void addOtherZoneTimestamp(Map<PathName, ValueTime> timestamps, String path, long offset) {
- timestamps.put(new PathName(path), TestUtil.addToTime(testTime, offset));
+ timestamps.put(new PathName(path), ValueUtils.addToTime(testTime, offset));
}
public void setupHierarchy() {
@@ -289,7 +290,7 @@ public class GossipGirlTest {
new SimpleImmutableEntry(
new ValueQuery("SELECT 3 AS one"),
// TODO: this should be modified by GTP
- TestUtil.addToTime(testTime, 10)
+ ValueUtils.addToTime(testTime, 10)
)
);
@@ -402,7 +403,7 @@ public class GossipGirlTest {
new SimpleImmutableEntry(
new ValueQuery("SELECT 3 AS one"),
// TODO: this should be modified by GTP
- TestUtil.addToTime(testTime, 10)
+ ValueUtils.addToTime(testTime, 10)
)
);
@@ -410,6 +411,48 @@ public class GossipGirlTest {
gossipGirl.handleTyped(queryMessage2);
}
+ @Test
+ public void cleanupOldGossips() throws Exception {
+ gossipGirl.handleTyped(hejkaMessage);
+ executor.messagesToPass.take();
+ gossipGirl.handleTyped(stateMessage);
+ executor.messagesToPass.take();
+
+ gossipGirl.handleTyped(attributesMessage1);
+ executor.messagesToPass.take();
+ executor.messagesToPass.take();
+ executor.messagesToPass.take();
+ executor.messagesToPass.take();
+ executor.messagesToPass.take();
+ executor.messagesToPass.take();
+
+ CleanOldGossipsMessage message = new CleanOldGossipsMessage("", 0, ValueUtils.addToTime(ValueUtils.currentTime(), 10));
+ gossipGirl.handleTyped(message);
+ gossipGirl.handleTyped(attributesMessage2);
+ assertEquals(0, executor.messagesToPass.size());
+ }
+
+ @Test
+ public void dontCleanFreshGossips() throws Exception {
+ gossipGirl.handleTyped(hejkaMessage);
+ executor.messagesToPass.take();
+ gossipGirl.handleTyped(stateMessage);
+ executor.messagesToPass.take();
+
+ gossipGirl.handleTyped(attributesMessage1);
+ executor.messagesToPass.take();
+ executor.messagesToPass.take();
+ executor.messagesToPass.take();
+ executor.messagesToPass.take();
+ executor.messagesToPass.take();
+ executor.messagesToPass.take();
+
+ CleanOldGossipsMessage message = new CleanOldGossipsMessage("", 0, ValueUtils.addToTime(testTime, -10));
+ gossipGirl.handleTyped(message);
+ gossipGirl.handleTyped(attributesMessage2);
+ assertEquals(1, executor.messagesToPass.size());
+ }
+
private void assertQueryMessage(AgentMessage message, String recipientPath, String name, String query) throws Exception {
assertUDUPMessage(
message,