示例#1
0
    def _setup_error_after_data(self):
        subscriptions = SubscriptionState(loop=self.loop)
        client = AIOKafkaClient(
            loop=self.loop,
            bootstrap_servers=[])
        fetcher = Fetcher(client, subscriptions, loop=self.loop)
        tp1 = TopicPartition('some_topic', 0)
        tp2 = TopicPartition('some_topic', 1)

        subscriptions.subscribe(set(["some_topic"]))
        subscriptions.assign_from_subscribed({tp1, tp2})
        assignment = subscriptions.subscription.assignment
        subscriptions.seek(tp1, 0)
        subscriptions.seek(tp2, 0)

        # Add some data
        messages = [ConsumerRecord(
            topic="some_topic", partition=1, offset=0, timestamp=0,
            timestamp_type=0, key=None, value=b"some", checksum=None,
            serialized_key_size=0, serialized_value_size=4)]
        fetcher._records[tp2] = FetchResult(
            tp2, assignment=assignment, loop=self.loop,
            message_iterator=iter(messages), backoff=0,
            fetch_offset=0)
        # Add some error
        fetcher._records[tp1] = FetchError(
            loop=self.loop, error=OffsetOutOfRangeError({}), backoff=0)
        return fetcher, tp1, tp2, messages
示例#2
0
    def _setup_error_after_data(self):
        subscriptions = SubscriptionState('latest')
        client = AIOKafkaClient(
            loop=self.loop,
            bootstrap_servers=[])
        fetcher = Fetcher(client, subscriptions, loop=self.loop)
        tp1 = TopicPartition('some_topic', 0)
        tp2 = TopicPartition('some_topic', 1)

        state = TopicPartitionState()
        state.seek(0)
        subscriptions.assignment[tp1] = state
        state = TopicPartitionState()
        state.seek(0)
        subscriptions.assignment[tp2] = state
        subscriptions.needs_partition_assignment = False

        # Add some data
        messages = [ConsumerRecord(
            topic="some_topic", partition=1, offset=0, timestamp=0,
            timestamp_type=0, key=None, value=b"some", checksum=None,
            serialized_key_size=0, serialized_value_size=4)]
        fetcher._records[tp2] = FetchResult(
            tp2, subscriptions=subscriptions, loop=self.loop,
            records=iter(messages), backoff=0)
        # Add some error
        fetcher._records[tp1] = FetchError(
            loop=self.loop, error=OffsetOutOfRangeError({}), backoff=0)
        return fetcher, tp1, tp2, messages
示例#3
0
def test_fetch_result_and_error(loop):
    # Add some data
    messages = [
        ConsumerRecord(topic="some_topic",
                       partition=1,
                       offset=0,
                       timestamp=0,
                       timestamp_type=0,
                       key=None,
                       value=b"some",
                       checksum=None,
                       serialized_key_size=0,
                       serialized_value_size=4)
    ]
    result = FetchResult(TopicPartition("test", 0),
                         assignment=mock.Mock(),
                         loop=loop,
                         message_iterator=iter(messages),
                         backoff=0,
                         fetch_offset=0)
    assert repr(result) == "<FetchResult position=0>"
    error = FetchError(loop=loop, error=OffsetOutOfRangeError({}), backoff=0)

    # Python3.7 got rid of trailing comma in exceptions, which makes the line
    # diffrent between 3.6 and 3.7.
    assert repr(error) in [
        "<FetchError error=OffsetOutOfRangeError({},)>",
        "<FetchError error=OffsetOutOfRangeError({})>"
    ]
示例#4
0
def test_fetch_result_and_error(loop):
    # Add some data
    result = FetchResult(TopicPartition("test", 0),
                         assignment=mock.Mock(),
                         partition_records=mock.Mock(next_fetch_offset=0),
                         backoff=0)

    assert repr(result) == "<FetchResult position=0>"
    error = FetchError(error=OffsetOutOfRangeError({}), backoff=0)

    # Python3.7 got rid of trailing comma in exceptions, which makes the line
    # different between 3.6 and 3.7.
    assert repr(error) in [
        "<FetchError error=OffsetOutOfRangeError({},)>",
        "<FetchError error=OffsetOutOfRangeError({})>"
    ]
示例#5
0
    def _setup_error_after_data(self):
        subscriptions = SubscriptionState()
        client = AIOKafkaClient(bootstrap_servers=[])
        fetcher = Fetcher(client, subscriptions)
        tp1 = TopicPartition('some_topic', 0)
        tp2 = TopicPartition('some_topic', 1)

        subscriptions.subscribe(set(["some_topic"]))
        subscriptions.assign_from_subscribed({tp1, tp2})
        assignment = subscriptions.subscription.assignment
        subscriptions.seek(tp1, 0)
        subscriptions.seek(tp2, 0)

        # Add some data
        messages = [
            ConsumerRecord(topic="some_topic",
                           partition=1,
                           offset=0,
                           timestamp=0,
                           timestamp_type=0,
                           key=None,
                           value=b"some",
                           checksum=None,
                           serialized_key_size=0,
                           serialized_value_size=4,
                           headers=[])
        ]
        partition_records = PartitionRecords(tp2, mock.Mock(), [], 0, None,
                                             None, False, READ_UNCOMMITTED)
        partition_records._records_iterator = iter(messages)
        fetcher._records[tp2] = FetchResult(
            tp2,
            assignment=assignment,
            partition_records=partition_records,
            backoff=0)
        # Add some error
        fetcher._records[tp1] = FetchError(error=OffsetOutOfRangeError({}),
                                           backoff=0)
        return fetcher, tp1, tp2, messages
示例#6
0
def test_fetch_result_and_error(loop):
    # Add some data
    messages = [
        ConsumerRecord(topic="some_topic",
                       partition=1,
                       offset=0,
                       timestamp=0,
                       timestamp_type=0,
                       key=None,
                       value=b"some",
                       checksum=None,
                       serialized_key_size=0,
                       serialized_value_size=4)
    ]
    result = FetchResult(TopicPartition("test", 0),
                         assignment=mock.Mock(),
                         loop=loop,
                         message_iterator=iter(messages),
                         backoff=0,
                         fetch_offset=0)
    assert repr(result) == "<FetchResult position=0>"
    error = FetchError(loop=loop, error=OffsetOutOfRangeError({}), backoff=0)
    assert repr(error) == "<FetchError error=OffsetOutOfRangeError({},)>"