From c515a2e3d673c565a7b5c406cd3ab4a7b33e8f4e Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Tue, 31 Dec 2019 14:16:03 +0100 Subject: Implement getting attributes in new API --- .../agent/NewApiImplementationTests.java | 75 ++++++++++++++++++++-- 1 file changed, 68 insertions(+), 7 deletions(-) (limited to 'src/test/java/pl') 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 a3b57a9..78e5970 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementationTests.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/NewApiImplementationTests.java @@ -6,15 +6,19 @@ import static org.junit.Assert.*; import static org.hamcrest.CoreMatchers.hasItems; import java.util.concurrent.TimeUnit; +import java.util.HashMap; import java.util.HashSet; import java.util.Set; import pl.edu.mimuw.cloudatlas.Container; -import pl.edu.mimuw.cloudatlas.model.ZMI; 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.StateMessage; +import pl.edu.mimuw.cloudatlas.model.AttributesMap; +import pl.edu.mimuw.cloudatlas.model.ValueString; +import pl.edu.mimuw.cloudatlas.model.ValueTime; +import pl.edu.mimuw.cloudatlas.model.ZMI; public class NewApiImplementationTests { private NewApiImplementation api; @@ -46,7 +50,6 @@ public class NewApiImplementationTests { ZMI root = new ZMI(); StateMessage responseMessage = new StateMessage("", ModuleType.RMI, 0, 0, root, null); - requestMessage.getFuture().complete(responseMessage); apiThread.join(100); @@ -56,14 +59,72 @@ public class NewApiImplementationTests { assertThat(zoneSet, hasItems("/")); } - /* @Test - public void testRootGetZoneAttributeValue() throws Exception { - AttributesMap rootAttributes = api.getZoneAttributeValues("/"); - assertEquals(new ValueInt(0l), rootAttributes.get("level")); - assertEquals(ValueNull.getInstance(), rootAttributes.get("name")); + public void testRootGetZoneAttributeValues() throws Exception { + final Container attributes = new Container(); + final Container exceptionContainer = new Container(); + Thread apiThread = new Thread(() -> { + try { + attributes.thing = api.getZoneAttributeValues("/"); + } catch (Exception e) { + exceptionContainer.thing = e; + } + }); + apiThread.start(); + + AgentMessage message = eventBus.events.poll(100, TimeUnit.MILLISECONDS); + assertNotNull(message); + assertEquals(ModuleType.RMI, message.getDestinationModule()); + RequestStateMessage requestMessage = (RequestStateMessage) message; + + ZMI zmi = new ZMI(); + zmi.getAttributes().add("timestamp", new ValueTime(42l)); + StateMessage response = new StateMessage("", ModuleType.RMI, 0, 0, zmi, new HashMap()); + requestMessage.getFuture().complete(response); + + apiThread.join(100); + assertFalse(apiThread.isAlive()); + assertNull(exceptionContainer.thing); + + assertEquals(new ValueTime(42l), attributes.thing.getOrNull("timestamp")); + } + + @Test + public void testGetZoneAttributeValues() throws Exception { + final Container attributes = new Container(); + final Container exceptionContainer = new Container(); + Thread apiThread = new Thread(() -> { + try { + attributes.thing = api.getZoneAttributeValues("/son"); + } catch (Exception e) { + exceptionContainer.thing = e; + } + }); + apiThread.start(); + + AgentMessage message = eventBus.events.poll(100, TimeUnit.MILLISECONDS); + assertNotNull(message); + assertEquals(ModuleType.RMI, message.getDestinationModule()); + RequestStateMessage requestMessage = (RequestStateMessage) message; + + ZMI zmi = new ZMI(); + zmi.getAttributes().add("timestamp", new ValueTime(42l)); + ZMI son = new ZMI(zmi); + zmi.addSon(son); + son.getAttributes().add("name", new ValueString("son")); + son.getAttributes().add("timestamp", new ValueTime(43l)); + StateMessage response = new StateMessage("", ModuleType.RMI, 0, 0, zmi, new HashMap()); + requestMessage.getFuture().complete(response); + + apiThread.join(100); + assertFalse(apiThread.isAlive()); + assertNull(exceptionContainer.thing); + + assertEquals(new ValueTime(43l), attributes.thing.getOrNull("timestamp")); + assertEquals(new ValueString("son"), attributes.thing.getOrNull("name")); } + /* @Test public void testIntermediateGetZoneAttributeValue() throws Exception { AttributesMap attributes = api.getZoneAttributeValues("/uw"); -- cgit v1.2.3