From f832a251e608836f4c8175ef0af555eee16ec4bc Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Tue, 17 Sep 2019 10:53:18 +0200 Subject: [PATCH 1/5] Allow dropping documents with auto-generated ID --- .../action/DocWriteResponse.java | 9 ++++---- .../action/bulk/TransportBulkAction.java | 3 ++- .../elasticsearch/ingest/IngestClientIT.java | 21 +++++++++++++++++++ .../ingest/IngestTestPlugin.java | 4 ++++ .../elasticsearch/ingest/TestProcessor.java | 15 +++++++++---- .../test/InternalTestCluster.java | 1 + 6 files changed, 44 insertions(+), 9 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/DocWriteResponse.java b/server/src/main/java/org/elasticsearch/action/DocWriteResponse.java index 55b80e58514bc..50036f95d16b7 100644 --- a/server/src/main/java/org/elasticsearch/action/DocWriteResponse.java +++ b/server/src/main/java/org/elasticsearch/action/DocWriteResponse.java @@ -40,6 +40,7 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Locale; +import java.util.Objects; import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken; import static org.elasticsearch.index.seqno.SequenceNumbers.UNASSIGNED_PRIMARY_TERM; @@ -121,13 +122,13 @@ public void writeTo(StreamOutput out) throws IOException { protected final Result result; public DocWriteResponse(ShardId shardId, String type, String id, long seqNo, long primaryTerm, long version, Result result) { - this.shardId = shardId; - this.type = type; - this.id = id; + this.shardId = Objects.requireNonNull(shardId); + this.type = Objects.requireNonNull(type); + this.id = Objects.requireNonNull(id); this.seqNo = seqNo; this.primaryTerm = primaryTerm; this.version = version; - this.result = result; + this.result = Objects.requireNonNull(result); } // needed for deserialization diff --git a/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java b/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java index a2f105df7e9b7..11b70b193cd15 100644 --- a/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java +++ b/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java @@ -672,11 +672,12 @@ ActionListener wrapActionListenerIfNeeded(long ingestTookInMillis, void markCurrentItemAsDropped() { IndexRequest indexRequest = getIndexWriteRequest(bulkRequest.requests().get(currentSlot)); failedSlots.set(currentSlot); + final String id = indexRequest.id() == null ? "auto-generated" : indexRequest.id(); itemResponses.add( new BulkItemResponse(currentSlot, indexRequest.opType(), new UpdateResponse( new ShardId(indexRequest.index(), IndexMetaData.INDEX_UUID_NA_VALUE, 0), - indexRequest.type(), indexRequest.id(), SequenceNumbers.UNASSIGNED_SEQ_NO, SequenceNumbers.UNASSIGNED_PRIMARY_TERM, + indexRequest.type(), id, SequenceNumbers.UNASSIGNED_SEQ_NO, SequenceNumbers.UNASSIGNED_PRIMARY_TERM, indexRequest.version(), DocWriteResponse.Result.NOOP ) ) diff --git a/server/src/test/java/org/elasticsearch/ingest/IngestClientIT.java b/server/src/test/java/org/elasticsearch/ingest/IngestClientIT.java index 6e5d862372ac6..2e3a23cd3be7e 100644 --- a/server/src/test/java/org/elasticsearch/ingest/IngestClientIT.java +++ b/server/src/test/java/org/elasticsearch/ingest/IngestClientIT.java @@ -272,4 +272,25 @@ public void testPutWithPipelineFactoryError() throws Exception { GetPipelineResponse response = client().admin().cluster().prepareGetPipeline("_id2").get(); assertFalse(response.isFound()); } + + public void testWithDedicatedMaster() throws Exception { + String masterOnlyNode = internalCluster().startMasterOnlyNode(); + BytesReference source = BytesReference.bytes(jsonBuilder().startObject() + .field("description", "my_pipeline") + .startArray("processors") + .startObject() + .startObject("test") + .endObject() + .endObject() + .endArray() + .endObject()); + PutPipelineRequest putPipelineRequest = new PutPipelineRequest("_id", source, XContentType.JSON); + client().admin().cluster().putPipeline(putPipelineRequest).get(); + + BulkItemResponse item = client(masterOnlyNode).prepareBulk().add( + client().prepareIndex("test", "type").setSource("field", "value2", "drop", true).setPipeline("_id")).get() + .getItems()[0]; + assertFalse(item.isFailed()); + assertEquals("auto-generated", item.getResponse().getId()); + } } diff --git a/test/framework/src/main/java/org/elasticsearch/ingest/IngestTestPlugin.java b/test/framework/src/main/java/org/elasticsearch/ingest/IngestTestPlugin.java index dd38a0707b4c4..1fe7edc745242 100644 --- a/test/framework/src/main/java/org/elasticsearch/ingest/IngestTestPlugin.java +++ b/test/framework/src/main/java/org/elasticsearch/ingest/IngestTestPlugin.java @@ -37,6 +37,10 @@ public Map getProcessors(Processor.Parameters paramet if (doc.hasField("fail") && doc.getFieldValue("fail", Boolean.class)) { throw new IllegalArgumentException("test processor failed"); } + if (doc.hasField("drop") && doc.getFieldValue("drop", Boolean.class)) { + return null; + } + return doc; })); } } diff --git a/test/framework/src/main/java/org/elasticsearch/ingest/TestProcessor.java b/test/framework/src/main/java/org/elasticsearch/ingest/TestProcessor.java index a1feb3e1f73be..19ffd69c5884b 100644 --- a/test/framework/src/main/java/org/elasticsearch/ingest/TestProcessor.java +++ b/test/framework/src/main/java/org/elasticsearch/ingest/TestProcessor.java @@ -22,6 +22,7 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; +import java.util.function.Function; /** * Processor used for testing, keeps track of how many times it is invoked and @@ -31,7 +32,7 @@ public class TestProcessor implements Processor { private final String type; private final String tag; - private final Consumer ingestDocumentConsumer; + private final Function ingestDocumentMapper; private final AtomicInteger invokedCounter = new AtomicInteger(); public TestProcessor(Consumer ingestDocumentConsumer) { @@ -39,7 +40,14 @@ public TestProcessor(Consumer ingestDocumentConsumer) { } public TestProcessor(String tag, String type, Consumer ingestDocumentConsumer) { - this.ingestDocumentConsumer = ingestDocumentConsumer; + this(tag, type, id -> { + ingestDocumentConsumer.accept(id); + return id; + }); + } + + public TestProcessor(String tag, String type, Function ingestDocumentMapper) { + this.ingestDocumentMapper = ingestDocumentMapper; this.type = type; this.tag = tag; } @@ -47,8 +55,7 @@ public TestProcessor(String tag, String type, Consumer ingestDoc @Override public IngestDocument execute(IngestDocument ingestDocument) throws Exception { invokedCounter.incrementAndGet(); - ingestDocumentConsumer.accept(ingestDocument); - return ingestDocument; + return ingestDocumentMapper.apply(ingestDocument); } @Override diff --git a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java index 47d6f83fc87e1..8410c96bbae67 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -2002,6 +2002,7 @@ public String startMasterOnlyNode(Settings settings) { .put(settings) .put(Node.NODE_MASTER_SETTING.getKey(), true) .put(Node.NODE_DATA_SETTING.getKey(), false) + .put(Node.NODE_INGEST_SETTING.getKey(), false) .build(); return startNode(settings1); } From 9a25b44567d41caf066a929686718e474f0ca451 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Tue, 17 Sep 2019 12:09:21 +0200 Subject: [PATCH 2/5] fix compilation --- .../ingest/SimulateExecutionServiceTests.java | 8 +++--- .../ingest/CompoundProcessorTests.java | 27 ++++++++++--------- .../ingest/TrackingResultProcessorTests.java | 2 +- .../elasticsearch/ingest/TestProcessor.java | 8 ++++++ 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/action/ingest/SimulateExecutionServiceTests.java b/server/src/test/java/org/elasticsearch/action/ingest/SimulateExecutionServiceTests.java index 5e44e196fe8d4..ac928d9194f80 100644 --- a/server/src/test/java/org/elasticsearch/action/ingest/SimulateExecutionServiceTests.java +++ b/server/src/test/java/org/elasticsearch/action/ingest/SimulateExecutionServiceTests.java @@ -101,8 +101,7 @@ public void testExecuteItem() throws Exception { public void testExecuteVerboseItemExceptionWithoutOnFailure() throws Exception { TestProcessor processor1 = new TestProcessor("processor_0", "mock", ingestDocument -> {}); - TestProcessor processor2 = new TestProcessor("processor_1", "mock", - ingestDocument -> { throw new RuntimeException("processor failed"); }); + TestProcessor processor2 = new TestProcessor("processor_1", "mock", new RuntimeException("processor failed")); TestProcessor processor3 = new TestProcessor("processor_2", "mock", ingestDocument -> {}); Pipeline pipeline = new Pipeline("_id", "_description", version, new CompoundProcessor(processor1, processor2, processor3)); SimulateDocumentResult actualItemResponse = executionService.executeDocument(pipeline, ingestDocument, true); @@ -126,8 +125,7 @@ public void testExecuteVerboseItemExceptionWithoutOnFailure() throws Exception { } public void testExecuteVerboseItemWithOnFailure() throws Exception { - TestProcessor processor1 = new TestProcessor("processor_0", "mock", - ingestDocument -> { throw new RuntimeException("processor failed"); }); + TestProcessor processor1 = new TestProcessor("processor_0", "mock", new RuntimeException("processor failed")); TestProcessor processor2 = new TestProcessor("processor_1", "mock", ingestDocument -> {}); TestProcessor processor3 = new TestProcessor("processor_2", "mock", ingestDocument -> {}); Pipeline pipeline = new Pipeline("_id", "_description", version, @@ -165,7 +163,7 @@ public void testExecuteVerboseItemWithOnFailure() throws Exception { public void testExecuteVerboseItemExceptionWithIgnoreFailure() throws Exception { RuntimeException exception = new RuntimeException("processor failed"); - TestProcessor testProcessor = new TestProcessor("processor_0", "mock", ingestDocument -> { throw exception; }); + TestProcessor testProcessor = new TestProcessor("processor_0", "mock", exception); CompoundProcessor processor = new CompoundProcessor(true, Collections.singletonList(testProcessor), Collections.emptyList()); Pipeline pipeline = new Pipeline("_id", "_description", version, new CompoundProcessor(processor)); SimulateDocumentResult actualItemResponse = executionService.executeDocument(pipeline, ingestDocument, true); diff --git a/server/src/test/java/org/elasticsearch/ingest/CompoundProcessorTests.java b/server/src/test/java/org/elasticsearch/ingest/CompoundProcessorTests.java index 24e3dcd76774b..575d5629b1a78 100644 --- a/server/src/test/java/org/elasticsearch/ingest/CompoundProcessorTests.java +++ b/server/src/test/java/org/elasticsearch/ingest/CompoundProcessorTests.java @@ -28,6 +28,7 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; import java.util.function.LongSupplier; import static org.hamcrest.CoreMatchers.equalTo; @@ -74,7 +75,7 @@ public void testSingleProcessor() throws Exception { } public void testSingleProcessorWithException() throws Exception { - TestProcessor processor = new TestProcessor(ingestDocument -> {throw new RuntimeException("error");}); + TestProcessor processor = new TestProcessor(new RuntimeException("error")); LongSupplier relativeTimeProvider = mock(LongSupplier.class); when(relativeTimeProvider.getAsLong()).thenReturn(0L); CompoundProcessor compoundProcessor = new CompoundProcessor(relativeTimeProvider, processor); @@ -93,7 +94,7 @@ public void testSingleProcessorWithException() throws Exception { } public void testIgnoreFailure() throws Exception { - TestProcessor processor1 = new TestProcessor(ingestDocument -> {throw new RuntimeException("error");}); + TestProcessor processor1 = new TestProcessor(new RuntimeException("error")); TestProcessor processor2 = new TestProcessor(ingestDocument -> {ingestDocument.setFieldValue("field", "value");}); LongSupplier relativeTimeProvider = mock(LongSupplier.class); when(relativeTimeProvider.getAsLong()).thenReturn(0L); @@ -108,7 +109,7 @@ public void testIgnoreFailure() throws Exception { } public void testSingleProcessorWithOnFailureProcessor() throws Exception { - TestProcessor processor1 = new TestProcessor("id", "first", ingestDocument -> {throw new RuntimeException("error");}); + TestProcessor processor1 = new TestProcessor("id", "first", new RuntimeException("error")); TestProcessor processor2 = new TestProcessor(ingestDocument -> { Map ingestMetadata = ingestDocument.getIngestMetadata(); assertThat(ingestMetadata.size(), equalTo(3)); @@ -130,7 +131,7 @@ public void testSingleProcessorWithOnFailureProcessor() throws Exception { } public void testSingleProcessorWithOnFailureDropProcessor() throws Exception { - TestProcessor processor1 = new TestProcessor("id", "first", ingestDocument -> {throw new RuntimeException("error");}); + TestProcessor processor1 = new TestProcessor("id", "first", new RuntimeException("error")); Processor processor2 = new Processor() { @Override public IngestDocument execute(IngestDocument ingestDocument) throws Exception { @@ -159,8 +160,8 @@ public String getTag() { } public void testSingleProcessorWithNestedFailures() throws Exception { - TestProcessor processor = new TestProcessor("id", "first", ingestDocument -> {throw new RuntimeException("error");}); - TestProcessor processorToFail = new TestProcessor("id2", "second", ingestDocument -> { + TestProcessor processor = new TestProcessor("id", "first", new RuntimeException("error")); + TestProcessor processorToFail = new TestProcessor("id2", "second", (Consumer) ingestDocument -> { Map ingestMetadata = ingestDocument.getIngestMetadata(); assertThat(ingestMetadata.size(), equalTo(3)); assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_MESSAGE_FIELD), equalTo("error")); @@ -189,7 +190,7 @@ public void testSingleProcessorWithNestedFailures() throws Exception { } public void testCompoundProcessorExceptionFailWithoutOnFailure() throws Exception { - TestProcessor firstProcessor = new TestProcessor("id1", "first", ingestDocument -> {throw new RuntimeException("error");}); + TestProcessor firstProcessor = new TestProcessor("id1", "first", new RuntimeException("error")); TestProcessor secondProcessor = new TestProcessor("id3", "second", ingestDocument -> { Map ingestMetadata = ingestDocument.getIngestMetadata(); assertThat(ingestMetadata.entrySet(), hasSize(3)); @@ -212,9 +213,9 @@ public void testCompoundProcessorExceptionFailWithoutOnFailure() throws Exceptio } public void testCompoundProcessorExceptionFail() throws Exception { - TestProcessor firstProcessor = new TestProcessor("id1", "first", ingestDocument -> {throw new RuntimeException("error");}); + TestProcessor firstProcessor = new TestProcessor("id1", "first", new RuntimeException("error")); TestProcessor failProcessor = - new TestProcessor("tag_fail", "fail", ingestDocument -> {throw new RuntimeException("custom error message");}); + new TestProcessor("tag_fail", "fail", new RuntimeException("custom error message")); TestProcessor secondProcessor = new TestProcessor("id3", "second", ingestDocument -> { Map ingestMetadata = ingestDocument.getIngestMetadata(); assertThat(ingestMetadata.entrySet(), hasSize(3)); @@ -238,9 +239,9 @@ public void testCompoundProcessorExceptionFail() throws Exception { } public void testCompoundProcessorExceptionFailInOnFailure() throws Exception { - TestProcessor firstProcessor = new TestProcessor("id1", "first", ingestDocument -> {throw new RuntimeException("error");}); + TestProcessor firstProcessor = new TestProcessor("id1", "first", new RuntimeException("error")); TestProcessor failProcessor = - new TestProcessor("tag_fail", "fail", ingestDocument -> {throw new RuntimeException("custom error message");}); + new TestProcessor("tag_fail", "fail", new RuntimeException("custom error message")); TestProcessor secondProcessor = new TestProcessor("id3", "second", ingestDocument -> { Map ingestMetadata = ingestDocument.getIngestMetadata(); assertThat(ingestMetadata.entrySet(), hasSize(3)); @@ -264,8 +265,8 @@ public void testCompoundProcessorExceptionFailInOnFailure() throws Exception { } public void testBreakOnFailure() throws Exception { - TestProcessor firstProcessor = new TestProcessor("id1", "first", ingestDocument -> {throw new RuntimeException("error1");}); - TestProcessor secondProcessor = new TestProcessor("id2", "second", ingestDocument -> {throw new RuntimeException("error2");}); + TestProcessor firstProcessor = new TestProcessor("id1", "first", new RuntimeException("error1")); + TestProcessor secondProcessor = new TestProcessor("id2", "second", new RuntimeException("error2")); TestProcessor onFailureProcessor = new TestProcessor("id2", "on_failure", ingestDocument -> {}); LongSupplier relativeTimeProvider = mock(LongSupplier.class); when(relativeTimeProvider.getAsLong()).thenReturn(0L); diff --git a/server/src/test/java/org/elasticsearch/ingest/TrackingResultProcessorTests.java b/server/src/test/java/org/elasticsearch/ingest/TrackingResultProcessorTests.java index 2c047283ed1bb..53a5cd1d753c2 100644 --- a/server/src/test/java/org/elasticsearch/ingest/TrackingResultProcessorTests.java +++ b/server/src/test/java/org/elasticsearch/ingest/TrackingResultProcessorTests.java @@ -101,7 +101,7 @@ public void testActualCompoundProcessorWithoutOnFailure() throws Exception { public void testActualCompoundProcessorWithOnFailure() throws Exception { RuntimeException exception = new RuntimeException("fail"); - TestProcessor failProcessor = new TestProcessor("fail", "test", ingestDocument -> { throw exception; }); + TestProcessor failProcessor = new TestProcessor("fail", "test", exception); TestProcessor onFailureProcessor = new TestProcessor("success", "test", ingestDocument -> {}); CompoundProcessor actualProcessor = new CompoundProcessor(false, Arrays.asList(new CompoundProcessor(false, diff --git a/test/framework/src/main/java/org/elasticsearch/ingest/TestProcessor.java b/test/framework/src/main/java/org/elasticsearch/ingest/TestProcessor.java index 19ffd69c5884b..80579831475e0 100644 --- a/test/framework/src/main/java/org/elasticsearch/ingest/TestProcessor.java +++ b/test/framework/src/main/java/org/elasticsearch/ingest/TestProcessor.java @@ -39,6 +39,14 @@ public TestProcessor(Consumer ingestDocumentConsumer) { this(null, "test-processor", ingestDocumentConsumer); } + public TestProcessor(RuntimeException e) { + this(null, "test-processor", e); + } + + public TestProcessor(String tag, String type, RuntimeException e) { + this(tag, type, (Consumer) i -> { throw e; }); + } + public TestProcessor(String tag, String type, Consumer ingestDocumentConsumer) { this(tag, type, id -> { ingestDocumentConsumer.accept(id); From 3d34d3e35eb518be7f6ab34cd8de85e5fa2212a0 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Tue, 17 Sep 2019 15:43:15 +0200 Subject: [PATCH 3/5] fix tests --- .../index/reindex/AsyncBulkByScrollActionTests.java | 2 +- .../test/java/org/elasticsearch/action/bulk/RetryTests.java | 4 +++- .../action/bulk/TransportShardBulkActionTests.java | 6 +++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/AsyncBulkByScrollActionTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/AsyncBulkByScrollActionTests.java index 0afd68296740e..1e9aacb5afa62 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/AsyncBulkByScrollActionTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/AsyncBulkByScrollActionTests.java @@ -878,7 +878,7 @@ void doExecute(ActionType action, Request request, ActionListener listener) { } private BulkItemResponse successfulResponse() { - return new BulkItemResponse(1, OpType.DELETE, new DeleteResponse(null, null, null, 0, 0, 0, false)); + return new BulkItemResponse(1, OpType.DELETE, new DeleteResponse( + new ShardId("test", "test", 0), "_doc", "test", 0, 0, 0, false)); } private BulkItemResponse failedResponse() { diff --git a/server/src/test/java/org/elasticsearch/action/bulk/TransportShardBulkActionTests.java b/server/src/test/java/org/elasticsearch/action/bulk/TransportShardBulkActionTests.java index 22d6c2f722db6..8acb3e8cc93a5 100644 --- a/server/src/test/java/org/elasticsearch/action/bulk/TransportShardBulkActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/bulk/TransportShardBulkActionTests.java @@ -240,6 +240,7 @@ public void testExecuteBulkIndexRequestWithMappingUpdates() throws Exception { Engine.IndexResult success = new FakeIndexResult(1, 1, 13, true, resultLocation); IndexShard shard = mock(IndexShard.class); + when(shard.shardId()).thenReturn(shardId); when(shard.applyIndexOperationOnPrimary(anyLong(), any(), any(), anyLong(), anyLong(), anyLong(), anyBoolean())) .thenReturn(mappingUpdate); @@ -583,6 +584,7 @@ public void testUpdateRequestWithSuccess() throws Exception { when(shard.applyIndexOperationOnPrimary(anyLong(), any(), any(), anyLong(), anyLong(), anyLong(), anyBoolean())) .thenReturn(indexResult); when(shard.indexSettings()).thenReturn(indexSettings); + when(shard.shardId()).thenReturn(shardId); UpdateHelper updateHelper = mock(UpdateHelper.class); when(updateHelper.prepare(any(), eq(shard), any())).thenReturn( @@ -629,6 +631,7 @@ public void testUpdateWithDelete() throws Exception { IndexShard shard = mock(IndexShard.class); when(shard.applyDeleteOperationOnPrimary(anyLong(), any(), any(), any(), anyLong(), anyLong())).thenReturn(deleteResult); when(shard.indexSettings()).thenReturn(indexSettings); + when(shard.shardId()).thenReturn(shardId); UpdateHelper updateHelper = mock(UpdateHelper.class); when(updateHelper.prepare(any(), eq(shard), any())).thenReturn( @@ -783,6 +786,7 @@ public void testRetries() throws Exception { } }); when(shard.indexSettings()).thenReturn(indexSettings); + when(shard.shardId()).thenReturn(shardId); UpdateHelper updateHelper = mock(UpdateHelper.class); when(updateHelper.prepare(any(), eq(shard), any())).thenReturn( @@ -814,7 +818,7 @@ public void testRetries() throws Exception { private void randomlySetIgnoredPrimaryResponse(BulkItemRequest primaryRequest) { if (randomBoolean()) { // add a response to the request and thereby check that it is ignored for the primary. - primaryRequest.setPrimaryResponse(new BulkItemResponse(0, DocWriteRequest.OpType.INDEX, new IndexResponse(null, "_doc", + primaryRequest.setPrimaryResponse(new BulkItemResponse(0, DocWriteRequest.OpType.INDEX, new IndexResponse(shardId, "_doc", "ignore-primary-response-on-primary", 42, 42, 42, false))); } } From 49e9b9ddf70d7ca47a91ba242b5d04785ca5407b Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Tue, 17 Sep 2019 15:46:58 +0200 Subject: [PATCH 4/5] add constant --- .../org/elasticsearch/action/bulk/TransportBulkAction.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java b/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java index 11b70b193cd15..940ebd037bde7 100644 --- a/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java +++ b/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java @@ -100,6 +100,7 @@ public class TransportBulkAction extends HandledTransportAction wrapActionListenerIfNeeded(long ingestTookInMillis, void markCurrentItemAsDropped() { IndexRequest indexRequest = getIndexWriteRequest(bulkRequest.requests().get(currentSlot)); failedSlots.set(currentSlot); - final String id = indexRequest.id() == null ? "auto-generated" : indexRequest.id(); + final String id = indexRequest.id() == null ? DROPPED_ITEM_WITH_AUTO_GENERATED_ID : indexRequest.id(); itemResponses.add( new BulkItemResponse(currentSlot, indexRequest.opType(), new UpdateResponse( From 0457c5adc385a52bb962a54da22dcabcf62dc15b Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Thu, 19 Sep 2019 15:30:17 +0200 Subject: [PATCH 5/5] more test fixes --- .../xpack/ml/job/persistence/JobResultsPersisterTests.java | 3 ++- .../action/oidc/TransportOpenIdConnectLogoutActionTests.java | 3 ++- .../saml/TransportSamlInvalidateSessionActionTests.java | 3 ++- .../security/action/saml/TransportSamlLogoutActionTests.java | 5 +++-- .../xpack/watcher/execution/ExecutionServiceTests.java | 4 +++- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsPersisterTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsPersisterTests.java index 4aff83ab39065..a6814c46c0e65 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsPersisterTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsPersisterTests.java @@ -16,6 +16,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.ml.datafeed.DatafeedTimingStats; @@ -249,7 +250,7 @@ public void testPersistDatafeedTimingStats() { // Take the listener passed to client::index as 2nd argument ActionListener listener = (ActionListener) invocationOnMock.getArguments()[1]; // Handle the response on the listener - listener.onResponse(new IndexResponse(null, null, null, 0, 0, 0, false)); + listener.onResponse(new IndexResponse(new ShardId("test", "test", 0), "_doc", "test", 0, 0, 0, false)); return null; }) .when(client).index(any(), any(ActionListener.class)); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/oidc/TransportOpenIdConnectLogoutActionTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/oidc/TransportOpenIdConnectLogoutActionTests.java index ba6da8e31eefb..efff417a09f72 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/oidc/TransportOpenIdConnectLogoutActionTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/oidc/TransportOpenIdConnectLogoutActionTests.java @@ -31,6 +31,7 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.env.Environment; import org.elasticsearch.env.TestEnvironment; +import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.tasks.Task; import org.elasticsearch.test.ClusterServiceUtils; @@ -143,7 +144,7 @@ public void setup() throws Exception { ActionListener listener = (ActionListener) invocationOnMock.getArguments()[2]; indexRequests.add(indexRequest); final IndexResponse response = new IndexResponse( - indexRequest.shardId(), indexRequest.type(), indexRequest.id(), 1, 1, 1, true); + new ShardId("test", "test", 0), indexRequest.type(), indexRequest.id(), 1, 1, 1, true); listener.onResponse(response); return Void.TYPE; }).when(client).execute(eq(IndexAction.INSTANCE), any(IndexRequest.class), any(ActionListener.class)); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/saml/TransportSamlInvalidateSessionActionTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/saml/TransportSamlInvalidateSessionActionTests.java index c5ed4365effcd..f0337a7a72bc6 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/saml/TransportSamlInvalidateSessionActionTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/saml/TransportSamlInvalidateSessionActionTests.java @@ -46,6 +46,7 @@ import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.TermQueryBuilder; +import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHits; @@ -149,7 +150,7 @@ void doExecute(ActionType action, Request request, ActionListener listener = (ActionListener) invocationOnMock.getArguments()[1]; indexRequests.add(indexRequest); final IndexResponse response = new IndexResponse( - indexRequest.shardId(), indexRequest.type(), indexRequest.id(), 1, 1, 1, true); + new ShardId("test", "test", 0), indexRequest.type(), indexRequest.id(), 1, 1, 1, true); listener.onResponse(response); return Void.TYPE; }).when(client).index(any(IndexRequest.class), any(ActionListener.class)); @@ -179,7 +180,7 @@ public void setup() throws Exception { ActionListener listener = (ActionListener) invocationOnMock.getArguments()[2]; indexRequests.add(indexRequest); final IndexResponse response = new IndexResponse( - indexRequest.shardId(), indexRequest.type(), indexRequest.id(), 1, 1, 1, true); + new ShardId("test", "test", 0), indexRequest.type(), indexRequest.id(), 1, 1, 1, true); listener.onResponse(response); return Void.TYPE; }).when(client).execute(eq(IndexAction.INSTANCE), any(IndexRequest.class), any(ActionListener.class)); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java index d42ddfeb2fe2c..b326b3aeebf9b 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java @@ -8,6 +8,7 @@ import org.elasticsearch.Version; import org.elasticsearch.action.ActionFuture; import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.DocWriteResponse; import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.get.GetResponse; @@ -1098,7 +1099,8 @@ public void testUpdateWatchStatusDoesNotUpdateState() throws Exception { } PlainActionFuture future = PlainActionFuture.newFuture(); - future.onResponse(new UpdateResponse(null, null, null, null, 0, 0, 0, null)); + future.onResponse(new UpdateResponse(null, new ShardId("test", "test", 0), "_doc", "test", 0, 0, 0, + DocWriteResponse.Result.CREATED)); return future; }).when(client).update(any());