當前位置: 首頁>>代碼示例>>Java>>正文


Java TransportAddress類代碼示例

本文整理匯總了Java中org.elasticsearch.common.transport.TransportAddress的典型用法代碼示例。如果您正苦於以下問題:Java TransportAddress類的具體用法?Java TransportAddress怎麽用?Java TransportAddress使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TransportAddress類屬於org.elasticsearch.common.transport包,在下文中一共展示了TransportAddress類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testThatNettyHttpServerDoesNotSupportPipelining

import org.elasticsearch.common.transport.TransportAddress; //導入依賴的package包/類
public void testThatNettyHttpServerDoesNotSupportPipelining() throws Exception {
    ensureGreen();
    String[] requests = new String[] {"/", "/_nodes/stats", "/", "/_cluster/state", "/", "/_nodes", "/"};

    HttpServerTransport httpServerTransport = internalCluster().getInstance(HttpServerTransport.class);
    TransportAddress[] boundAddresses = httpServerTransport.boundAddress().boundAddresses();
    TransportAddress transportAddress = (TransportAddress) randomFrom(boundAddresses);

    try (Netty4HttpClient nettyHttpClient = new Netty4HttpClient()) {
        Collection<FullHttpResponse> responses = nettyHttpClient.get(transportAddress.address(), requests);
        assertThat(responses, hasSize(requests.length));

        List<String> opaqueIds = new ArrayList<>(Netty4HttpClient.returnOpaqueIds(responses));

        assertResponsesOutOfOrder(opaqueIds);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:18,代碼來源:Netty4PipeliningDisabledIT.java

示例2: testThatHttpPipeliningWorksWhenEnabled

import org.elasticsearch.common.transport.TransportAddress; //導入依賴的package包/類
public void testThatHttpPipeliningWorksWhenEnabled() throws Exception {
    final Settings settings = Settings.builder()
        .put("http.pipelining", true)
        .put("http.port", "0")
        .build();
    try (HttpServerTransport httpServerTransport = new CustomNettyHttpServerTransport(settings)) {
        httpServerTransport.start();
        final TransportAddress transportAddress = randomFrom(httpServerTransport.boundAddress().boundAddresses());

        final int numberOfRequests = randomIntBetween(4, 16);
        final List<String> requests = new ArrayList<>(numberOfRequests);
        for (int i = 0; i < numberOfRequests; i++) {
            if (rarely()) {
                requests.add("/slow/" + i);
            } else {
                requests.add("/" + i);
            }
        }

        try (Netty4HttpClient nettyHttpClient = new Netty4HttpClient()) {
            Collection<FullHttpResponse> responses = nettyHttpClient.get(transportAddress.address(), requests.toArray(new String[]{}));
            Collection<String> responseBodies = Netty4HttpClient.returnHttpResponseBodies(responses);
            assertThat(responseBodies, contains(requests.toArray()));
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:27,代碼來源:Netty4HttpServerPipeliningTests.java

示例3: testDoesNotLimitExcludedRequests

import org.elasticsearch.common.transport.TransportAddress; //導入依賴的package包/類
public void testDoesNotLimitExcludedRequests() throws Exception {
    ensureGreen();

    @SuppressWarnings("unchecked")
    Tuple<String, CharSequence>[] requestUris = new Tuple[1500];
    for (int i = 0; i < requestUris.length; i++) {
        requestUris[i] = Tuple.tuple("/_cluster/settings",
            "{ \"transient\": {\"search.default_search_timeout\": \"40s\" } }");
    }

    HttpServerTransport httpServerTransport = internalCluster().getInstance(HttpServerTransport.class);
    TransportAddress transportAddress = (TransportAddress) randomFrom(httpServerTransport.boundAddress
        ().boundAddresses());

    try (Netty4HttpClient nettyHttpClient = new Netty4HttpClient()) {
        Collection<FullHttpResponse> responses = nettyHttpClient.put(transportAddress.address(), requestUris);
        assertThat(responses, hasSize(requestUris.length));
        assertAllInExpectedStatus(responses, HttpResponseStatus.OK);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:21,代碼來源:Netty4HttpRequestSizeLimitIT.java

示例4: testThatTransportClientCanConnect

import org.elasticsearch.common.transport.TransportAddress; //導入依賴的package包/類
public void testThatTransportClientCanConnect() throws Exception {
    Settings settings = Settings.builder()
        .put("cluster.name", internalCluster().getClusterName())
        .put(NetworkModule.TRANSPORT_TYPE_KEY, Netty4Plugin.NETTY_TRANSPORT_NAME)
        .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
        .build();
    try (TransportClient transportClient = new MockTransportClient(settings, Netty4Plugin.class)) {
        transportClient.addTransportAddress(new TransportAddress(InetAddress.getByName("127.0.0.1"), randomPort));
        ClusterHealthResponse response = transportClient.admin().cluster().prepareHealth().get();
        assertThat(response.getStatus(), is(ClusterHealthStatus.GREEN));
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:13,代碼來源:Netty4TransportMultiPortIntegrationIT.java

示例5: testEnforceLimitsWhenBoundToNonLocalAddress

import org.elasticsearch.common.transport.TransportAddress; //導入依賴的package包/類
public void testEnforceLimitsWhenBoundToNonLocalAddress() {
    final List<TransportAddress> transportAddresses = new ArrayList<>();
    final TransportAddress nonLocalTransportAddress = buildNewFakeTransportAddress();
    transportAddresses.add(nonLocalTransportAddress);

    for (int i = 0; i < randomIntBetween(0, 7); i++) {
        final TransportAddress randomTransportAddress = randomBoolean() ? buildNewFakeTransportAddress() :
            new TransportAddress(InetAddress.getLoopbackAddress(), i);
        transportAddresses.add(randomTransportAddress);
    }

    final TransportAddress publishAddress = randomBoolean() ? buildNewFakeTransportAddress() :
        new TransportAddress(InetAddress.getLoopbackAddress(), 0);

    final BoundTransportAddress boundTransportAddress = mock(BoundTransportAddress.class);
    Collections.shuffle(transportAddresses, random());
    when(boundTransportAddress.boundAddresses()).thenReturn(transportAddresses.toArray(new TransportAddress[0]));
    when(boundTransportAddress.publishAddress()).thenReturn(publishAddress);

    assertTrue(BootstrapChecks.enforceLimits(boundTransportAddress));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:BootstrapCheckTests.java

示例6: startClient

import org.elasticsearch.common.transport.TransportAddress; //導入依賴的package包/類
private static Client startClient(Path tempDir, TransportAddress... transportAddresses) {
    Settings.Builder builder = Settings.builder()
        .put("node.name", "qa_smoke_client_" + counter.getAndIncrement())
        .put("client.transport.ignore_cluster_name", true)
        .put(Environment.PATH_HOME_SETTING.getKey(), tempDir);
    final Collection<Class<? extends Plugin>> plugins;
    if (random().nextBoolean()) {
        builder.put(NetworkModule.TRANSPORT_TYPE_KEY, MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME);
        plugins = Collections.singleton(MockTcpTransportPlugin.class);
    } else {
        plugins = Collections.emptyList();
    }
    TransportClient client = new PreBuiltTransportClient(builder.build(), plugins).addTransportAddresses(transportAddresses);

    logger.info("--> Elasticsearch Java TransportClient started");

    Exception clientException = null;
    try {
        ClusterHealthResponse health = client.admin().cluster().prepareHealth().get();
        logger.info("--> connected to [{}] cluster which is running [{}] node(s).",
                health.getClusterName(), health.getNumberOfNodes());
    } catch (Exception e) {
        clientException = e;
    }

    assumeNoException("Sounds like your cluster is not running at " + clusterAddresses, clientException);

    return client;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:30,代碼來源:ESSmokeClientTestCase.java

示例7: testTcpHandshakeTimeout

import org.elasticsearch.common.transport.TransportAddress; //導入依賴的package包/類
public void testTcpHandshakeTimeout() throws IOException {
    try (ServerSocket socket = new MockServerSocket()) {
        socket.bind(new InetSocketAddress(InetAddress.getLocalHost(), 0), 1);
        socket.setReuseAddress(true);
        DiscoveryNode dummy = new DiscoveryNode("TEST", new TransportAddress(socket.getInetAddress(),
            socket.getLocalPort()), emptyMap(),
            emptySet(), version0);
        ConnectionProfile.Builder builder = new ConnectionProfile.Builder();
        builder.addConnections(1,
            TransportRequestOptions.Type.BULK,
            TransportRequestOptions.Type.PING,
            TransportRequestOptions.Type.RECOVERY,
            TransportRequestOptions.Type.REG,
            TransportRequestOptions.Type.STATE);
        builder.setHandshakeTimeout(TimeValue.timeValueMillis(1));
        ConnectTransportException ex = expectThrows(ConnectTransportException.class,
            () -> serviceA.connectToNode(dummy, builder.build()));
        assertEquals("[][" + dummy.getAddress() + "] handshake_timeout[1ms]", ex.getMessage());
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:21,代碼來源:AbstractSimpleTransportTestCase.java

示例8: addFailToSendNoConnectRule

import org.elasticsearch.common.transport.TransportAddress; //導入依賴的package包/類
/**
 * Adds a rule that will cause every send request to fail, and each new connect since the rule
 * is added to fail as well.
 */
public void addFailToSendNoConnectRule(TransportAddress transportAddress) {
    addDelegate(transportAddress, new DelegateTransport(original) {

        @Override
        public void connectToNode(DiscoveryNode node, ConnectionProfile connectionProfile,
                                  CheckedBiConsumer<Connection, ConnectionProfile, IOException> connectionValidator)
            throws ConnectTransportException {
            if (original.nodeConnected(node) == false) {
                // connecting to an already connected node is a no-op
                throw new ConnectTransportException(node, "DISCONNECT: simulated");
            }
        }

        @Override
        protected void sendRequest(Connection connection, long requestId, String action, TransportRequest request,
                                   TransportRequestOptions options) throws IOException {
            simulateDisconnect(connection, original, "DISCONNECT: simulated");
        }
    });
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:25,代碼來源:MockTransportService.java

示例9: addUnresponsiveRule

import org.elasticsearch.common.transport.TransportAddress; //導入依賴的package包/類
/**
 * Adds a rule that will cause ignores each send request, simulating an unresponsive node
 * and failing to connect once the rule was added.
 */
public void addUnresponsiveRule(TransportAddress transportAddress) {
    addDelegate(transportAddress, new DelegateTransport(original) {

        @Override
        public void connectToNode(DiscoveryNode node, ConnectionProfile connectionProfile,
                                  CheckedBiConsumer<Connection, ConnectionProfile, IOException> connectionValidator)
            throws ConnectTransportException {
            if (original.nodeConnected(node) == false) {
                // connecting to an already connected node is a no-op
                throw new ConnectTransportException(node, "UNRESPONSIVE: simulated");
            }
        }

        @Override
        protected void sendRequest(Connection connection, long requestId, String action, TransportRequest request,
                                   TransportRequestOptions options) throws IOException {
            // don't send anything, the receiving node is unresponsive
        }
    });
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:25,代碼來源:MockTransportService.java

示例10: testPublicIp

import org.elasticsearch.common.transport.TransportAddress; //導入依賴的package包/類
public void testPublicIp() throws InterruptedException {
    int nodes = randomInt(10);
    for (int i = 0; i < nodes; i++) {
        poorMansDNS.put(AmazonEC2Mock.PREFIX_PUBLIC_IP + (i+1), buildNewFakeTransportAddress());
    }
    Settings nodeSettings = Settings.builder()
            .put(DISCOVERY_EC2.HOST_TYPE_SETTING.getKey(), "public_ip")
            .build();
    List<DiscoveryNode> discoveryNodes = buildDynamicNodes(nodeSettings, nodes);
    assertThat(discoveryNodes, hasSize(nodes));
    // We check that we are using here expected address
    int node = 1;
    for (DiscoveryNode discoveryNode : discoveryNodes) {
        TransportAddress address = discoveryNode.getAddress();
        TransportAddress expected = poorMansDNS.get(AmazonEC2Mock.PREFIX_PUBLIC_IP + node++);
        assertEquals(address, expected);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:Ec2DiscoveryTests.java

示例11: doStart

import org.elasticsearch.common.transport.TransportAddress; //導入依賴的package包/類
@Override
protected void doStart() {
    add(localNodeMasterListeners);
    add(taskManager);
    this.clusterState = ClusterState.builder(clusterState).blocks(initialBlocks).build();
    this.updateTasksExecutor = EsExecutors.newSinglePrioritizing(UPDATE_THREAD_NAME, daemonThreadFactory(settings, UPDATE_THREAD_NAME));
    this.reconnectToNodes = threadPool.schedule(reconnectInterval, ThreadPool.Names.GENERIC, new ReconnectToNodes());
    Map<String, String> nodeAttributes = discoveryNodeService.buildAttributes();
    // note, we rely on the fact that its a new id each time we start, see FD and "kill -9" handling
    final String nodeId = DiscoveryService.generateNodeId(settings);
    final TransportAddress publishAddress = transportService.boundAddress().publishAddress();
    DiscoveryNode localNode = new DiscoveryNode(settings.get("name"), nodeId, publishAddress, nodeAttributes, version);
    DiscoveryNodes.Builder nodeBuilder = DiscoveryNodes.builder().put(localNode).localNodeId(localNode.id());
    this.clusterState = ClusterState.builder(clusterState).nodes(nodeBuilder).blocks(initialBlocks).build();
    this.transportService.setLocalNode(localNode);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:17,代碼來源:InternalClusterService.java

示例12: testBuiltRemoteClustersSeeds

import org.elasticsearch.common.transport.TransportAddress; //導入依賴的package包/類
public void testBuiltRemoteClustersSeeds() throws Exception {
    Map<String, List<DiscoveryNode>> map = RemoteClusterService.buildRemoteClustersSeeds(
        Settings.builder().put("search.remote.foo.seeds", "192.168.0.1:8080").put("search.remote.bar.seeds", "[::1]:9090").build());
    assertEquals(2, map.size());
    assertTrue(map.containsKey("foo"));
    assertTrue(map.containsKey("bar"));
    assertEquals(1, map.get("foo").size());
    assertEquals(1, map.get("bar").size());

    DiscoveryNode foo = map.get("foo").get(0);

    assertEquals(foo.getAddress(), new TransportAddress(new InetSocketAddress(InetAddress.getByName("192.168.0.1"), 8080)));
    assertEquals(foo.getId(), "foo#192.168.0.1:8080");
    assertEquals(foo.getVersion(), Version.CURRENT.minimumCompatibilityVersion());

    DiscoveryNode bar = map.get("bar").get(0);
    assertEquals(bar.getAddress(), new TransportAddress(new InetSocketAddress(InetAddress.getByName("[::1]"), 9090)));
    assertEquals(bar.getId(), "bar#[::1]:9090");
    assertEquals(bar.getVersion(), Version.CURRENT.minimumCompatibilityVersion());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:21,代碼來源:RemoteClusterServiceTests.java

示例13: sendErrorResponse

import org.elasticsearch.common.transport.TransportAddress; //導入依賴的package包/類
/**
 * Sends back an error response to the caller via the given channel
 * @param nodeVersion the caller node version
 * @param channel the channel to send the response to
 * @param error the error to return
 * @param requestId the request ID this response replies to
 * @param action the action this response replies to
 */
public void sendErrorResponse(Version nodeVersion, Channel channel, final Exception error, final long requestId,
                              final String action) throws IOException {
    try (BytesStreamOutput stream = new BytesStreamOutput()) {
        stream.setVersion(nodeVersion);
        RemoteTransportException tx = new RemoteTransportException(
            nodeName(), new TransportAddress(getLocalAddress(channel)), action, error);
        threadPool.getThreadContext().writeTo(stream);
        stream.writeException(tx);
        byte status = 0;
        status = TransportStatus.setResponse(status);
        status = TransportStatus.setError(status);
        final BytesReference bytes = stream.bytes();
        final BytesReference header = buildHeader(requestId, status, nodeVersion, bytes.length());
        Runnable onRequestSent = () -> transportServiceAdapter.onResponseSent(requestId, action, error);
        sendMessage(channel, new CompositeBytesReference(header, bytes), onRequestSent);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:26,代碼來源:TcpTransport.java

示例14: buildMessage

import org.elasticsearch.common.transport.TransportAddress; //導入依賴的package包/類
private static String buildMessage(String name, TransportAddress address, String action, String msg) {
    StringBuilder sb = new StringBuilder();
    if (name != null) {
        sb.append('[').append(name).append(']');
    }
    if (address != null) {
        sb.append('[').append(address).append(']');
    }
    if (action != null) {
        sb.append('[').append(action).append(']');
    }
    if (msg != null) {
        sb.append(" ").append(msg);
    }
    return sb.toString();
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:ActionTransportException.java

示例15: buildRemoteClustersSeeds

import org.elasticsearch.common.transport.TransportAddress; //導入依賴的package包/類
static Map<String, List<DiscoveryNode>> buildRemoteClustersSeeds(Settings settings) {
    Stream<Setting<List<InetSocketAddress>>> allConcreteSettings = REMOTE_CLUSTERS_SEEDS.getAllConcreteSettings(settings);
    return allConcreteSettings.collect(
        Collectors.toMap(REMOTE_CLUSTERS_SEEDS::getNamespace,  concreteSetting -> {
        String clusterName = REMOTE_CLUSTERS_SEEDS.getNamespace(concreteSetting);
        List<DiscoveryNode> nodes = new ArrayList<>();
        for (InetSocketAddress address : concreteSetting.get(settings)) {
            TransportAddress transportAddress = new TransportAddress(address);
            DiscoveryNode node = new DiscoveryNode(clusterName + "#" + transportAddress.toString(),
                transportAddress,
                Version.CURRENT.minimumCompatibilityVersion());
            nodes.add(node);
        }
        return nodes;
    }));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:RemoteClusterService.java


注:本文中的org.elasticsearch.common.transport.TransportAddress類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。