Search in sources :

Example 1 with EventLoopContext

use of io.vertx.core.impl.EventLoopContext in project vert.x by eclipse.

the class HttpTest method testInVerticle.

private void testInVerticle(boolean worker) throws Exception {
    client.close();
    server.close();
    class MyVerticle extends AbstractVerticle {

        Context ctx;

        @Override
        public void start() {
            ctx = Vertx.currentContext();
            if (worker) {
                assertTrue(ctx instanceof WorkerContext);
            } else {
                assertTrue(ctx instanceof EventLoopContext);
            }
            Thread thr = Thread.currentThread();
            server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT));
            server.requestHandler(req -> {
                req.response().end();
                assertSame(ctx, Vertx.currentContext());
                if (!worker) {
                    assertSame(thr, Thread.currentThread());
                }
            });
            server.listen(ar -> {
                assertTrue(ar.succeeded());
                assertSame(ctx, Vertx.currentContext());
                if (!worker) {
                    assertSame(thr, Thread.currentThread());
                }
                client = vertx.createHttpClient(new HttpClientOptions());
                client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/", res -> {
                    assertSame(ctx, Vertx.currentContext());
                    if (!worker) {
                        assertSame(thr, Thread.currentThread());
                    }
                    assertEquals(200, res.statusCode());
                    testComplete();
                }).end();
            });
        }
    }
    MyVerticle verticle = new MyVerticle();
    vertx.deployVerticle(verticle, new DeploymentOptions().setWorker(worker));
    await();
}
Also used : Context(io.vertx.core.Context) WorkerContext(io.vertx.core.impl.WorkerContext) EventLoopContext(io.vertx.core.impl.EventLoopContext) VertxException(io.vertx.core.VertxException) MultiMap(io.vertx.core.MultiMap) TimeoutException(java.util.concurrent.TimeoutException) Context(io.vertx.core.Context) InetAddress(java.net.InetAddress) HttpFrame(io.vertx.core.http.HttpFrame) HttpVersion(io.vertx.core.http.HttpVersion) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) TestLoggerFactory(io.vertx.test.netty.TestLoggerFactory) HttpHeaders(io.vertx.core.http.HttpHeaders) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) UUID(java.util.UUID) Future(io.vertx.core.Future) FileNotFoundException(java.io.FileNotFoundException) Nullable(io.vertx.codegen.annotations.Nullable) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) HttpServerResponse(io.vertx.core.http.HttpServerResponse) AbstractVerticle(io.vertx.core.AbstractVerticle) WorkerContext(io.vertx.core.impl.WorkerContext) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpClient(io.vertx.core.http.HttpClient) NetSocket(io.vertx.core.net.NetSocket) IntStream(java.util.stream.IntStream) HeadersAdaptor(io.vertx.core.http.impl.HeadersAdaptor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) TestUtils.assertNullPointerException(io.vertx.test.core.TestUtils.assertNullPointerException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClientResponse(io.vertx.core.http.HttpClientResponse) OutputStreamWriter(java.io.OutputStreamWriter) Assume(org.junit.Assume) AsyncResult(io.vertx.core.AsyncResult) HttpClientOptions(io.vertx.core.http.HttpClientOptions) HttpConnection(io.vertx.core.http.HttpConnection) BufferedWriter(java.io.BufferedWriter) Vertx(io.vertx.core.Vertx) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) EventLoopContext(io.vertx.core.impl.EventLoopContext) URLEncoder(java.net.URLEncoder) Rule(org.junit.Rule) DeploymentOptions(io.vertx.core.DeploymentOptions) HttpMethod(io.vertx.core.http.HttpMethod) HttpServerOptions(io.vertx.core.http.HttpServerOptions) InternalLoggerFactory(io.netty.util.internal.logging.InternalLoggerFactory) Handler(io.vertx.core.Handler) Collections(java.util.Collections) TestUtils.assertIllegalStateException(io.vertx.test.core.TestUtils.assertIllegalStateException) TemporaryFolder(org.junit.rules.TemporaryFolder) TestUtils.assertIllegalArgumentException(io.vertx.test.core.TestUtils.assertIllegalArgumentException) DeploymentOptions(io.vertx.core.DeploymentOptions) HttpServerOptions(io.vertx.core.http.HttpServerOptions) WorkerContext(io.vertx.core.impl.WorkerContext) EventLoopContext(io.vertx.core.impl.EventLoopContext) AbstractVerticle(io.vertx.core.AbstractVerticle) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Aggregations

DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)1 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)1 InternalLoggerFactory (io.netty.util.internal.logging.InternalLoggerFactory)1 Nullable (io.vertx.codegen.annotations.Nullable)1 AbstractVerticle (io.vertx.core.AbstractVerticle)1 AsyncResult (io.vertx.core.AsyncResult)1 Context (io.vertx.core.Context)1 DeploymentOptions (io.vertx.core.DeploymentOptions)1 Future (io.vertx.core.Future)1 Handler (io.vertx.core.Handler)1 MultiMap (io.vertx.core.MultiMap)1 Vertx (io.vertx.core.Vertx)1 VertxException (io.vertx.core.VertxException)1 Buffer (io.vertx.core.buffer.Buffer)1 HttpClient (io.vertx.core.http.HttpClient)1 HttpClientOptions (io.vertx.core.http.HttpClientOptions)1 HttpClientRequest (io.vertx.core.http.HttpClientRequest)1 HttpClientResponse (io.vertx.core.http.HttpClientResponse)1 HttpConnection (io.vertx.core.http.HttpConnection)1 HttpFrame (io.vertx.core.http.HttpFrame)1