# My Unit Tests with Elastic Search 0.13 throw ClusterBlockException

**URL:** https://discuss.elastic.co/t/my-unit-tests-with-elastic-search-0-13-throw-clusterblockexception/3609
**Category:** Elasticsearch
**Created:** [November 29, 2010, 9:23pm UTC](https://discuss.elastic.co/t/my-unit-tests-with-elastic-search-0-13-throw-clusterblockexception/3609 "2010-11-29T21:23:32Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![John\_Chang](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@John\_Chang](https://discuss.elastic.co/u/John_Chang)
#### Post date: [November 29, 2010, 9:23pm UTC](https://discuss.elastic.co/t/my-unit-tests-with-elastic-search-0-13-throw-clusterblockexception/3609/1 "2010-11-29T21:23:32Z")

</div>

I just tried upgrading my project to ElasticSearch 0.13 and the unit tests are throwing out:

org.elasticsearch.cluster.block.ClusterBlockException: blocked by: [1/not recovered from gateway];

I read the thread from this form entitled "Search failures on server restarts" (which discusses ClusterBlockException) and tried the following advice from it without success:

client().admin().cluster().prepareHealth(INDEX\_NAME).setWaitForYellowStatus().execute().actionGet();

In case it is useful info, this is how I start up the node and create the index in my test:

hostNode = NodeBuilder.nodeBuilder().loadConfigSettings(false).clusterName("test.cluster").local(true).settings(  
ImmutableSettings.settingsBuilder()  
.put("index.number\_of\_shards", 1)  
.put("index.number\_of\_replicas", 1)  
.put("gateway.type", "none")  
.build()

```
    ).node().start();
    elasticSearchClient = hostNode.client();

    elasticSearchClient.admin().indices().create(Requests.createIndexRequest("index0")).actionGet();
    
    String json = (new FileUtil()).readTextFileFromClasspath("mail_mappings.json");
    elasticSearchClient.admin().indices().putMapping(Requests.putMappingRequest("index0").source(json)).actionGet();
    json = (new FileUtil()).readTextFileFromClasspath("attachment_mappings.json");
    elasticSearchClient.admin().indices().putMapping(Requests.putMappingRequest("index0").source(json)).actionGet();

```

At the end of each test, I do this:  
 elasticSearchClient.close();  
hostNode.close();  
(I tried taking this last part out, and it doesn't to help; I just get different a different error (IndexAlreadyExistsException) when the next tests run.)

Thanks in advance for any help you can afford.  
-john

---

<div class="post-metadata">

### Author: ![John\_Chang](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@John\_Chang](https://discuss.elastic.co/u/John_Chang)
#### Post date: [November 29, 2010, 9:24pm UTC](https://discuss.elastic.co/t/my-unit-tests-with-elastic-search-0-13-throw-clusterblockexception/3609/2 "2010-11-29T21:24:15Z")

</div>

I should add: these tests were working fine with Elastic Search 0.12.1.

---

<div class="post-metadata">

### Author: ![John\_Chang](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@John\_Chang](https://discuss.elastic.co/u/John_Chang)
#### Post date: [November 29, 2010, 11:44pm UTC](https://discuss.elastic.co/t/my-unit-tests-with-elastic-search-0-13-throw-clusterblockexception/3609/3 "2010-11-29T23:44:45Z")

</div>

Seems I've found something that gets the job done. I took this part out of the end of the test class:

elasticSearchClient.close();  
hostNode.close();

And then when I create the index at the beginning of the next test class, I wrap the index creation in a try/catch and ignore and keep going if I catch:  
 try {  
elasticSearchClient.admin().indices().create(Requests.createIndexRequest("index0")).actionGet();  
} catch (ElasticSearchException e) {  
e.printStackTrace();  
}

This way, my tests can be run in any order or one at a time, as they create the index but don't fail if another has already created it.

Anyway, seems to be working; let me know if this is a bad way of doing things, but it looks ok to me.

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [November 30, 2010, 12:04pm UTC](https://discuss.elastic.co/t/my-unit-tests-with-elastic-search-0-13-throw-clusterblockexception/3609/4 "2010-11-30T12:04:50Z")

</div>

In case of none gateway, there shouldn't be the block created (for a very  
short time) if it not being recovered from the gateway. You can try and  
prepare a cluster health but wait for nodes and not on a specific index, it  
should help.

On Tue, Nov 30, 2010 at 1:44 AM, John Chang [jchangkihtest2@gmail.com](mailto:jchangkihtest2@gmail.com)wrote:

> Seems I've found something that gets the job done. I took this part out of  
> the end of the test class:
> 
> ```
> elasticSearchClient.close();
> hostNode.close();
> 
> ```
> 
> And then when I create the index at the beginning of the next test class, I  
> wrap the index creation in a try/catch and ignore and keep going if I  
> catch:  
> try {
> 
> elasticSearchClient.admin().indices().create(Requests.createIndexRequest("index0")).actionGet();  
> } catch (ElasticSearchException e) {  
> e.printStackTrace();  
> }
> 
> This way, my tests can be run in any order or one at a time, as they create  
> the index but don't fail if another has already created it.
> 
> ## Anyway, seems to be working; let me know if this is a bad way of doing things, but it looks ok to me.
> 
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/My-Unit-Tests-with-Elastic-Search-0-13-throw-ClusterBlockException-tp1989068p1989668.html](http://elasticsearch-users.115913.n3.nabble.com/My-Unit-Tests-with-Elastic-Search-0-13-throw-ClusterBlockException-tp1989068p1989668.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<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: [July 6, 2017, 4:15am UTC](https://discuss.elastic.co/t/my-unit-tests-with-elastic-search-0-13-throw-clusterblockexception/3609/5 "2017-07-06T04:15:59Z")

</div>


