def test_group_protocols(coordinator): # Requires a subscription try: coordinator.group_protocols() except AssertionError: pass else: assert False, 'Exception not raised when expected' coordinator._subscription.subscribe(topics=['foobar']) assert coordinator.group_protocols() == [ ('range', ConsumerProtocolMemberMetadata(RangePartitionAssignor.version, ['foobar'], b'')), ('roundrobin', ConsumerProtocolMemberMetadata(RoundRobinPartitionAssignor.version, ['foobar'], b'')), ]
def build_metadata(topics, member_assignment_partitions, generation=-1): partitions_by_topic = defaultdict(list) for topic_partition in member_assignment_partitions: partitions_by_topic[topic_partition.topic].append( topic_partition.partition) data = StickyAssignorUserDataV1(six.viewitems(partitions_by_topic), generation) user_data = data.encode() return ConsumerProtocolMemberMetadata(StickyPartitionAssignor.version, list(topics), user_data)
def metadata(self, topics) -> ConsumerProtocolMemberMetadata: """ Return an ConsumerProtocolMemberMetadata with version, topics in list, and assignors_data as bytes Args: topics : list of topics Returns: ConsumerProtocolMemberMetadata """ return ConsumerProtocolMemberMetadata(self.version, list(topics), self.assignors_data)
def test_perform_assignment(mocker, coordinator): member_metadata = { 'member-foo': ConsumerProtocolMemberMetadata(0, ['foo1'], b''), 'member-bar': ConsumerProtocolMemberMetadata(0, ['foo1'], b'') } assignments = { 'member-foo': ConsumerProtocolMemberAssignment(0, [('foo1', [0])], b''), 'member-bar': ConsumerProtocolMemberAssignment(0, [('foo1', [1])], b'') } mocker.patch.object(RoundRobinPartitionAssignor, 'assign') RoundRobinPartitionAssignor.assign.return_value = assignments ret = coordinator._perform_assignment( 'member-foo', 'roundrobin', [(member, metadata.encode()) for member, metadata in member_metadata.items()]) assert RoundRobinPartitionAssignor.assign.call_count == 1 RoundRobinPartitionAssignor.assign.assert_called_with( coordinator._client.cluster, member_metadata) assert ret == assignments
def metadata(cls, topics): if cls.member_assignment is None: log.debug("No member assignment available") user_data = b"" else: log.debug( "Member assignment is available, generating the metadata: generation {}" .format(cls.generation)) partitions_by_topic = defaultdict(list) for (topic_partition) in cls.member_assignment: # pylint: disable=not-an-iterable partitions_by_topic[topic_partition.topic].append( topic_partition.partition) data = StickyAssignorUserDataV1(six.iteritems(partitions_by_topic), cls.generation) user_data = data.encode() return ConsumerProtocolMemberMetadata(cls.version, list(topics), user_data)
def metadata(self, topics: Set[str]) -> ConsumerProtocolMemberMetadata: return ConsumerProtocolMemberMetadata(self.version, list(topics), self._metadata.dumps())
def metadata(cls, topics): return ConsumerProtocolMemberMetadata(cls.version, list(topics), b'')
def metadata(self, topics): return ConsumerProtocolMemberMetadata(self.version, list(topics), self.assignors_data)