Search in sources :

Example 11 with DomainSocketAddress

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

the class KQueueSocketTest method testPeerCreds.

@Test
public void testPeerCreds() throws IOException {
    BsdSocket s1 = BsdSocket.newSocketDomain();
    BsdSocket s2 = BsdSocket.newSocketDomain();
    try {
        DomainSocketAddress dsa = UnixTestUtils.newDomainSocketAddress();
        s1.bind(dsa);
        s1.listen(1);
        assertTrue(s2.connect(dsa));
        byte[] addr = new byte[64];
        s1.accept(addr);
        PeerCredentials pc = s1.getPeerCredentials();
        assertNotEquals(pc.uid(), -1);
    } finally {
        s1.close();
        s2.close();
    }
}
Also used : DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) PeerCredentials(io.netty.channel.unix.PeerCredentials) Test(org.junit.jupiter.api.Test) SocketTest(io.netty.channel.unix.tests.SocketTest)

Example 12 with DomainSocketAddress

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

the class SocketAddressPropertyTest method bindTypeWorks_udsWithEquals.

@Test
public void bindTypeWorks_udsWithEquals() {
    SocketAddress address = SocketAddressProperty.Decoder.INSTANCE.apply("UDS=/var/run/zuul=.sock");
    assertEquals(DomainSocketAddress.class, address.getClass());
    DomainSocketAddress domainSocketAddress = (DomainSocketAddress) address;
    assertEquals("/var/run/zuul=.sock", domainSocketAddress.path());
}
Also used : DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) Test(org.junit.Test)

Example 13 with DomainSocketAddress

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

the class Utils method parseServerSocketAddress.

/**
 * Parse a {@link SocketAddress} from the given string.
 */
public static SocketAddress parseServerSocketAddress(String value) {
    if (value.startsWith(UNIX_DOMAIN_SOCKET_PREFIX)) {
        DomainSocketAddress domainAddress = parseUnixSocketAddress(value);
        File file = new File(domainAddress.path());
        try {
            if (file.createNewFile()) {
                // If this application created the file, delete it when the application exits.
                file.deleteOnExit();
            }
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        return domainAddress;
    } else {
        // Standard TCP/IP address.
        String[] parts = value.split(":", 2);
        if (parts.length < 2) {
            throw new IllegalArgumentException("Address must be a unix:// path or be in the form host:port. Got: " + value);
        }
        String host = parts[0];
        int port = Integer.parseInt(parts[1]);
        return new InetSocketAddress(host, port);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) IOException(java.io.IOException) ByteString(com.google.protobuf.ByteString) File(java.io.File)

Example 14 with DomainSocketAddress

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

the class Utils method parseUnixSocketAddress.

private static DomainSocketAddress parseUnixSocketAddress(String value) {
    Preconditions.checkArgument(value.startsWith(UNIX_DOMAIN_SOCKET_PREFIX), "Must start with %s: %s", UNIX_DOMAIN_SOCKET_PREFIX, value);
    // Unix Domain Socket address.
    // Create the underlying file for the Unix Domain Socket.
    String filePath = value.substring(UNIX_DOMAIN_SOCKET_PREFIX.length());
    File file = new File(filePath);
    if (!file.isAbsolute()) {
        throw new IllegalArgumentException("File path must be absolute: " + filePath);
    }
    // Create the SocketAddress referencing the file.
    return new DomainSocketAddress(file);
}
Also used : DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) ByteString(com.google.protobuf.ByteString) File(java.io.File)

Example 15 with DomainSocketAddress

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

the class BinlogHelperTest method socketToProto_unix.

@Test
public void socketToProto_unix() throws Exception {
    String path = "/some/path";
    DomainSocketAddress socketAddress = new DomainSocketAddress(path);
    assertEquals(Address.newBuilder().setType(Address.Type.TYPE_UNIX).setAddress("/some/path").build(), BinlogHelper.socketToProto(socketAddress));
}
Also used : DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) ByteString(com.google.protobuf.ByteString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

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