Search in sources :

Example 1 with Item

use of io.divolte.server.processing.Item in project divolte-collector by divolte.

the class GoogleCloudPubSubFlusherTest method testMessageBatchSentToPublisher.

@Test
public void testMessageBatchSentToPublisher() {
    final Publisher publisher = mockPublisher.orElseThrow(IllegalStateException::new);
    // Process a bunch of messages.
    final DivolteSchema schema = new DivolteSchema(MINIMAL_SCHEMA, Optional.empty());
    final GoogleCloudPubSubFlusher flusher = new GoogleCloudPubSubFlusher(publisher, schema);
    final Queue<Item<AvroRecordBuffer>> items = Stream.generate(this::generateMessage).limit(10).map(this::itemFromAvroRecordBuffer).collect(Collectors.toCollection(() -> new ArrayBlockingQueue<>(10)));
    flusher.process(items);
    // Check the messages were all forwarded to the publisher.
    verify(publisher, times(10)).publish(any(PubsubMessage.class));
    verifyNoMoreInteractions(publisher);
}
Also used : Item(io.divolte.server.processing.Item) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Publisher(com.google.cloud.pubsub.v1.Publisher) PubsubMessage(com.google.pubsub.v1.PubsubMessage) DivolteSchema(io.divolte.server.DivolteSchema) Test(org.junit.Test)

Aggregations

Publisher (com.google.cloud.pubsub.v1.Publisher)1 PubsubMessage (com.google.pubsub.v1.PubsubMessage)1 DivolteSchema (io.divolte.server.DivolteSchema)1 Item (io.divolte.server.processing.Item)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 Test (org.junit.Test)1