Package org.elasticsearch.client.transport

Examples of org.elasticsearch.client.transport.TransportClient


  @Test
  public void test_transport_client_namespace() {
    Client client = checkClient("testTransportClient");
        assertThat(client, instanceOf(org.elasticsearch.client.transport.TransportClient.class));

    TransportClient tClient = (TransportClient) client;
    ImmutableList<TransportAddress> adresses = tClient.transportAddresses();
        assertThat("Nodes urls must not be empty...", adresses, not(emptyCollectionOf(TransportAddress.class)));

    // Testing if we are really connected to a cluster node
        assertThat("We should be connected at least to one node.", tClient.connectedNodes(), not(emptyCollectionOf(DiscoveryNode.class)));

    DiscoveryNode node = tClient.connectedNodes().get(0);
        assertThat(node.getName(), is("junit.node.transport"));
        assertThat("We should be connected to the master node.", node.isMasterNode(), is(true));
  }
View Full Code Here


    public void testTransportClient() {

        /**
         * InOut plugin modules must not be loaded for TransportClient instances
         */
        TransportClient client = new TransportClient();
        assertNotNull(client);

        /**
         * Internally, this get determined by the settings flag node.client which is set to true in case of
         * a TransportClient object. Thought the setting was given to the TransportClient with node.client = false
         * the constructor of TransportClient overwrites it to node.client = true
         */
        Settings settings = ImmutableSettings.settingsBuilder()
                .put("node.client", false)
                .build();

        client = null;
        client = new TransportClient(settings);
        assertNotNull(client);

    }
View Full Code Here

            ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder();
            builder.put("config.ignore_system_properties", true);
            builder.put("client.transport.sniff", true);
            builder.put("client.transport.ignore_cluster_name", true);
            builder.put("client.transport.ignore_cluster_name", true);
            transportClient = new TransportClient(builder, false);
            for (InetSocketTransportAddress address : ctx.targetNodes()) {
                ((TransportClient)transportClient).addTransportAddress(address);
            }
            return transportClient;
        }
View Full Code Here

    }


    private void closeClient() {
        if (transportClient != null) {
            TransportClient tc = ((TransportClient) transportClient);
            for (TransportAddress address : tc.transportAddresses()) {
                tc.removeTransportAddress(address);
            }
            transportClient.close();
        }

    }
View Full Code Here

                    .put("cluster.name", config.getClusterName())
                    .put("client.transport.ignore_cluster_name", false)
                    .put("node.client", true)
                    .put("client.transport.sniff", true)
                    .build();
            Client client = new TransportClient(settings)
                    .addTransportAddress(new InetSocketTransportAddress(config.getIp(), config.getPort()));
            this.client = client;
        } else {
            node = config.buildNode();
            client = node.client();
View Full Code Here

                .put("client.transport.sniff", true).build();

        CompositeTestCluster compositeTestCluster = backwardsCluster();
        TransportAddress transportAddress = compositeTestCluster.externalTransportAddress();

        try(TransportClient client = new TransportClient(settings)) {
            client.addTransportAddress(transportAddress);

            assertAcked(client.admin().indices().prepareCreate("test"));
            ensureYellow("test");

            int numDocs = iterations(10, 100);
            IndexRequestBuilder[] indexRequestBuilders = new IndexRequestBuilder[numDocs];
            for (int i = 0; i < numDocs; i++) {
                String id = "id" + i;
                indexRequestBuilders[i] = client.prepareIndex("test", "test", id).setSource("field", "value" + i);
            }
            indexRandom(false, indexRequestBuilders);

            String randomId = "id" + randomInt(numDocs-1);
            GetResponse getResponse = client.prepareGet("test", "test", randomId).get();
            assertThat(getResponse.isExists(), equalTo(true));

            refresh();

            SearchResponse searchResponse = client.prepareSearch("test").get();
            assertThat(searchResponse.getHits().totalHits(), equalTo((long)numDocs));

            int randomDocId = randomInt(numDocs-1);
            String fieldValue = "value" + randomDocId;
            String id = "id" + randomDocId;
            searchResponse = client.prepareSearch("test").setQuery(QueryBuilders.termQuery("field", fieldValue)).get();
            assertSearchHits(searchResponse, id);
        }
    }
View Full Code Here

                .put("client.transport.ignore_cluster_name", true)
                .put("node.name", "transport_client_" + getTestName()).build();

        // We explicitly connect to each node with a custom TransportClient
        for (NodeInfo n : nodesInfo.getNodes()) {
            TransportClient tc = new TransportClient(settings).addTransportAddress(n.getNode().address());
            // Just verify that the NS can be sent and serialized/deserialized between nodes with basic indices
            NodesStatsResponse ns = tc.admin().cluster().prepareNodesStats().setIndices(true).execute().actionGet();
            tc.close();
        }
    }
View Full Code Here

                .put("node.name", "transport_client_" + getTestName())
                .put("client.transport.ignore_cluster_name", true).build();

        // We explicitly connect to each node with a custom TransportClient
        for (NodeInfo n : nodesInfo.getNodes()) {
            TransportClient tc = new TransportClient(settings).addTransportAddress(n.getNode().address());

            // randomize the combination of flags set
            // Uses reflection to find methods in an attempt to future-proof this test against newly added flags
            NodesStatsRequestBuilder nsBuilder = tc.admin().cluster().prepareNodesStats();

            Class c = nsBuilder.getClass();
            for (Method method : c.getDeclaredMethods()) {
                if (method.getName().startsWith("set")) {
                    if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == boolean.class) {
                        method.invoke(nsBuilder, randomBoolean());
                    }
                } else if ((method.getName().equals("all") || method.getName().equals("clear")) && randomBoolean()) {
                    method.invoke(nsBuilder);
                }
            }
            NodesStatsResponse ns = nsBuilder.execute().actionGet();
            tc.close();

        }
    }
View Full Code Here

   */
  @Test
  public void createSuggest() throws Exception {
    Client client = null;
    try {
      client = new TransportClient().addTransportAddress(new InetSocketTransportAddress("localhost",9300));
     
      client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
     
      // Create index and mapping
      String mapping = readFileInClasspath("/productmapping.json");
View Full Code Here

    @Test
    //https://github.com/elasticsearch/elasticsearch/issues/5038
    public void testBulkProcessorConcurrentRequestsNoNodeAvailableException() throws Exception {
        //we create a transport client with no nodes to make sure it throws NoNodeAvailableException
        Client transportClient = new TransportClient();

        int bulkActions = randomIntBetween(10, 100);
        int numDocs = randomIntBetween(bulkActions, bulkActions + 100);
        int concurrentRequests = randomIntBetween(0, 10);

        int expectedBulkActions = numDocs / bulkActions;

        final CountDownLatch latch = new CountDownLatch(expectedBulkActions);
        int totalExpectedBulkActions = numDocs % bulkActions == 0 ? expectedBulkActions : expectedBulkActions + 1;
        final CountDownLatch closeLatch = new CountDownLatch(totalExpectedBulkActions);

        BulkProcessorTestListener listener = new BulkProcessorTestListener(latch, closeLatch);

        try (BulkProcessor processor = BulkProcessor.builder(transportClient, listener)
                .setConcurrentRequests(concurrentRequests).setBulkActions(bulkActions)
                //set interval and size to high values
                .setFlushInterval(TimeValue.timeValueHours(24)).setBulkSize(new ByteSizeValue(1, ByteSizeUnit.GB)).build()) {

            indexDocs(transportClient, processor, numDocs);

            latch.await();

            assertThat(listener.beforeCounts.get(), equalTo(expectedBulkActions));
            assertThat(listener.afterCounts.get(), equalTo(expectedBulkActions));
            assertThat(listener.bulkFailures.size(), equalTo(expectedBulkActions));
            assertThat(listener.bulkItems.size(), equalTo(0));
        }

        closeLatch.await();

        assertThat(listener.bulkFailures.size(), equalTo(totalExpectedBulkActions));
        assertThat(listener.bulkItems.size(), equalTo(0));
        transportClient.close();
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.client.transport.TransportClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.