From 4c728b0ba906799afd30f0a337b540cf167a0cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Mon, 23 Dec 2019 19:50:46 +0100 Subject: Make timer inherit from module, move to modules package --- .../edu/mimuw/cloudatlas/agent/EventBusTest.java | 1 + .../edu/mimuw/cloudatlas/agent/ExecutorTest.java | 1 + .../edu/mimuw/cloudatlas/agent/SchedulerTest.java | 48 ++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 src/test/java/pl/edu/mimuw/cloudatlas/agent/SchedulerTest.java (limited to 'src/test/java/pl') 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 initializeModule() { + HashMap modules = new HashMap(); + + modules.put(AgentMessage.AgentModule.TIMER_SCHEDULER, new TimerScheduler(AgentMessage.AgentModule.RMI)); + + return modules; + } + + @Test + void scheduleTask() { + + } + + @Test + void scheduleTwoTasks() { + HashMap modules = ini(); + HashMap executors = Agent.initializeExecutors(modules); + ArrayList 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); + } +} -- cgit v1.2.3