From 28795098ebebd6a244b249355808a37912656f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Wed, 25 Dec 2019 12:52:48 +0100 Subject: Add timer scheduler tests with messages --- .../edu/mimuw/cloudatlas/agent/SchedulerTest.java | 41 +++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'src/test/java/pl/edu/mimuw/cloudatlas') diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/SchedulerTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/SchedulerTest.java index 5f0d1a7..133b3b9 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/SchedulerTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/SchedulerTest.java @@ -10,7 +10,7 @@ import pl.edu.mimuw.cloudatlas.agent.modules.TimerScheduler; import java.util.ArrayList; import java.util.HashMap; -// TODO better task tests after enabling messaging from tasks +// TODO better task tests with counters after enabling messaging from tasks // TODO add wrong message test with switched types public class SchedulerTest { @@ -118,4 +118,43 @@ public class SchedulerTest { Thread.sleep(1000); } + + @Test + public void scheduleTwoMessagingTasks() throws InterruptedException { + TimerSchedulerMessage messageToSend = new TimerSchedulerMessage( + "0", + AgentMessage.AgentModule.TIMER_SCHEDULER, + System.currentTimeMillis() / 1000L, + "1", + 20, + System.currentTimeMillis() / 1000L, + new TimerScheduledTask() { + @Override + public void run() { + System.out.println("Task 2 executed"); + } + }); + + this.eventBus.addMessage(new TimerSchedulerMessage( + "0", + AgentMessage.AgentModule.TIMER_SCHEDULER, + System.currentTimeMillis() / 1000L, + "1", + 10, + System.currentTimeMillis() / 1000L, + new TimerScheduledTask() { + @Override + public void run() { + try { + this.sendMessage(messageToSend); + } catch (InterruptedException e) { + System.out.println("Task 1 message interrupted"); + e.printStackTrace(); + } + System.out.println("Task 1 executed"); + } + })); + + Thread.sleep(1000); + } } -- cgit v1.2.3