From 393f087e7e3d2e3a636ae0ffeb075c2354ff0966 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Tue, 31 Dec 2019 14:54:02 +0100 Subject: Handle removed queries in Qurnik --- .../mimuw/cloudatlas/agent/modules/QurnikTest.java | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src/test') 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> 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); + } } -- cgit v1.2.3