Search in sources :

Example 1 with HttpRequestHead

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

the class HttpClientConnectionTest method testConnectionClose.

@Test
public void testConnectionClose() throws Exception {
    waitFor(2);
    server.requestHandler(req -> {
        req.response().close();
    });
    startServer(testAddress);
    client.connect(testAddress, peerAddress).onComplete(onSuccess(conn -> {
        AtomicInteger evictions = new AtomicInteger();
        conn.evictionHandler(v -> {
            assertEquals(1, evictions.incrementAndGet());
            complete();
        });
        conn.createStream((ContextInternal) vertx.getOrCreateContext(), onSuccess(stream -> {
            stream.writeHead(new HttpRequestHead(HttpMethod.GET, "/", MultiMap.caseInsensitiveMultiMap(), "localhost:8080", "", null), false, Unpooled.EMPTY_BUFFER, true, new StreamPriority(), false, onSuccess(v -> {
            }));
            stream.headHandler(resp -> {
                fail();
            });
            stream.endHandler(headers -> {
                fail();
            });
            stream.closeHandler(v -> {
                assertEquals(1, evictions.get());
                complete();
            });
        }));
    }));
    await();
}
Also used : HttpRequestHead(io.vertx.core.http.impl.HttpRequestHead) HttpClientImpl(io.vertx.core.http.impl.HttpClientImpl) TestUtils(io.vertx.test.core.TestUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MultiMap(io.vertx.core.MultiMap) ContextInternal(io.vertx.core.impl.ContextInternal) Test(org.junit.Test) File(java.io.File) Unpooled(io.netty.buffer.Unpooled) SocketAddress(io.vertx.core.net.SocketAddress) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContextInternal(io.vertx.core.impl.ContextInternal) HttpRequestHead(io.vertx.core.http.impl.HttpRequestHead) Test(org.junit.Test)

Example 2 with HttpRequestHead

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

the class HttpClientConnectionTest method testGet.

@Test
public void testGet() throws Exception {
    waitFor(3);
    server.requestHandler(req -> {
        req.response().end();
    });
    startServer(testAddress);
    client.connect(testAddress, peerAddress).onComplete(onSuccess(conn -> {
        conn.createStream((ContextInternal) vertx.getOrCreateContext(), onSuccess(stream -> {
            stream.writeHead(new HttpRequestHead(HttpMethod.GET, "/", MultiMap.caseInsensitiveMultiMap(), "localhost:8080", "", null), false, Unpooled.EMPTY_BUFFER, true, new StreamPriority(), false, onSuccess(v -> {
            }));
            stream.headHandler(resp -> {
                assertEquals(200, resp.statusCode);
                complete();
            });
            stream.endHandler(headers -> {
                assertEquals(0, headers.size());
                complete();
            });
            stream.closeHandler(v -> {
                complete();
            });
        }));
    }));
    await();
}
Also used : HttpRequestHead(io.vertx.core.http.impl.HttpRequestHead) HttpClientImpl(io.vertx.core.http.impl.HttpClientImpl) TestUtils(io.vertx.test.core.TestUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MultiMap(io.vertx.core.MultiMap) ContextInternal(io.vertx.core.impl.ContextInternal) Test(org.junit.Test) File(java.io.File) Unpooled(io.netty.buffer.Unpooled) SocketAddress(io.vertx.core.net.SocketAddress) ContextInternal(io.vertx.core.impl.ContextInternal) HttpRequestHead(io.vertx.core.http.impl.HttpRequestHead) Test(org.junit.Test)

Example 3 with HttpRequestHead

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

the class Http1xClientConnectionTest method testServerConnectionClose.

@Test
public void testServerConnectionClose() throws Exception {
    waitFor(1);
    server.requestHandler(req -> {
        req.response().putHeader("Connection", "close").end();
    });
    startServer(testAddress);
    client.connect(testAddress).onComplete(onSuccess(conn -> {
        AtomicInteger evictions = new AtomicInteger();
        conn.evictionHandler(v -> {
            assertEquals(1, evictions.incrementAndGet());
        });
        conn.createStream((ContextInternal) vertx.getOrCreateContext(), onSuccess(stream -> {
            stream.closeHandler(v -> {
                assertEquals(1, evictions.get());
                complete();
            });
            stream.writeHead(new HttpRequestHead(HttpMethod.GET, "/", MultiMap.caseInsensitiveMultiMap(), "localhost:8080", "", null), false, Unpooled.EMPTY_BUFFER, true, new StreamPriority(), false, null);
        }));
    }));
    await();
}
Also used : HttpRequestHead(io.vertx.core.http.impl.HttpRequestHead) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Promise(io.vertx.core.Promise) MultiMap(io.vertx.core.MultiMap) ContextInternal(io.vertx.core.impl.ContextInternal) Test(org.junit.Test) Unpooled(io.netty.buffer.Unpooled) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContextInternal(io.vertx.core.impl.ContextInternal) HttpRequestHead(io.vertx.core.http.impl.HttpRequestHead) Test(org.junit.Test)

Example 4 with HttpRequestHead

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

the class Http1xClientConnectionTest method testResetStreamRequestSent.

@Test
public void testResetStreamRequestSent() throws Exception {
    waitFor(1);
    Promise<Void> continuation = Promise.promise();
    server.requestHandler(req -> {
        continuation.complete();
    });
    startServer(testAddress);
    client.connect(testAddress).onComplete(onSuccess(conn -> {
        AtomicInteger evictions = new AtomicInteger();
        conn.evictionHandler(v -> {
            evictions.incrementAndGet();
        });
        conn.createStream((ContextInternal) vertx.getOrCreateContext(), onSuccess(stream -> {
            Exception cause = new Exception();
            stream.closeHandler(v -> {
                assertEquals(1, evictions.get());
                complete();
            });
            continuation.future().onSuccess(v -> {
                stream.reset(cause);
            });
            stream.writeHead(new HttpRequestHead(HttpMethod.GET, "/", MultiMap.caseInsensitiveMultiMap(), "localhost:8080", "", null), false, Unpooled.EMPTY_BUFFER, false, new StreamPriority(), false, null);
        }));
    }));
    await();
}
Also used : HttpRequestHead(io.vertx.core.http.impl.HttpRequestHead) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Promise(io.vertx.core.Promise) MultiMap(io.vertx.core.MultiMap) ContextInternal(io.vertx.core.impl.ContextInternal) Test(org.junit.Test) Unpooled(io.netty.buffer.Unpooled) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContextInternal(io.vertx.core.impl.ContextInternal) HttpRequestHead(io.vertx.core.http.impl.HttpRequestHead) Test(org.junit.Test)

Aggregations

Unpooled (io.netty.buffer.Unpooled)4 MultiMap (io.vertx.core.MultiMap)4 HttpRequestHead (io.vertx.core.http.impl.HttpRequestHead)4 ContextInternal (io.vertx.core.impl.ContextInternal)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Test (org.junit.Test)4 Promise (io.vertx.core.Promise)2 HttpClientImpl (io.vertx.core.http.impl.HttpClientImpl)2 SocketAddress (io.vertx.core.net.SocketAddress)2 TestUtils (io.vertx.test.core.TestUtils)2 File (java.io.File)2