protected void findNodeAddress() { NodesInfoRequest nodesInfoRequest = new NodesInfoRequest().transport(true); NodesInfoResponse response = client("1").admin().cluster().nodesInfo(nodesInfoRequest).actionGet(); Object obj = response.iterator().next().getTransport().getAddress().publishAddress(); if (obj instanceof InetSocketTransportAddress) { InetSocketTransportAddress address = (InetSocketTransportAddress) obj; host = address.address().getHostName(); port = address.address().getPort(); } }
public void testThatNettyHttpServerSupportsPipelining() throws Exception { List<String> requests = Arrays.asList("/", "/_nodes/stats", "/", "/_cluster/state", "/"); HttpServerTransport httpServerTransport = internalCluster().getInstance(HttpServerTransport.class); InetSocketTransportAddress inetSocketTransportAddress = (InetSocketTransportAddress) randomFrom(httpServerTransport.boundAddress().boundAddresses()); try (NettyHttpClient nettyHttpClient = new NettyHttpClient()) { Collection<HttpResponse> responses = nettyHttpClient.sendRequests( inetSocketTransportAddress.address(), requests.toArray(new String[] {})); assertThat(responses, hasSize(5)); Collection<String> opaqueIds = returnOpaqueIds(responses); assertOpaqueIdsInOrder(opaqueIds); } }
@Test public void testSimplePings() { ThreadPool threadPool = new ThreadPool(); ClusterName clusterName = new ClusterName("test"); NettyTransport transportA = new NettyTransport(threadPool); final TransportService transportServiceA = new TransportService(transportA, threadPool).start(); final DiscoveryNode nodeA = new DiscoveryNode("A", transportServiceA.boundAddress().publishAddress()); InetSocketTransportAddress addressA = (InetSocketTransportAddress) transportA.boundAddress().publishAddress(); NettyTransport transportB = new NettyTransport(threadPool); final TransportService transportServiceB = new TransportService(transportB, threadPool).start(); final DiscoveryNode nodeB = new DiscoveryNode("B", transportServiceA.boundAddress().publishAddress()); InetSocketTransportAddress addressB = (InetSocketTransportAddress) transportB.boundAddress().publishAddress(); Settings hostsSettings = ImmutableSettings.settingsBuilder() .putArray( "discovery.zen.ping.unicast.hosts", addressA.address().getAddress().getHostAddress() + ":" + addressA.address().getPort(), addressB.address().getAddress().getHostAddress() + ":" + addressB.address().getPort()) .build(); UnicastZenPing zenPingA = new UnicastZenPing(hostsSettings, threadPool, transportServiceA, clusterName, null); zenPingA.setNodesProvider( new DiscoveryNodesProvider() { @Override public DiscoveryNodes nodes() { return DiscoveryNodes.newNodesBuilder().put(nodeA).localNodeId("A").build(); } @Override public NodeService nodeService() { return null; } }); zenPingA.start(); UnicastZenPing zenPingB = new UnicastZenPing(hostsSettings, threadPool, transportServiceB, clusterName, null); zenPingB.setNodesProvider( new DiscoveryNodesProvider() { @Override public DiscoveryNodes nodes() { return DiscoveryNodes.newNodesBuilder().put(nodeB).localNodeId("B").build(); } @Override public NodeService nodeService() { return null; } }); zenPingB.start(); try { ZenPing.PingResponse[] pingResponses = zenPingA.pingAndWait(TimeValue.timeValueSeconds(1)); assertThat(pingResponses.length, equalTo(1)); assertThat(pingResponses[0].target().id(), equalTo("B")); } finally { zenPingA.close(); zenPingB.close(); transportServiceA.close(); transportServiceB.close(); threadPool.shutdown(); } }