fake admin client
FakeAdminClientImpl Class¶
Description¶
The FakeAdminClientImpl class is a mock implementation of the Confluent Kafka AdminClient for testing purposes. It utilizes an in-memory storage (KafkaStore) to simulate Kafka behavior. This class includes methods for managing partitions, topics, and other administrative actions.
Properties¶
- kafka: An instance of the
KafkaStoreclass for in-memory storage. - clean (bool): A flag indicating whether to start with a clean slate.
Methods¶
__init__(self, clean: bool = True, *args, **kwargs)¶
- Description: Initializes the
FakeAdminClientImpl. - Parameters:
clean (bool): Flag indicating whether to start with a clean slate.args: Additional arguments (unused).kwargs: Additional keyword arguments (unused).
create_partitions(self, partitions: list[NewPartitions])¶
- Description: Creates partitions in the in-memory Kafka store.
- Parameters:
partitions (List[NewPartitions]): List of partition objects to be created.
create_partition(self, partition: NewPartitions)¶
- Description: Creates a single partition in the in-memory Kafka store.
- Parameters:
partition (NewPartitions): The partition object to be created.
create_topics(self, topics: list[NewTopic])¶
- Description: Creates topics in the in-memory Kafka store.
- Parameters:
topics (List[NewTopic]): List of topic objects to be created.
create_topic(self, topic: NewTopic)¶
- Description: Creates a single topic in the in-memory Kafka store.
- Parameters:
topic (NewTopic): The topic object to be created.
delete_topics(self, topics, future=None, request_timeout=None, operation_timeout=None)¶
- Description: Deletes topics from the in-memory Kafka store.
- Parameters:
topics: Topics to be deleted.future: Unused parameter (for compatibility).request_timeout: Unused parameter (for compatibility).operation_timeout: Unused parameter (for compatibility).
delete_topic(self, topic: NewTopic)¶
- Description: Deletes a single topic from the in-memory Kafka store.
- Parameters:
topic (NewTopic): The topic object to be deleted.
describe_acls(self, acl_binding_filter, future, request_timeout=None)¶
- Description: Describes ACLs (unsupported in mockafka).
- Parameters:
acl_binding_filter: Unused parameter (unsupported).future: Unused parameter (unsupported).request_timeout: Unused parameter (unsupported).
describe_configs(self, resources, future, request_timeout=None, broker=None)¶
- Description: Describes configurations (unsupported in mockafka).
- Parameters:
resources: Unused parameter (unsupported).future: Unused parameter (unsupported).request_timeout: Unused parameter (unsupported).broker: Unused parameter (unsupported).
delete_acls(self, acl_binding_filters, future, request_timeout=None)¶
- Description: Deletes ACLs (unsupported in mockafka).
- Parameters:
acl_binding_filters: Unused parameter (unsupported).future: Unused parameter (unsupported).request_timeout: Unused parameter (unsupported).
alter_configs(self, *args, **kwargs)¶
- Description: Alters configurations (unsupported in mockafka).
- Parameters:
args: Unused parameter (unsupported).kwargs: Unused parameter (unsupported).
create_acls(self, *args, **kwargs)¶
- Description: Creates ACLs (unsupported in mockafka).
- Parameters:
args: Unused parameter (unsupported).kwargs: Unused parameter (unsupported).
list_groups(self, group=None, *args, **kwargs)¶
- Description: Lists consumer groups (unsupported in mockafka).
- Parameters:
group: Unused parameter (unsupported).args: Unused parameter (unsupported).kwargs: Unused parameter (unsupported).
list_topics(self, topic=None, *args, **kwargs) -> ClusterMetadata¶
- Description: Lists topics and returns
ClusterMetadata. - Parameters:
topic: Unused parameter (for compatibility).args: Unused parameter (for compatibility).kwargs: Unused parameter (for compatibility).- Returns: (ClusterMetadata) Metadata of the listed topics.
poll(self, timeout=None)¶
- Description: Polls for events (unsupported in mockafka).
- Parameters:
timeout: Unused parameter (unsupported).
__len__(self, *args, **kwargs)¶
- Description: Gets the length of the Kafka store (not implemented).
- Parameters:
args: Unused parameters (not implemented).kwargs: Unused parameters (not implemented).
Example Usage¶
from mockafka.admin_client import FakeAdminClientImpl, NewTopic, NewPartitions
# Create an instance of FakeAdminClientImpl
fake_admin_client = FakeAdminClientImpl()
# Create a topic with partitions
fake_admin_client.create_topic(topic=NewTopic(topic='sample_topic', num_partitions=3))
# Delete a topic
fake_admin_client.delete_topic(topic=NewTopic(topic='sample_topic', num_partitions=3))
# List topics
topics_metadata = fake_admin_client.list_topics()
# Create partitions for a topic
fake_admin_client.create_partitions(partitions=[NewPartitions(topic='sample_topic', new_total_count=5)])