use of org.apache.samza.checkpoint.CheckpointV1 in project samza by apache.
the class TestKafkaCheckpointManager method testConsumerStopsAfterInitialRead.
@Test
public void testConsumerStopsAfterInitialRead() throws Exception {
setupSystemFactory(config());
CheckpointV1 checkpointV1 = buildCheckpointV1(INPUT_SSP0, "0");
setupConsumer(ImmutableList.of(newCheckpointV1Envelope(TASK0, checkpointV1, "0")));
KafkaCheckpointManager kafkaCheckpointManager = buildKafkaCheckpointManager(true, config());
kafkaCheckpointManager.register(TASK0);
assertEquals(checkpointV1, kafkaCheckpointManager.readLastCheckpoint(TASK0));
// 1 call to get actual checkpoints, 1 call for empty poll to signal done reading
verify(this.systemConsumer, times(2)).poll(ImmutableSet.of(CHECKPOINT_SSP), SystemConsumer.BLOCK_ON_OUTSTANDING_MESSAGES);
verify(this.systemConsumer).stop();
// reading checkpoint again should not read more messages from the consumer
assertEquals(checkpointV1, kafkaCheckpointManager.readLastCheckpoint(TASK0));
verifyNoMoreInteractions(this.systemConsumer);
}
use of org.apache.samza.checkpoint.CheckpointV1 in project samza by apache.
the class TestKafkaCheckpointManager method testWriteCheckpointShouldRecreateSystemProducerOnFailure.
@Test
public void testWriteCheckpointShouldRecreateSystemProducerOnFailure() {
setupSystemFactory(config());
SystemProducer secondKafkaProducer = mock(SystemProducer.class);
// override default mock behavior to return a second producer on the second call to create a producer
when(this.systemFactory.getProducer(CHECKPOINT_SYSTEM, config(), this.metricsRegistry, KafkaCheckpointManager.class.getSimpleName())).thenReturn(this.systemProducer, secondKafkaProducer);
// first producer throws an exception on flush
doThrow(new RuntimeException("flush failed")).when(this.systemProducer).flush(TASK0.getTaskName());
KafkaCheckpointManager kafkaCheckpointManager = buildKafkaCheckpointManager(true, config());
kafkaCheckpointManager.register(TASK0);
CheckpointV1 checkpointV1 = buildCheckpointV1(INPUT_SSP0, "0");
kafkaCheckpointManager.writeCheckpoint(TASK0, checkpointV1);
// first producer should be stopped
verify(this.systemProducer).stop();
// register and start the second producer
verify(secondKafkaProducer).register(TASK0.getTaskName());
verify(secondKafkaProducer).start();
// check that the second producer was given the message to send out
ArgumentCaptor<OutgoingMessageEnvelope> outgoingMessageEnvelopeArgumentCaptor = ArgumentCaptor.forClass(OutgoingMessageEnvelope.class);
verify(secondKafkaProducer).send(eq(TASK0.getTaskName()), outgoingMessageEnvelopeArgumentCaptor.capture());
assertEquals(CHECKPOINT_SSP, outgoingMessageEnvelopeArgumentCaptor.getValue().getSystemStream());
assertEquals(new KafkaCheckpointLogKey(KafkaCheckpointLogKey.CHECKPOINT_V1_KEY_TYPE, TASK0, GROUPER_FACTORY_CLASS), KAFKA_CHECKPOINT_LOG_KEY_SERDE.fromBytes((byte[]) outgoingMessageEnvelopeArgumentCaptor.getValue().getKey()));
assertEquals(checkpointV1, CHECKPOINT_V1_SERDE.fromBytes((byte[]) outgoingMessageEnvelopeArgumentCaptor.getValue().getMessage()));
verify(secondKafkaProducer).flush(TASK0.getTaskName());
}
Aggregations