m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/pl
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2019-12-31 15:00:10 +0100
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2019-12-31 15:00:10 +0100
commit17d87268246d32a75407590f8fef118148b87ccd (patch)
tree7f0ea4c5d0559e0adc3c3ee1b865ee55bf2bb7c6 /src/test/java/pl
parent393f087e7e3d2e3a636ae0ffeb075c2354ff0966 (diff)
Implement query removal in new API
Diffstat (limited to 'src/test/java/pl')
-rw-r--r--src/test/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementationTests.java54
1 files changed, 16 insertions, 38 deletions
diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementationTests.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementationTests.java
index e48df0b..a2c1adf 100644
--- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementationTests.java
+++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementationTests.java
@@ -153,50 +153,28 @@ public class NewApiImplementationTests {
assertTrue(timestamp <= timeAfter);
}
- /*
- @Test
- public void testInstallQueryRuns() throws Exception {
- api.installQuery("&query", "SELECT 1 AS one");
- assertAttributeInZmiEquals("one", new ValueInt(1l), "/");
- assertAttributeInZmiEquals("one", new ValueInt(1l), "/uw");
- assertAttributeInZmiEquals("one", new ValueInt(1l), "/pjwstk");
- }
-
- @Test
- public void testInstallQueryRuns2() throws Exception {
- api.installQuery("&query", "SELECT sum(num_processes) AS num_processes");
- assertAttributeInZmiEquals("num_processes", new ValueInt(362l), "/uw");
- assertAttributeInZmiEquals("num_processes", new ValueInt(437l), "/pjwstk");
- assertAttributeInZmiEquals("num_processes", new ValueInt(799l), "/");
- }
-
- @Test
- public void testInstallQueryWithInvalidNameFails() throws Exception {
- String name = "query";
- String queryCode = "SELECT 1 AS one";
- try {
- api.installQuery(name, queryCode);
- assertTrue("should have thrown", false);
- } catch (Exception e) {
- assertEquals("Invalid query identifier", e.getMessage());
- }
- }
-
- public void assertAttributeInZmiEquals(String attribute, Value expected, String zmiPath) throws Exception {
- AttributesMap attributes = api.getZoneAttributeValues(zmiPath);
- assertEquals(expected, attributes.get(attribute));
- }
-
@Test
public void testUninstallQuery() throws Exception {
String name = "&query";
- String queryCode = "SELECT 1 AS one";
- api.installQuery(name, queryCode);
+ long timeBefore = System.currentTimeMillis();
api.uninstallQuery(name);
- AttributesMap attributes = api.getZoneAttributeValues("/pjwstk");
- assertNull(attributes.getOrNull(name));
+ long timeAfter = System.currentTimeMillis();
+
+ assertEquals(1, eventBus.events.size());
+ AgentMessage message = eventBus.events.take();
+ assertEquals(ModuleType.STATE, message.getDestinationModule());
+ StanikMessage stanikMessage = (StanikMessage) message;
+ assertEquals(StanikMessage.Type.UPDATE_QUERIES, stanikMessage.getType());
+ UpdateQueriesMessage updateMessage = (UpdateQueriesMessage) stanikMessage;
+ Map<Attribute, Entry<ValueQuery, ValueTime>> queries = updateMessage.getQueries();
+ assertEquals(1, TestUtil.iterableSize(queries.keySet()));
+ assertNull(queries.get(new Attribute("&query")).getKey());
+ long timestamp = queries.get(new Attribute("&query")).getValue().getValue();
+ assertTrue(timeBefore <= timestamp);
+ assertTrue(timestamp <= timeAfter);
}
+ /*
@Test
public void testSetAttributeValueChange() throws Exception {
Value numProcesses = new ValueInt(42l);