diff options
Diffstat (limited to 'src/test/java/pl/edu')
3 files changed, 48 insertions, 83 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 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<Attribute, Entry<ValueQuery, ValueTime>> initiatorQueries; + private Map<Attribute, ValueQuery> 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<Attribute, Entry<ValueQuery, ValueTime>> queries, String name, String query, ValueTime timestamp) throws Exception { + public void addQuery(Map<Attribute, ValueQuery> 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<Attribute, Entry<ValueQuery, ValueTime>> queries = new HashMap(); + Map<Attribute, ValueQuery> 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<Attribute, Entry<ValueQuery, ValueTime>> setupSampleQueries() throws Exception { - Map<Attribute, Entry<ValueQuery, ValueTime>> queries = new HashMap(); + public Map<Attribute, ValueQuery> setupSampleQueries() throws Exception { + Map<Attribute, ValueQuery> 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<Attribute, Entry<ValueQuery, ValueTime>> queries = setupSampleQueries(); + Map<Attribute, ValueQuery> 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<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) - ) - ); + Map<Attribute, ValueQuery> 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<Attribute, Entry<ValueQuery, ValueTime>> queries = stateMessage.getQueries(); + Map<Attribute, ValueQuery> queries = stateMessage.getQueries(); assertEquals(2, TestUtil.iterableSize(queries.keySet())); } @@ -218,57 +218,58 @@ public class StanikTest { @Test public void addQuery() throws Exception { - HashMap<Attribute, Entry<ValueQuery, ValueTime>> queries = new HashMap<Attribute, Entry<ValueQuery, ValueTime>>(); - queries.put(new Attribute("&query"), new SimpleImmutableEntry(new ValueQuery("SELECT 1 AS one"), new ValueTime(42l))); + HashMap<Attribute, ValueQuery> queries = new HashMap<Attribute, ValueQuery>(); + 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<Attribute, Entry<ValueQuery, ValueTime>> actualQueries = stanik.getQueries(); + HashMap<Attribute, ValueQuery> actualQueries = stanik.getQueries(); 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()); - 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<Attribute, Entry<ValueQuery, ValueTime>> queries = new HashMap<Attribute, Entry<ValueQuery, ValueTime>>(); - 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<Attribute, ValueQuery> queries = new HashMap<Attribute, ValueQuery>(); + 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<Attribute, Entry<ValueQuery, ValueTime>> otherQueries = new HashMap<Attribute, Entry<ValueQuery, ValueTime>>(); - 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<Attribute, ValueQuery> otherQueries = new HashMap<Attribute, ValueQuery>(); + 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<Attribute, Entry<ValueQuery, ValueTime>> actualQueries = stanik.getQueries(); + HashMap<Attribute, ValueQuery> 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<ValueQuery, ValueTime> 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<ValueQuery, ValueTime> 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<ValueQuery, ValueTime> 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<ValueQuery, ValueTime> 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 |