def test_set_offsets_offset_to_delta_all_topics( topic: str, interactive_cli_runner, producer: ConfluenceProducer, consumer_group: str, consumergroup_controller: ConsumerGroupController, ): produce_text_test_messages(producer=producer, topic_name=topic, amount=10) consumergroup_controller.commit_offsets( consumer_group, [TopicPartition(topic=topic, partition=0, offset=10)]) consumergroup_desc_before = consumergroup_controller.get_consumer_group( consumer_id=consumer_group).describe(partitions=True) interactive_cli_runner.invoke( esque, args=["set", "offsets", consumer_group, "--offset-by-delta", "-2"], input="y\n", catch_exceptions=False) # Check assertions: consumergroup_desc_after = consumergroup_controller.get_consumer_group( consumer_id=consumer_group).describe(partitions=True) assert consumergroup_desc_before["offsets"][topic][0][ "consumer_offset"] == 10 assert consumergroup_desc_after["offsets"][topic][0][ "consumer_offset"] == 8
def test_edit_offsets( monkeypatch: MonkeyPatch, interactive_cli_runner, topic: str, producer: ConfluenceProducer, consumer_group: str, consumergroup_controller: ConsumerGroupController, ): produce_text_test_messages(producer=producer, topic_name=topic, amount=10) consumergroup_controller.commit_offsets(consumer_group, [TopicPartition(topic=topic, partition=0, offset=10)]) consumergroup_desc_before = consumergroup_controller.get_consumer_group(consumer_id=consumer_group).describe( partitions=True ) offset_config = {"offsets": [{"topic": topic, "partition": 0, "offset": 1}]} def mock_edit_function(text=None, editor=None, env=None, require_save=None, extension=None, filename=None): return yaml.dump(offset_config, default_flow_style=False) monkeypatch.setattr(click, "edit", mock_edit_function) result = interactive_cli_runner.invoke( esque, args=["edit", "offsets", consumer_group, "-t", topic], input="y\n", catch_exceptions=False ) assert result.exit_code == 0 # Check assertions: consumergroup_desc_after = consumergroup_controller.get_consumer_group(consumer_id=consumer_group).describe( partitions=True ) assert consumergroup_desc_before["offsets"][topic][0]["consumer_offset"] == 10 assert consumergroup_desc_after["offsets"][topic][0]["consumer_offset"] == 1
def test_consumer_group_offset_set( consumergroup_controller: ConsumerGroupController, filled_topic: Topic): topic = TopicPartition(topic=filled_topic.name, offset=5, partition=0) consumer_group_name = "non_existing" consumergroup_controller.commit_offsets(consumer_group_name, [topic]) consumer_group: ConsumerGroup = consumergroup_controller.get_consumer_group( consumer_group_name) offsets = consumer_group.get_offsets() assert offsets[filled_topic.name][0] == 5
def test_set_offsets_offset_from_group( topic: str, interactive_cli_runner, producer: ConfluenceProducer, consumer_group: str, target_consumer_group: str, consumergroup_controller: ConsumerGroupController, ): produce_text_test_messages(producer=producer, topic_name=topic, amount=10) consumergroup_controller.commit_offsets( consumer_group, [TopicPartition(topic=topic, partition=0, offset=10)]) consumergroup_desc_before = consumergroup_controller.get_consumer_group( consumer_id=consumer_group).describe(partitions=True) interactive_cli_runner.invoke( esque, args=["set", "offsets", consumer_group, "--offset-by-delta", "-2"], input="y\n", catch_exceptions=False) consumergroup_desc_after = consumergroup_controller.get_consumer_group( consumer_id=consumer_group).describe(partitions=True) # create a new consumer in a separate group and consume just one message consumergroup_controller.commit_offsets( target_consumer_group, [TopicPartition(topic=topic, partition=0, offset=1)]) interactive_cli_runner.invoke( esque, args=[ "set", "offsets", target_consumer_group, "--offset-from-group", consumer_group ], input="y\n", catch_exceptions=False, ) consumergroup_desc_target = consumergroup_controller.get_consumer_group( consumer_id=target_consumer_group).describe(partitions=True) assert consumergroup_desc_before["offsets"][topic][0][ "consumer_offset"] == 10 assert consumergroup_desc_after["offsets"][topic][0][ "consumer_offset"] == 8 assert consumergroup_desc_target["offsets"][topic][0][ "consumer_offset"] == 8
def test_set_offsets_offset_to_timestamp_value( topic: str, interactive_cli_runner, producer: ConfluenceProducer, consumer_group: str, consumergroup_controller: ConsumerGroupController, ): messages = produce_text_test_messages(producer=producer, topic_name=topic, amount=10) consumergroup_controller.commit_offsets( consumer_group, [TopicPartition(topic=topic, partition=0, offset=10)]) consumergroup_desc_before = consumergroup_controller.get_consumer_group( consumer_id=consumer_group).describe(partitions=True) fifth_message = messages[4] timestamp = fifth_message.timestamp dt = pendulum.from_timestamp(round(timestamp / 1000) - 1) interactive_cli_runner.invoke( esque, args=[ "set", "offsets", consumer_group, "--topic-name", topic, "--offset-to-timestamp", dt.format("YYYY-MM-DDTHH:mm:ss"), ], input="y\n", catch_exceptions=False, ) # Check assertions: consumergroup_desc_after = consumergroup_controller.get_consumer_group( consumer_id=consumer_group).describe(partitions=True) assert consumergroup_desc_before["offsets"][topic][0][ "consumer_offset"] == 10 assert consumergroup_desc_after["offsets"][topic][0][ "consumer_offset"] == 4