m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/pl/edu/mimuw/cloudatlas/agent
diff options
context:
space:
mode:
authorMartin <marcin.j.chrzanowski@gmail.com>2019-12-22 17:29:25 +0100
committerGitHub <noreply@github.com>2019-12-22 17:29:25 +0100
commit651c2b76ff3db39cefd1542d6f4c19d8686dfb85 (patch)
tree4184366307a88f149e68b6d4ab79f253e004982e /src/test/java/pl/edu/mimuw/cloudatlas/agent
parent3fff4cef0bf33c7fa88dba92c81be7e402ec2bc9 (diff)
Implement executor (#65)
Diffstat (limited to 'src/test/java/pl/edu/mimuw/cloudatlas/agent')
-rw-r--r--src/test/java/pl/edu/mimuw/cloudatlas/agent/ExecutorTest.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/ExecutorTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/ExecutorTest.java
new file mode 100644
index 0000000..445a5b4
--- /dev/null
+++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/ExecutorTest.java
@@ -0,0 +1,54 @@
+package pl.edu.mimuw.cloudatlas.agent;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import pl.edu.mimuw.cloudatlas.agent.message.AgentMessage;
+import pl.edu.mimuw.cloudatlas.agent.message.AgentMessage.AgentModule;
+
+public class ExecutorTest {
+ public class MessageCounterModule extends Module {
+ public int counter = 0;
+ public void handle(AgentMessage m) {
+ counter++;
+ }
+ }
+
+ @Test
+ public void testDoesntExecuteWhenNoMessages() throws Exception {
+ MessageCounterModule module = new MessageCounterModule();
+ Executor executor = new Executor(module);
+ Thread thread = new Thread(executor);
+ thread.start();
+ Thread.sleep(100);
+ thread.interrupt();
+ assertEquals(0, module.counter);
+ }
+
+ @Test
+ public void testExecutesHandlerOnce() throws Exception {
+ MessageCounterModule module = new MessageCounterModule();
+ Executor executor = new Executor(module);
+ executor.addMessage(new AgentMessage("", AgentModule.UDP, 0) {});
+ Thread thread = new Thread(executor);
+ thread.start();
+ Thread.sleep(100);
+ thread.interrupt();
+ assertEquals(1, module.counter);
+ }
+
+ @Test
+ public void testExecutesHandlerMultipleTimes() throws Exception {
+ MessageCounterModule module = new MessageCounterModule();
+ Executor executor = new Executor(module);
+ executor.addMessage(new AgentMessage("", AgentModule.UDP, 0) {});
+ executor.addMessage(new AgentMessage("", AgentModule.UDP, 0) {});
+ Thread thread = new Thread(executor);
+ thread.start();
+ Thread.sleep(100);
+ executor.addMessage(new AgentMessage("", AgentModule.UDP, 0) {});
+ Thread.sleep(100);
+ thread.interrupt();
+ assertEquals(3, module.counter);
+ }
+}