From 52084f7b4e6f50c90b3255cdf2eb9deab560c970 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 2 Jun 2013 12:32:29 +0200 Subject: o Making some test cases. --- .../io/trygvis/test/spring/PlainSpringTest.java | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/test/java/io/trygvis/test/spring/PlainSpringTest.java (limited to 'src/test/java/io/trygvis/test/spring/PlainSpringTest.java') 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> ref = new AtomicReference<>(); + Queue test = asyncService.registerQueue("test", 10, new AsyncService.AsyncCallable() { + public void run(List 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 args = ref.get(); + assertNotNull(args); + assertThat(args).containsExactly("hello", "world"); + } +} -- cgit v1.2.3