Search in sources :

Example 66 with InetSocketAddress

use of java.net.InetSocketAddress in project grpc-java by grpc.

the class StressTestClient method runStressTest.

@VisibleForTesting
void runStressTest() throws Exception {
    Preconditions.checkState(!shutdown, "client was shutdown.");
    if (testCaseWeightPairs.isEmpty()) {
        return;
    }
    int numChannels = addresses.size() * channelsPerServer;
    int numThreads = numChannels * stubsPerChannel;
    threadpool = MoreExecutors.listeningDecorator(newFixedThreadPool(numThreads));
    int serverIdx = -1;
    for (InetSocketAddress address : addresses) {
        serverIdx++;
        for (int i = 0; i < channelsPerServer; i++) {
            ManagedChannel channel = createChannel(address);
            channels.add(channel);
            for (int j = 0; j < stubsPerChannel; j++) {
                String gaugeName = String.format("/stress_test/server_%d/channel_%d/stub_%d/qps", serverIdx, i, j);
                Worker worker = new Worker(channel, testCaseWeightPairs, durationSecs, gaugeName);
                workerFutures.add(threadpool.submit(worker));
            }
        }
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ManagedChannel(io.grpc.ManagedChannel) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 67 with InetSocketAddress

use of java.net.InetSocketAddress in project grpc-java by grpc.

the class StressTestClient method serverAddressesToString.

private static String serverAddressesToString(List<InetSocketAddress> addresses) {
    List<String> tmp = new ArrayList<String>();
    for (InetSocketAddress address : addresses) {
        URI uri;
        try {
            uri = new URI(null, null, address.getHostName(), address.getPort(), null, null, null);
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }
        tmp.add(uri.getAuthority());
    }
    return Joiner.on(',').join(tmp);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 68 with InetSocketAddress

use of java.net.InetSocketAddress in project grpc-java by grpc.

the class NettyFlowControlTest method resetConnection.

/**
   * Resets client/server and their flow control windows.
   */
private void resetConnection(int clientFlowControlWindow) throws InterruptedException {
    if (channel != null) {
        if (!channel.isShutdown()) {
            channel.shutdown();
            channel.awaitTermination(100, TimeUnit.MILLISECONDS);
        }
    }
    channel = NettyChannelBuilder.forAddress(new InetSocketAddress("localhost", proxyPort)).flowControlWindow(clientFlowControlWindow).negotiationType(NegotiationType.PLAINTEXT).build();
}
Also used : InetSocketAddress(java.net.InetSocketAddress)

Example 69 with InetSocketAddress

use of java.net.InetSocketAddress in project grpc-java by grpc.

the class StressTestClientTest method ipv6AddressesShouldBeSupported.

@Test
public void ipv6AddressesShouldBeSupported() {
    StressTestClient client = new StressTestClient();
    client.parseArgs(new String[] { "--server_addresses=[0:0:0:0:0:0:0:1]:8080," + "[1:2:3:4:f:e:a:b]:8083" });
    assertEquals(2, client.addresses().size());
    assertEquals(new InetSocketAddress("0:0:0:0:0:0:0:1", 8080), client.addresses().get(0));
    assertEquals(new InetSocketAddress("1:2:3:4:f:e:a:b", 8083), client.addresses().get(1));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test)

Example 70 with InetSocketAddress

use of java.net.InetSocketAddress in project grpc-java by grpc.

the class NettyServerTest method getPort.

@Test
public void getPort() throws Exception {
    InetSocketAddress addr = new InetSocketAddress(0);
    NettyServer ns = new NettyServer(addr, NioServerSocketChannel.class, // no boss group
    null, // no event group
    null, new ProtocolNegotiators.PlaintextNegotiator(), // ignore
    1, // ignore
    1, // ignore
    1, // ignore
    1);
    ns.start(new ServerListener() {

        @Override
        public ServerTransportListener transportCreated(ServerTransport transport) {
            return null;
        }

        @Override
        public void serverShutdown() {
        }
    });
    // Check that we got an actual port.
    assertThat(ns.getPort()).isGreaterThan(0);
    // Cleanup
    ns.shutdown();
}
Also used : ServerTransportListener(io.grpc.internal.ServerTransportListener) ServerTransport(io.grpc.internal.ServerTransport) InetSocketAddress(java.net.InetSocketAddress) ServerListener(io.grpc.internal.ServerListener) Test(org.junit.Test)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)2731 IOException (java.io.IOException)626 Test (org.junit.Test)614 Socket (java.net.Socket)362 InetAddress (java.net.InetAddress)253 ServerSocket (java.net.ServerSocket)182 SocketAddress (java.net.SocketAddress)180 ArrayList (java.util.ArrayList)179 Configuration (org.apache.hadoop.conf.Configuration)141 ByteBuffer (java.nio.ByteBuffer)135 UnknownHostException (java.net.UnknownHostException)127 InputStream (java.io.InputStream)106 SocketChannel (java.nio.channels.SocketChannel)106 OutputStream (java.io.OutputStream)104 SocketException (java.net.SocketException)94 File (java.io.File)93 URI (java.net.URI)80 HashMap (java.util.HashMap)79 Proxy (java.net.Proxy)72 ServerSocketChannel (java.nio.channels.ServerSocketChannel)69