Search in sources :

Example 1 with TestBuffer

use of com.amazon.dataprepper.plugins.buffer.TestBuffer in project data-prepper by opensearch-project.

the class RandomStringSourceTests method testPutRecord.

@Test
public void testPutRecord() throws InterruptedException {
    final RandomStringSource randomStringSource = new RandomStringSource();
    final Queue<Record<Event>> bufferQueue = new ConcurrentLinkedQueue<>();
    final TestBuffer buffer = new TestBuffer(bufferQueue, 1);
    // Start source, and sleep for 1000 millis
    randomStringSource.start(buffer);
    Thread.sleep(1000);
    // Stop the source, and wait long enough that another message would be sent
    // if the source was running
    assertThat(buffer.size(), greaterThan(0));
    Thread.sleep(1000);
    randomStringSource.stop();
    assertThat(buffer.size(), greaterThan(0));
}
Also used : TestBuffer(com.amazon.dataprepper.plugins.buffer.TestBuffer) Record(com.amazon.dataprepper.model.record.Record) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Test(org.junit.Test)

Example 2 with TestBuffer

use of com.amazon.dataprepper.plugins.buffer.TestBuffer in project data-prepper by opensearch-project.

the class StdInSourceTests method testStdInSourceWhenStopped.

@Test
public void testStdInSourceWhenStopped() {
    final Queue<Record<Event>> bufferQueue = new LinkedList<>();
    final TestBuffer buffer = new TestBuffer(bufferQueue, 1);
    final StdInSource stdInSource = new StdInSource(TEST_WRITE_TIMEOUT, TEST_PIPELINE_NAME);
    assertThat(buffer.size(), is(equalTo(0)));
    stdInSource.stop();
    stdInSource.start(buffer);
    assertThat(buffer.size(), is(equalTo(0)));
}
Also used : TestBuffer(com.amazon.dataprepper.plugins.buffer.TestBuffer) Record(com.amazon.dataprepper.model.record.Record) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 3 with TestBuffer

use of com.amazon.dataprepper.plugins.buffer.TestBuffer in project data-prepper by opensearch-project.

the class StdInSourceTests method testStdInSourceWhenBufferTimesout.

@Test
public void testStdInSourceWhenBufferTimesout() {
    final Queue<Record<Event>> bufferQueue = new LinkedList<>();
    final TestBuffer buffer = new TestBuffer(bufferQueue, 1, true);
    final StdInSource stdInSource = new StdInSource(TEST_WRITE_TIMEOUT, TEST_PIPELINE_NAME);
    assertThat(buffer.size(), is(equalTo(0)));
    try {
        stdInSource.start(buffer);
    } catch (RuntimeException ex) {
        assertThat(ex.getMessage(), is(equalTo(format("Pipeline [%s] - Timed out writing to buffer", TEST_PIPELINE_NAME))));
    }
    assertThat(buffer.size(), is(equalTo(0)));
}
Also used : TestBuffer(com.amazon.dataprepper.plugins.buffer.TestBuffer) Record(com.amazon.dataprepper.model.record.Record) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 4 with TestBuffer

use of com.amazon.dataprepper.plugins.buffer.TestBuffer in project data-prepper by opensearch-project.

the class StdInSourceTests method testStdInSourceSuccessfulWriteToBuffer.

@Test
public void testStdInSourceSuccessfulWriteToBuffer() {
    final Queue<Record<Event>> bufferQueue = new LinkedList<>();
    final TestBuffer buffer = new TestBuffer(bufferQueue, 1);
    final StdInSource stdInSource = new StdInSource(TEST_WRITE_TIMEOUT, TEST_PIPELINE_NAME);
    assertThat(buffer.size(), is(equalTo(0)));
    stdInSource.start(buffer);
    assertThat(buffer.size(), is(equalTo(1)));
    final Map.Entry<Collection<Record<Event>>, CheckpointState> readResult = buffer.read(TEST_WRITE_TIMEOUT);
    final Collection<Record<Event>> recordsFromBuffer = readResult.getKey();
    assertThat(recordsFromBuffer.size(), is(equalTo(1)));
    recordsFromBuffer.forEach(actualRecord -> assertThat(actualRecord.getData().get("message", String.class), is(equalTo(READ_CONTENT))));
}
Also used : TestBuffer(com.amazon.dataprepper.plugins.buffer.TestBuffer) Collection(java.util.Collection) Event(com.amazon.dataprepper.model.event.Event) Record(com.amazon.dataprepper.model.record.Record) CheckpointState(com.amazon.dataprepper.model.CheckpointState) Map(java.util.Map) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

Record (com.amazon.dataprepper.model.record.Record)4 TestBuffer (com.amazon.dataprepper.plugins.buffer.TestBuffer)4 Test (org.junit.Test)4 LinkedList (java.util.LinkedList)3 CheckpointState (com.amazon.dataprepper.model.CheckpointState)1 Event (com.amazon.dataprepper.model.event.Event)1 Collection (java.util.Collection)1 Map (java.util.Map)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1