m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/pl/edu/mimuw/cloudatlas
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/pl/edu/mimuw/cloudatlas')
-rw-r--r--src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java1
-rw-r--r--src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java23
-rw-r--r--src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java36
3 files changed, 45 insertions, 15 deletions
diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java
index f731706..922ebe2 100644
--- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java
+++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java
@@ -20,6 +20,7 @@ import java.net.UnknownHostException;
// TODO add serialization tests that target custom serializers (type collections!)
+@Ignore
public class UDUPTest {
@Test
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 d443fad..dbacfe5 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
@@ -34,6 +34,7 @@ import pl.edu.mimuw.cloudatlas.model.Attribute;
import pl.edu.mimuw.cloudatlas.model.PathName;
import pl.edu.mimuw.cloudatlas.model.TestUtil;
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.ValueQuery;
import pl.edu.mimuw.cloudatlas.model.ValueString;
@@ -57,6 +58,7 @@ public class GossipGirlTest {
private AttributesMessage attributesMessage2;
private QueryMessage queryMessage1;
private QueryMessage queryMessage2;
+ private ValueDuration offset;
private HejkaMessage hejkaMessage;
@@ -84,7 +86,10 @@ public class GossipGirlTest {
Map<PathName, ValueTime> otherZoneTimestamps = makeOtherZoneTimestamps();
Map<Attribute, ValueTime> otherQueryTimestamps = makeOtherQueryTimestamps();
- noCoTamMessage = new NoCoTamMessage("", 0, 42, 0, otherZoneTimestamps, otherQueryTimestamps, ValueUtils.addToTime(testTime, 10), ValueUtils.addToTime(testTime, 22));
+ noCoTamMessage = new NoCoTamMessage("", 0, 42, 0, otherZoneTimestamps, otherQueryTimestamps, ValueUtils.addToTime(testTime, 10), ValueUtils.addToTime(testTime, 30));
+ noCoTamMessage.setSentTimestamp(ValueUtils.addToTime(testTime, 35));
+ noCoTamMessage.setReceivedTimestamp(ValueUtils.addToTime(testTime, 255));
+ offset = new ValueDuration(-100l);
attributesMessage1 = makeAttributesMessage("/son/bro", makeAttributes1());
attributesMessage2 = makeAttributesMessage("/son/whodis", makeAttributes2());
@@ -99,7 +104,7 @@ public class GossipGirlTest {
public QueryMessage makeQueryMessage(String name, String query) throws Exception {
- return new QueryMessage("", 0, new Attribute(name), new ValueQuery(query), 0);
+ return new QueryMessage("", 0, new Attribute(name), new ValueQuery(query), 0, offset);
}
public AttributesMap makeAttributes1() {
@@ -121,12 +126,12 @@ public class GossipGirlTest {
}
public AttributesMessage makeAttributesMessage(String path, AttributesMap attributes) {
- return new AttributesMessage("", 0, new PathName(path), attributes, 0);
+ return new AttributesMessage("", 0, new PathName(path), attributes, 0, offset);
}
public Map<PathName, ValueTime> makeOtherZoneTimestamps() {
Map<PathName, ValueTime> zoneTimestamps = new HashMap();
- addOtherZoneTimestamp(zoneTimestamps, "/son/sis", -100);
+ addOtherZoneTimestamp(zoneTimestamps, "/son/sis", -120);
addOtherZoneTimestamp(zoneTimestamps, "/son/bro", 0);
addOtherZoneTimestamp(zoneTimestamps, "/son/whodis", -300);
@@ -272,8 +277,7 @@ public class GossipGirlTest {
assertEquals(StanikMessage.Type.UPDATE_ATTRIBUTES, stanikMessage1.getType());
UpdateAttributesMessage updateMessage1 = (UpdateAttributesMessage) stanikMessage1;
assertEquals("/son/bro", updateMessage1.getPathName());
- // TODO: this should be modified by GTP
- assertEquals(testTime, updateMessage1.getAttributes().getOrNull("timestamp"));
+ assertEquals(ValueUtils.addToTime(testTime, 100), updateMessage1.getAttributes().getOrNull("timestamp"));
assertEquals(new ValueInt(140l), updateMessage1.getAttributes().getOrNull("foo"));
assertEquals(new ValueString(":wq"), updateMessage1.getAttributes().getOrNull("bar"));
@@ -289,7 +293,6 @@ public class GossipGirlTest {
assertEquals(updateMessage2.getQueries().get(new Attribute("&one")),
new SimpleImmutableEntry(
new ValueQuery("SELECT 3 AS one"),
- // TODO: this should be modified by GTP
ValueUtils.addToTime(testTime, 10)
)
);
@@ -385,8 +388,7 @@ public class GossipGirlTest {
assertEquals(StanikMessage.Type.UPDATE_ATTRIBUTES, stanikMessage1.getType());
UpdateAttributesMessage updateMessage1 = (UpdateAttributesMessage) stanikMessage1;
assertEquals("/son/bro", updateMessage1.getPathName());
- // TODO: this should be modified by GTP
- assertEquals(testTime, updateMessage1.getAttributes().getOrNull("timestamp"));
+ assertEquals(ValueUtils.addToTime(testTime, -100), updateMessage1.getAttributes().getOrNull("timestamp"));
assertEquals(new ValueInt(140l), updateMessage1.getAttributes().getOrNull("foo"));
assertEquals(new ValueString(":wq"), updateMessage1.getAttributes().getOrNull("bar"));
@@ -402,7 +404,6 @@ public class GossipGirlTest {
assertEquals(updateMessage2.getQueries().get(new Attribute("&one")),
new SimpleImmutableEntry(
new ValueQuery("SELECT 3 AS one"),
- // TODO: this should be modified by GTP
ValueUtils.addToTime(testTime, 10)
)
);
@@ -462,6 +463,7 @@ public class GossipGirlTest {
QueryMessage queryMessage = (QueryMessage) ((UDUPMessage) message).getContent();
assertEquals(new Attribute(name), queryMessage.getName());
assertEquals(new ValueQuery(query), queryMessage.getQuery());
+ assertEquals(new ValueDuration(-100l), queryMessage.getOffset());
}
private void assertAttributeMessage(AgentMessage message, String recipientPath, String zonePath) throws Exception {
@@ -472,6 +474,7 @@ public class GossipGirlTest {
);
AttributesMessage attributesMessage = (AttributesMessage) ((UDUPMessage) message).getContent();
assertEquals(new PathName(zonePath), attributesMessage.getPath());
+ assertEquals(new ValueDuration(-100l), attributesMessage.getOffset());
}
private void assertUDUPMessage(AgentMessage message, PathName destinationName, GossipGirlMessage.Type type) throws Exception {
diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java
index f3ea0b0..92ba051 100644
--- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java
+++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java
@@ -39,7 +39,7 @@ public class StanikTest {
@Before
public void setupLocals() {
- stanik = new Stanik(freshnessPeriod);
+ stanik = new Stanik(new PathName("/new"), freshnessPeriod);
executor = new MockExecutor(stanik);
testTime = ValueUtils.currentTime();
}
@@ -57,9 +57,11 @@ public class StanikTest {
ZMI zmi = stateMessage.getZMI();
assertNull(zmi.getFather());
assertTrue(zmi.getSons().isEmpty());
- assertEquals(1, TestUtil.iterableSize(zmi.getAttributes()));
+ assertEquals(3, TestUtil.iterableSize(zmi.getAttributes()));
+ assertEquals(new ValueInt(0l), zmi.getAttributes().getOrNull("level"));
+ assertEquals(new ValueString("/new"), zmi.getAttributes().getOrNull("owner"));
Map<Attribute, Entry<ValueQuery, ValueTime>> queries = stateMessage.getQueries();
- assertEquals(0, TestUtil.iterableSize(queries.keySet()));
+ assertEquals(2, TestUtil.iterableSize(queries.keySet()));
}
@Test
@@ -112,6 +114,30 @@ public class StanikTest {
}
@Test
+ public void newZoneHasNewLevel() throws Exception {
+ AttributesMap attributes = new AttributesMap();
+ attributes.add("foo", new ValueInt(1337l));
+ attributes.add("bar", new ValueString("baz"));
+ attributes.add("name", new ValueString("new"));
+ attributes.add("timestamp", testTime);
+ UpdateAttributesMessage message = new UpdateAttributesMessage("test_msg", 0, "/new", attributes);
+ stanik.handleTyped(message);
+ GetStateMessage newMessage = new GetStateMessage("test_msg2", 123, ModuleType.TEST, 43);
+ stanik.handleTyped(newMessage);
+
+ StateMessage newReceivedMessage = (StateMessage) executor.messagesToPass.poll();
+ AttributesMap actualAttributes = newReceivedMessage.getZMI().findDescendant("/new").getAttributes();
+ assertEquals(7, TestUtil.iterableSize(actualAttributes));
+ assertEquals(new ValueInt(1337l), actualAttributes.getOrNull("foo"));
+ assertEquals(new ValueString("baz"), actualAttributes.getOrNull("bar"));
+ assertEquals(new ValueString("new"), actualAttributes.getOrNull("name"));
+ assertEquals(new ValueString("/new"), actualAttributes.getOrNull("owner"));
+ assertEquals(new ValueInt(1l), actualAttributes.getOrNull("cardinality"));
+ assertEquals(testTime, actualAttributes.getOrNull("timestamp"));
+ assertEquals(new ValueInt(1l), actualAttributes.getOrNull("level"));
+ }
+
+ @Test
public void updateWithRemovedAttributes() throws Exception {
AttributesMap attributes = new AttributesMap();
attributes.add("foo", new ValueInt(1337l));
@@ -198,7 +224,7 @@ public class StanikTest {
stanik.handleTyped(message);
HashMap<Attribute, Entry<ValueQuery, ValueTime>> actualQueries = stanik.getQueries();
- assertEquals(1, TestUtil.iterableSize(actualQueries.keySet()));
+ assertEquals(3, TestUtil.iterableSize(actualQueries.keySet()));
assertTrue(actualQueries.containsKey(new Attribute("&query")));
Entry<ValueQuery, ValueTime> timestampedQuery = actualQueries.get(new Attribute("&query"));
assertEquals(new ValueTime(42l), timestampedQuery.getValue());
@@ -222,7 +248,7 @@ public class StanikTest {
stanik.handleTyped(otherMessage);
HashMap<Attribute, Entry<ValueQuery, ValueTime>> actualQueries = stanik.getQueries();
- assertEquals(4, TestUtil.iterableSize(actualQueries.keySet()));
+ assertEquals(6, TestUtil.iterableSize(actualQueries.keySet()));
assertTrue(actualQueries.containsKey(new Attribute("&query1")));
assertTrue(actualQueries.containsKey(new Attribute("&query2")));
assertTrue(actualQueries.containsKey(new Attribute("&query3")));