m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/pl/edu
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/pl/edu')
-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);
+ }
+}