Search in sources :

Example 81 with Client

use of org.elasticsearch.client.Client in project elasticsearch by elastic.

the class RelocationIT method beforeIndexDeletion.

@Override
protected void beforeIndexDeletion() throws Exception {
    super.beforeIndexDeletion();
    assertBusy(() -> {
        IndicesStatsResponse stats = client().admin().indices().prepareStats().clear().get();
        for (IndexStats indexStats : stats.getIndices().values()) {
            for (IndexShardStats indexShardStats : indexStats.getIndexShards().values()) {
                Optional<ShardStats> maybePrimary = Stream.of(indexShardStats.getShards()).filter(s -> s.getShardRouting().active() && s.getShardRouting().primary()).findFirst();
                if (maybePrimary.isPresent() == false) {
                    continue;
                }
                ShardStats primary = maybePrimary.get();
                final SeqNoStats primarySeqNoStats = primary.getSeqNoStats();
                assertThat(primary.getShardRouting() + " should have set the global checkpoint", primarySeqNoStats.getGlobalCheckpoint(), not(equalTo(SequenceNumbersService.UNASSIGNED_SEQ_NO)));
                for (ShardStats shardStats : indexShardStats) {
                    final SeqNoStats seqNoStats = shardStats.getSeqNoStats();
                    assertThat(shardStats.getShardRouting() + " local checkpoint mismatch", seqNoStats.getLocalCheckpoint(), equalTo(primarySeqNoStats.getLocalCheckpoint()));
                    assertThat(shardStats.getShardRouting() + " global checkpoint mismatch", seqNoStats.getGlobalCheckpoint(), equalTo(primarySeqNoStats.getGlobalCheckpoint()));
                    assertThat(shardStats.getShardRouting() + " max seq no mismatch", seqNoStats.getMaxSeqNo(), equalTo(primarySeqNoStats.getMaxSeqNo()));
                }
            }
        }
    });
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) Arrays(java.util.Arrays) TransportRequest(org.elasticsearch.transport.TransportRequest) Nullable(org.elasticsearch.common.Nullable) SearchHits(org.elasticsearch.search.SearchHits) Matchers.not(org.hamcrest.Matchers.not) IndexStats(org.elasticsearch.action.admin.indices.stats.IndexStats) MoveAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand) SeqNoStats(org.elasticsearch.index.seqno.SeqNoStats) ClusterState(org.elasticsearch.cluster.ClusterState) Settings(org.elasticsearch.common.settings.Settings) Scope(org.elasticsearch.test.ESIntegTestCase.Scope) SearchResponse(org.elasticsearch.action.search.SearchResponse) Path(java.nio.file.Path) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) SearchHit(org.elasticsearch.search.SearchHit) MockIndexEventListener(org.elasticsearch.test.MockIndexEventListener) Priority(org.elasticsearch.common.Priority) PeerRecoveryTargetService(org.elasticsearch.indices.recovery.PeerRecoveryTargetService) Transport(org.elasticsearch.transport.Transport) TestLogging(org.elasticsearch.test.junit.annotations.TestLogging) Collection(java.util.Collection) RecoveryFileChunkRequest(org.elasticsearch.indices.recovery.RecoveryFileChunkRequest) ElasticsearchAssertions.assertHitCount(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount) Matchers.startsWith(org.hamcrest.Matchers.startsWith) ElasticsearchAssertions.assertSearchHits(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits) FileVisitResult(java.nio.file.FileVisitResult) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Stream(java.util.stream.Stream) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) ESIntegTestCase(org.elasticsearch.test.ESIntegTestCase) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) INDEX_SEQ_NO_CHECKPOINT_SYNC_INTERVAL(org.elasticsearch.index.IndexSettings.INDEX_SEQ_NO_CHECKPOINT_SYNC_INTERVAL) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) IntProcedure(com.carrotsearch.hppc.procedures.IntProcedure) XContentType(org.elasticsearch.common.xcontent.XContentType) IndexShardStats(org.elasticsearch.action.admin.indices.stats.IndexShardStats) ClusterService(org.elasticsearch.cluster.service.ClusterService) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) ArrayList(java.util.ArrayList) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) SequenceNumbersService(org.elasticsearch.index.seqno.SequenceNumbersService) ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) TimeValue(org.elasticsearch.common.unit.TimeValue) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportService(org.elasticsearch.transport.TransportService) EnableAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider) ClusterScope(org.elasticsearch.test.ESIntegTestCase.ClusterScope) IndexShardState(org.elasticsearch.index.shard.IndexShardState) QueryBuilders.matchAllQuery(org.elasticsearch.index.query.QueryBuilders.matchAllQuery) IndexEventListener(org.elasticsearch.index.shard.IndexEventListener) Files(java.nio.file.Files) Semaphore(java.util.concurrent.Semaphore) Client(org.elasticsearch.client.Client) IndexShard(org.elasticsearch.index.shard.IndexShard) IntHashSet(com.carrotsearch.hppc.IntHashSet) IndexFileNames(org.apache.lucene.index.IndexFileNames) Plugin(org.elasticsearch.plugins.Plugin) BackgroundIndexer(org.elasticsearch.test.BackgroundIndexer) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) English(org.apache.lucene.util.English) ElasticsearchAssertions.assertAcked(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked) ElasticsearchAssertions.assertNoFailures(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures) IndexShardStats(org.elasticsearch.action.admin.indices.stats.IndexShardStats) ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) SeqNoStats(org.elasticsearch.index.seqno.SeqNoStats) IndexShardStats(org.elasticsearch.action.admin.indices.stats.IndexShardStats) IndexStats(org.elasticsearch.action.admin.indices.stats.IndexStats)

Example 82 with Client

use of org.elasticsearch.client.Client in project elasticsearch by elastic.

the class RelocationIT method testRelocationWhileIndexingRandom.

@TestLogging("org.elasticsearch.action.bulk:TRACE,org.elasticsearch.action.search:TRACE")
public void testRelocationWhileIndexingRandom() throws Exception {
    int numberOfRelocations = scaledRandomIntBetween(1, rarely() ? 10 : 4);
    int numberOfReplicas = randomBoolean() ? 0 : 1;
    int numberOfNodes = numberOfReplicas == 0 ? 2 : 3;
    logger.info("testRelocationWhileIndexingRandom(numRelocations={}, numberOfReplicas={}, numberOfNodes={})", numberOfRelocations, numberOfReplicas, numberOfNodes);
    String[] nodes = new String[numberOfNodes];
    logger.info("--> starting [node1] ...");
    nodes[0] = internalCluster().startNode();
    logger.info("--> creating test index ...");
    prepareCreate("test", Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", numberOfReplicas)).get();
    for (int i = 2; i <= numberOfNodes; i++) {
        logger.info("--> starting [node{}] ...", i);
        nodes[i - 1] = internalCluster().startNode();
        if (i != numberOfNodes) {
            ClusterHealthResponse healthResponse = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNodes(Integer.toString(i)).setWaitForGreenStatus().execute().actionGet();
            assertThat(healthResponse.isTimedOut(), equalTo(false));
        }
    }
    int numDocs = scaledRandomIntBetween(200, 2500);
    try (BackgroundIndexer indexer = new BackgroundIndexer("test", "type1", client(), numDocs)) {
        logger.info("--> waiting for {} docs to be indexed ...", numDocs);
        waitForDocs(numDocs, indexer);
        logger.info("--> {} docs indexed", numDocs);
        logger.info("--> starting relocations...");
        // if we have replicas shift those
        int nodeShiftBased = numberOfReplicas;
        for (int i = 0; i < numberOfRelocations; i++) {
            int fromNode = (i % 2);
            int toNode = fromNode == 0 ? 1 : 0;
            fromNode += nodeShiftBased;
            toNode += nodeShiftBased;
            numDocs = scaledRandomIntBetween(200, 1000);
            logger.debug("--> Allow indexer to index [{}] documents", numDocs);
            indexer.continueIndexing(numDocs);
            logger.info("--> START relocate the shard from {} to {}", nodes[fromNode], nodes[toNode]);
            client().admin().cluster().prepareReroute().add(new MoveAllocationCommand("test", 0, nodes[fromNode], nodes[toNode])).get();
            if (rarely()) {
                logger.debug("--> flushing");
                client().admin().indices().prepareFlush().get();
            }
            ClusterHealthResponse clusterHealthResponse = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNoRelocatingShards(true).setTimeout(ACCEPTABLE_RELOCATION_TIME).execute().actionGet();
            assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
            indexer.pauseIndexing();
            logger.info("--> DONE relocate the shard from {} to {}", fromNode, toNode);
        }
        logger.info("--> done relocations");
        logger.info("--> waiting for indexing threads to stop ...");
        indexer.stop();
        logger.info("--> indexing threads stopped");
        logger.info("--> refreshing the index");
        client().admin().indices().prepareRefresh("test").execute().actionGet();
        logger.info("--> searching the index");
        boolean ranOnce = false;
        for (int i = 0; i < 10; i++) {
            logger.info("--> START search test round {}", i + 1);
            SearchHits hits = client().prepareSearch("test").setQuery(matchAllQuery()).setSize((int) indexer.totalIndexedDocs()).storedFields().execute().actionGet().getHits();
            ranOnce = true;
            if (hits.getTotalHits() != indexer.totalIndexedDocs()) {
                int[] hitIds = new int[(int) indexer.totalIndexedDocs()];
                for (int hit = 0; hit < indexer.totalIndexedDocs(); hit++) {
                    hitIds[hit] = hit + 1;
                }
                IntHashSet set = IntHashSet.from(hitIds);
                for (SearchHit hit : hits.getHits()) {
                    int id = Integer.parseInt(hit.getId());
                    if (!set.remove(id)) {
                        logger.error("Extra id [{}]", id);
                    }
                }
                set.forEach((IntProcedure) value -> {
                    logger.error("Missing id [{}]", value);
                });
            }
            assertThat(hits.getTotalHits(), equalTo(indexer.totalIndexedDocs()));
            logger.info("--> DONE search test round {}", i + 1);
        }
        if (!ranOnce) {
            fail();
        }
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) Arrays(java.util.Arrays) TransportRequest(org.elasticsearch.transport.TransportRequest) Nullable(org.elasticsearch.common.Nullable) SearchHits(org.elasticsearch.search.SearchHits) Matchers.not(org.hamcrest.Matchers.not) IndexStats(org.elasticsearch.action.admin.indices.stats.IndexStats) MoveAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand) SeqNoStats(org.elasticsearch.index.seqno.SeqNoStats) ClusterState(org.elasticsearch.cluster.ClusterState) Settings(org.elasticsearch.common.settings.Settings) Scope(org.elasticsearch.test.ESIntegTestCase.Scope) SearchResponse(org.elasticsearch.action.search.SearchResponse) Path(java.nio.file.Path) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) SearchHit(org.elasticsearch.search.SearchHit) MockIndexEventListener(org.elasticsearch.test.MockIndexEventListener) Priority(org.elasticsearch.common.Priority) PeerRecoveryTargetService(org.elasticsearch.indices.recovery.PeerRecoveryTargetService) Transport(org.elasticsearch.transport.Transport) TestLogging(org.elasticsearch.test.junit.annotations.TestLogging) Collection(java.util.Collection) RecoveryFileChunkRequest(org.elasticsearch.indices.recovery.RecoveryFileChunkRequest) ElasticsearchAssertions.assertHitCount(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount) Matchers.startsWith(org.hamcrest.Matchers.startsWith) ElasticsearchAssertions.assertSearchHits(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits) FileVisitResult(java.nio.file.FileVisitResult) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Stream(java.util.stream.Stream) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) ESIntegTestCase(org.elasticsearch.test.ESIntegTestCase) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) INDEX_SEQ_NO_CHECKPOINT_SYNC_INTERVAL(org.elasticsearch.index.IndexSettings.INDEX_SEQ_NO_CHECKPOINT_SYNC_INTERVAL) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) IntProcedure(com.carrotsearch.hppc.procedures.IntProcedure) XContentType(org.elasticsearch.common.xcontent.XContentType) IndexShardStats(org.elasticsearch.action.admin.indices.stats.IndexShardStats) ClusterService(org.elasticsearch.cluster.service.ClusterService) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) ArrayList(java.util.ArrayList) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) SequenceNumbersService(org.elasticsearch.index.seqno.SequenceNumbersService) ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) TimeValue(org.elasticsearch.common.unit.TimeValue) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportService(org.elasticsearch.transport.TransportService) EnableAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider) ClusterScope(org.elasticsearch.test.ESIntegTestCase.ClusterScope) IndexShardState(org.elasticsearch.index.shard.IndexShardState) QueryBuilders.matchAllQuery(org.elasticsearch.index.query.QueryBuilders.matchAllQuery) IndexEventListener(org.elasticsearch.index.shard.IndexEventListener) Files(java.nio.file.Files) Semaphore(java.util.concurrent.Semaphore) Client(org.elasticsearch.client.Client) IndexShard(org.elasticsearch.index.shard.IndexShard) IntHashSet(com.carrotsearch.hppc.IntHashSet) IndexFileNames(org.apache.lucene.index.IndexFileNames) Plugin(org.elasticsearch.plugins.Plugin) BackgroundIndexer(org.elasticsearch.test.BackgroundIndexer) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) English(org.apache.lucene.util.English) ElasticsearchAssertions.assertAcked(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked) ElasticsearchAssertions.assertNoFailures(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) BackgroundIndexer(org.elasticsearch.test.BackgroundIndexer) SearchHit(org.elasticsearch.search.SearchHit) MoveAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand) IntHashSet(com.carrotsearch.hppc.IntHashSet) SearchHits(org.elasticsearch.search.SearchHits) ElasticsearchAssertions.assertSearchHits(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits) TestLogging(org.elasticsearch.test.junit.annotations.TestLogging)

Example 83 with Client

use of org.elasticsearch.client.Client in project elasticsearch by elastic.

the class RelocationIT method testRelocationWhileRefreshing.

@TestLogging("org.elasticsearch.action.bulk:TRACE,org.elasticsearch.action.search:TRACE")
public void testRelocationWhileRefreshing() throws Exception {
    int numberOfRelocations = scaledRandomIntBetween(1, rarely() ? 10 : 4);
    int numberOfReplicas = randomBoolean() ? 0 : 1;
    int numberOfNodes = numberOfReplicas == 0 ? 2 : 3;
    logger.info("testRelocationWhileIndexingRandom(numRelocations={}, numberOfReplicas={}, numberOfNodes={})", numberOfRelocations, numberOfReplicas, numberOfNodes);
    String[] nodes = new String[numberOfNodes];
    logger.info("--> starting [node_0] ...");
    nodes[0] = internalCluster().startNode();
    logger.info("--> creating test index ...");
    prepareCreate("test", Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", numberOfReplicas).put("index.refresh_interval", // we want to control refreshes c
    -1)).get();
    for (int i = 1; i < numberOfNodes; i++) {
        logger.info("--> starting [node_{}] ...", i);
        nodes[i] = internalCluster().startNode();
        if (i != numberOfNodes - 1) {
            ClusterHealthResponse healthResponse = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNodes(Integer.toString(i + 1)).setWaitForGreenStatus().execute().actionGet();
            assertThat(healthResponse.isTimedOut(), equalTo(false));
        }
    }
    final Semaphore postRecoveryShards = new Semaphore(0);
    final IndexEventListener listener = new IndexEventListener() {

        @Override
        public void indexShardStateChanged(IndexShard indexShard, @Nullable IndexShardState previousState, IndexShardState currentState, @Nullable String reason) {
            if (currentState == IndexShardState.POST_RECOVERY) {
                postRecoveryShards.release();
            }
        }
    };
    for (MockIndexEventListener.TestEventListener eventListener : internalCluster().getInstances(MockIndexEventListener.TestEventListener.class)) {
        eventListener.setNewDelegate(listener);
    }
    logger.info("--> starting relocations...");
    // if we have replicas shift those
    int nodeShiftBased = numberOfReplicas;
    for (int i = 0; i < numberOfRelocations; i++) {
        int fromNode = (i % 2);
        int toNode = fromNode == 0 ? 1 : 0;
        fromNode += nodeShiftBased;
        toNode += nodeShiftBased;
        List<IndexRequestBuilder> builders1 = new ArrayList<>();
        for (int numDocs = randomIntBetween(10, 30); numDocs > 0; numDocs--) {
            builders1.add(client().prepareIndex("test", "type").setSource("{}", XContentType.JSON));
        }
        List<IndexRequestBuilder> builders2 = new ArrayList<>();
        for (int numDocs = randomIntBetween(10, 30); numDocs > 0; numDocs--) {
            builders2.add(client().prepareIndex("test", "type").setSource("{}", XContentType.JSON));
        }
        logger.info("--> START relocate the shard from {} to {}", nodes[fromNode], nodes[toNode]);
        client().admin().cluster().prepareReroute().add(new MoveAllocationCommand("test", 0, nodes[fromNode], nodes[toNode])).get();
        logger.debug("--> index [{}] documents", builders1.size());
        indexRandom(false, true, builders1);
        // wait for shard to reach post recovery
        postRecoveryShards.acquire(1);
        logger.debug("--> index [{}] documents", builders2.size());
        indexRandom(true, true, builders2);
        // verify cluster was finished.
        assertFalse(client().admin().cluster().prepareHealth().setWaitForNoRelocatingShards(true).setWaitForEvents(Priority.LANGUID).setTimeout("30s").get().isTimedOut());
        logger.info("--> DONE relocate the shard from {} to {}", fromNode, toNode);
        logger.debug("--> verifying all searches return the same number of docs");
        long expectedCount = -1;
        for (Client client : clients()) {
            SearchResponse response = client.prepareSearch("test").setPreference("_local").setSize(0).get();
            assertNoFailures(response);
            if (expectedCount < 0) {
                expectedCount = response.getHits().getTotalHits();
            } else {
                assertEquals(expectedCount, response.getHits().getTotalHits());
            }
        }
    }
}
Also used : MockIndexEventListener(org.elasticsearch.test.MockIndexEventListener) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) IndexShard(org.elasticsearch.index.shard.IndexShard) ArrayList(java.util.ArrayList) MoveAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand) Semaphore(java.util.concurrent.Semaphore) SearchResponse(org.elasticsearch.action.search.SearchResponse) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) MockIndexEventListener(org.elasticsearch.test.MockIndexEventListener) IndexEventListener(org.elasticsearch.index.shard.IndexEventListener) Client(org.elasticsearch.client.Client) IndexShardState(org.elasticsearch.index.shard.IndexShardState) Nullable(org.elasticsearch.common.Nullable) TestLogging(org.elasticsearch.test.junit.annotations.TestLogging)

Example 84 with Client

use of org.elasticsearch.client.Client in project elasticsearch by elastic.

the class MoreLikeThisIT method testMoreLikeThisIssue2197.

public void testMoreLikeThisIssue2197() throws Exception {
    Client client = client();
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("bar").startObject("properties").endObject().endObject().endObject().string();
    client().admin().indices().prepareCreate("foo").addMapping("bar", mapping, XContentType.JSON).execute().actionGet();
    client().prepareIndex("foo", "bar", "1").setSource(jsonBuilder().startObject().startObject("foo").field("bar", "boz").endObject().endObject()).execute().actionGet();
    client().admin().indices().prepareRefresh("foo").execute().actionGet();
    assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN));
    SearchResponse response = client().prepareSearch().setQuery(new MoreLikeThisQueryBuilder(null, new Item[] { new Item("foo", "bar", "1") })).get();
    assertNoFailures(response);
    assertThat(response, notNullValue());
    response = client().prepareSearch().setQuery(new MoreLikeThisQueryBuilder(null, new Item[] { new Item("foo", "bar", "1") })).get();
    assertNoFailures(response);
    assertThat(response, notNullValue());
}
Also used : Item(org.elasticsearch.index.query.MoreLikeThisQueryBuilder.Item) MoreLikeThisQueryBuilder(org.elasticsearch.index.query.MoreLikeThisQueryBuilder) Client(org.elasticsearch.client.Client) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 85 with Client

use of org.elasticsearch.client.Client in project elasticsearch by elastic.

the class Netty4TransportIT method testThatConnectionFailsAsIntended.

public void testThatConnectionFailsAsIntended() throws Exception {
    Client transportClient = internalCluster().transportClient();
    ClusterHealthResponse clusterIndexHealths = transportClient.admin().cluster().prepareHealth().get();
    assertThat(clusterIndexHealths.getStatus(), is(ClusterHealthStatus.GREEN));
    try {
        transportClient.filterWithHeader(Collections.singletonMap("ERROR", "MY MESSAGE")).admin().cluster().prepareHealth().get();
        fail("Expected exception, but didn't happen");
    } catch (ElasticsearchException e) {
        assertThat(e.getMessage(), containsString("MY MESSAGE"));
        assertThat(channelProfileName, is(TransportSettings.DEFAULT_PROFILE));
    }
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ElasticsearchException(org.elasticsearch.ElasticsearchException) Client(org.elasticsearch.client.Client)

Aggregations

Client (org.elasticsearch.client.Client)164 CreateSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)42 Settings (org.elasticsearch.common.settings.Settings)38 Path (java.nio.file.Path)30 RestoreSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)28 PutRepositoryResponse (org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse)24 ArrayList (java.util.ArrayList)23 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)23 IOException (java.io.IOException)20 Matchers.containsString (org.hamcrest.Matchers.containsString)20 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)18 ClusterState (org.elasticsearch.cluster.ClusterState)17 ExecutionException (java.util.concurrent.ExecutionException)16 SearchResponse (org.elasticsearch.action.search.SearchResponse)14 ClusterAdminClient (org.elasticsearch.client.ClusterAdminClient)13 ClusterService (org.elasticsearch.cluster.service.ClusterService)10 List (java.util.List)9 ActionRequestValidationException (org.elasticsearch.action.ActionRequestValidationException)9 CloseIndexResponse (org.elasticsearch.action.admin.indices.close.CloseIndexResponse)9 OpenIndexResponse (org.elasticsearch.action.admin.indices.open.OpenIndexResponse)9