Skip to content

Commit 118c303

Browse files
authored
Add check for event handle releases in integration tests (#6089)
Signed-off-by: Kondaka <krishkdk@amazon.com>
1 parent e9cbfa9 commit 118c303

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

  • data-prepper-plugins/cloudwatch-logs/src/integrationTest/java/org/opensearch/dataprepper/plugins/sink/cloudwatch_logs

data-prepper-plugins/cloudwatch-logs/src/integrationTest/java/org/opensearch/dataprepper/plugins/sink/cloudwatch_logs/CloudWatchLogsIT.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
4242
import org.opensearch.dataprepper.model.event.Event;
43+
import org.opensearch.dataprepper.model.event.EventHandle;
4344
import org.opensearch.dataprepper.model.log.JacksonLog;
4445
import org.opensearch.dataprepper.model.record.Record;
4546
import software.amazon.awssdk.regions.Region;
@@ -50,6 +51,8 @@
5051
import static org.awaitility.Awaitility.await;
5152
import static org.mockito.ArgumentMatchers.anyString;
5253
import static org.mockito.ArgumentMatchers.any;
54+
import static org.mockito.Mockito.verify;
55+
import static org.mockito.Mockito.times;
5356
import static org.mockito.Mockito.mock;
5457
import static org.mockito.Mockito.when;
5558
import static org.mockito.Mockito.lenient;
@@ -88,6 +91,9 @@ public class CloudWatchLogsIT {
8891
@Mock
8992
private ThresholdConfig thresholdConfig;
9093

94+
@Mock
95+
private EventHandle eventHandle;
96+
9197
@Mock
9298
private CloudWatchLogsSinkConfig cloudWatchLogsSinkConfig;
9399

@@ -127,6 +133,7 @@ void setUp() {
127133
requestsFailedCount = new AtomicInteger(0);
128134
dlqSuccessCount = new AtomicInteger(0);
129135
objectMapper = new ObjectMapper();
136+
eventHandle = mock(EventHandle.class);
130137
pluginSetting = mock(PluginSetting.class);
131138
pluginFactory = mock(PluginFactory.class);
132139
when(pluginSetting.getPipelineName()).thenReturn("pipeline");
@@ -208,6 +215,7 @@ void setUp() {
208215
when(thresholdConfig.getFlushInterval()).thenReturn(60L);
209216
when(thresholdConfig.getMaxEventSizeBytes()).thenReturn(1000L);
210217
when(cloudWatchLogsSinkConfig.getThresholdConfig()).thenReturn(thresholdConfig);
218+
when(cloudWatchLogsSinkConfig.getWorkers()).thenReturn(3);
211219
}
212220

213221
private List<String> listObjectsWithPrefix(String bucketName, String prefix) {
@@ -297,7 +305,7 @@ void TestSinkOperationWithLogSendInterval() throws Exception {
297305
assertThat(eventsSuccessCount.get(), equalTo(NUM_RECORDS));
298306
assertThat(requestsSuccessCount.get(), equalTo(1));
299307
assertThat(dlqSuccessCount.get(), equalTo(0));
300-
308+
verify(eventHandle, times(NUM_RECORDS)).release(true);
301309
}
302310

303311
@Test
@@ -333,6 +341,7 @@ void TestSinkOperationWithBatchSize() throws Exception {
333341
assertThat(eventsSuccessCount.get(), equalTo(NUM_RECORDS));
334342
assertThat(requestsSuccessCount.get(), equalTo(NUM_RECORDS));
335343
assertThat(dlqSuccessCount.get(), equalTo(0));
344+
verify(eventHandle, times(NUM_RECORDS)).release(true);
336345

337346
}
338347

@@ -368,6 +377,7 @@ void TestSinkOperationWithMaxRequestSize() throws Exception {
368377
assertThat(eventsSuccessCount.get(), equalTo(NUM_RECORDS));
369378
assertThat(requestsSuccessCount.get(), equalTo(1));
370379
assertThat(dlqSuccessCount.get(), equalTo(0));
380+
verify(eventHandle, times(NUM_RECORDS)).release(true);
371381

372382
}
373383

@@ -423,6 +433,7 @@ void testWithLargeSingleMessagesSentToDLQ() {
423433
assertThat(eventsSuccessCount.get(), equalTo(NUM_RECORDS));
424434
assertThat(requestsSuccessCount.get(), equalTo(1));
425435
assertThat(dlqSuccessCount.get(), equalTo(1));
436+
verify(eventHandle, times(NUM_RECORDS+1)).release(true);
426437

427438
}
428439

@@ -461,21 +472,28 @@ void testWithBadCredentials_AllEventsToDLQ() {
461472
assertThat(eventsSuccessCount.get(), equalTo(0));
462473
assertThat(requestsSuccessCount.get(), equalTo(0));
463474
assertThat(dlqSuccessCount.get(), equalTo(NUM_RECORDS));
475+
verify(eventHandle, times(NUM_RECORDS)).release(true);
464476

465477
}
466478

467479
private Collection<Record<Event>> getRecordList(int numberOfRecords) {
468480
final Collection<Record<Event>> recordList = new ArrayList<>();
469481
List<HashMap> records = generateRecords(numberOfRecords);
470482
for (int i = 0; i < numberOfRecords; i++) {
471-
final Event event = JacksonLog.builder().withData(records.get(i)).build();
483+
final Event event = JacksonLog.builder()
484+
.withData(records.get(i))
485+
.withEventHandle(eventHandle)
486+
.build();
472487
recordList.add(new Record<>(event));
473488
}
474489
return recordList;
475490
}
476491

477492
private Record<Event> getLargeRecord(int size) {
478-
final Event event = JacksonLog.builder().withData(Map.of("key", RandomStringUtils.randomAlphabetic(size))).build();
493+
final Event event = JacksonLog.builder()
494+
.withData(Map.of("key", RandomStringUtils.randomAlphabetic(size)))
495+
.withEventHandle(eventHandle)
496+
.build();
479497
return new Record<>(event);
480498
}
481499

0 commit comments

Comments
 (0)