Skip to content

Commit 1d14569

Browse files
authored
Remove one unnecesary test and simply some code in a test (#14360)
Signed-off-by: Liyun Xiu <xiliyun@amazon.com>
1 parent a32035b commit 1d14569

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

+4-46
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

+11-16
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

@@ -1923,27 +1924,21 @@ public void testExecuteBulkRequestInBatchWithExceptionAndDropInCallback() {
19231924
return null;
19241925
}).when(mockCompoundProcessor).batchExecute(any(), any());
19251926

1926-
@SuppressWarnings("unchecked")
1927-
final BiConsumer<Integer, Exception> failureHandler = mock(BiConsumer.class);
1928-
@SuppressWarnings("unchecked")
1929-
final BiConsumer<Thread, Exception> completionHandler = mock(BiConsumer.class);
1930-
final IntConsumer dropHandler = mock(IntConsumer.class);
1927+
final Map<Integer, Exception> failureHandler = new HashMap<>();
1928+
final Map<Thread, Exception> completionHandler = new HashMap<>();
1929+
final List<Integer> dropHandler = new ArrayList<>();
19311930
ingestService.executeBulkRequest(
19321931
3,
19331932
bulkRequest.requests(),
1934-
failureHandler,
1935-
completionHandler,
1936-
dropHandler,
1933+
failureHandler::put,
1934+
completionHandler::put,
1935+
dropHandler::add,
19371936
Names.WRITE,
19381937
bulkRequest
19391938
);
1940-
ArgumentCaptor<Integer> failureSlotCaptor = ArgumentCaptor.forClass(Integer.class);
1941-
verify(failureHandler, times(1)).accept(failureSlotCaptor.capture(), any());
1942-
assertEquals(1, failureSlotCaptor.getValue().intValue());
1943-
ArgumentCaptor<Integer> dropSlotCaptor = ArgumentCaptor.forClass(Integer.class);
1944-
verify(dropHandler, times(1)).accept(dropSlotCaptor.capture());
1945-
assertEquals(2, dropSlotCaptor.getValue().intValue());
1946-
verify(completionHandler, times(1)).accept(Thread.currentThread(), null);
1939+
assertEquals(Set.of(1), failureHandler.keySet());
1940+
assertEquals(List.of(2), dropHandler);
1941+
assertEquals(Set.of(Thread.currentThread()), completionHandler.keySet());
19471942
verify(mockCompoundProcessor, times(1)).batchExecute(any(), any());
19481943
verify(mockCompoundProcessor, never()).execute(any(), any());
19491944
}

0 commit comments

Comments
 (0)