Search in sources :

Example 21 with ByteBufferMessageSet

use of kafka.javaapi.message.ByteBufferMessageSet in project storm by apache.

the class KafkaUtilsTest method generateTuplesWithValueAndStringMultiSchemeWithTopic.

@Test
public void generateTuplesWithValueAndStringMultiSchemeWithTopic() {
    config.scheme = new StringMultiSchemeWithTopic();
    String value = "value";
    createTopicAndSendMessage(value);
    ByteBufferMessageSet messageAndOffsets = getLastMessage();
    for (MessageAndOffset msg : messageAndOffsets) {
        Iterable<List<Object>> lists = KafkaUtils.generateTuples(config, msg.message(), config.topic);
        List<Object> list = lists.iterator().next();
        assertEquals(value, list.get(0));
        assertEquals(config.topic, list.get(1));
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) MessageAndOffset(kafka.message.MessageAndOffset) ByteBufferMessageSet(kafka.javaapi.message.ByteBufferMessageSet) Test(org.junit.Test)

Example 22 with ByteBufferMessageSet

use of kafka.javaapi.message.ByteBufferMessageSet in project storm by apache.

the class KafkaUtilsTest method generateTuplesWithValueSchemeAndKeyValueMessage.

@Test
public void generateTuplesWithValueSchemeAndKeyValueMessage() {
    config.scheme = new SchemeAsMultiScheme(new StringScheme());
    String value = "value";
    String key = "key";
    createTopicAndSendMessage(key, value);
    ByteBufferMessageSet messageAndOffsets = getLastMessage();
    for (MessageAndOffset msg : messageAndOffsets) {
        Iterable<List<Object>> lists = KafkaUtils.generateTuples(config, msg.message(), config.topic);
        assertEquals(value, lists.iterator().next().get(0));
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) MessageAndOffset(kafka.message.MessageAndOffset) SchemeAsMultiScheme(org.apache.storm.spout.SchemeAsMultiScheme) ByteBufferMessageSet(kafka.javaapi.message.ByteBufferMessageSet) Test(org.junit.Test)

Example 23 with ByteBufferMessageSet

use of kafka.javaapi.message.ByteBufferMessageSet in project storm by apache.

the class KafkaUtilsTest method generateTuplesWithMessageAndMetadataScheme.

@Test
public void generateTuplesWithMessageAndMetadataScheme() {
    String value = "value";
    Partition mockPartition = Mockito.mock(Partition.class);
    mockPartition.partition = 0;
    long offset = 0L;
    MessageMetadataSchemeAsMultiScheme scheme = new MessageMetadataSchemeAsMultiScheme(new StringMessageAndMetadataScheme());
    createTopicAndSendMessage(null, value);
    ByteBufferMessageSet messageAndOffsets = getLastMessage();
    for (MessageAndOffset msg : messageAndOffsets) {
        Iterable<List<Object>> lists = KafkaUtils.generateTuples(scheme, msg.message(), mockPartition, offset);
        List<Object> values = lists.iterator().next();
        assertEquals("Message is incorrect", value, values.get(0));
        assertEquals("Partition is incorrect", mockPartition.partition, values.get(1));
        assertEquals("Offset is incorrect", offset, values.get(2));
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) MessageAndOffset(kafka.message.MessageAndOffset) ByteBufferMessageSet(kafka.javaapi.message.ByteBufferMessageSet) Test(org.junit.Test)

Example 24 with ByteBufferMessageSet

use of kafka.javaapi.message.ByteBufferMessageSet in project storm by apache.

the class KafkaUtilsTest method runGetValueOnlyTuplesTest.

private void runGetValueOnlyTuplesTest() {
    String value = "value";
    createTopicAndSendMessage(null, value);
    ByteBufferMessageSet messageAndOffsets = getLastMessage();
    for (MessageAndOffset msg : messageAndOffsets) {
        Iterable<List<Object>> lists = KafkaUtils.generateTuples(config, msg.message(), config.topic);
        assertEquals(value, lists.iterator().next().get(0));
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) MessageAndOffset(kafka.message.MessageAndOffset) ByteBufferMessageSet(kafka.javaapi.message.ByteBufferMessageSet)

Example 25 with ByteBufferMessageSet

use of kafka.javaapi.message.ByteBufferMessageSet in project storm by apache.

the class KafkaBoltTest method mockSingleMessage.

private static ByteBufferMessageSet mockSingleMessage(byte[] key, byte[] message) {
    ByteBufferMessageSet sets = mock(ByteBufferMessageSet.class);
    MessageAndOffset msg = mock(MessageAndOffset.class);
    final List<MessageAndOffset> msgs = ImmutableList.of(msg);
    doReturn(msgs.iterator()).when(sets).iterator();
    Message kafkaMessage = mock(Message.class);
    doReturn(ByteBuffer.wrap(key)).when(kafkaMessage).key();
    doReturn(ByteBuffer.wrap(message)).when(kafkaMessage).payload();
    doReturn(kafkaMessage).when(msg).message();
    return sets;
}
Also used : Message(kafka.message.Message) MessageAndOffset(kafka.message.MessageAndOffset) ByteBufferMessageSet(kafka.javaapi.message.ByteBufferMessageSet)

Aggregations

ByteBufferMessageSet (kafka.javaapi.message.ByteBufferMessageSet)34 MessageAndOffset (kafka.message.MessageAndOffset)24 ArrayList (java.util.ArrayList)11 List (java.util.List)10 Test (org.junit.Test)10 IOException (java.io.IOException)6 FetchRequest (kafka.api.FetchRequest)5 Message (kafka.message.Message)5 ByteBuffer (java.nio.ByteBuffer)4 FetchRequestBuilder (kafka.api.FetchRequestBuilder)4 FetchResponse (kafka.javaapi.FetchResponse)4 SimpleConsumer (kafka.javaapi.consumer.SimpleConsumer)4 ConnectException (java.net.ConnectException)3 SocketTimeoutException (java.net.SocketTimeoutException)3 UnresolvedAddressException (java.nio.channels.UnresolvedAddressException)3 Future (java.util.concurrent.Future)2 Callback (org.apache.kafka.clients.producer.Callback)2 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)2 SchemeAsMultiScheme (org.apache.storm.spout.SchemeAsMultiScheme)2 Tuple (org.apache.storm.tuple.Tuple)2