Search in sources :

Example 41 with DomainSocketAddress

use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress in project reactor-netty by reactor.

the class Application method main.

public static void main(String[] args) {
    DisposableServer server = HttpServer.create().bindAddress(// <1>
    () -> new DomainSocketAddress("/tmp/test.sock")).bindNow();
    server.onDispose().block();
}
Also used : DisposableServer(reactor.netty.DisposableServer) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress)

Example 42 with DomainSocketAddress

use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress in project reactor-netty by reactor.

the class TcpServerTests method testTcpServerWithDomainSockets.

@Test
void testTcpServerWithDomainSockets() throws Exception {
    assumeThat(LoopResources.hasNativeSupport()).isTrue();
    DisposableServer disposableServer = TcpServer.create().bindAddress(() -> new DomainSocketAddress("/tmp/test.sock")).wiretap(true).handle((in, out) -> out.send(in.receive().retain())).bindNow();
    Connection conn = TcpClient.create().remoteAddress(disposableServer::address).wiretap(true).connectNow();
    conn.outbound().sendString(Flux.just("1", "2", "3")).then().subscribe();
    CountDownLatch latch = new CountDownLatch(1);
    conn.inbound().receive().asString().doOnNext(s -> {
        if (s.endsWith("3")) {
            latch.countDown();
        }
    }).subscribe();
    assertThat(latch.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
    conn.disposeNow();
    disposableServer.disposeNow();
}
Also used : SNIHostName(javax.net.ssl.SNIHostName) DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) BiFunction(java.util.function.BiFunction) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ByteBuffer(java.nio.ByteBuffer) Unpooled(io.netty.buffer.Unpooled) ConnectionObserver(reactor.netty.ConnectionObserver) Loggers(reactor.util.Loggers) SocketChannel(java.nio.channels.SocketChannel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) BeforeAll(org.junit.jupiter.api.BeforeAll) NettyPipeline(reactor.netty.NettyPipeline) Duration(java.time.Duration) Logger(reactor.util.Logger) Path(java.nio.file.Path) JsonObjectDecoder(io.netty.handler.codec.json.JsonObjectDecoder) LoopResources(reactor.netty.resources.LoopResources) ChannelGroup(io.netty.channel.group.ChannelGroup) FileSystem(java.nio.file.FileSystem) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ChannelBindException(reactor.netty.ChannelBindException) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) LineBasedFrameDecoder(io.netty.handler.codec.LineBasedFrameDecoder) NettyOutbound(reactor.netty.NettyOutbound) Exceptions(reactor.core.Exceptions) DisposableServer(reactor.netty.DisposableServer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ChannelOption(io.netty.channel.ChannelOption) SocketUtils(reactor.netty.SocketUtils) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) StandardCopyOption(java.nio.file.StandardCopyOption) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) SniCompletionEvent(io.netty.handler.ssl.SniCompletionEvent) Charset(java.nio.charset.Charset) ByteBuf(io.netty.buffer.ByteBuf) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) AdaptiveRecvByteBufAllocator(io.netty.channel.AdaptiveRecvByteBufAllocator) Connection(reactor.netty.Connection) SslContext(io.netty.handler.ssl.SslContext) Assumptions.assumeThat(org.assertj.core.api.Assumptions.assumeThat) Files(java.nio.file.Files) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) Publisher(org.reactivestreams.Publisher) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) NetUtil(io.netty.util.NetUtil) IOException(java.io.IOException) Mono(reactor.core.publisher.Mono) CertificateException(java.security.cert.CertificateException) TimeUnit(java.util.concurrent.TimeUnit) DefaultEventExecutor(io.netty.util.concurrent.DefaultEventExecutor) Flux(reactor.core.publisher.Flux) SslProvider(io.netty.handler.ssl.SslProvider) FutureMono(reactor.netty.FutureMono) Paths(java.nio.file.Paths) SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) NettyInbound(reactor.netty.NettyInbound) Timeout(org.junit.jupiter.api.Timeout) FileSystems(java.nio.file.FileSystems) DisposableServer(reactor.netty.DisposableServer) Connection(reactor.netty.Connection) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 43 with DomainSocketAddress

use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress in project reactor-netty by reactor.

the class UdpClientTest method domainSocketsSmokeTest.

@Test
void domainSocketsSmokeTest() throws Exception {
    assumeThat(LoopResources.hasNativeSupport()).isTrue();
    LoopResources resources = LoopResources.create("domainSocketsSmokeTest");
    CountDownLatch latch = new CountDownLatch(4);
    Connection server = null;
    Connection client1 = null;
    Connection client2 = null;
    try {
        server = UdpServer.create().bindAddress(UdpClientTest::newDomainSocketAddress).runOn(resources).handle((in, out) -> in.receiveObject().map(o -> {
            if (o instanceof DomainDatagramPacket) {
                DomainDatagramPacket received = (DomainDatagramPacket) o;
                ByteBuf buffer = received.content();
                System.out.println("Server received " + buffer.readCharSequence(buffer.readableBytes(), CharsetUtil.UTF_8));
                ByteBuf buf1 = Unpooled.copiedBuffer("echo ", CharsetUtil.UTF_8);
                ByteBuf buf2 = Unpooled.copiedBuffer(buf1, buffer);
                buf1.release();
                return new DomainDatagramPacket(buf2, received.sender());
            } else {
                return Mono.error(new Exception());
            }
        }).flatMap(out::sendObject)).wiretap(true).bind().block(Duration.ofSeconds(30));
        assertThat(server).isNotNull();
        DomainSocketAddress address = (DomainSocketAddress) server.address();
        client1 = UdpClient.create().bindAddress(UdpClientTest::newDomainSocketAddress).remoteAddress(() -> address).runOn(resources).handle((in, out) -> {
            in.receive().subscribe(b -> latch.countDown());
            return out.sendString(Mono.just("ping1")).then(out.sendString(Mono.just("ping2"))).neverComplete();
        }).wiretap(true).connect().block(Duration.ofSeconds(30));
        assertThat(client1).isNotNull();
        client2 = UdpClient.create().bindAddress(UdpClientTest::newDomainSocketAddress).remoteAddress(() -> address).runOn(resources).handle((in, out) -> {
            in.receive().subscribe(b -> latch.countDown());
            return out.sendString(Mono.just("ping3")).then(out.sendString(Mono.just("ping4"))).neverComplete();
        }).wiretap(true).connect().block(Duration.ofSeconds(30));
        assertThat(client2).isNotNull();
        assertThat(latch.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
    } finally {
        if (server != null) {
            server.disposeNow();
        }
        if (client1 != null) {
            client1.disposeNow();
        }
        if (client2 != null) {
            client2.disposeNow();
        }
    }
}
Also used : LoopResources(reactor.netty.resources.LoopResources) Connection(reactor.netty.Connection) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) CountDownLatch(java.util.concurrent.CountDownLatch) DomainDatagramPacket(io.netty.channel.unix.DomainDatagramPacket) ByteBuf(io.netty.buffer.ByteBuf) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.jupiter.api.Test)

Example 44 with DomainSocketAddress

use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress in project reactor-netty by reactor.

the class UdpClientTest method testUdpClientWithDomainSocketsConnectionRefused.

@Test
void testUdpClientWithDomainSocketsConnectionRefused() {
    assumeThat(LoopResources.hasNativeSupport()).isTrue();
    UdpClient.create().remoteAddress(() -> new DomainSocketAddress("/tmp/test.sock")).connect().as(StepVerifier::create).expectError(FileNotFoundException.class).verify(Duration.ofSeconds(5));
}
Also used : FileNotFoundException(java.io.FileNotFoundException) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 45 with DomainSocketAddress

use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress in project reactor-netty by reactor.

the class Application method main.

public static void main(String[] args) {
    HttpClient client = HttpClient.create().remoteAddress(// <1>
    () -> new DomainSocketAddress("/tmp/test.sock"));
    client.get().uri("/").response().block();
}
Also used : HttpClient(reactor.netty.http.client.HttpClient) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress)

Aggregations

DomainSocketAddress (io.netty.channel.unix.DomainSocketAddress)42 File (java.io.File)15 InetSocketAddress (java.net.InetSocketAddress)15 SocketAddress (java.net.SocketAddress)14 IOException (java.io.IOException)9 Test (org.junit.jupiter.api.Test)8 Connection (reactor.netty.Connection)7 ByteBuf (io.netty.buffer.ByteBuf)6 Test (org.junit.Test)6 Mono (reactor.core.publisher.Mono)5 DisposableServer (reactor.netty.DisposableServer)5 ByteString (com.google.protobuf.ByteString)4 AddressedEnvelope (io.netty.channel.AddressedEnvelope)4 DefaultAddressedEnvelope (io.netty.channel.DefaultAddressedEnvelope)4 Duration (java.time.Duration)4 List (java.util.List)4 TimeUnit (java.util.concurrent.TimeUnit)4 LoopResources (reactor.netty.resources.LoopResources)4 Channel (io.netty.channel.Channel)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3