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));
}
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)));
}
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)));
}
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))));
}
Aggregations