コード例 #1
0
ファイル: test_kafka.py プロジェクト: zjureel/flink
    def _check_specified_offsets_initializer(
            self,
            source: KafkaSource,
            offsets: Dict[KafkaTopicPartition, int],
            reset_strategy: KafkaOffsetResetStrategy,
            is_start: bool = True):
        if is_start:
            field_name = 'startingOffsetsInitializer'
        else:
            field_name = 'stoppingOffsetsInitializer'
        offsets_initializer = get_field_value(source.get_java_function(),
                                              field_name)
        self.assertEqual(
            offsets_initializer.getClass().getCanonicalName(),
            'org.apache.flink.connector.kafka.source.enumerator.initializer'
            '.SpecifiedOffsetsInitializer')

        initial_offsets = get_field_value(offsets_initializer,
                                          'initialOffsets')
        self.assertTrue(
            is_instance_of(initial_offsets,
                           get_gateway().jvm.java.util.Map))
        self.assertEqual(initial_offsets.size(), len(offsets))
        for j_topic_partition in initial_offsets:
            topic_partition = KafkaTopicPartition(
                j_topic_partition.topic(), j_topic_partition.partition())
            self.assertIsNotNone(offsets.get(topic_partition))
            self.assertEqual(initial_offsets[j_topic_partition],
                             offsets[topic_partition])

        offset_reset_strategy = get_field_value(offsets_initializer,
                                                'offsetResetStrategy')
        self.assertTrue(
            offset_reset_strategy.equals(
                reset_strategy._to_j_offset_reset_strategy()))
コード例 #2
0
ファイル: test_kafka.py プロジェクト: zjureel/flink
    def _check_reader_handled_offsets_initializer(
            self,
            source: KafkaSource,
            offset: int,
            reset_strategy: KafkaOffsetResetStrategy,
            is_start: bool = True):
        if is_start:
            field_name = 'startingOffsetsInitializer'
        else:
            field_name = 'stoppingOffsetsInitializer'
        offsets_initializer = get_field_value(source.get_java_function(),
                                              field_name)
        self.assertEqual(
            offsets_initializer.getClass().getCanonicalName(),
            'org.apache.flink.connector.kafka.source.enumerator.initializer'
            '.ReaderHandledOffsetsInitializer')

        starting_offset = get_field_value(offsets_initializer,
                                          'startingOffset')
        self.assertEqual(starting_offset, offset)

        offset_reset_strategy = get_field_value(offsets_initializer,
                                                'offsetResetStrategy')
        self.assertTrue(
            offset_reset_strategy.equals(
                reset_strategy._to_j_offset_reset_strategy()))