Search in sources :

Example 16 with KafkaMessageId

use of nl.minvenj.nfi.storm.kafka.util.KafkaMessageId in project kafka-spout by HolmesNL.

the class UnreliableFailHandlerTest method testShouldReplay.

@Test
public void testShouldReplay() {
    final FailHandler subject = new UnreliableFailHandler();
    final KafkaMessageId id = new KafkaMessageId(1, 1234);
    // unreliable handler should never tell spout to replay
    assertFalse(subject.shouldReplay(id));
}
Also used : KafkaMessageId(nl.minvenj.nfi.storm.kafka.util.KafkaMessageId) Test(org.junit.Test)

Example 17 with KafkaMessageId

use of nl.minvenj.nfi.storm.kafka.util.KafkaMessageId in project kafka-spout by HolmesNL.

the class KafkaSpout method nextTuple.

@Override
public void nextTuple() {
    // see class documentation for implementation note on the rationale behind this condition
    if (!_queue.isEmpty() || (_inProgress.isEmpty() && fillBuffer())) {
        final KafkaMessageId nextId = _queue.poll();
        if (nextId != null) {
            final byte[] message = _inProgress.get(nextId);
            // the next id from buffer should correspond to a message in the pending map
            if (message == null) {
                throw new IllegalStateException("no pending message for next id " + nextId);
            }
            // use specified scheme to deserialize messages (single-field Values by default)
            _collector.emit(_serializationScheme.deserialize(wrap(message)), nextId);
            LOG.debug("emitted kafka message id {} ({} bytes payload)", nextId, message.length);
        }
    }
}
Also used : KafkaMessageId(nl.minvenj.nfi.storm.kafka.util.KafkaMessageId)

Example 18 with KafkaMessageId

use of nl.minvenj.nfi.storm.kafka.util.KafkaMessageId in project kafka-spout by HolmesNL.

the class KafkaSpoutBufferBehaviourTest method testAck.

@Test
public void testAck() {
    final KafkaMessageId id = new KafkaMessageId(1, 1234);
    _subject._queue.add(id);
    _subject._inProgress.put(id, new byte[0]);
    _subject.nextTuple();
    // verify that the message left buffer but not pending
    assertTrue(_subject._queue.isEmpty());
    assertTrue(_subject._inProgress.containsKey(id));
    _subject.ack(id);
    // verify that the buffer is still empty and the key is no longer in pending
    assertTrue(_subject._queue.isEmpty());
    assertFalse(_subject._inProgress.containsKey(id));
    // verify that a non-KafkaMessageId argument is ignored
    final SortedMap<KafkaMessageId, byte[]> spy = spy(_subject._inProgress);
    _subject.ack(new Object());
    verifyNoMoreInteractions(spy);
}
Also used : KafkaMessageId(nl.minvenj.nfi.storm.kafka.util.KafkaMessageId) Test(org.junit.Test)

Example 19 with KafkaMessageId

use of nl.minvenj.nfi.storm.kafka.util.KafkaMessageId in project kafka-spout by HolmesNL.

the class KafkaSpoutBufferBehaviourTest method testRefuseRefillOnNonEmptyBoth.

@Test(expected = IllegalStateException.class)
public void testRefuseRefillOnNonEmptyBoth() {
    final KafkaMessageId id = new KafkaMessageId(1, 1234);
    _subject._queue.add(id);
    _subject._inProgress.put(id, new byte[0]);
    _subject.fillBuffer();
}
Also used : KafkaMessageId(nl.minvenj.nfi.storm.kafka.util.KafkaMessageId) Test(org.junit.Test)

Example 20 with KafkaMessageId

use of nl.minvenj.nfi.storm.kafka.util.KafkaMessageId in project kafka-spout by HolmesNL.

the class KafkaSpoutBufferBehaviourTest method testFail.

@Test
public void testFail() {
    final KafkaMessageId id = new KafkaMessageId(1, 1234);
    _subject._queue.add(id);
    _subject._inProgress.put(id, new byte[0]);
    _subject.nextTuple();
    // verify that the message left buffer but not pending
    assertTrue(_subject._queue.isEmpty());
    assertTrue(_subject._inProgress.containsKey(id));
    _subject.fail(id);
    // verify that the buffer is no longer empty and id is still pending
    assertFalse(_subject._queue.isEmpty());
    assertTrue(_subject._inProgress.containsKey(id));
    _subject.nextTuple();
    // verify that the buffer is once again empty and the id has been emitted twice
    assertTrue(_subject._queue.isEmpty());
    verify(_subject._collector, times(2)).emit(any(Values.class), eq(id));
    // verify that a non-KafkaMessageId argument is ignored
    final SortedMap<KafkaMessageId, byte[]> spy = spy(_subject._inProgress);
    _subject.fail(new Object());
    verifyNoMoreInteractions(spy);
}
Also used : KafkaMessageId(nl.minvenj.nfi.storm.kafka.util.KafkaMessageId) Values(org.apache.storm.tuple.Values) Test(org.junit.Test)

Aggregations

KafkaMessageId (nl.minvenj.nfi.storm.kafka.util.KafkaMessageId)22 Test (org.junit.Test)18 Map (java.util.Map)4 List (java.util.List)3 FailHandler (nl.minvenj.nfi.storm.kafka.fail.FailHandler)3 ReliableFailHandler (nl.minvenj.nfi.storm.kafka.fail.ReliableFailHandler)3 UnreliableFailHandler (nl.minvenj.nfi.storm.kafka.fail.UnreliableFailHandler)3 SpoutOutputCollector (org.apache.storm.spout.SpoutOutputCollector)3 TopologyContext (org.apache.storm.task.TopologyContext)3 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 SortedMap (java.util.SortedMap)1 ConsumerTimeoutException (kafka.consumer.ConsumerTimeoutException)1 ConsumerConnector (kafka.javaapi.consumer.ConsumerConnector)1 InvalidMessageException (kafka.message.InvalidMessageException)1 ConfigUtils.createFailHandlerFromString (nl.minvenj.nfi.storm.kafka.util.ConfigUtils.createFailHandlerFromString)1 Values (org.apache.storm.tuple.Values)1