|
| 1 | +/* |
| 2 | + * Copyright OpenSearch Contributors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package org.opensearch.dataprepper.integration; |
| 7 | + |
| 8 | +import org.junit.jupiter.api.AfterEach; |
| 9 | +import org.junit.jupiter.api.Test; |
| 10 | +import org.opensearch.dataprepper.model.event.Event; |
| 11 | +import org.opensearch.dataprepper.model.event.JacksonEvent; |
| 12 | +import org.opensearch.dataprepper.model.record.Record; |
| 13 | +import org.opensearch.dataprepper.plugins.InMemorySinkAccessor; |
| 14 | +import org.opensearch.dataprepper.plugins.InMemorySourceAccessor; |
| 15 | +import org.opensearch.dataprepper.test.framework.DataPrepperTestRunner; |
| 16 | +import org.slf4j.Logger; |
| 17 | +import org.slf4j.LoggerFactory; |
| 18 | + |
| 19 | +import java.util.List; |
| 20 | +import java.util.UUID; |
| 21 | +import java.util.concurrent.TimeUnit; |
| 22 | +import java.util.stream.Collectors; |
| 23 | +import java.util.stream.IntStream; |
| 24 | + |
| 25 | +import static org.awaitility.Awaitility.await; |
| 26 | +import static org.hamcrest.CoreMatchers.equalTo; |
| 27 | +import static org.hamcrest.CoreMatchers.not; |
| 28 | +import static org.hamcrest.CoreMatchers.notNullValue; |
| 29 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 30 | +import static org.hamcrest.Matchers.empty; |
| 31 | + |
| 32 | +class DLQHeadlessPipelinesIT { |
| 33 | + private static final Logger LOG = LoggerFactory.getLogger(ProcessorPipelineIT.class); |
| 34 | + private static final String IN_MEMORY_IDENTIFIER_DLQ = "PipelineDLQIT"; |
| 35 | + private static final String IN_MEMORY_IDENTIFIER_FORWARD = "ForwardPipelineIT"; |
| 36 | + private static final String PIPELINE_DLQ_TEST_CONFIGURATION= "pipeline-dlq.yaml"; |
| 37 | + private static final String FORWARD_PIPELINE_TEST_CONFIGURATION= "forward-pipeline.yaml"; |
| 38 | + private DataPrepperTestRunner dataPrepperTestRunner; |
| 39 | + private InMemorySourceAccessor inMemorySourceAccessor; |
| 40 | + private InMemorySinkAccessor inMemorySinkAccessor; |
| 41 | + |
| 42 | + private void createPipeline(final String pipelineConfiguration) { |
| 43 | + dataPrepperTestRunner = DataPrepperTestRunner.builder() |
| 44 | + .withPipelinesDirectoryOrFile(pipelineConfiguration) |
| 45 | + .build(); |
| 46 | + inMemorySourceAccessor = dataPrepperTestRunner.getInMemorySourceAccessor(); |
| 47 | + inMemorySinkAccessor = dataPrepperTestRunner.getInMemorySinkAccessor(); |
| 48 | + dataPrepperTestRunner.start(); |
| 49 | + LOG.info("Started test runner."); |
| 50 | + } |
| 51 | + |
| 52 | + @AfterEach |
| 53 | + void tearDown() { |
| 54 | + LOG.info("Test tear down. Stop the test runner."); |
| 55 | + dataPrepperTestRunner.stop(); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + void dlq_pipeline_test() { |
| 60 | + createPipeline(PIPELINE_DLQ_TEST_CONFIGURATION); |
| 61 | + |
| 62 | + final int recordsToCreate = 200; |
| 63 | + final List<Record<Event>> inputRecords = IntStream.range(0, recordsToCreate) |
| 64 | + .mapToObj(i -> UUID.randomUUID().toString()) |
| 65 | + .map(JacksonEvent::fromMessage) |
| 66 | + .map(Record::new) |
| 67 | + .collect(Collectors.toList()); |
| 68 | + |
| 69 | + LOG.info("Submitting a batch of record."); |
| 70 | + inMemorySourceAccessor.submit(IN_MEMORY_IDENTIFIER_DLQ, inputRecords); |
| 71 | + |
| 72 | + await().atMost(400, TimeUnit.MILLISECONDS) |
| 73 | + .untilAsserted(() -> { |
| 74 | + assertThat(inMemorySinkAccessor.get(IN_MEMORY_IDENTIFIER_DLQ), not(empty())); |
| 75 | + }); |
| 76 | + |
| 77 | + assertThat(inMemorySinkAccessor.get(IN_MEMORY_IDENTIFIER_DLQ).size(), equalTo(recordsToCreate)); |
| 78 | + |
| 79 | + final List<Record<Event>> sinkRecords = inMemorySinkAccessor.get(IN_MEMORY_IDENTIFIER_DLQ); |
| 80 | + |
| 81 | + assertThat(sinkRecords.size(), equalTo(recordsToCreate)); |
| 82 | + for (int i = 0; i < sinkRecords.size(); i++) { |
| 83 | + final Record<Event> inputRecord = inputRecords.get(i); |
| 84 | + final Record<Event> sinkRecord = sinkRecords.get(i); |
| 85 | + assertThat(sinkRecord, notNullValue()); |
| 86 | + final Event recordData = sinkRecord.getData(); |
| 87 | + assertThat(recordData, notNullValue()); |
| 88 | + assertThat( |
| 89 | + recordData.get("message", String.class), |
| 90 | + equalTo(inputRecord.getData().get("message", String.class))); |
| 91 | + assertThat(recordData.get("test1", String.class), |
| 92 | + equalTo(null)); |
| 93 | + |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | +} |
| 98 | + |
0 commit comments