# Discard changes to ElasticSearch after every test case

**URL:** <https://discuss.elastic.co/t/discard-changes-to-elasticsearch-after-every-test-case/13278>\
**Category:** Elasticsearch\
**Created:** [August 21, 2013, 6:06am UTC](https://discuss.elastic.co/t/discard-changes-to-elasticsearch-after-every-test-case/13278 "2013-08-21T06:06:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![garnaes](https://avatars.discourse-cdn.com/v4/letter/g/ea5d25/32.png) [@garnaes](https://discuss.elastic.co/u/garnaes)\
**Post date:** [August 21, 2013, 6:06am UTC](https://discuss.elastic.co/t/discard-changes-to-elasticsearch-after-every-test-case/13278/1 "2013-08-21T06:06:39Z")

</div>

I have a test suite, which assumes a certain fixture dataset is loaded into  
MySQL and ElasticSearch prior to running. Loading this data is only done  
when the fixture data changes, which is quite infrequent. When running the  
tests, changes to MySQL are rolled back using transactions. Changes to ES,  
I currently don't have a good way to handle, as I can't simply clear out  
the test index after every test case. Instead the tests need to take this  
into account.

Is there a clever way to discard changes made to ES during a test case? I  
have this (possibly terrible) idea of disabling translog flushing and then  
somehow making ES drop the translog afterwards, but I have no idea whether  
that's feasible at all.

TIA,  
Andreas

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![daniel\_koller](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_koller/32/2149_2.png) [@daniel\_koller](https://discuss.elastic.co/u/daniel_koller)\
**Post date:** [August 21, 2013, 6:29am UTC](https://discuss.elastic.co/t/discard-changes-to-elasticsearch-after-every-test-case/13278/2 "2013-08-21T06:29:36Z")

</div>

Hi Andreas,

since loading something into elasticsearch is really fast, we load our test  
from the DB into ES just before we start our test suite (in the  
@BeforeClass of the parent class of our ES tests). We do this only if the  
indices are not present in ES.  
We have a special jUnit test suite so we could do this also in the suite  
and tear down after all tests run.

Of course we try to minimize the data which is needed for our tests. So, to  
initialization before our 3000 test takes about 20s (but this is because  
the DB is the bottle neck).

Best regards,  
Daniel

Am Mittwoch, 21. August 2013 08:06:39 UTC+2 schrieb Andreas Garnæs:

> I have a test suite, which assumes a certain fixture dataset is loaded  
> into MySQL and Elasticsearch prior to running. Loading this data is only  
> done when the fixture data changes, which is quite infrequent. When running  
> the tests, changes to MySQL are rolled back using transactions. Changes to  
> ES, I currently don't have a good way to handle, as I can't simply clear  
> out the test index after every test case. Instead the tests need to take  
> this into account.
> 
> Is there a clever way to discard changes made to ES during a test case? I  
> have this (possibly terrible) idea of disabling translog flushing and then  
> somehow making ES drop the translog afterwards, but I have no idea whether  
> that's feasible at all.
> 
> TIA,  
> Andreas

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![garnaes](https://avatars.discourse-cdn.com/v4/letter/g/ea5d25/32.png) [@garnaes](https://discuss.elastic.co/u/garnaes)\
**Post date:** [August 21, 2013, 6:35am UTC](https://discuss.elastic.co/t/discard-changes-to-elasticsearch-after-every-test-case/13278/3 "2013-08-21T06:35:38Z")

</div>

Hi Daniel,

Thanks for your reply.

How do you make sure your test cases are independent? If two test cases  
both modify ES they could step on each others toes unless the changes are  
"rolled back".

Thanks,  
Andreas

On Wednesday, 21 August 2013 08:29:36 UTC+2, daniel koller wrote:

> Hi Andreas,
> 
> since loading something into elasticsearch is really fast, we load our  
> test from the DB into ES just before we start our test suite (in the  
> @BeforeClass of the parent class of our ES tests). We do this only if the  
> indices are not present in ES.  
> We have a special jUnit test suite so we could do this also in the suite  
> and tear down after all tests run.
> 
> Of course we try to minimize the data which is needed for our tests. So,  
> to initialization before our 3000 test takes about 20s (but this is because  
> the DB is the bottle neck).
> 
> Best regards,  
> Daniel
> 
> Am Mittwoch, 21. August 2013 08:06:39 UTC+2 schrieb Andreas Garnæs:
> 
> > I have a test suite, which assumes a certain fixture dataset is loaded  
> > into MySQL and Elasticsearch prior to running. Loading this data is only  
> > done when the fixture data changes, which is quite infrequent. When running  
> > the tests, changes to MySQL are rolled back using transactions. Changes to  
> > ES, I currently don't have a good way to handle, as I can't simply clear  
> > out the test index after every test case. Instead the tests need to take  
> > this into account.
> > 
> > Is there a clever way to discard changes made to ES during a test case? I  
> > have this (possibly terrible) idea of disabling translog flushing and then  
> > somehow making ES drop the translog afterwards, but I have no idea whether  
> > that's feasible at all.
> > 
> > TIA,  
> > Andreas

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![daniel\_koller](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_koller/32/2149_2.png) [@daniel\_koller](https://discuss.elastic.co/u/daniel_koller)\
**Post date:** [August 21, 2013, 6:49am UTC](https://discuss.elastic.co/t/discard-changes-to-elasticsearch-after-every-test-case/13278/4 "2013-08-21T06:49:27Z")

</div>

Hi Andreas,

A) we have some tests which use the global test-fixture (data loaded at the  
start of the suite)  
B) we have some tests which use the same test-fixture for all test methods  
of a class (data loaded in the @BeforeClass method and reset in the  
@AfterClass method), they use other index names then used in the global  
fixture  
C) we have some tests which need a fresh fixture for every method (data  
loaded in the @Before and reset in the @After method), again other indicies  
names then A) and B)

All tests of a category A, B, or C share a parent class which delivers a  
prefix for the index name for there subclasses, so we never get a conflict  
between them.

Best regards,  
Daniel

Am Mittwoch, 21. August 2013 08:35:38 UTC+2 schrieb Andreas Garnæs:

> Hi Daniel,
> 
> Thanks for your reply.
> 
> How do you make sure your test cases are independent? If two test cases  
> both modify ES they could step on each others toes unless the changes are  
> "rolled back".
> 
> Thanks,  
> Andreas
> 
> On Wednesday, 21 August 2013 08:29:36 UTC+2, daniel koller wrote:
> 
> > Hi Andreas,
> > 
> > since loading something into elasticsearch is really fast, we load our  
> > test from the DB into ES just before we start our test suite (in the  
> > @BeforeClass of the parent class of our ES tests). We do this only if the  
> > indices are not present in ES.  
> > We have a special jUnit test suite so we could do this also in the suite  
> > and tear down after all tests run.
> > 
> > Of course we try to minimize the data which is needed for our tests. So,  
> > to initialization before our 3000 test takes about 20s (but this is because  
> > the DB is the bottle neck).
> > 
> > Best regards,  
> > Daniel
> > 
> > Am Mittwoch, 21. August 2013 08:06:39 UTC+2 schrieb Andreas Garnæs:
> > 
> > > I have a test suite, which assumes a certain fixture dataset is loaded  
> > > into MySQL and Elasticsearch prior to running. Loading this data is only  
> > > done when the fixture data changes, which is quite infrequent. When running  
> > > the tests, changes to MySQL are rolled back using transactions. Changes to  
> > > ES, I currently don't have a good way to handle, as I can't simply clear  
> > > out the test index after every test case. Instead the tests need to take  
> > > this into account.
> > > 
> > > Is there a clever way to discard changes made to ES during a test case?  
> > > I have this (possibly terrible) idea of disabling translog flushing and  
> > > then somehow making ES drop the translog afterwards, but I have no idea  
> > > whether that's feasible at all.
> > > 
> > > TIA,  
> > > Andreas

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [August 21, 2013, 7:05am UTC](https://discuss.elastic.co/t/discard-changes-to-elasticsearch-after-every-test-case/13278/5 "2013-08-21T07:05:18Z")

</div>

In the JDBC river, I have an extensive set of in-memory RDBMS test cases.  
The cases are organized by testng annotations. To discard changes, I simply  
shutdown ES after each test. If you set the gateway to none, the index is  
gone.

> **[GitHub - jprante/elasticsearch-jdbc: JDBC importer for Elasticsearch](https://github.com/jprante/elasticsearch-jdbc)**
>
> JDBC importer for Elasticsearch. Contribute to jprante/elasticsearch-jdbc development by creating an account on GitHub.

If you want to test a chain of situations, depending on data already  
indexed, I would suggest using a test suite.

Jörg

On Wed, Aug 21, 2013 at 8:06 AM, Andreas Garnæs [garnaes@hoisthq.com](mailto:garnaes@hoisthq.com) wrote:

> I have a test suite, which assumes a certain fixture dataset is loaded  
> into MySQL and Elasticsearch prior to running. Loading this data is only  
> done when the fixture data changes, which is quite infrequent. When running  
> the tests, changes to MySQL are rolled back using transactions. Changes to  
> ES, I currently don't have a good way to handle, as I can't simply clear  
> out the test index after every test case. Instead the tests need to take  
> this into account.
> 
> Is there a clever way to discard changes made to ES during a test case? I  
> have this (possibly terrible) idea of disabling translog flushing and then  
> somehow making ES drop the translog afterwards, but I have no idea whether  
> that's feasible at all.
> 
> TIA,  
> Andreas
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![garnaes](https://avatars.discourse-cdn.com/v4/letter/g/ea5d25/32.png) [@garnaes](https://discuss.elastic.co/u/garnaes)\
**Post date:** [August 21, 2013, 10:03am UTC](https://discuss.elastic.co/t/discard-changes-to-elasticsearch-after-every-test-case/13278/6 "2013-08-21T10:03:39Z")

</div>

Thanks for elaborating. Does B) and C) mean that you "manually undo" the  
changes made in the test case(s) in @AfterClass/@After?

On Wednesday, 21 August 2013 08:49:27 UTC+2, daniel koller wrote:

> Hi Andreas,
> 
> A) we have some tests which use the global test-fixture (data loaded at  
> the start of the suite)  
> B) we have some tests which use the same test-fixture for all test methods  
> of a class (data loaded in the @BeforeClass method and reset in the  
> @AfterClass method), they use other index names then used in the global  
> fixture  
> C) we have some tests which need a fresh fixture for every method (data  
> loaded in the @Before and reset in the @After method), again other indicies  
> names then A) and B)
> 
> All tests of a category A, B, or C share a parent class which delivers a  
> prefix for the index name for there subclasses, so we never get a conflict  
> between them.
> 
> Best regards,  
> Daniel
> 
> Am Mittwoch, 21. August 2013 08:35:38 UTC+2 schrieb Andreas Garnæs:
> 
> > Hi Daniel,
> > 
> > Thanks for your reply.
> > 
> > How do you make sure your test cases are independent? If two test cases  
> > both modify ES they could step on each others toes unless the changes are  
> > "rolled back".
> > 
> > Thanks,  
> > Andreas
> > 
> > On Wednesday, 21 August 2013 08:29:36 UTC+2, daniel koller wrote:
> > 
> > > Hi Andreas,
> > > 
> > > since loading something into elasticsearch is really fast, we load our  
> > > test from the DB into ES just before we start our test suite (in the  
> > > @BeforeClass of the parent class of our ES tests). We do this only if the  
> > > indices are not present in ES.  
> > > We have a special jUnit test suite so we could do this also in the suite  
> > > and tear down after all tests run.
> > > 
> > > Of course we try to minimize the data which is needed for our tests. So,  
> > > to initialization before our 3000 test takes about 20s (but this is because  
> > > the DB is the bottle neck).
> > > 
> > > Best regards,  
> > > Daniel
> > > 
> > > Am Mittwoch, 21. August 2013 08:06:39 UTC+2 schrieb Andreas Garnæs:
> > > 
> > > > I have a test suite, which assumes a certain fixture dataset is loaded  
> > > > into MySQL and Elasticsearch prior to running. Loading this data is only  
> > > > done when the fixture data changes, which is quite infrequent. When running  
> > > > the tests, changes to MySQL are rolled back using transactions. Changes to  
> > > > ES, I currently don't have a good way to handle, as I can't simply clear  
> > > > out the test index after every test case. Instead the tests need to take  
> > > > this into account.
> > > > 
> > > > Is there a clever way to discard changes made to ES during a test case?  
> > > > I have this (possibly terrible) idea of disabling translog flushing and  
> > > > then somehow making ES drop the translog afterwards, but I have no idea  
> > > > whether that's feasible at all.
> > > > 
> > > > TIA,  
> > > > Andreas

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![daniel\_koller](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_koller/32/2149_2.png) [@daniel\_koller](https://discuss.elastic.co/u/daniel_koller)\
**Post date:** [August 21, 2013, 10:50am UTC](https://discuss.elastic.co/t/discard-changes-to-elasticsearch-after-every-test-case/13278/7 "2013-08-21T10:50:53Z")

</div>

HI Andreas,

yes, since the super classes provide the @Before(Class) and @After(Class),  
they know which indices they have created and can delete them.  
Depending on the number of test and the execution speed you need you might  
choose a A, B or C fixture for your tests.

Best regards,  
Daniel

Am Mittwoch, 21. August 2013 12:03:39 UTC+2 schrieb Andreas Garnæs:

> Thanks for elaborating. Does B) and C) mean that you "manually undo" the  
> changes made in the test case(s) in @AfterClass/@After?
> 
> On Wednesday, 21 August 2013 08:49:27 UTC+2, daniel koller wrote:
> 
> > Hi Andreas,
> > 
> > A) we have some tests which use the global test-fixture (data loaded at  
> > the start of the suite)  
> > B) we have some tests which use the same test-fixture for all test  
> > methods of a class (data loaded in the @BeforeClass method and reset in the  
> > @AfterClass method), they use other index names then used in the global  
> > fixture  
> > C) we have some tests which need a fresh fixture for every method (data  
> > loaded in the @Before and reset in the @After method), again other indicies  
> > names then A) and B)
> > 
> > All tests of a category A, B, or C share a parent class which delivers a  
> > prefix for the index name for there subclasses, so we never get a conflict  
> > between them.
> > 
> > Best regards,  
> > Daniel
> > 
> > Am Mittwoch, 21. August 2013 08:35:38 UTC+2 schrieb Andreas Garnæs:
> > 
> > > Hi Daniel,
> > > 
> > > Thanks for your reply.
> > > 
> > > How do you make sure your test cases are independent? If two test cases  
> > > both modify ES they could step on each others toes unless the changes are  
> > > "rolled back".
> > > 
> > > Thanks,  
> > > Andreas
> > > 
> > > On Wednesday, 21 August 2013 08:29:36 UTC+2, daniel koller wrote:
> > > 
> > > > Hi Andreas,
> > > > 
> > > > since loading something into elasticsearch is really fast, we load our  
> > > > test from the DB into ES just before we start our test suite (in the  
> > > > @BeforeClass of the parent class of our ES tests). We do this only if the  
> > > > indices are not present in ES.  
> > > > We have a special jUnit test suite so we could do this also in the  
> > > > suite and tear down after all tests run.
> > > > 
> > > > Of course we try to minimize the data which is needed for our tests.  
> > > > So, to initialization before our 3000 test takes about 20s (but this is  
> > > > because the DB is the bottle neck).
> > > > 
> > > > Best regards,  
> > > > Daniel
> > > > 
> > > > Am Mittwoch, 21. August 2013 08:06:39 UTC+2 schrieb Andreas Garnæs:
> > > > 
> > > > > I have a test suite, which assumes a certain fixture dataset is loaded  
> > > > > into MySQL and Elasticsearch prior to running. Loading this data is only  
> > > > > done when the fixture data changes, which is quite infrequent. When running  
> > > > > the tests, changes to MySQL are rolled back using transactions. Changes to  
> > > > > ES, I currently don't have a good way to handle, as I can't simply clear  
> > > > > out the test index after every test case. Instead the tests need to take  
> > > > > this into account.
> > > > > 
> > > > > Is there a clever way to discard changes made to ES during a test  
> > > > > case? I have this (possibly terrible) idea of disabling translog flushing  
> > > > > and then somehow making ES drop the translog afterwards, but I have no idea  
> > > > > whether that's feasible at all.
> > > > > 
> > > > > TIA,  
> > > > > Andreas

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:20am UTC](https://discuss.elastic.co/t/discard-changes-to-elasticsearch-after-every-test-case/13278/8 "2017-07-06T02:20:22Z")

</div>


