From b3dd7a505549662d558eec550f210f0d6f0ec547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Tue, 14 Jan 2020 21:53:53 +0100 Subject: Fix tests after value query change --- .../cloudatlas/agent/modules/GossipGirlTest.java | 16 ++---- .../mimuw/cloudatlas/agent/modules/QurnikTest.java | 58 ++++++---------------- .../mimuw/cloudatlas/agent/modules/StanikTest.java | 57 ++++++++++----------- 3 files changed, 48 insertions(+), 83 deletions(-) (limited to 'src/test/java') 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 dbacfe5..0a0042f 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 @@ -51,7 +51,7 @@ public class GossipGirlTest { private InitiateGossipMessage initiateGossipMessage; private ValueTime testTime; private ZMI initiatorHierarchy; - private Map> initiatorQueries; + private Map initiatorQueries; private StateMessage stateMessage; private NoCoTamMessage noCoTamMessage; private AttributesMessage attributesMessage1; @@ -170,10 +170,10 @@ public class GossipGirlTest { addQuery(initiatorQueries, "&query", "SELECT sum(foo) AS foo", testTime); } - public void addQuery(Map> queries, String name, String query, ValueTime timestamp) throws Exception { + public void addQuery(Map queries, String name, String query, ValueTime timestamp) throws Exception { queries.put( new Attribute(name), - new SimpleImmutableEntry(new ValueQuery(query), timestamp) + new ValueQuery(query, timestamp.getValue()) ); } @@ -291,10 +291,7 @@ public class GossipGirlTest { assertEquals(1, updateMessage2.getQueries().keySet().size()); assertThat(updateMessage2.getQueries().keySet(), hasItems(new Attribute("&one"))); assertEquals(updateMessage2.getQueries().get(new Attribute("&one")), - new SimpleImmutableEntry( - new ValueQuery("SELECT 3 AS one"), - ValueUtils.addToTime(testTime, 10) - ) + new ValueQuery("SELECT 3 AS one", ValueUtils.addToTime(testTime, 10).getValue()) ); gossipGirl.handleTyped(attributesMessage2); @@ -402,10 +399,7 @@ public class GossipGirlTest { assertEquals(1, updateMessage2.getQueries().keySet().size()); assertThat(updateMessage2.getQueries().keySet(), hasItems(new Attribute("&one"))); assertEquals(updateMessage2.getQueries().get(new Attribute("&one")), - new SimpleImmutableEntry( - new ValueQuery("SELECT 3 AS one"), - ValueUtils.addToTime(testTime, 10) - ) + new ValueQuery("SELECT 3 AS one", ValueUtils.addToTime(testTime, 10).getValue()) ); gossipGirl.handleTyped(attributesMessage2); 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 a8d0ecb..2749d3f 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 @@ -56,13 +56,10 @@ public class QurnikTest { root.addSon(son); AttributesMap sonAttributes = new AttributesMap(); sonAttributes.add("name", new ValueString("son")); - Map> queries = new HashMap(); + Map queries = new HashMap(); queries.put( new Attribute("&query"), - new SimpleImmutableEntry( - new ValueQuery("SELECT 1 AS one"), - new ValueTime(0l) - ) + new ValueQuery("SELECT 1 AS one") ); StateMessage message = new StateMessage("", ModuleType.QUERY, 0, 0, root, queries, new HashSet()); long timeBefore = System.currentTimeMillis(); @@ -122,43 +119,28 @@ public class QurnikTest { return root; } - public Map> setupSampleQueries() throws Exception { - Map> queries = new HashMap(); + public Map setupSampleQueries() throws Exception { + Map queries = new HashMap(); queries.put( new Attribute("&query1"), - new SimpleImmutableEntry( - new ValueQuery("SELECT sum(x) AS x"), - new ValueTime(0l) - ) + new ValueQuery("SELECT sum(x) AS x") ); queries.put( new Attribute("&query2"), - new SimpleImmutableEntry( - new ValueQuery("SELECT min(y) AS y"), - new ValueTime(0l) - ) + new ValueQuery("SELECT min(y) AS y") ); queries.put( new Attribute("&query3"), - new SimpleImmutableEntry( - new ValueQuery("SELECT max(z) AS z"), - new ValueTime(0l) - ) + new ValueQuery("SELECT max(z) AS z") ); queries.put( new Attribute("&query4"), - new SimpleImmutableEntry( - new ValueQuery("SELECT sum(a + 1) AS a"), - new ValueTime(0l) - ) + new ValueQuery("SELECT sum(a + 1) AS a") ); queries.put( new Attribute("&query5"), - new SimpleImmutableEntry( - new ValueQuery("SELECT sum(2 * b) AS b"), - new ValueTime(0l) - ) + new ValueQuery("SELECT sum(2 * b) AS b") ); return queries; @@ -168,7 +150,7 @@ public class QurnikTest { public void multipleQueries() throws Exception { ZMI root = setupSampleHierarchy(); - Map> queries = setupSampleQueries(); + Map queries = setupSampleQueries(); StateMessage message = new StateMessage("", ModuleType.QUERY, 0, 0, root, queries, new HashSet()); long timeBefore = System.currentTimeMillis(); qurnik.handleTyped(message); @@ -209,22 +191,10 @@ public class QurnikTest { 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) - ) - ); + Map queries = new HashMap(); + queries.put(new Attribute("&query1"), new ValueQuery("SELECT 1 AS one")); + queries.put(new Attribute("&query2"), null); + queries.put(new Attribute("&query3"), new ValueQuery("SELECT 2 AS two")); StateMessage message = new StateMessage("", ModuleType.QUERY, 0, 0, root, queries, new HashSet()); long timeBefore = System.currentTimeMillis(); qurnik.handleTyped(message); 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 92ba051..3ad176a 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 @@ -60,7 +60,7 @@ public class StanikTest { assertEquals(3, TestUtil.iterableSize(zmi.getAttributes())); assertEquals(new ValueInt(0l), zmi.getAttributes().getOrNull("level")); assertEquals(new ValueString("/new"), zmi.getAttributes().getOrNull("owner")); - Map> queries = stateMessage.getQueries(); + Map queries = stateMessage.getQueries(); assertEquals(2, TestUtil.iterableSize(queries.keySet())); } @@ -218,57 +218,58 @@ public class StanikTest { @Test public void addQuery() throws Exception { - HashMap> queries = new HashMap>(); - queries.put(new Attribute("&query"), new SimpleImmutableEntry(new ValueQuery("SELECT 1 AS one"), new ValueTime(42l))); + HashMap queries = new HashMap(); + queries.put(new Attribute("&query"), new ValueQuery("SELECT 1 AS one", 42l)); UpdateQueriesMessage message = new UpdateQueriesMessage("test_msg", 0, queries); + System.out.println(message); stanik.handleTyped(message); - HashMap> actualQueries = stanik.getQueries(); + HashMap actualQueries = stanik.getQueries(); assertEquals(3, TestUtil.iterableSize(actualQueries.keySet())); assertTrue(actualQueries.containsKey(new Attribute("&query"))); - Entry timestampedQuery = actualQueries.get(new Attribute("&query")); - assertEquals(new ValueTime(42l), timestampedQuery.getValue()); - assertEquals(new ValueQuery("SELECT 1 AS one"), timestampedQuery.getKey()); + ValueQuery timestampedQuery = actualQueries.get(new Attribute("&query")); + assertEquals(42l, timestampedQuery.getTimestamp()); + assertEquals("SELECT 1 AS one", timestampedQuery.getCode()); } @Test public void updateQueries() throws Exception { - HashMap> queries = new HashMap>(); - queries.put(new Attribute("&query1"), new SimpleImmutableEntry(new ValueQuery("SELECT 1 AS one"), new ValueTime(42l))); - queries.put(new Attribute("&query3"), new SimpleImmutableEntry(new ValueQuery("SELECT 23 AS x"), new ValueTime(43l))); - queries.put(new Attribute("&query4"), new SimpleImmutableEntry(new ValueQuery("SELECT 1000 AS foo"), new ValueTime(43l))); + HashMap queries = new HashMap(); + queries.put(new Attribute("&query1"), new ValueQuery("SELECT 1 AS one", 42l)); + queries.put(new Attribute("&query3"), new ValueQuery("SELECT 23 AS x", 43l)); + queries.put(new Attribute("&query4"), new ValueQuery("SELECT 1000 AS foo", 43l)); UpdateQueriesMessage message = new UpdateQueriesMessage("test_msg", 0, queries); stanik.handleTyped(message); - HashMap> otherQueries = new HashMap>(); - otherQueries.put(new Attribute("&query1"), new SimpleImmutableEntry(new ValueQuery("SELECT 2 AS one"), new ValueTime(41l))); - otherQueries.put(new Attribute("&query2"), new SimpleImmutableEntry(new ValueQuery("SELECT 42 AS answer"), new ValueTime(39l))); - otherQueries.put(new Attribute("&query3"), new SimpleImmutableEntry(new ValueQuery("SELECT 17 AS y"), new ValueTime(44l))); + HashMap otherQueries = new HashMap(); + otherQueries.put(new Attribute("&query1"), new ValueQuery("SELECT 2 AS one", 41l)); + otherQueries.put(new Attribute("&query2"), new ValueQuery("SELECT 42 AS answer", 39l)); + otherQueries.put(new Attribute("&query3"), new ValueQuery("SELECT 17 AS y", 44l)); UpdateQueriesMessage otherMessage = new UpdateQueriesMessage("test_msg", 0, otherQueries); stanik.handleTyped(otherMessage); - HashMap> actualQueries = stanik.getQueries(); + HashMap actualQueries = stanik.getQueries(); assertEquals(6, TestUtil.iterableSize(actualQueries.keySet())); assertTrue(actualQueries.containsKey(new Attribute("&query1"))); assertTrue(actualQueries.containsKey(new Attribute("&query2"))); assertTrue(actualQueries.containsKey(new Attribute("&query3"))); assertTrue(actualQueries.containsKey(new Attribute("&query4"))); - Entry timestampedQuery1 = actualQueries.get(new Attribute("&query1")); - assertEquals(new ValueTime(42l), timestampedQuery1.getValue()); - assertEquals(new ValueQuery("SELECT 1 AS one"), timestampedQuery1.getKey()); + ValueQuery timestampedQuery1 = actualQueries.get(new Attribute("&query1")); + assertEquals(42l, timestampedQuery1.getTimestamp()); + assertEquals("SELECT 1 AS one", timestampedQuery1.getCode()); - Entry timestampedQuery2 = actualQueries.get(new Attribute("&query2")); - assertEquals(new ValueTime(39l), timestampedQuery2.getValue()); - assertEquals(new ValueQuery("SELECT 42 AS answer"), timestampedQuery2.getKey()); + ValueQuery timestampedQuery2 = actualQueries.get(new Attribute("&query2")); + assertEquals(39l, timestampedQuery2.getTimestamp()); + assertEquals("SELECT 42 AS answer", timestampedQuery2.getCode()); - Entry timestampedQuery3 = actualQueries.get(new Attribute("&query3")); - assertEquals(new ValueTime(44l), timestampedQuery3.getValue()); - assertEquals(new ValueQuery("SELECT 17 AS y"), timestampedQuery3.getKey()); + ValueQuery timestampedQuery3 = actualQueries.get(new Attribute("&query3")); + assertEquals(44l, timestampedQuery3.getTimestamp()); + assertEquals("SELECT 17 AS y", timestampedQuery3.getCode()); - Entry timestampedQuery4 = actualQueries.get(new Attribute("&query4")); - assertEquals(new ValueTime(43l), timestampedQuery4.getValue()); - assertEquals(new ValueQuery("SELECT 1000 AS foo"), timestampedQuery4.getKey()); + ValueQuery timestampedQuery4 = actualQueries.get(new Attribute("&query4")); + assertEquals(43l, timestampedQuery4.getTimestamp()); + assertEquals("SELECT 1000 AS foo", timestampedQuery4.getCode()); } @Test -- cgit v1.2.3