diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/main/java/io/trygvis/queue/Task.java | 12 | ||||
-rw-r--r-- | src/test/java/io/trygvis/test/spring/PlainSpringTest.java | 43 |
2 files changed, 35 insertions, 20 deletions
diff --git a/src/main/java/io/trygvis/queue/Task.java b/src/main/java/io/trygvis/queue/Task.java index 29e37ac..8038050 100755 --- a/src/main/java/io/trygvis/queue/Task.java +++ b/src/main/java/io/trygvis/queue/Task.java @@ -84,16 +84,16 @@ public class Task { return completed != null; } - public Task childTask(String name, Date scheduled, String... arguments) { - return new Task(0, id(), name, NEW, scheduled, null, 0, null, asList(arguments)); + public Task childTask(String queue, Date scheduled, String... arguments) { + return new Task(0, id(), queue, NEW, scheduled, null, 0, null, asList(arguments)); } - public static Task newTask(String name, Date scheduled, String... arguments) { - return new Task(0, null, name, NEW, scheduled, null, 0, null, asList(arguments)); + public static Task newTask(String queue, Date scheduled, String... arguments) { + return new Task(0, null, queue, NEW, scheduled, null, 0, null, asList(arguments)); } - public static Task newTask(String name, Date scheduled, List<String> arguments) { - return new Task(0, null, name, NEW, scheduled, null, 0, null, arguments); + public static Task newTask(String queue, Date scheduled, List<String> arguments) { + return new Task(0, null, queue, NEW, scheduled, null, 0, null, arguments); } public static List<String> stringToArguments(String arguments) { diff --git a/src/test/java/io/trygvis/test/spring/PlainSpringTest.java b/src/test/java/io/trygvis/test/spring/PlainSpringTest.java index 38d3361..cde0c97 100644 --- a/src/test/java/io/trygvis/test/spring/PlainSpringTest.java +++ b/src/test/java/io/trygvis/test/spring/PlainSpringTest.java @@ -13,6 +13,7 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.sql.SQLException; +import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.concurrent.atomic.AtomicReference; @@ -45,31 +46,45 @@ public class PlainSpringTest { @Test public void testBasic() throws SQLException, InterruptedException { - QueueExecutor test = queueService.getQueue("test", 10, true); - final AtomicReference<List<String>> ref = new AtomicReference<>(); - asyncService.registerQueue(test.queue, req, new TaskEffect() { + QueueExecutor queueA = queueService.getQueue("a", 1000, true); +// final AtomicReference<List<String>> refA = new AtomicReference<>(); + asyncService.registerQueue(queueA.queue, req, new TaskEffect() { @Override public List<Task> apply(Task task) throws Exception { - System.out.println("PlainSpringTest.run"); - ref.set(task.arguments); - synchronized (ref) { - ref.notify(); +// refA.set(task.arguments); +// synchronized (refA) { +// refA.notify(); +// } + System.out.println("task.arguments = " + task.arguments); + return asList(task.childTask("b", new Date(), task.arguments.get(0), "world")); + } + }); + + QueueExecutor queueB = queueService.getQueue("b", 1000, true); + final AtomicReference<List<String>> refB = new AtomicReference<>(); + asyncService.registerQueue(queueB.queue, req, new TaskEffect() { + @Override + public List<Task> apply(Task task) throws Exception { +// System.out.println("task.arguments = " + task.arguments); + refB.set(task.arguments); + synchronized (refB) { + refB.notify(); } return emptyList(); } }); - synchronized (ref) { + synchronized (refB) { System.out.println("Scheduling task"); - queueService.schedule(test.queue, new Date(), asList("hello", "world")); + queueService.schedule(queueA.queue, new Date(), asList("hello")); System.out.println("Task scheduled, waiting"); - ref.wait(1000); + refB.wait(10000); System.out.println("Back!"); } - List<String> args = ref.get(); - System.out.println("args = " + args); - assertNotNull(args); - assertThat(args).containsExactly("hello", "world"); +// System.out.println("refA.get() = " + refA.get()); + System.out.println("refB.get() = " + refB.get()); + + assertThat(refB.get()).containsExactly("hello", "world"); } } |