From c6d52cd949257b54d6dff4e85b54ae5d67a0902e Mon Sep 17 00:00:00 2001 From: David Roberts Date: Mon, 21 Nov 2016 15:49:26 +0000 Subject: [PATCH] Fix a knock-on effect of removing JobLogs Original commit: elastic/x-pack-elasticsearch@501fcda0455c55d10c99729b7c3dc77aeb2ed38f --- .../job/persistence/ElasticsearchJobProviderTests.java | 9 ++++++--- .../xpack/prelert/job/persistence/MockClientBuilder.java | 5 +++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchJobProviderTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchJobProviderTests.java index d417fcabc89..328b99d43a0 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchJobProviderTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchJobProviderTests.java @@ -17,6 +17,7 @@ import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHitField; import org.elasticsearch.search.SearchHits; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.prelert.action.DeleteJobAction; import org.elasticsearch.xpack.prelert.job.AnalysisLimits; import org.elasticsearch.xpack.prelert.job.CategorizerState; import org.elasticsearch.xpack.prelert.job.Job; @@ -163,7 +164,7 @@ public class ElasticsearchJobProviderTests extends ESTestCase { public void testDeleteJob() throws InterruptedException, ExecutionException, IOException { @SuppressWarnings("unchecked") - ActionListener actionListener = mock(ActionListener.class); + ActionListener actionListener = mock(ActionListener.class); String jobId = "ThisIsMyJob"; MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse() .addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true); @@ -176,12 +177,14 @@ public class ElasticsearchJobProviderTests extends ESTestCase { provider.deleteJobRelatedIndices(jobId, actionListener); - verify(actionListener).onResponse(true); + ArgumentCaptor responseCaptor = ArgumentCaptor.forClass(DeleteJobAction.Response.class); + verify(actionListener).onResponse(responseCaptor.capture()); + assertTrue(responseCaptor.getValue().isAcknowledged()); } public void testDeleteJob_InvalidIndex() throws InterruptedException, ExecutionException, IOException { @SuppressWarnings("unchecked") - ActionListener actionListener = mock(ActionListener.class); + ActionListener actionListener = mock(ActionListener.class); String jobId = "ThisIsMyJob"; MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse() .addIndicesExistsResponse(ElasticsearchJobProvider.PRELERT_USAGE_INDEX, true); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/MockClientBuilder.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/MockClientBuilder.java index de9f3b024e0..d1c2f47fe8c 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/MockClientBuilder.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/MockClientBuilder.java @@ -58,6 +58,7 @@ import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.script.Script; import org.elasticsearch.search.sort.SortBuilder; import org.elasticsearch.search.sort.SortOrder; +import org.elasticsearch.xpack.prelert.action.DeleteJobAction; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatcher; import org.mockito.Mock; @@ -161,7 +162,7 @@ public class MockClientBuilder { @SuppressWarnings({ "unchecked" }) public MockClientBuilder addIndicesDeleteResponse(String index, boolean exists, boolean exception, - ActionListener actionListener) throws InterruptedException, ExecutionException, IOException { + ActionListener actionListener) throws InterruptedException, ExecutionException, IOException { DeleteIndexResponse response = DeleteIndexAction.INSTANCE.newResponse(); StreamInput si = mock(StreamInput.class); when(si.readByte()).thenReturn((byte) 0x41); @@ -174,7 +175,7 @@ public class MockClientBuilder { if (exception) { actionListener.onFailure(new InterruptedException()); } else { - actionListener.onResponse(true); + actionListener.onResponse(new DeleteJobAction.Response(true)); } return null; }).when(indicesAdminClient).delete(any(DeleteIndexRequest.class), any(ActionListener.class));