Exemplo n.º 1
0
  @Test
  public void testAsyncHttpServer() {
    Log.debugging();

    On.req(
        req -> {
          U.must(!req.isAsync());
          req.async();
          U.must(req.isAsync());

          Jobs.after(10, TimeUnit.MILLISECONDS)
              .run(
                  () -> {
                    IO.write(req.out(), "O");

                    Jobs.after(10, TimeUnit.MILLISECONDS)
                        .run(
                            () -> {
                              IO.write(req.out(), "K");
                              req.done();
                            });
                  });

          return req;
        });

    Self.get("/").expect("OK").benchmark(1, 100, 10000);
    Self.post("/").expect("OK").benchmark(1, 100, 10000);
  }
Exemplo n.º 2
0
  @Test
  public void testAsyncHttpServer2() {
    On.req(
        req ->
            Jobs.after(10, TimeUnit.MILLISECONDS)
                .run(
                    () -> {
                      IO.write(req.out(), "A");

                      Jobs.after(10, TimeUnit.MILLISECONDS)
                          .run(
                              () -> {
                                IO.write(req.out(), "SYNC");
                                req.done();
                              });
                    }));

    Self.get("/").expect("ASYNC").benchmark(1, 100, 10000);
    Self.post("/").expect("ASYNC").benchmark(1, 100, 10000);
  }