# Integration tests and consistency

**URL:** <https://discuss.elastic.co/t/integration-tests-and-consistency/6602>\
**Category:** Elasticsearch\
**Created:** [February 6, 2012, 9:51am UTC](https://discuss.elastic.co/t/integration-tests-and-consistency/6602 "2012-02-06T09:51:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Runar\_Myklebust\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/runar_myklebust_2/32/2047_2.png) [@Runar\_Myklebust\_2](https://discuss.elastic.co/u/Runar_Myklebust_2)\
**Post date:** [February 6, 2012, 9:51am UTC](https://discuss.elastic.co/t/integration-tests-and-consistency/6602/1 "2012-02-06T09:51:47Z")

</div>

Hi.

Ive created integration tests for the ES integration in our product. We use  
version 0.18.6

For all tests, the flow is like this:

Index data -\> this.client.index( request ).actionGet();  
Flush index -\> client.admin().indices().flush( Requests.flushRequest(  
INDEX\_NAME ).refresh( true ) ).actionGet();  
Query -\> this.client.search( req ).actionGet();

When running a lot of tests, usually one or two test fails with not  
expected results from query, meaning that the query is executed before the  
index is updated properly. When running all tests again, another test may  
fail while to previous was successfull.  
What can I do to enshure that the test will run properly each time? I  
thought the flush-index would make shure that everything was flushed into  
the index?

The settings for the test-environment is like this:

protected static final String NUMBER\_OF\_SHARDS = "5";

protected static final String NUMBER\_OF\_REPLICAS = "1";

```
public ImmutableSettings.Builder buildSettings()
{
    ImmutableSettings.Builder settings =

```

ImmutableSettings.settingsBuilder();  
settings.loadFromSource( buildDistributionSettings() );  
settings.loadFromSource( buildStorageSettings() );  
[//settings.loadFromSource](https://settings.loadFromSource)( buildAnalyserSettings() );

```
    return settings;
}

private String buildStorageSettings()
{
    try
    {
        return jsonBuilder().startObject().startObject( "store"

```

).field( "type", "memory" ).endObject().endObject().string();  
}  
catch ( IOException e )  
{  
throw new ContentIndexException( "Not able to create settings  
for index", e );  
}  
}

```
private String buildDistributionSettings()
{
    try
    {
        return jsonBuilder().startObject()
            .field( "number_of_shards", NUMBER_OF_SHARDS )
            .field( "number_of_replicas", NUMBER_OF_REPLICAS )
            .endObject()
            .string();
    }
    catch ( IOException e )
    {
        throw new ContentIndexException( "Not able to create settings

```

for index", e );  
}  
}

## mvh

Runar Myklebust

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [February 6, 2012, 10:15am UTC](https://discuss.elastic.co/t/integration-tests-and-consistency/6602/2 "2012-02-06T10:15:00Z")

</div>

Hi,

Not sure what is the problem here but there are some things that hit me:

1. You use memory index and flush flushes the index into its store (which  
in this case is memory). Have never seen this use case before 🙂 Flush is  
used to make sure that your index data is persistently written into a store  
(and won't be lost if machine crashes). I am not sure that flush on memory  
based indices do...

2. All you need to do to make indexed data searchable it refresh (not  
flush). Although I see you call refresh on flush API as well, I would try  
only Refresh first.

I did some basic ES test implementation some time ago here  
[https://github.com/lukas-vlcek/elasticsearch.demo/blob/master/src/test/java/org/elasticsearch/demo/BasicTest.java](https://github.com/lukas-vlcek/elasticsearch.demo/blob/master/src/test/java/org/elasticsearch/demo/BasicTest.java)  
May be it can help you.

If the above will not help then I think you might want to share more code  
(how you get client and how you configure and start nodes).

Regards,  
Lukas

On Mon, Feb 6, 2012 at 10:51 AM, Runar Myklebust [runar@myklebust.me](mailto:runar@myklebust.me) wrote:

> Hi.
> 
> Ive created integration tests for the ES integration in our product. We  
> use version 0.18.6
> 
> For all tests, the flow is like this:
> 
> Index data -\> this.client.index( request ).actionGet();  
> Flush index -\> client.admin().indices().flush( Requests.flushRequest(  
> INDEX\_NAME ).refresh( true ) ).actionGet();  
> Query -\> this.client.search( req ).actionGet();
> 
> When running a lot of tests, usually one or two test fails with not  
> expected results from query, meaning that the query is executed before the  
> index is updated properly. When running all tests again, another test may  
> fail while to previous was successfull.  
> What can I do to enshure that the test will run properly each time? I  
> thought the flush-index would make shure that everything was flushed into  
> the index?
> 
> The settings for the test-environment is like this:
> 
> protected static final String NUMBER\_OF\_SHARDS = "5";
> 
> protected static final String NUMBER\_OF\_REPLICAS = "1";
> 
> ```
> public ImmutableSettings.Builder buildSettings()
> {
> ImmutableSettings.Builder settings =
> 
> ```
> 
> ImmutableSettings.settingsBuilder();  
> settings.loadFromSource( buildDistributionSettings() );  
> settings.loadFromSource( buildStorageSettings() );  
> [//settings.loadFromSource](https://settings.loadFromSource)( buildAnalyserSettings() );
> 
> ```
> return settings;
> }
> 
> private String buildStorageSettings()
> {
> try
> {
> return jsonBuilder().startObject().startObject( "store"
> 
> ```
> 
> ).field( "type", "memory" ).endObject().endObject().string();  
> }  
> catch ( IOException e )  
> {  
> throw new ContentIndexException( "Not able to create settings  
> for index", e );  
> }  
> }
> 
> ```
> private String buildDistributionSettings()
> {
> try
> {
> return jsonBuilder().startObject()
> .field( "number_of_shards", NUMBER_OF_SHARDS )
> .field( "number_of_replicas", NUMBER_OF_REPLICAS )
> .endObject()
> .string();
> }
> catch ( IOException e )
> {
> throw new ContentIndexException( "Not able to create settings
> 
> ```
> 
> for index", e );  
> }  
> }
> 
> ## mvh
> 
> Runar Myklebust

---

<div class="post-metadata">

**Author:** ![louis\_gueye](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/louis_gueye/32/2772_2.png) [@louis\_gueye](https://discuss.elastic.co/u/louis_gueye)\
**Post date:** [February 6, 2012, 5:07pm UTC](https://discuss.elastic.co/t/integration-tests-and-consistency/6602/3 "2012-02-06T17:07:02Z")

</div>

Hi Runar,

You should take a look at this class  
[https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/AbstractNodesTests.java](https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/AbstractNodesTests.java)

It will give you some hints on how to correctly isolate nodes and clients  
you create.  
It's important because you don't want a node to join your cluster without  
knowing it.

Hope, this helps,

--  
Cordialement/Regards,

Louis GUEYE  
linkedin [http://fr.linkedin.com/in/louisgueye](http://fr.linkedin.com/in/louisgueye) |  
blog[http://deepintojee.wordpress.com/](http://deepintojee.wordpress.com/)  
| twitter [http://twitter.com/#!/lgueye](http://twitter.com/#%21/lgueye)

2012/2/6 Lukáš Vlček [lukas.vlcek@gmail.com](mailto:lukas.vlcek@gmail.com)

> Hi,
> 
> Not sure what is the problem here but there are some things that hit me:
> 
> 1. You use memory index and flush flushes the index into its store (which  
> in this case is memory). Have never seen this use case before 🙂 Flush is  
> used to make sure that your index data is persistently written into a store  
> (and won't be lost if machine crashes). I am not sure that flush on memory  
> based indices do...
> 
> 2. All you need to do to make indexed data searchable it refresh (not  
> flush). Although I see you call refresh on flush API as well, I would try  
> only Refresh first.
> 
> I did some basic ES test implementation some time ago here  
> [https://github.com/lukas-vlcek/elasticsearch.demo/blob/master/src/test/java/org/elasticsearch/demo/BasicTest.java](https://github.com/lukas-vlcek/elasticsearch.demo/blob/master/src/test/java/org/elasticsearch/demo/BasicTest.java)  
> May be it can help you.
> 
> If the above will not help then I think you might want to share more code  
> (how you get client and how you configure and start nodes).
> 
> Regards,  
> Lukas

---

<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:** [February 7, 2012, 10:11am UTC](https://discuss.elastic.co/t/integration-tests-and-consistency/6602/4 "2012-02-07T10:11:42Z")

</div>

As was suggested, there isn't a need to flush in order to refresh the index, just a refresh will do. Can you try and run your tests with the default store type or ram type and see if it makes a difference?

On Monday, February 6, 2012 at 7:07 PM, louis gueye wrote:

> Hi Runar,
> 
> You should take a look at this class [https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/AbstractNodesTests.java](https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/AbstractNodesTests.java)
> 
> It will give you some hints on how to correctly isolate nodes and clients you create.  
> It's important because you don't want a node to join your cluster without knowing it.
> 
> Hope, this helps,
> 
> -- Cordialement/Regards,
> 
> Louis GUEYE  
> linkedin ([http://fr.linkedin.com/in/louisgueye](http://fr.linkedin.com/in/louisgueye)) | blog ([http://deepintojee.wordpress.com/](http://deepintojee.wordpress.com/)) | twitter ([http://twitter.com/#!/lgueye](http://twitter.com/#%21/lgueye))
> 
> 2012/2/6 Lukáš Vlček \<[lukas.vlcek@gmail.com](mailto:lukas.vlcek@gmail.com) ([mailto:lukas.vlcek@gmail.com](mailto:lukas.vlcek@gmail.com))\>
> 
> > Hi,
> > 
> > Not sure what is the problem here but there are some things that hit me:
> > 
> > 1. You use memory index and flush flushes the index into its store (which in this case is memory). Have never seen this use case before 🙂 Flush is used to make sure that your index data is persistently written into a store (and won't be lost if machine crashes). I am not sure that flush on memory based indices do...
> > 
> > 2. All you need to do to make indexed data searchable it refresh (not flush). Although I see you call refresh on flush API as well, I would try only Refresh first.
> > 
> > I did some basic ES test implementation some time ago here [https://github.com/lukas-vlcek/elasticsearch.demo/blob/master/src/test/java/org/elasticsearch/demo/BasicTest.java](https://github.com/lukas-vlcek/elasticsearch.demo/blob/master/src/test/java/org/elasticsearch/demo/BasicTest.java)  
> > May be it can help you.
> > 
> > If the above will not help then I think you might want to share more code (how you get client and how you configure and start nodes).
> > 
> > Regards,  
> > Lukas

---

<div class="post-metadata">

**Author:** ![Runar\_Myklebust\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/runar_myklebust_2/32/2047_2.png) [@Runar\_Myklebust\_2](https://discuss.elastic.co/u/Runar_Myklebust_2)\
**Post date:** [February 7, 2012, 12:58pm UTC](https://discuss.elastic.co/t/integration-tests-and-consistency/6602/5 "2012-02-07T12:58:48Z")

</div>

Hi, thanks a lot. The "gateway.type", "none" - setting did the trick.

On Mon, Feb 6, 2012 at 6:07 PM, louis gueye [louis.gueye@gmail.com](mailto:louis.gueye@gmail.com) wrote:

> Hi Runar,
> 
> You should take a look at this class  
> [https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/AbstractNodesTests.java](https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/AbstractNodesTests.java)
> 
> It will give you some hints on how to correctly isolate nodes and clients  
> you create.  
> It's important because you don't want a node to join your cluster without  
> knowing it.
> 
> Hope, this helps,
> 
> --  
> Cordialement/Regards,
> 
> Louis GUEYE  
> linkedin [http://fr.linkedin.com/in/louisgueye](http://fr.linkedin.com/in/louisgueye) | blog[http://deepintojee.wordpress.com/](http://deepintojee.wordpress.com/)  
> | twitter [http://twitter.com/#!/lgueye](http://twitter.com/#%21/lgueye)
> 
> 2012/2/6 Lukáš Vlček [lukas.vlcek@gmail.com](mailto:lukas.vlcek@gmail.com)
> 
> > Hi,
> > 
> > Not sure what is the problem here but there are some things that hit me:
> > 
> > 1. You use memory index and flush flushes the index into its store (which  
> > in this case is memory). Have never seen this use case before 🙂 Flush is  
> > used to make sure that your index data is persistently written into a store  
> > (and won't be lost if machine crashes). I am not sure that flush on memory  
> > based indices do...
> > 
> > 2. All you need to do to make indexed data searchable it refresh (not  
> > flush). Although I see you call refresh on flush API as well, I would try  
> > only Refresh first.
> > 
> > I did some basic ES test implementation some time ago here  
> > [https://github.com/lukas-vlcek/elasticsearch.demo/blob/master/src/test/java/org/elasticsearch/demo/BasicTest.java](https://github.com/lukas-vlcek/elasticsearch.demo/blob/master/src/test/java/org/elasticsearch/demo/BasicTest.java)  
> > May be it can help you.
> > 
> > If the above will not help then I think you might want to share more code  
> > (how you get client and how you configure and start nodes).
> > 
> > Regards,  
> > Lukas

## -- mvh

Runar Myklebust

---

<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, 3:40am UTC](https://discuss.elastic.co/t/integration-tests-and-consistency/6602/6 "2017-07-06T03:40:16Z")

</div>


