m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/pl/edu/mimuw/cloudatlas/agent
diff options
context:
space:
mode:
authorMagdalena Grodzińska <mag.grodzinska@gmail.com>2019-12-23 19:50:46 +0100
committerMagdalena Grodzińska <mag.grodzinska@gmail.com>2019-12-23 19:53:22 +0100
commit4c728b0ba906799afd30f0a337b540cf167a0cfd (patch)
treed9d453d9402a8af5de8ee76a0d5b7141952822ea /src/test/java/pl/edu/mimuw/cloudatlas/agent
parent9d24163dc71c345fb2197f91abb62478e1e9e3ee (diff)
Make timer inherit from module, move to modules package
Diffstat (limited to 'src/test/java/pl/edu/mimuw/cloudatlas/agent')
-rw-r--r--src/test/java/pl/edu/mimuw/cloudatlas/agent/EventBusTest.java1
-rw-r--r--src/test/java/pl/edu/mimuw/cloudatlas/agent/ExecutorTest.java1
-rw-r--r--src/test/java/pl/edu/mimuw/cloudatlas/agent/SchedulerTest.java48
3 files changed, 50 insertions, 0 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 fd7c244..178fb38 100644
--- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/EventBusTest.java
+++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/EventBusTest.java
@@ -2,6 +2,7 @@ package pl.edu.mimuw.cloudatlas.agent;
import org.junit.Test;
import pl.edu.mimuw.cloudatlas.agent.message.AgentMessage;
+import pl.edu.mimuw.cloudatlas.agent.modules.Module;
import java.util.ArrayList;
import java.util.HashMap;
diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/ExecutorTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/ExecutorTest.java
index 2a6ef49..2b998f9 100644
--- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/ExecutorTest.java
+++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/ExecutorTest.java
@@ -5,6 +5,7 @@ import static org.junit.Assert.*;
import pl.edu.mimuw.cloudatlas.agent.message.AgentMessage;
import pl.edu.mimuw.cloudatlas.agent.message.AgentMessage.AgentModule;
+import pl.edu.mimuw.cloudatlas.agent.modules.Module;
public class ExecutorTest {
public class MessageCounterModule extends Module {
diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/SchedulerTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/SchedulerTest.java
new file mode 100644
index 0000000..45017c8
--- /dev/null
+++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/SchedulerTest.java
@@ -0,0 +1,48 @@
+package pl.edu.mimuw.cloudatlas.agent;
+
+import org.junit.Test;
+import pl.edu.mimuw.cloudatlas.agent.message.AgentMessage;
+import pl.edu.mimuw.cloudatlas.agent.modules.Module;
+import pl.edu.mimuw.cloudatlas.agent.modules.TimerScheduler;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import static org.junit.Assert.assertEquals;
+
+public class SchedulerTest {
+
+ public HashMap<AgentMessage.AgentModule, Module> initializeModule() {
+ HashMap<AgentMessage.AgentModule, Module> modules = new HashMap<AgentMessage.AgentModule, Module>();
+
+ modules.put(AgentMessage.AgentModule.TIMER_SCHEDULER, new TimerScheduler(AgentMessage.AgentModule.RMI));
+
+ return modules;
+ }
+
+ @Test
+ void scheduleTask() {
+
+ }
+
+ @Test
+ void scheduleTwoTasks() {
+ HashMap<AgentMessage.AgentModule, Module> modules = ini();
+ HashMap<AgentMessage.AgentModule, Executor> executors = Agent.initializeExecutors(modules);
+ ArrayList<Thread> executorThreads = Agent.initializeExecutorThreads(executors);
+ EventBus eventBus = new EventBus(executors);
+ Thread eventBusThread = new Thread(eventBus);
+ eventBusThread.start();
+
+ eventBus.addMessage(new AgentMessage(
+ "0",
+ AgentMessage.AgentModule.RMI,
+ System.currentTimeMillis() / 1000L));
+
+ Thread.sleep(1000);
+
+ eventBusThread.interrupt();
+ Agent.closeExecutors(executorThreads);
+ assertEquals(1, ((EventBusTest.MessageCounterModule) modules.get(AgentMessage.AgentModule.RMI)).counter);
+ }
+}