Search in sources :

Example 21 with CheckpointV2

use of org.apache.samza.checkpoint.CheckpointV2 in project samza by apache.

the class TestKafkaCheckpointManager method testWriteCheckpointV2.

@Test
public void testWriteCheckpointV2() {
    setupSystemFactory(config());
    KafkaCheckpointManager kafkaCheckpointManager = buildKafkaCheckpointManager(true, config());
    kafkaCheckpointManager.register(TASK0);
    CheckpointV2 checkpointV2 = buildCheckpointV2(INPUT_SSP0, "0");
    kafkaCheckpointManager.writeCheckpoint(TASK0, checkpointV2);
    ArgumentCaptor<OutgoingMessageEnvelope> outgoingMessageEnvelopeArgumentCaptor = ArgumentCaptor.forClass(OutgoingMessageEnvelope.class);
    verify(this.systemProducer).send(eq(TASK0.getTaskName()), outgoingMessageEnvelopeArgumentCaptor.capture());
    assertEquals(CHECKPOINT_SSP, outgoingMessageEnvelopeArgumentCaptor.getValue().getSystemStream());
    assertEquals(new KafkaCheckpointLogKey(KafkaCheckpointLogKey.CHECKPOINT_V2_KEY_TYPE, TASK0, GROUPER_FACTORY_CLASS), KAFKA_CHECKPOINT_LOG_KEY_SERDE.fromBytes((byte[]) outgoingMessageEnvelopeArgumentCaptor.getValue().getKey()));
    assertEquals(checkpointV2, CHECKPOINT_V2_SERDE.fromBytes((byte[]) outgoingMessageEnvelopeArgumentCaptor.getValue().getMessage()));
    verify(this.systemProducer).flush(TASK0.getTaskName());
}
Also used : CheckpointV2(org.apache.samza.checkpoint.CheckpointV2) OutgoingMessageEnvelope(org.apache.samza.system.OutgoingMessageEnvelope) Test(org.junit.Test)

Example 22 with CheckpointV2

use of org.apache.samza.checkpoint.CheckpointV2 in project samza by apache.

the class TestKafkaCheckpointManager method testReadCheckpointPriority.

@Test
public void testReadCheckpointPriority() throws InterruptedException {
    Config config = config(ImmutableMap.of(TaskConfig.CHECKPOINT_READ_VERSIONS, "2,1"));
    setupSystemFactory(config);
    CheckpointV2 checkpointV2 = buildCheckpointV2(INPUT_SSP0, "1");
    List<IncomingMessageEnvelope> checkpointEnvelopes = ImmutableList.of(newCheckpointV1Envelope(TASK0, buildCheckpointV1(INPUT_SSP0, "0"), "0"), newCheckpointV2Envelope(TASK0, checkpointV2, "1"));
    setupConsumer(checkpointEnvelopes);
    KafkaCheckpointManager kafkaCheckpointManager = buildKafkaCheckpointManager(true, config);
    kafkaCheckpointManager.register(TASK0);
    Checkpoint actualCheckpoint = kafkaCheckpointManager.readLastCheckpoint(TASK0);
    assertEquals(checkpointV2, actualCheckpoint);
}
Also used : CheckpointV2(org.apache.samza.checkpoint.CheckpointV2) Checkpoint(org.apache.samza.checkpoint.Checkpoint) MapConfig(org.apache.samza.config.MapConfig) Config(org.apache.samza.config.Config) JobConfig(org.apache.samza.config.JobConfig) TaskConfig(org.apache.samza.config.TaskConfig) IncomingMessageEnvelope(org.apache.samza.system.IncomingMessageEnvelope) Test(org.junit.Test)

Example 23 with CheckpointV2

use of org.apache.samza.checkpoint.CheckpointV2 in project samza by apache.

the class TestKafkaCheckpointManager method testWriteCheckpointShouldRetryFiniteTimesOnFailure.

@Test
public void testWriteCheckpointShouldRetryFiniteTimesOnFailure() {
    setupSystemFactory(config());
    doThrow(new RuntimeException("send failed")).when(this.systemProducer).send(any(), any());
    KafkaCheckpointManager kafkaCheckpointManager = buildKafkaCheckpointManager(true, config());
    kafkaCheckpointManager.register(TASK0);
    // setter for scala var MaxRetryDurationInMillis
    kafkaCheckpointManager.MaxRetryDurationInMillis_$eq(100);
    CheckpointV2 checkpointV2 = buildCheckpointV2(INPUT_SSP0, "0");
    try {
        kafkaCheckpointManager.writeCheckpoint(TASK0, checkpointV2);
        fail("Expected to throw SamzaException");
    } catch (SamzaException e) {
    // expected to get here
    }
    // one call to send which fails, then writeCheckpoint gives up
    verify(this.systemProducer).send(any(), any());
    verify(this.systemProducer, never()).flush(any());
}
Also used : CheckpointV2(org.apache.samza.checkpoint.CheckpointV2) SamzaException(org.apache.samza.SamzaException) Test(org.junit.Test)

Example 24 with CheckpointV2

use of org.apache.samza.checkpoint.CheckpointV2 in project samza by apache.

the class TestKafkaCheckpointManager method testReadMultipleCheckpointsUpgradeCheckpointVersion.

@Test
public void testReadMultipleCheckpointsUpgradeCheckpointVersion() throws InterruptedException {
    Config config = config(ImmutableMap.of(TaskConfig.CHECKPOINT_READ_VERSIONS, "2,1"));
    setupSystemFactory(config);
    KafkaCheckpointManager kafkaCheckpointManager = buildKafkaCheckpointManager(true, config);
    kafkaCheckpointManager.register(TASK0);
    kafkaCheckpointManager.register(TASK1);
    List<IncomingMessageEnvelope> checkpointEnvelopesV1 = ImmutableList.of(newCheckpointV1Envelope(TASK0, buildCheckpointV1(INPUT_SSP0, "0"), "0"), newCheckpointV1Envelope(TASK1, buildCheckpointV1(INPUT_SSP1, "0"), "1"));
    CheckpointV2 ssp0CheckpointV2 = buildCheckpointV2(INPUT_SSP0, "10");
    CheckpointV2 ssp1CheckpointV2 = buildCheckpointV2(INPUT_SSP1, "11");
    List<IncomingMessageEnvelope> checkpointEnvelopesV2 = ImmutableList.of(newCheckpointV2Envelope(TASK0, ssp0CheckpointV2, "2"), newCheckpointV2Envelope(TASK1, ssp1CheckpointV2, "3"));
    setupConsumerMultiplePoll(ImmutableList.of(checkpointEnvelopesV1, checkpointEnvelopesV2));
    assertEquals(ssp0CheckpointV2, kafkaCheckpointManager.readLastCheckpoint(TASK0));
    assertEquals(ssp1CheckpointV2, kafkaCheckpointManager.readLastCheckpoint(TASK1));
    // 2 polls for actual checkpoints, 1 final empty poll
    verify(this.systemConsumer, times(3)).poll(ImmutableSet.of(CHECKPOINT_SSP), SystemConsumer.BLOCK_ON_OUTSTANDING_MESSAGES);
}
Also used : CheckpointV2(org.apache.samza.checkpoint.CheckpointV2) MapConfig(org.apache.samza.config.MapConfig) Config(org.apache.samza.config.Config) JobConfig(org.apache.samza.config.JobConfig) TaskConfig(org.apache.samza.config.TaskConfig) IncomingMessageEnvelope(org.apache.samza.system.IncomingMessageEnvelope) Test(org.junit.Test)

Aggregations

CheckpointV2 (org.apache.samza.checkpoint.CheckpointV2)24 Test (org.junit.Test)18 HashMap (java.util.HashMap)13 Checkpoint (org.apache.samza.checkpoint.Checkpoint)13 Map (java.util.Map)12 SamzaException (org.apache.samza.SamzaException)11 File (java.io.File)10 CheckpointId (org.apache.samza.checkpoint.CheckpointId)10 ImmutableMap (com.google.common.collect.ImmutableMap)9 Collections (java.util.Collections)9 CompletableFuture (java.util.concurrent.CompletableFuture)9 TaskName (org.apache.samza.container.TaskName)9 SystemStreamPartition (org.apache.samza.system.SystemStreamPartition)9 Optional (java.util.Optional)8 CheckpointV1 (org.apache.samza.checkpoint.CheckpointV1)8 Config (org.apache.samza.config.Config)8 MapConfig (org.apache.samza.config.MapConfig)8 TaskMode (org.apache.samza.job.model.TaskMode)8 SystemStream (org.apache.samza.system.SystemStream)8 IOException (java.io.IOException)7