Search in sources :

Example 71 with Record

use of com.amazon.dataprepper.model.record.Record in project data-prepper by opensearch-project.

the class DropEventsProcessorTests method testGivenWhenSettingThenIsStatementFalseUsed.

@Test
void testGivenWhenSettingThenIsStatementFalseUsed() {
    final Event event = mock(Event.class);
    final Record<Event> record = mock(Record.class);
    final int inputRecordCount = 10;
    final List<Record<Event>> recordsToBeProcessed = Collections.nCopies(inputRecordCount, record);
    final int numberOfMockedFalseEvaluations = 8;
    final boolean repeatedReturnValue = false;
    doReturn(whenSetting).when(dropEventProcessorConfig).getDropWhen();
    doReturn(true, true, repeatedReturnValue).when(expressionEvaluator).evaluate(eq(whenSetting), eq(event));
    doReturn(event).when(record).getData();
    dropProcessor = new DropEventsProcessor(pluginMetrics, dropEventProcessorConfig, expressionEvaluator);
    final Collection<Record<Event>> results = dropProcessor.doExecute(recordsToBeProcessed);
    assertThat(results.size(), is(numberOfMockedFalseEvaluations));
    verify(record, times(inputRecordCount)).getData();
}
Also used : JacksonEvent(com.amazon.dataprepper.model.event.JacksonEvent) Event(com.amazon.dataprepper.model.event.Event) Record(com.amazon.dataprepper.model.record.Record) Test(org.junit.jupiter.api.Test)

Example 72 with Record

use of com.amazon.dataprepper.model.record.Record in project data-prepper by opensearch-project.

the class PipelineTests method testPipelineState.

@Test
public void testPipelineState() {
    final Source<Record<String>> testSource = new TestSource();
    final TestSink testSink = new TestSink();
    final Pipeline testPipeline = new Pipeline(TEST_PIPELINE_NAME, testSource, new BlockingBuffer(TEST_PIPELINE_NAME), Collections.emptyList(), Collections.singletonList(testSink), TEST_PROCESSOR_THREADS, TEST_READ_BATCH_TIMEOUT);
    assertThat("Pipeline isStopRequested is expected to be false", testPipeline.isStopRequested(), is(false));
    assertThat("Pipeline is expected to have a default buffer", testPipeline.getBuffer(), notNullValue());
    assertTrue("Pipeline processors should be empty", testPipeline.getProcessorSets().isEmpty());
    testPipeline.execute();
    assertThat("Pipeline isStopRequested is expected to be false", testPipeline.isStopRequested(), is(false));
    testPipeline.shutdown();
    assertThat("Pipeline isStopRequested is expected to be true", testPipeline.isStopRequested(), is(true));
    assertThat("Sink shutdown should be called", testSink.isShutdown, is(true));
}
Also used : TestSource(com.amazon.dataprepper.plugins.TestSource) BlockingBuffer(com.amazon.dataprepper.plugins.buffer.blockingbuffer.BlockingBuffer) Record(com.amazon.dataprepper.model.record.Record) TestSink(com.amazon.dataprepper.plugins.TestSink) Test(org.junit.Test)

Example 73 with Record

use of com.amazon.dataprepper.model.record.Record in project data-prepper by opensearch-project.

the class PipelineTests method testPipelineStateWithPrepper.

@Test
public void testPipelineStateWithPrepper() {
    final Source<Record<String>> testSource = new TestSource();
    final TestSink testSink = new TestSink();
    final TestProcessor testProcessor = new TestPrepper(new PluginSetting("test_processor", new HashMap<>()));
    final Pipeline testPipeline = new Pipeline(TEST_PIPELINE_NAME, testSource, new BlockingBuffer(TEST_PIPELINE_NAME), Collections.singletonList(Collections.singletonList(testProcessor)), Collections.singletonList(testSink), TEST_PROCESSOR_THREADS, TEST_READ_BATCH_TIMEOUT);
    assertThat("Pipeline isStopRequested is expected to be false", testPipeline.isStopRequested(), is(false));
    assertThat("Pipeline is expected to have a default buffer", testPipeline.getBuffer(), notNullValue());
    assertEquals("Pipeline processorSets size should be 1", 1, testPipeline.getProcessorSets().size());
    testPipeline.execute();
    assertThat("Pipeline isStopRequested is expected to be false", testPipeline.isStopRequested(), is(false));
    testPipeline.shutdown();
    assertThat("Pipeline isStopRequested is expected to be true", testPipeline.isStopRequested(), is(true));
    assertThat("Sink shutdown should be called", testSink.isShutdown, is(true));
    assertThat("Processor shutdown should be called", testProcessor.isShutdown, is(true));
}
Also used : TestSource(com.amazon.dataprepper.plugins.TestSource) HashMap(java.util.HashMap) BlockingBuffer(com.amazon.dataprepper.plugins.buffer.blockingbuffer.BlockingBuffer) TestPrepper(com.amazon.dataprepper.pipeline.common.TestPrepper) TestProcessor(com.amazon.dataprepper.pipeline.common.TestProcessor) Record(com.amazon.dataprepper.model.record.Record) TestSink(com.amazon.dataprepper.plugins.TestSink) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Test(org.junit.Test)

Example 74 with Record

use of com.amazon.dataprepper.model.record.Record in project data-prepper by opensearch-project.

the class PipelineTests method testPipelineStateWithProcessor.

@Test
public void testPipelineStateWithProcessor() {
    final Source<Record<String>> testSource = new TestSource();
    final TestSink testSink = new TestSink();
    final TestProcessor testProcessor = new TestProcessor(new PluginSetting("test_processor", new HashMap<>()));
    final Pipeline testPipeline = new Pipeline(TEST_PIPELINE_NAME, testSource, new BlockingBuffer(TEST_PIPELINE_NAME), Collections.singletonList(Collections.singletonList(testProcessor)), Collections.singletonList(testSink), TEST_PROCESSOR_THREADS, TEST_READ_BATCH_TIMEOUT);
    assertThat("Pipeline isStopRequested is expected to be false", testPipeline.isStopRequested(), is(false));
    assertThat("Pipeline is expected to have a default buffer", testPipeline.getBuffer(), notNullValue());
    assertEquals("Pipeline processorSets size should be 1", 1, testPipeline.getProcessorSets().size());
    testPipeline.execute();
    assertThat("Pipeline isStopRequested is expected to be false", testPipeline.isStopRequested(), is(false));
    testPipeline.shutdown();
    assertThat("Pipeline isStopRequested is expected to be true", testPipeline.isStopRequested(), is(true));
    assertThat("Sink shutdown should be called", testSink.isShutdown, is(true));
    assertThat("Processor shutdown should be called", testProcessor.isShutdown, is(true));
}
Also used : TestSource(com.amazon.dataprepper.plugins.TestSource) HashMap(java.util.HashMap) BlockingBuffer(com.amazon.dataprepper.plugins.buffer.blockingbuffer.BlockingBuffer) TestProcessor(com.amazon.dataprepper.pipeline.common.TestProcessor) Record(com.amazon.dataprepper.model.record.Record) TestSink(com.amazon.dataprepper.plugins.TestSink) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Test(org.junit.Test)

Example 75 with Record

use of com.amazon.dataprepper.model.record.Record in project data-prepper by opensearch-project.

the class AbstractBufferTest method testCheckpointMetrics.

@Test
public void testCheckpointMetrics() throws Exception {
    // Given
    final AbstractBuffer<Record<String>> abstractBuffer = new AbstractBufferImpl(testPluginSetting);
    final Collection<Record<String>> testRecords = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        testRecords.add(new Record<>(UUID.randomUUID().toString()));
    }
    abstractBuffer.writeAll(testRecords, 1000);
    final Map.Entry<Collection<Record<String>>, CheckpointState> readResult = abstractBuffer.read(1000);
    final List<Measurement> checkpointTimeMeasurements = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add(PIPELINE_NAME).add(BUFFER_NAME).add(MetricNames.CHECKPOINT_TIME_ELAPSED).toString());
    Assert.assertEquals(0.0, MetricsTestUtil.getMeasurementFromList(checkpointTimeMeasurements, Statistic.COUNT).getValue(), 0);
    Assert.assertEquals(0.0, MetricsTestUtil.getMeasurementFromList(checkpointTimeMeasurements, Statistic.TOTAL_TIME).getValue(), 0);
    // When
    abstractBuffer.checkpoint(readResult.getValue());
    // Then
    Assert.assertEquals(0, abstractBuffer.getRecordsInFlight());
    final List<Measurement> recordsInFlightMeasurements = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add(PIPELINE_NAME).add(BUFFER_NAME).add(MetricNames.RECORDS_INFLIGHT).toString());
    final List<Measurement> recordsProcessedMeasurements = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add(PIPELINE_NAME).add(MetricNames.RECORDS_PROCESSED).toString());
    final Measurement recordsInFlightMeasurement = recordsInFlightMeasurements.get(0);
    final Measurement recordsProcessedMeasurement = recordsProcessedMeasurements.get(0);
    Assert.assertEquals(0.0, recordsInFlightMeasurement.getValue(), 0);
    Assert.assertEquals(5.0, recordsProcessedMeasurement.getValue(), 0);
    Assert.assertEquals(1.0, MetricsTestUtil.getMeasurementFromList(checkpointTimeMeasurements, Statistic.COUNT).getValue(), 0);
    Assert.assertTrue(MetricsTestUtil.isBetween(MetricsTestUtil.getMeasurementFromList(checkpointTimeMeasurements, Statistic.TOTAL_TIME).getValue(), 0.0, 0.001));
}
Also used : Measurement(io.micrometer.core.instrument.Measurement) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Record(com.amazon.dataprepper.model.record.Record) CheckpointState(com.amazon.dataprepper.model.CheckpointState) AbstractMap(java.util.AbstractMap) Map(java.util.Map) StringJoiner(java.util.StringJoiner) Test(org.junit.jupiter.api.Test)

Aggregations

Record (com.amazon.dataprepper.model.record.Record)103 Test (org.junit.Test)43 Measurement (io.micrometer.core.instrument.Measurement)35 StringJoiner (java.util.StringJoiner)35 PluginSetting (com.amazon.dataprepper.model.configuration.PluginSetting)33 ArrayList (java.util.ArrayList)31 Map (java.util.Map)30 Test (org.junit.jupiter.api.Test)30 HashMap (java.util.HashMap)29 List (java.util.List)28 Event (com.amazon.dataprepper.model.event.Event)23 ExportTraceServiceRequest (io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest)20 ResourceSpans (io.opentelemetry.proto.trace.v1.ResourceSpans)19 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)16 JacksonEvent (com.amazon.dataprepper.model.event.JacksonEvent)14 ByteString (com.google.protobuf.ByteString)13 ExecutorService (java.util.concurrent.ExecutorService)13 Resource (io.opentelemetry.proto.resource.v1.Resource)12 Channel (io.grpc.Channel)11 MetricNames (com.amazon.dataprepper.metrics.MetricNames)10