m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2019-12-31 14:54:02 +0100
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2019-12-31 14:54:02 +0100
commit393f087e7e3d2e3a636ae0ffeb075c2354ff0966 (patch)
treed32ece657f423b5b5e1417b01a8771bcb28765fc /src/test/java
parentcc3c39501d22a7901e3f6d164d040a08c7d897a7 (diff)
Handle removed queries in Qurnik
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/QurnikTest.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/QurnikTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/QurnikTest.java
index 0c10092..b6e4ea8 100644
--- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/QurnikTest.java
+++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/QurnikTest.java
@@ -16,6 +16,7 @@ import pl.edu.mimuw.cloudatlas.model.Attribute;
import pl.edu.mimuw.cloudatlas.model.AttributesMap;
import pl.edu.mimuw.cloudatlas.model.TestUtil;
import pl.edu.mimuw.cloudatlas.model.ValueInt;
+import pl.edu.mimuw.cloudatlas.model.ValueNull;
import pl.edu.mimuw.cloudatlas.model.ValueQuery;
import pl.edu.mimuw.cloudatlas.model.ValueString;
import pl.edu.mimuw.cloudatlas.model.ValueTime;
@@ -200,4 +201,51 @@ public class QurnikTest {
assertTrue(timeBefore <= timestamp2);
assertTrue(timestamp2 <= timeAfter);
}
+
+ @Test
+ public void ignoresNullQueries() throws Exception {
+ ZMI root = setupSampleHierarchy();
+
+ Map<Attribute, Entry<ValueQuery, ValueTime>> queries = new HashMap();
+ queries.put(new Attribute("&query1"), new SimpleImmutableEntry(
+ new ValueQuery("SELECT 1 AS one"),
+ new ValueTime(42l)
+ )
+ );
+ queries.put(new Attribute("&query2"), new SimpleImmutableEntry(
+ null,
+ new ValueTime(43l)
+ )
+ );
+ queries.put(new Attribute("&query3"), new SimpleImmutableEntry(
+ new ValueQuery("SELECT 2 AS two"),
+ new ValueTime(44l)
+ )
+ );
+ StateMessage message = new StateMessage("", ModuleType.QUERY, 0, 0, root, queries);
+ long timeBefore = System.currentTimeMillis();
+ qurnik.handleTyped(message);
+ long timeAfter = System.currentTimeMillis();
+
+ UpdateAttributesMessage message1 = (UpdateAttributesMessage) executor.messagesToPass.take();
+ assertEquals("/uw", message1.getPathName());
+ AttributesMap attributes1 = message1.getAttributes();
+ assertEquals(4, TestUtil.iterableSize(attributes1));
+ assertEquals(new ValueInt(1l), attributes1.getOrNull("one"));
+ assertEquals(new ValueInt(2l), attributes1.getOrNull("two"));
+ long timestamp1 = ((ValueTime) attributes1.getOrNull("timestamp")).getValue();
+ assertTrue(timeBefore <= timestamp1);
+ assertTrue(timestamp1 <= timeAfter);
+
+ UpdateAttributesMessage message2 = (UpdateAttributesMessage) executor.messagesToPass.take();
+ assertEquals("/", message2.getPathName());
+ AttributesMap attributes2 = message2.getAttributes();
+ System.out.println("got attributes " + attributes2.toString());
+ assertEquals(3, TestUtil.iterableSize(attributes2));
+ assertEquals(new ValueInt(1l), attributes2.getOrNull("one"));
+ assertEquals(new ValueInt(2l), attributes2.getOrNull("two"));
+ long timestamp2 = ((ValueTime) attributes2.getOrNull("timestamp")).getValue();
+ assertTrue(timeBefore <= timestamp2);
+ assertTrue(timestamp2 <= timeAfter);
+ }
}