Ejemplo n.º 1
0
def test_assignment_change_size(assignments: Assignments):
    with pytest.raises(ValueError):
        changed = assignments.changeMaxMembers(0)

    changed = assignments.changeMaxMembers(8)
    assert changed

    changed = assignments.changeMaxMembers(8)
    assert not changed
Ejemplo n.º 2
0
    def _updateAssignments(self):
        # potentially generate new member assignments based on our `StaticConfig`
        topics = self._fetchAllTopicMetadata(self._conf.topics)

        if self._assignments is None:
            assignments = self._coord.assignments(self._meta())
        else:
            assignments = self._assignments

        # this may be the first run ever for this group so no assignments are available
        if assignments is None:
            assignments = Assignments(
                group=self._conf.group,
                maxMembers=self._conf.maxGroupSize,
                topics=topics,
                configVersion=self._conf.configVersion,
                version=0,
            )
            changed = True
        else:

            # partition counts can change outside of the configuration updates
            changed = assignments.changeTopicPartitions(topics)

            # Update the assignments if our configVersion is greater than the one
            # provided by the coordinator
            if self._conf.configVersion > assignments.configVersion:
                # may or may not cause a recalculation of the assignments
                assignments.changeMaxMembers(self._conf.maxGroupSize)

                # this must be updated though
                assignments.configVersion = self._conf.configVersion
                changed = True

        if changed:
            if assignments.version < 1:
                assignments.version = 1
            else:
                assignments.version += 1
            self._coord.updateAssignments(self._meta(), assignments)

        return assignments