Skip to content

Commit 3833d66

Browse files
Remove one unnecesary test and simply some code in a test (opensearch-project#14360) (opensearch-project#14412)
(cherry picked from commit 1d14569) Signed-off-by: Liyun Xiu <xiliyun@amazon.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent f9a5979 commit 3833d66

File tree

2 files changed

+15
-62
lines changed

2 files changed

+15
-62
lines changed

server/src/internalClusterTest/java/org/opensearch/ingest/IngestClientIT.java

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ private void runBulkTestWithRandomDocs(boolean shouldSetBatchSize) throws Except
189189
int numRequests = scaledRandomIntBetween(32, 128);
190190
BulkRequest bulkRequest = new BulkRequest();
191191
if (shouldSetBatchSize) {
192-
bulkRequest.batchSize(numRequests);
192+
bulkRequest.batchSize(scaledRandomIntBetween(2, numRequests));
193193
}
194194
for (int i = 0; i < numRequests; i++) {
195195
IndexRequest indexRequest = new IndexRequest("index").id(Integer.toString(i)).setPipeline("_id");
@@ -214,6 +214,9 @@ private void runBulkTestWithRandomDocs(boolean shouldSetBatchSize) throws Except
214214
);
215215
assertThat(indexResponse, notNullValue());
216216
assertThat(indexResponse.getId(), equalTo(Integer.toString(i)));
217+
// verify field of successful doc
218+
Map<String, Object> successDoc = client().prepareGet("index", indexResponse.getId()).get().getSourceAsMap();
219+
assertThat(successDoc.get("processed"), equalTo(true));
217220
assertEquals(DocWriteResponse.Result.CREATED, indexResponse.getResult());
218221
}
219222
}
@@ -223,51 +226,6 @@ private void runBulkTestWithRandomDocs(boolean shouldSetBatchSize) throws Except
223226
assertTrue(deletePipelineResponse.isAcknowledged());
224227
}
225228

226-
public void testBulkWithIngestFailuresBatch() throws Exception {
227-
createIndex("index");
228-
229-
BytesReference source = BytesReference.bytes(
230-
jsonBuilder().startObject()
231-
.field("description", "my_pipeline")
232-
.startArray("processors")
233-
.startObject()
234-
.startObject("test")
235-
.endObject()
236-
.endObject()
237-
.endArray()
238-
.endObject()
239-
);
240-
PutPipelineRequest putPipelineRequest = new PutPipelineRequest("_id", source, MediaTypeRegistry.JSON);
241-
client().admin().cluster().putPipeline(putPipelineRequest).get();
242-
243-
BulkRequest bulkRequest = new BulkRequest();
244-
bulkRequest.batchSize(2);
245-
bulkRequest.add(
246-
new IndexRequest("index").id("_fail").setPipeline("_id").source(Requests.INDEX_CONTENT_TYPE, "field", "value", "fail", true)
247-
);
248-
bulkRequest.add(
249-
new IndexRequest("index").id("_success").setPipeline("_id").source(Requests.INDEX_CONTENT_TYPE, "field", "value", "fail", false)
250-
);
251-
252-
BulkResponse response = client().bulk(bulkRequest).actionGet();
253-
MatcherAssert.assertThat(response.getItems().length, equalTo(bulkRequest.requests().size()));
254-
255-
Map<String, BulkItemResponse> results = Arrays.stream(response.getItems())
256-
.collect(Collectors.toMap(BulkItemResponse::getId, r -> r));
257-
258-
MatcherAssert.assertThat(results.keySet(), containsInAnyOrder("_fail", "_success"));
259-
assertNotNull(results.get("_fail").getFailure());
260-
assertNull(results.get("_success").getFailure());
261-
262-
// verify field of successful doc
263-
Map<String, Object> successDoc = client().prepareGet("index", "_success").get().getSourceAsMap();
264-
assertThat(successDoc.get("processed"), equalTo(true));
265-
266-
// cleanup
267-
AcknowledgedResponse deletePipelineResponse = client().admin().cluster().prepareDeletePipeline("_id").get();
268-
assertTrue(deletePipelineResponse.isAcknowledged());
269-
}
270-
271229
public void testBulkWithIngestFailuresAndDropBatch() throws Exception {
272230
createIndex("index");
273231

server/src/test/java/org/opensearch/ingest/IngestServiceTests.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,15 @@
8181
import org.junit.Before;
8282

8383
import java.nio.charset.StandardCharsets;
84+
import java.util.ArrayList;
8485
import java.util.Arrays;
8586
import java.util.Collections;
8687
import java.util.Comparator;
8788
import java.util.HashMap;
8889
import java.util.List;
8990
import java.util.Map;
9091
import java.util.Objects;
92+
import java.util.Set;
9193
import java.util.concurrent.ExecutorService;
9294
import java.util.concurrent.atomic.AtomicInteger;
9395
import java.util.concurrent.atomic.AtomicReference;
@@ -97,7 +99,6 @@
9799
import java.util.function.LongSupplier;
98100
import java.util.stream.Collectors;
99101

100-
import org.mockito.ArgumentCaptor;
101102
import org.mockito.ArgumentMatcher;
102103
import org.mockito.invocation.InvocationOnMock;
103104

@@ -1937,27 +1938,21 @@ public void testExecuteBulkRequestInBatchWithExceptionAndDropInCallback() {
19371938
return null;
19381939
}).when(mockCompoundProcessor).batchExecute(any(), any());
19391940

1940-
@SuppressWarnings("unchecked")
1941-
final BiConsumer<Integer, Exception> failureHandler = mock(BiConsumer.class);
1942-
@SuppressWarnings("unchecked")
1943-
final BiConsumer<Thread, Exception> completionHandler = mock(BiConsumer.class);
1944-
final IntConsumer dropHandler = mock(IntConsumer.class);
1941+
final Map<Integer, Exception> failureHandler = new HashMap<>();
1942+
final Map<Thread, Exception> completionHandler = new HashMap<>();
1943+
final List<Integer> dropHandler = new ArrayList<>();
19451944
ingestService.executeBulkRequest(
19461945
3,
19471946
bulkRequest.requests(),
1948-
failureHandler,
1949-
completionHandler,
1950-
dropHandler,
1947+
failureHandler::put,
1948+
completionHandler::put,
1949+
dropHandler::add,
19511950
Names.WRITE,
19521951
bulkRequest
19531952
);
1954-
ArgumentCaptor<Integer> failureSlotCaptor = ArgumentCaptor.forClass(Integer.class);
1955-
verify(failureHandler, times(1)).accept(failureSlotCaptor.capture(), any());
1956-
assertEquals(1, failureSlotCaptor.getValue().intValue());
1957-
ArgumentCaptor<Integer> dropSlotCaptor = ArgumentCaptor.forClass(Integer.class);
1958-
verify(dropHandler, times(1)).accept(dropSlotCaptor.capture());
1959-
assertEquals(2, dropSlotCaptor.getValue().intValue());
1960-
verify(completionHandler, times(1)).accept(Thread.currentThread(), null);
1953+
assertEquals(Set.of(1), failureHandler.keySet());
1954+
assertEquals(List.of(2), dropHandler);
1955+
assertEquals(Set.of(Thread.currentThread()), completionHandler.keySet());
19611956
verify(mockCompoundProcessor, times(1)).batchExecute(any(), any());
19621957
verify(mockCompoundProcessor, never()).execute(any(), any());
19631958
}

0 commit comments

Comments
 (0)