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