aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/io/trygvis/test/spring/PlainSpringTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/io/trygvis/test/spring/PlainSpringTest.java')
-rw-r--r--src/test/java/io/trygvis/test/spring/PlainSpringTest.java59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/test/java/io/trygvis/test/spring/PlainSpringTest.java b/src/test/java/io/trygvis/test/spring/PlainSpringTest.java
new file mode 100644
index 0000000..9a7a436
--- /dev/null
+++ b/src/test/java/io/trygvis/test/spring/PlainSpringTest.java
@@ -0,0 +1,59 @@
+package io.trygvis.test.spring;
+
+import io.trygvis.async.AsyncService;
+import io.trygvis.queue.Queue;
+import io.trygvis.spring.DefaultConfig;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import java.sql.SQLException;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static java.lang.System.getProperty;
+import static java.lang.System.setProperty;
+import static org.fest.assertions.Assertions.assertThat;
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(classes = {TestConfig.class, DefaultConfig.class})
+public class PlainSpringTest {
+
+ @Autowired
+ private AsyncService asyncService;
+
+ static {
+ String username = getProperty("user.name");
+ setProperty("database.url", getProperty("jdbc.url", "jdbc:postgresql://localhost/" + username));
+ setProperty("database.username", username);
+ setProperty("database.password", username);
+ }
+
+ @Test
+ public void testBasic() throws SQLException, InterruptedException {
+ final AtomicReference<List<String>> ref = new AtomicReference<>();
+ Queue test = asyncService.registerQueue("test", 10, new AsyncService.AsyncCallable() {
+ public void run(List<String> arguments) throws Exception {
+ System.out.println("PlainSpringTest.run");
+ ref.set(arguments);
+ synchronized (ref) {
+ ref.notify();
+ }
+ }
+ });
+
+ synchronized (ref) {
+ System.out.println("Scheduling task");
+ asyncService.schedule(test, "hello", "world");
+ System.out.println("Waiting");
+ ref.wait(1000);
+ }
+
+ List<String> args = ref.get();
+ assertNotNull(args);
+ assertThat(args).containsExactly("hello", "world");
+ }
+}