Example usage for java.util.concurrent LinkedTransferQueue add

List of usage examples for java.util.concurrent LinkedTransferQueue add

Introduction

In this page you can find the example usage for java.util.concurrent LinkedTransferQueue add.

Prototype

public boolean add(E e) 

Source Link

Document

Inserts the specified element at the tail of this queue.

Usage

From source file:com.streamsets.pipeline.stage.origin.kinesis.TestKinesisSource.java

@SuppressWarnings("unchecked")
@Test// w  w w . j a  v a  2s .  c  o m
public void testDefaultConsume() throws Exception {
    KinesisConsumerConfigBean config = getKinesisConsumerConfig();

    KinesisSource source = PowerMockito.spy(new KinesisSource(config));
    SourceRunner sourceRunner = new SourceRunner.Builder(KinesisDSource.class, source).addOutputLane("lane")
            .build();

    KinesisTestUtil.mockKinesisUtil(1);

    PowerMockito.doReturn(null).when(source, "createKinesisWorker", any(IRecordProcessorFactory.class));

    sourceRunner.runInit();

    // Set this flag to avoid actually launching a KCL worker
    Whitebox.setInternalState(source, "isStarted", true);

    // Generate test records
    List<Record> testRecords = KinesisTestUtil.getConsumerTestRecords(3);

    // Drop them into the work queue
    LinkedTransferQueue<RecordsAndCheckpointer> queue = new LinkedTransferQueue<>();

    IRecordProcessorCheckpointer checkpointer = mock(IRecordProcessorCheckpointer.class);

    List<Record> batch1 = ImmutableList.of(testRecords.get(0));
    List<Record> batch2 = ImmutableList.of(testRecords.get(1), testRecords.get(2));
    queue.add(new RecordsAndCheckpointer(batch1, checkpointer));
    queue.add(new RecordsAndCheckpointer(batch2, checkpointer));

    Whitebox.setInternalState(source, "batchQueue", queue);

    StageRunner.Output output = sourceRunner.runProduce("", 1);
    assertEquals("sequenceNumber=0::subSequenceNumber=0", output.getNewOffset());
    List<com.streamsets.pipeline.api.Record> records = output.getRecords().get("lane");
    assertEquals(1, records.size());

    output = sourceRunner.runProduce("", 10);
    assertEquals("sequenceNumber=2::subSequenceNumber=0", output.getNewOffset());
    records = output.getRecords().get("lane");
    assertEquals(2, records.size());
}