m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/pl/edu/mimuw
diff options
context:
space:
mode:
authorMagdalena Grodzińska <mag.grodzinska@gmail.com>2019-12-23 19:16:54 +0100
committerMagdalena Grodzińska <mag.grodzinska@gmail.com>2019-12-23 19:16:54 +0100
commit7a104ca7eeb0d312bc76d2393495387079032aed (patch)
tree7f573d76b1c89c1165513d90ecd82694e849e4da /src/test/java/pl/edu/mimuw
parent87577a88139354a9640a2afc1058dad4c2ef9d27 (diff)
Improve event bus tests
Diffstat (limited to 'src/test/java/pl/edu/mimuw')
-rw-r--r--src/test/java/pl/edu/mimuw/cloudatlas/agent/EventBusTest.java27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/EventBusTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/EventBusTest.java
index d9a30ed..fd7c244 100644
--- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/EventBusTest.java
+++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/EventBusTest.java
@@ -6,35 +6,47 @@ import pl.edu.mimuw.cloudatlas.agent.message.AgentMessage;
import java.util.ArrayList;
import java.util.HashMap;
+import static org.junit.Assert.assertEquals;
+
public class EventBusTest {
+ public abstract class MessageCounterModule extends Module {
+ public int counter = 0;
+
+ MessageCounterModule(AgentMessage.AgentModule moduleType) {
+ super(moduleType);
+ }
+ }
- public static HashMap<AgentMessage.AgentModule, Module> initializeTwoModules() {
+ public HashMap<AgentMessage.AgentModule, Module> initializeTwoModules() {
HashMap<AgentMessage.AgentModule, Module> modules = new HashMap<AgentMessage.AgentModule, Module>();
- modules.put(AgentMessage.AgentModule.RMI, new Module(AgentMessage.AgentModule.RMI) {
+ modules.put(AgentMessage.AgentModule.RMI, new MessageCounterModule(AgentMessage.AgentModule.RMI) {
@Override
public void handle(AgentMessage event) throws InterruptedException {
System.out.println("Module 1 handle called");
sendMessage(new AgentMessage("1", AgentMessage.AgentModule.UDP));
+ counter ++;
}
});
- modules.put(AgentMessage.AgentModule.UDP, new Module(AgentMessage.AgentModule.UDP) {
+ modules.put(AgentMessage.AgentModule.UDP, new MessageCounterModule(AgentMessage.AgentModule.UDP) {
@Override
public void handle(AgentMessage event) {
System.out.println("Module 2 handle called");
+ counter++;
}
});
return modules;
}
- public static HashMap<AgentMessage.AgentModule, Module> initializeModule() {
+ public HashMap<AgentMessage.AgentModule, Module> initializeModule() {
HashMap<AgentMessage.AgentModule, Module> modules = new HashMap<AgentMessage.AgentModule, Module>();
- modules.put(AgentMessage.AgentModule.RMI, new Module(AgentMessage.AgentModule.RMI) {
+ modules.put(AgentMessage.AgentModule.RMI, new MessageCounterModule(AgentMessage.AgentModule.RMI) {
@Override
public void handle(AgentMessage event) {
System.out.println("Module 1 handle called");
+ counter++;
}
});
@@ -54,6 +66,7 @@ public class EventBusTest {
Thread.sleep(1000);
eventBusThread.interrupt();
Agent.closeExecutors(executorThreads);
+ assertEquals(1, ((MessageCounterModule) modules.get(AgentMessage.AgentModule.RMI)).counter);
}
@Test
@@ -70,9 +83,11 @@ public class EventBusTest {
AgentMessage.AgentModule.RMI,
System.currentTimeMillis() / 1000L));
- Thread.sleep(10000);
+ Thread.sleep(1000);
eventBusThread.interrupt();
Agent.closeExecutors(executorThreads);
+ assertEquals(1, ((MessageCounterModule) modules.get(AgentMessage.AgentModule.RMI)).counter);
+ assertEquals(1, ((MessageCounterModule) modules.get(AgentMessage.AgentModule.UDP)).counter);
}
}