Ejemplo n.º 1
0
    def test_count_siblings(self):
        t1, t1.id = sentinel.t1, 't1'
        t2, t2.id = sentinel.t2, 't2'
        p1, p3, p4 = Partition(t1, 0), Partition(t1, 1), Partition(t2, 0),

        # verify sibling count
        p_group = [p1, p4, p3]
        assert p3.count_siblings(p_group) == 2
        assert p4.count_siblings(p_group) == 1
        p_group = [p4]
        assert p1.count_siblings(p_group) == 0

        # Empty group
        p_group = []
        assert p1.count_siblings(p_group) == 0
Ejemplo n.º 2
0
 def _add_partition(topic_id, partition_id, replication_factor=1):
     if topic_id not in topics:
         topics[topic_id] = Topic(topic_id, replication_factor)
     topic = topics[topic_id]
     partition = Partition(topic, partition_id)
     topic.add_partition(partition)
     return partition
Ejemplo n.º 3
0
    def test_followers_2(self):
        # Case:2 No-followers
        mock_topic = sentinel.t1
        mock_topic.id = 't1'
        p2 = Partition(mock_topic, 0, [sentinel.r1])

        assert p2.followers == []
Ejemplo n.º 4
0
 def partition(self):
     mock_topic = sentinel.t1
     mock_topic.id = 't1'
     return Partition(
         mock_topic,
         0,
         [sentinel.r1, sentinel.r2],
     )
Ejemplo n.º 5
0
    def test_count_siblings(self):
        t1, t1.id = sentinel.t1, 't1'
        t2, t2.id = sentinel.t2, 't2'
        p1, p3, p4 = Partition(t1, 0), Partition(t1, 1), Partition(t2, 0),

        # verify sibling count
        p_group = [p1, p4, p3]
        assert p3.count_siblings(p_group) == 2
        assert p4.count_siblings(p_group) == 1
        p_group = [p4]
        assert p1.count_siblings(p_group) == 0

        # Empty group
        p_group = []
        assert p1.count_siblings(p_group) == 0
Ejemplo n.º 6
0
 def partition(self):
     mock_topic = Mock(spec=Topic, id='t1')
     return Partition(mock_topic, 0)
Ejemplo n.º 7
0
 def test_size_negative(self):
     mock_topic = sentinel.t1
     mock_topic.id = 't1'
     with pytest.raises(InvalidPartitionMeasurementError):
         Partition(mock_topic, 0, [sentinel.r1, sentinel.r2], 1, -1)
Ejemplo n.º 8
0
def create_and_attach_partition(topic, partition_id):
    partition = Partition(topic, partition_id)
    topic.add_partition(partition)
    return partition