m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/RemikTest.java
diff options
context:
space:
mode:
authorMartin <marcin.j.chrzanowski@gmail.com>2020-01-03 18:29:55 +0100
committerGitHub <noreply@github.com>2020-01-03 18:29:55 +0100
commit9be545d6f2609d5fe8143a1964d44f6eee588ea2 (patch)
treef0bb8d159249e9ddf328e92d7fb5eda10122ab3b /src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/RemikTest.java
parentfda20e7aa496926d4f4d78921925025040414d9b (diff)
parentec2da92e9636e219f5ad7caa73c9334dae12e5b1 (diff)
Merge pull request #83 from m-chrzan/remik
Use new modular architecture when implementing the RMI API
Diffstat (limited to 'src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/RemikTest.java')
-rw-r--r--src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/RemikTest.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/RemikTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/RemikTest.java
new file mode 100644
index 0000000..8ac8bed
--- /dev/null
+++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/RemikTest.java
@@ -0,0 +1,61 @@
+package pl.edu.mimuw.cloudatlas.agent.modules;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.HashMap;
+
+import pl.edu.mimuw.cloudatlas.agent.messages.AgentMessage;
+import pl.edu.mimuw.cloudatlas.agent.messages.GetStateMessage;
+import pl.edu.mimuw.cloudatlas.agent.messages.RequestStateMessage;
+import pl.edu.mimuw.cloudatlas.agent.messages.ResponseMessage;
+import pl.edu.mimuw.cloudatlas.agent.messages.StanikMessage;
+import pl.edu.mimuw.cloudatlas.agent.messages.StateMessage;
+import pl.edu.mimuw.cloudatlas.agent.MockExecutor;
+import pl.edu.mimuw.cloudatlas.model.ValueTime;
+import pl.edu.mimuw.cloudatlas.model.ZMI;
+
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class RemikTest {
+ private Remik remik;
+ private MockExecutor executor;
+
+ @Before
+ public void setupLocals() {
+ remik = new Remik();
+ executor = new MockExecutor(remik);
+ }
+
+ @Test
+ public void asksForStateOnStateRequest() throws Exception {
+ CompletableFuture<ResponseMessage> future = new CompletableFuture();
+ RequestStateMessage message = new RequestStateMessage("", 0, future);
+ remik.handleTyped(message);
+ AgentMessage receivedMessage = (AgentMessage) executor.messagesToPass.take();
+ assertEquals(ModuleType.STATE, receivedMessage.getDestinationModule());
+ StanikMessage stanikMessage = (StanikMessage) receivedMessage;
+ assertEquals(StanikMessage.Type.GET_STATE, stanikMessage.getType());
+ GetStateMessage getStateMessage = (GetStateMessage) stanikMessage;
+ assertEquals(ModuleType.RMI, getStateMessage.getRequestingModule());
+ }
+
+ @Test
+ public void completesFutureOnReceivedState() throws Exception {
+ CompletableFuture<ResponseMessage> future = new CompletableFuture();
+ RequestStateMessage message = new RequestStateMessage("", 0, future);
+ remik.handleTyped(message);
+
+ ZMI zmi = new ZMI();
+ zmi.getAttributes().add("timestamp", new ValueTime(42l));
+ StateMessage response = new StateMessage("", ModuleType.RMI, 0, 0, zmi, new HashMap());
+ remik.handleTyped(response);
+
+ ResponseMessage passedResponse = future.get(100, TimeUnit.MILLISECONDS);
+ assertNotNull(passedResponse);
+ assertEquals(ResponseMessage.Type.STATE, passedResponse.getType());
+ StateMessage stateMessage = (StateMessage) passedResponse;
+ assertEquals(new ValueTime(42l), stateMessage.getZMI().getAttributes().get("timestamp"));
+ }
+}