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"); } }