test: add logging to randomly failing IndexAuditIT

Original commit: elastic/x-pack-elasticsearch@3abd1ec0b5
This commit is contained in:
jaymode 2016-05-31 12:21:17 -04:00
parent d5d8d13aad
commit fbeda210ae
1 changed files with 25 additions and 10 deletions

View File

@ -9,6 +9,7 @@ import com.carrotsearch.hppc.cursors.ObjectCursor;
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse;
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.query.QueryBuilders;
@ -24,6 +25,8 @@ import org.elasticsearch.xpack.XPackPlugin;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
@ -33,29 +36,41 @@ public class IndexAuditIT extends ESIntegTestCase {
private static final String PASS = "changeme";
public void testShieldIndexAuditTrailWorking() throws Exception {
HttpResponse response = httpClient().path("/_cluster/health")
HttpResponse response = httpClient().path("/")
.addHeader("Authorization", UsernamePasswordToken.basicAuthHeaderValue(USER, new SecuredString(PASS.toCharArray())))
.execute();
assertThat(response.getStatusCode(), is(200));
final AtomicReference<ClusterState> lastClusterState = new AtomicReference<>();
final AtomicBoolean indexExists = new AtomicBoolean(false);
boolean found = awaitBusy(() -> {
boolean exists = false;
for (ObjectCursor<String> cursor :
client().admin().cluster().prepareState().get().getState().getMetaData().getIndices().keys()) {
if (cursor.value.startsWith(".shield_audit_log")) {
exists = true;
break;
if (indexExists.get() == false) {
ClusterState state = client().admin().cluster().prepareState().get().getState();
lastClusterState.set(state);
for (ObjectCursor<String> cursor : state.getMetaData().getIndices().keys()) {
if (cursor.value.startsWith(".shield_audit_log")) {
logger.info("found audit index [{}]", cursor.value);
indexExists.set(true);
break;
}
}
if (indexExists.get() == false) {
return false;
}
}
if (exists == false) {
return false;
}
ensureYellow(".shield_audit_log*");
ClusterState state = client().admin().cluster().prepareState().get().getState();
lastClusterState.set(state);
client().admin().indices().prepareRefresh().get();
return client().prepareSearch(".shield_audit_log*").setQuery(QueryBuilders.matchQuery("principal", USER))
.get().getHits().totalHits() > 0;
}, 10L, TimeUnit.SECONDS);
if (!found) {
logger.info("current cluster state: {}", lastClusterState.get());
}
assertThat(found, is(true));
SearchResponse searchResponse = client().prepareSearch(".shield_audit_log*").setQuery(