use of org.apache.samza.system.kafka.KafkaSystemAdmin.KafkaStartpointToOffsetResolver in project samza by apache.
the class TestKafkaSystemAdminJava method testStartpointUpcomingVisitorShouldResolveToCorrectOffset.
@Test
public void testStartpointUpcomingVisitorShouldResolveToCorrectOffset() {
// Define dummy variables for testing.
final KafkaConsumer consumer = Mockito.mock(KafkaConsumer.class);
final KafkaStartpointToOffsetResolver kafkaStartpointToOffsetResolver = new KafkaStartpointToOffsetResolver(consumer);
final StartpointUpcoming testStartpointSpecific = new StartpointUpcoming();
// Mock the consumer interactions.
Mockito.when(consumer.endOffsets(ImmutableSet.of(TEST_TOPIC_PARTITION))).thenReturn(ImmutableMap.of(TEST_TOPIC_PARTITION, 10L));
// Invoke the consumer with startpoint.
String resolvedOffset = kafkaStartpointToOffsetResolver.visit(TEST_SYSTEM_STREAM_PARTITION, testStartpointSpecific);
Assert.assertEquals(TEST_OFFSET, resolvedOffset);
}
use of org.apache.samza.system.kafka.KafkaSystemAdmin.KafkaStartpointToOffsetResolver in project samza by apache.
the class TestKafkaSystemAdminJava method testStartpointOldestVisitorShouldResolveToCorrectOffset.
@Test
public void testStartpointOldestVisitorShouldResolveToCorrectOffset() {
// Define dummy variables for testing.
final KafkaConsumer consumer = Mockito.mock(KafkaConsumer.class);
final KafkaStartpointToOffsetResolver kafkaStartpointToOffsetResolver = new KafkaStartpointToOffsetResolver(consumer);
final StartpointOldest testStartpointSpecific = new StartpointOldest();
// Mock the consumer interactions.
Mockito.when(consumer.beginningOffsets(ImmutableSet.of(TEST_TOPIC_PARTITION))).thenReturn(ImmutableMap.of(TEST_TOPIC_PARTITION, 10L));
// Invoke the consumer with startpoint.
String resolvedOffset = kafkaStartpointToOffsetResolver.visit(TEST_SYSTEM_STREAM_PARTITION, testStartpointSpecific);
Assert.assertEquals(TEST_OFFSET, resolvedOffset);
}
use of org.apache.samza.system.kafka.KafkaSystemAdmin.KafkaStartpointToOffsetResolver in project samza by apache.
the class TestKafkaSystemAdminJava method testStartpointTimestampVisitorShouldResolveToCorrectOffsetWhenTimestampDoesNotExist.
@Test
public void testStartpointTimestampVisitorShouldResolveToCorrectOffsetWhenTimestampDoesNotExist() {
final KafkaConsumer consumer = Mockito.mock(KafkaConsumer.class);
final KafkaStartpointToOffsetResolver kafkaStartpointToOffsetResolver = new KafkaStartpointToOffsetResolver(consumer);
final StartpointTimestamp startpointTimestamp = new StartpointTimestamp(0L);
final Map<TopicPartition, OffsetAndTimestamp> offsetForTimesResult = new HashMap<>();
offsetForTimesResult.put(TEST_TOPIC_PARTITION, null);
// Mock the consumer interactions.
Mockito.when(consumer.offsetsForTimes(ImmutableMap.of(TEST_TOPIC_PARTITION, 0L))).thenReturn(offsetForTimesResult);
Mockito.when(consumer.endOffsets(ImmutableSet.of(TEST_TOPIC_PARTITION))).thenReturn(ImmutableMap.of(TEST_TOPIC_PARTITION, 10L));
String resolvedOffset = kafkaStartpointToOffsetResolver.visit(TEST_SYSTEM_STREAM_PARTITION, startpointTimestamp);
Assert.assertEquals(TEST_OFFSET, resolvedOffset);
// Mock verifications.
Mockito.verify(consumer).offsetsForTimes(ImmutableMap.of(TEST_TOPIC_PARTITION, 0L));
}
use of org.apache.samza.system.kafka.KafkaSystemAdmin.KafkaStartpointToOffsetResolver in project samza by apache.
the class TestKafkaSystemAdminJava method testStartpointSpecificOffsetVisitorShouldResolveToCorrectOffset.
@Test
public void testStartpointSpecificOffsetVisitorShouldResolveToCorrectOffset() {
final KafkaConsumer consumer = Mockito.mock(KafkaConsumer.class);
final KafkaStartpointToOffsetResolver kafkaStartpointToOffsetResolver = new KafkaStartpointToOffsetResolver(consumer);
final StartpointSpecific testStartpointSpecific = new StartpointSpecific(TEST_OFFSET);
// Invoke the consumer with startpoint.
String resolvedOffset = kafkaStartpointToOffsetResolver.visit(TEST_SYSTEM_STREAM_PARTITION, testStartpointSpecific);
Assert.assertEquals(TEST_OFFSET, resolvedOffset);
}
use of org.apache.samza.system.kafka.KafkaSystemAdmin.KafkaStartpointToOffsetResolver in project samza by apache.
the class TestKafkaSystemAdminJava method testStartpointTimestampVisitorShouldResolveToCorrectOffset.
@Test
public void testStartpointTimestampVisitorShouldResolveToCorrectOffset() {
// Define dummy variables for testing.
final Long testTimeStamp = 10L;
final KafkaConsumer consumer = Mockito.mock(KafkaConsumer.class);
final KafkaStartpointToOffsetResolver kafkaStartpointToOffsetResolver = new KafkaStartpointToOffsetResolver(consumer);
final StartpointTimestamp startpointTimestamp = new StartpointTimestamp(testTimeStamp);
final Map<TopicPartition, OffsetAndTimestamp> offsetForTimesResult = ImmutableMap.of(TEST_TOPIC_PARTITION, new OffsetAndTimestamp(Long.valueOf(TEST_OFFSET), testTimeStamp));
// Mock the consumer interactions.
Mockito.when(consumer.offsetsForTimes(ImmutableMap.of(TEST_TOPIC_PARTITION, testTimeStamp))).thenReturn(offsetForTimesResult);
Mockito.when(consumer.position(TEST_TOPIC_PARTITION)).thenReturn(Long.valueOf(TEST_OFFSET));
String resolvedOffset = kafkaStartpointToOffsetResolver.visit(TEST_SYSTEM_STREAM_PARTITION, startpointTimestamp);
Assert.assertEquals(TEST_OFFSET, resolvedOffset);
}
Aggregations