elasticsearch/elasticsearch — pull request #9015 by javanna (2014-12-19 15:15:55+00:00)
Title: [TEST] Make sure we restart the global cluster after each test failure

`CurrentTestFailedMarker` is a `RunListener` that gets notified whenever a test fails, and we were using it to be able to restart the global cluster after each failure. We were checking whether a test had failed in the `@After` method though, which runs before the listener gets notified, so the failed flag would always be false.

This PR makes sure that the global cluster gets restarted not only when there are problems in the `afterInternal` method, but also after each test failure. In order to achieve this, we need to reset the cluster afterwards, when we get to know about both of the events (problem in afterInternal and test failure), and before resetting the `currentCluster`. Introduced a `TestRule` that keeps track of test failures and allows to execute arbitrary tasks when a test fails and when a test is completed (regardless of its result). Allows also to force the execution of the failure task (used in case of `afterInternal` issues rather than actual test failure).

Also updated `ElasticsearchRestTests` to make sure that the `RestClient` gets re-initialized in case we restart the global cluster, otherwise all the subsequent tests fail. Improved this mechanism also to relate it directly to the restart of the cluster instead of checking whether the addresses have changed, which doesn't work anyway as the new cluster will use the same addresses but the client needs to be recreated anyway.