Search in sources :

Example 6 with CheckingSender

use of io.vertx.test.core.CheckingSender in project vert.x by eclipse.

the class NetTest method testServerNetSocketShouldBeClosedWhenTheClosedHandlerIsCalled.

// We only do it for server, as client uses the same NetSocket implementation
@Test
public void testServerNetSocketShouldBeClosedWhenTheClosedHandlerIsCalled() throws Exception {
    waitFor(2);
    server.connectHandler(so -> {
        CheckingSender sender = new CheckingSender(vertx.getOrCreateContext(), 2, so);
        sender.send();
        so.closeHandler(v -> {
            Throwable failure = sender.close();
            if (failure != null) {
                fail(failure);
            } else {
                complete();
            }
        });
        so.endHandler(v -> {
            Throwable failure = sender.close();
            if (failure != null) {
                fail(failure);
            } else {
                complete();
            }
        });
    });
    startServer();
    client.connect(testAddress, onSuccess(so -> {
        vertx.setTimer(1000, id -> {
            so.close();
        });
    }));
    await();
}
Also used : HAProxyMessageCompletionHandler(io.vertx.core.net.impl.HAProxyMessageCompletionHandler) CoreMatchers(org.hamcrest.CoreMatchers) NetServerImpl(io.vertx.core.net.impl.NetServerImpl) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) Utils(io.vertx.core.impl.Utils) Unpooled(io.netty.buffer.Unpooled) PlatformDependent(io.netty.util.internal.PlatformDependent) TestUtils(io.vertx.test.core.TestUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ReadStream(io.vertx.core.streams.ReadStream) JsonObject(io.vertx.core.json.JsonObject) CheckingSender(io.vertx.test.core.CheckingSender) Logger(io.vertx.core.impl.logging.Logger) VertxHandler(io.vertx.core.net.impl.VertxHandler) ChannelHandlerAdapter(io.netty.channel.ChannelHandlerAdapter) ConnectTimeoutException(io.netty.channel.ConnectTimeoutException) TestLoggerFactory(io.vertx.test.netty.TestLoggerFactory) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) java.util.concurrent(java.util.concurrent) Message(io.vertx.core.eventbus.Message) Trust(io.vertx.test.tls.Trust) ChannelPipeline(io.netty.channel.ChannelPipeline) InetSocketAddress(java.net.InetSocketAddress) io.vertx.core.http(io.vertx.core.http) StandardCharsets(java.nio.charset.StandardCharsets) io.netty.handler.codec.http(io.netty.handler.codec.http) SSLException(javax.net.ssl.SSLException) Certificate(java.security.cert.Certificate) Buffer(io.vertx.core.buffer.Buffer) Cert(io.vertx.test.tls.Cert) MessageConsumer(io.vertx.core.eventbus.MessageConsumer) NetSocketInternal(io.vertx.core.net.impl.NetSocketInternal) HttpVersion(io.netty.handler.codec.http.HttpVersion) java.util(java.util) LoggerFactory(io.vertx.core.impl.logging.LoggerFactory) io.vertx.core(io.vertx.core) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) VertxTestBase(io.vertx.test.core.VertxTestBase) AtomicReference(java.util.concurrent.atomic.AtomicReference) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) SSLSession(javax.net.ssl.SSLSession) ByteBuf(io.netty.buffer.ByteBuf) io.vertx.test.proxy(io.vertx.test.proxy) OutputStreamWriter(java.io.OutputStreamWriter) Assume(org.junit.Assume) VertxInternal(io.vertx.core.impl.VertxInternal) ConcurrentHashSet(io.vertx.core.impl.ConcurrentHashSet) BufferedWriter(java.io.BufferedWriter) HttpMethod(io.netty.handler.codec.http.HttpMethod) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test) File(java.io.File) Consumer(java.util.function.Consumer) JsonArray(io.vertx.core.json.JsonArray) AtomicLong(java.util.concurrent.atomic.AtomicLong) Rule(org.junit.Rule) TemporaryFolder(org.junit.rules.TemporaryFolder) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) CheckingSender(io.vertx.test.core.CheckingSender) Test(org.junit.Test)

Aggregations

Buffer (io.vertx.core.buffer.Buffer)6 ConcurrentHashSet (io.vertx.core.impl.ConcurrentHashSet)6 CheckingSender (io.vertx.test.core.CheckingSender)6 TestUtils (io.vertx.test.core.TestUtils)6 Cert (io.vertx.test.tls.Cert)6 java.util (java.util)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Consumer (java.util.function.Consumer)6 Test (org.junit.Test)6 Future (io.vertx.core.Future)5 Http1xServerConnection (io.vertx.core.http.impl.Http1xServerConnection)5 BiConsumer (java.util.function.BiConsumer)5 Function (java.util.function.Function)5 PlatformDependent (io.netty.util.internal.PlatformDependent)4 HttpHeaderNames (io.netty.handler.codec.http.HttpHeaderNames)2 CloseWebSocketFrame (io.netty.handler.codec.http.websocketx.CloseWebSocketFrame)2 WebSocket13FrameDecoder (io.netty.handler.codec.http.websocketx.WebSocket13FrameDecoder)2 WebSocket13FrameEncoder (io.netty.handler.codec.http.websocketx.WebSocket13FrameEncoder)2