diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java | 27 | ||||
-rw-r--r-- | src/test/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementationTests.java | 52 |
2 files changed, 34 insertions, 45 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java index c0b313d..3bedd90 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementation.java @@ -6,8 +6,11 @@ import java.rmi.RemoteException; import java.util.concurrent.CompletableFuture; import java.util.List; +import java.util.AbstractMap.SimpleImmutableEntry; +import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.regex.Pattern; import java.util.regex.Matcher; @@ -16,6 +19,7 @@ import java.util.regex.Matcher; import pl.edu.mimuw.cloudatlas.agent.messages.RequestStateMessage; import pl.edu.mimuw.cloudatlas.agent.messages.ResponseMessage; import pl.edu.mimuw.cloudatlas.agent.messages.StateMessage; +import pl.edu.mimuw.cloudatlas.agent.messages.UpdateQueriesMessage; import pl.edu.mimuw.cloudatlas.interpreter.Interpreter; import pl.edu.mimuw.cloudatlas.interpreter.InterpreterException; import pl.edu.mimuw.cloudatlas.interpreter.Main; @@ -25,9 +29,10 @@ import pl.edu.mimuw.cloudatlas.model.AttributesMap; import pl.edu.mimuw.cloudatlas.model.PathName; import pl.edu.mimuw.cloudatlas.model.ValueContact; import pl.edu.mimuw.cloudatlas.model.Value; +import pl.edu.mimuw.cloudatlas.model.ValueNull; import pl.edu.mimuw.cloudatlas.model.ValueQuery; import pl.edu.mimuw.cloudatlas.model.ValueSet; -import pl.edu.mimuw.cloudatlas.model.ValueNull; +import pl.edu.mimuw.cloudatlas.model.ValueTime; import pl.edu.mimuw.cloudatlas.model.Type; import pl.edu.mimuw.cloudatlas.model.TypePrimitive; import pl.edu.mimuw.cloudatlas.model.ZMI; @@ -90,7 +95,6 @@ public class NewApiImplementation implements Api { } public void installQuery(String name, String queryCode) throws RemoteException { - /* Pattern queryNamePattern = Pattern.compile("&[a-zA-Z][\\w_]*"); Matcher matcher = queryNamePattern.matcher(name); if (!matcher.matches()) { @@ -99,23 +103,14 @@ public class NewApiImplementation implements Api { try { ValueQuery query = new ValueQuery(queryCode); Attribute attributeName = new Attribute(name); - installQueryInHierarchy(root, attributeName, query); - executeAllQueries(root); + ValueTime timestamp = new ValueTime(System.currentTimeMillis()); + Map<Attribute, Entry<ValueQuery, ValueTime>> queries = new HashMap(); + queries.put(attributeName, new SimpleImmutableEntry(query, timestamp)); + UpdateQueriesMessage message = new UpdateQueriesMessage("", 0, queries); + eventBus.addMessage(message); } catch (Exception e) { throw new RemoteException("Failed to install query", e); } - */ - } - - private void installQueryInHierarchy(ZMI zmi, Attribute queryName, ValueQuery query) { - /* - if (!zmi.getSons().isEmpty()) { - zmi.getAttributes().addOrChange(queryName, query); - for (ZMI son : zmi.getSons()) { - installQueryInHierarchy(son, queryName, query); - } - } - */ } public void uninstallQuery(String queryName) throws RemoteException { 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 78e5970..e48df0b 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementationTests.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementationTests.java @@ -8,15 +8,22 @@ import static org.hamcrest.CoreMatchers.hasItems; import java.util.concurrent.TimeUnit; import java.util.HashMap; import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import pl.edu.mimuw.cloudatlas.Container; import pl.edu.mimuw.cloudatlas.agent.modules.ModuleType; import pl.edu.mimuw.cloudatlas.agent.messages.AgentMessage; import pl.edu.mimuw.cloudatlas.agent.messages.RequestStateMessage; +import pl.edu.mimuw.cloudatlas.agent.messages.StanikMessage; import pl.edu.mimuw.cloudatlas.agent.messages.StateMessage; +import pl.edu.mimuw.cloudatlas.agent.messages.UpdateQueriesMessage; +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.ValueString; +import pl.edu.mimuw.cloudatlas.model.ValueQuery; import pl.edu.mimuw.cloudatlas.model.ValueTime; import pl.edu.mimuw.cloudatlas.model.ZMI; @@ -124,42 +131,29 @@ public class NewApiImplementationTests { assertEquals(new ValueString("son"), attributes.thing.getOrNull("name")); } - /* - @Test - public void testIntermediateGetZoneAttributeValue() throws Exception { - AttributesMap attributes = api.getZoneAttributeValues("/uw"); - assertEquals(new ValueInt(1l), attributes.get("level")); - assertEquals(new ValueString("uw"), attributes.get("name")); - } - - @Test - public void testLeafGetZoneAttributeValue() throws Exception { - AttributesMap attributes = api.getZoneAttributeValues("/pjwstk/whatever01"); - assertEquals(new ValueInt(2l), attributes.get("level")); - assertEquals(new ValueString("whatever01"), attributes.get("name")); - assertEquals(new ValueString("/pjwstk/whatever01"), attributes.get("owner")); - assertEquals(new ValueTime("2012/11/09 21:12:00.000"), attributes.get("timestamp")); - assertEquals(new ValueInt(1l), attributes.get("cardinality")); - assertEquals(new ValueTime("2012/10/18 07:03:00.000"), attributes.get("creation")); - assertEquals(new ValueDouble(0.1), attributes.get("cpu_usage")); - assertEquals(new ValueInt(7l), attributes.get("num_cores")); - assertEquals(new ValueInt(215l), attributes.get("num_processes")); - - List<Value> phpModules = new ArrayList<Value>(); - phpModules.add(new ValueString("rewrite")); - assertEquals(new ValueList(phpModules, TypePrimitive.STRING), attributes.get("php_modules")); - } - @Test public void testInstallQuery() throws Exception { String name = "&query"; String queryCode = "SELECT 1 AS one"; + long timeBefore = System.currentTimeMillis(); api.installQuery(name, queryCode); - assertAttributeInZmiEquals(name, new ValueQuery(queryCode), "/"); - assertAttributeInZmiEquals(name, new ValueQuery(queryCode), "/uw"); - assertAttributeInZmiEquals(name, new ValueQuery(queryCode), "/pjwstk"); + 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())); + assertEquals(new ValueQuery("SELECT 1 AS one"), queries.get(new Attribute("&query")).getKey()); + long timestamp = queries.get(new Attribute("&query")).getValue().getValue(); + assertTrue(timeBefore <= timestamp); + assertTrue(timestamp <= timeAfter); } + /* @Test public void testInstallQueryRuns() throws Exception { api.installQuery("&query", "SELECT 1 AS one"); |