From 7cd3b8301bb5b97d58e8f3cda1607d684f379dcb Mon Sep 17 00:00:00 2001 From: jaymode Date: Thu, 3 Nov 2016 14:55:05 -0400 Subject: [PATCH] test: stop audit trails, increase logging and time to wait for it to start See elastic/elasticsearch#3979 Original commit: elastic/x-pack-elasticsearch@79d559cb8f351a90e7fa8fab868abd0c50e62dc2 --- .../RemoteIndexAuditTrailStartingTests.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/index/RemoteIndexAuditTrailStartingTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/index/RemoteIndexAuditTrailStartingTests.java index 17397385eb1..0e38a32cc69 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/index/RemoteIndexAuditTrailStartingTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/index/RemoteIndexAuditTrailStartingTests.java @@ -14,6 +14,7 @@ import org.elasticsearch.test.ESIntegTestCase.Scope; import org.elasticsearch.test.InternalTestCluster; import org.elasticsearch.test.SecurityIntegTestCase; import org.elasticsearch.test.SecuritySettingsSource; +import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.xpack.security.audit.AuditTrail; import org.elasticsearch.xpack.security.audit.AuditTrailService; import org.junit.After; @@ -26,9 +27,9 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; -import java.util.concurrent.TimeUnit; import static org.elasticsearch.test.InternalTestCluster.clusterName; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout; import static org.hamcrest.Matchers.is; /** @@ -38,6 +39,7 @@ import static org.hamcrest.Matchers.is; * The cluster started by the integrations tests may also index into itself... */ @ClusterScope(scope = Scope.TEST) +@TestLogging("org.elasticsearch.xpack.security.audit.index:TRACE") public class RemoteIndexAuditTrailStartingTests extends SecurityIntegTestCase { public static final String SECOND_CLUSTER_NODE_PREFIX = "remote_" + TEST_CLUSTER_NODE_PREFIX; @@ -112,15 +114,15 @@ public class RemoteIndexAuditTrailStartingTests extends SecurityIntegTestCase { numNodes, numNodes, cluster2Name, cluster2SettingsSource, 0, false, SECOND_CLUSTER_NODE_PREFIX, getMockPlugins(), getClientWrapper()); remoteCluster.beforeTest(random(), 0.5); + assertNoTimeout(remoteCluster.client().admin().cluster().prepareHealth().setWaitForGreenStatus().get()); } @After public void stopRemoteCluster() throws Exception { if (remoteCluster != null) { - /*Iterable auditTrails = internalCluster().getInstances(IndexAuditTrail.class); - for (IndexAuditTrail auditTrail : auditTrails) { - auditTrail.close(); - }*/ + remoteCluster.getInstance(AuditTrailService.class).getAuditTrails().stream() + .filter(t -> t.name().equals(IndexAuditTrail.NAME)) + .forEach((auditTrail) -> ((IndexAuditTrail) auditTrail).stop()); try { remoteCluster.wipe(Collections.emptySet()); @@ -131,12 +133,9 @@ public class RemoteIndexAuditTrailStartingTests extends SecurityIntegTestCase { } // stop the index audit trail so that the shards aren't locked causing the test to fail - /*if (outputs.contains("index")) { - Iterable auditTrails = internalCluster().getInstances(IndexAuditTrail.class); - for (IndexAuditTrail auditTrail : auditTrails) { - auditTrail.close(); - } - }*/ + internalCluster().getInstance(AuditTrailService.class).getAuditTrails().stream() + .filter(t -> t.name().equals(IndexAuditTrail.NAME)) + .forEach((auditTrail) -> ((IndexAuditTrail) auditTrail).stop()); } public void testThatRemoteAuditInstancesAreStarted() throws Exception { @@ -146,7 +145,7 @@ public class RemoteIndexAuditTrailStartingTests extends SecurityIntegTestCase { assertTrue(auditTrail.isPresent()); IndexAuditTrail indexAuditTrail = (IndexAuditTrail)auditTrail.get(); - awaitBusy(() -> indexAuditTrail.state() == IndexAuditTrail.State.STARTED, 2L, TimeUnit.SECONDS); + awaitBusy(() -> indexAuditTrail.state() == IndexAuditTrail.State.STARTED); assertThat(indexAuditTrail.state(), is(IndexAuditTrail.State.STARTED)); } }