Search in sources :

Example 1 with SimpleHttpClient

use of io.javalin.util.SimpleHttpClient in project javalin by tipsy.

the class TestAsync method test_async.

@Test
@Ignore("Just for running manually")
public void test_async() throws Exception {
    Javalin app = Javalin.create().embeddedServer(new EmbeddedJettyFactory(() -> new Server(new QueuedThreadPool(16, 10, 60_000)))).port(5454).start();
    app.get("/test-async", ctx -> ctx.async(() -> {
        CompletableFuture<Void> future = new CompletableFuture<>();
        new Timer().schedule(new TimerTask() {

            public void run() {
                ctx.status(418);
                future.complete(null);
            }
        }, 1000);
        return future;
    }));
    long startTime = System.currentTimeMillis();
    ForkJoinPool forkJoinPool = new ForkJoinPool(200);
    forkJoinPool.submit(() -> IntStream.range(0, 50).parallel().forEach(i -> {
        try {
            assertThat(new SimpleHttpClient().http_GET("http://localhost:5454/test-async").getStatus(), is(418));
        } catch (IOException e) {
            e.printStackTrace();
        }
    })).get();
    log.info("took " + (System.currentTimeMillis() - startTime) + " milliseconds");
    app.stop();
}
Also used : EmbeddedJettyFactory(io.javalin.embeddedserver.jetty.EmbeddedJettyFactory) CompletableFuture(java.util.concurrent.CompletableFuture) Server(org.eclipse.jetty.server.Server) Timer(java.util.Timer) TimerTask(java.util.TimerTask) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) IOException(java.io.IOException) SimpleHttpClient(io.javalin.util.SimpleHttpClient) ForkJoinPool(java.util.concurrent.ForkJoinPool) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with SimpleHttpClient

use of io.javalin.util.SimpleHttpClient in project javalin by tipsy.

the class _SimpleClientBaseTest method setup.

@BeforeClass
public static void setup() throws IOException {
    app = Javalin.create().port(0).start();
    simpleHttpClient = new SimpleHttpClient();
    origin = "http://localhost:" + app.port();
}
Also used : SimpleHttpClient(io.javalin.util.SimpleHttpClient) BeforeClass(org.junit.BeforeClass)

Aggregations

SimpleHttpClient (io.javalin.util.SimpleHttpClient)2 EmbeddedJettyFactory (io.javalin.embeddedserver.jetty.EmbeddedJettyFactory)1 IOException (java.io.IOException)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ForkJoinPool (java.util.concurrent.ForkJoinPool)1 Server (org.eclipse.jetty.server.Server)1 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)1 BeforeClass (org.junit.BeforeClass)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1