# No\_shard\_available\_action\_exception in integration tests

**URL:** <https://discuss.elastic.co/t/no-shard-available-action-exception-in-integration-tests/262941>\
**Category:** Elasticsearch\
**Created:** [February 2, 2021, 8:28am UTC](https://discuss.elastic.co/t/no-shard-available-action-exception-in-integration-tests/262941 "2021-02-02T08:28:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rdehuyss](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rdehuyss/32/83278_2.png) [@rdehuyss](https://discuss.elastic.co/u/rdehuyss)\
**Post date:** [February 2, 2021, 8:28am UTC](https://discuss.elastic.co/t/no-shard-available-action-exception-in-integration-tests/262941/1 "2021-02-02T08:28:09Z")

</div>

Hi,

I'm the author of JobRunr, a distributed job scheduling library that also supports ElasticSearch as a storage provider.

For my integration tests, I use TestContainers and start an ElasticSearch.

```java
@Container
    private static final ElasticsearchContainer elasticSearchContainer = new ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch:7.10.1")
            .withNetwork(network)
            .withNetworkAliases("elasticsearch")
            .withExposedPorts(9200);

```

There is one case where I always get a `no_shard_available_action_exception` even though the cluster health is yellow.

My code is as follows:

```java
@Override
    protected boolean isNewMigration(NoSqlMigration noSqlMigration) {
        try {
            System.out.println("Testing for new migration...");
            waitForHealthyCluster(client);
            GetResponse migration = client.get(new GetRequest(JOBRUNR_MIGRATIONS_INDEX_NAME, substringBefore(noSqlMigration.getClassName(), "_")), RequestOptions.DEFAULT);
            return !migration.isExists();
        } catch (IOException e) {
            throw new StorageException(e);
        }
    }

```

And the logs:

```auto
========================================================================
Cluster health:YELLOW
========================================================================
Testing for new migration...
========================================================================
Cluster health:YELLOW
========================================================================
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
Exception in thread "main" ElasticsearchStatusException[Elasticsearch exception [type=no_shard_available_action_exception, reason=No shard available for [get [jobrunr_migrations][_doc][M001]: routing [null]]]]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_index_shard_state_exception, reason=CurrentState[RECOVERING] operations only allowed when shard state is one of [POST_RECOVERY, STARTED]]];

```

How can I be sure that ES is ready to receive `GetRequest`s?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 2, 2021, 10:38am UTC](https://discuss.elastic.co/t/no-shard-available-action-exception-in-integration-tests/262941/2 "2021-02-02T10:38:37Z")

</div>

IIRC there's an issue on that.

What I'm doing on my side is to wait if some issues like this are happening and retry until I reach a timeout.

You can see that here:

> <https://github.com/dadoonet/fscrawler/blob/f2d21ea4e49e480400b6bcd421efbdf9681ca32a/integration-tests/it-common/src/main/java/fr/pilato/elasticsearch/crawler/fs/test/integration/AbstractITCase.java#L337-L354>

This is not ideal for sure but at least I don't have non stable integration tests anymore...

A thing you could do, is to check the index status (`waitForHealthyIndex(JOBRUNR_MIGRATIONS_INDEX_NAME)`) instead of the cluster status. But I guess you might hit the same issue though.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [February 2, 2021, 10:49am UTC](https://discuss.elastic.co/t/no-shard-available-action-exception-in-integration-tests/262941/3 "2021-02-02T10:49:42Z")

</div>

An index reports `yellow` health if it's newly created, because we don't want clusters to indicate they're unhealthy just because a new index was created. I'm guessing it's that. Most of the Elasticsearch integration tests wait for a newly-created index to be `green` before proceeding.

---

<div class="post-metadata">

**Author:** ![rdehuyss](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rdehuyss/32/83278_2.png) [@rdehuyss](https://discuss.elastic.co/u/rdehuyss)\
**Post date:** [February 3, 2021, 11:13am UTC](https://discuss.elastic.co/t/no-shard-available-action-exception-in-integration-tests/262941/4 "2021-02-03T11:13:21Z")

</div>

Hi,

Thank you both for the answers.

Will the cluster become green if there is only 1 node participating?

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [February 3, 2021, 11:49am UTC](https://discuss.elastic.co/t/no-shard-available-action-exception-in-integration-tests/262941/5 "2021-02-03T11:49:34Z")

</div>

Yes, as long as you set `number_of_replicas: 0` on any indices you create.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 3, 2021, 11:50am UTC](https://discuss.elastic.co/t/no-shard-available-action-exception-in-integration-tests/262941/6 "2021-03-03T11:50:17Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
