Ejemplo n.º 1
0
    def test_generate_sibling_count(self):
        t1 = Topic('topic1', 2)
        t2 = Topic('topic2', 2)
        t3 = Topic('topic3', 1)
        p10 = create_and_attach_partition(t1, 0)
        p11 = create_and_attach_partition(t1, 1)
        p12 = create_and_attach_partition(t1, 2)
        p20 = create_and_attach_partition(t2, 0)
        p21 = create_and_attach_partition(t2, 1)
        p22 = create_and_attach_partition(t2, 2)
        p30 = create_and_attach_partition(t3, 0)
        p31 = create_and_attach_partition(t3, 1)
        b1 = create_broker('b1', [p10, p11, p20, p21, p30, p31])
        b2 = create_broker('b2', [p12, p21, p22])
        b3 = create_broker('b3', [p10, p11, p22])
        rg = ReplicationGroup('rg', set([b1, b2, b3]))

        expected = {
            b1: {b2: {t1: 1, t2: 0, t3: 2}, b3: {t1: 0, t2: 1, t3: 2}},
            b2: {b1: {t1: -1, t2: 0, t3: -2}, b3: {t1: -1, t2: 1, t3: 0}},
            b3: {b1: {t1: 0, t2: -1, t3: -2}, b2: {t1: 1, t2: -1, t3: 0}},
        }
        actual = rg.generate_sibling_distance()

        assert dict(actual) == expected
Ejemplo n.º 2
0
    def test_get_target_brokers_3(self, create_partition):
        p10 = create_partition('topic1', 0)
        p11 = create_partition('topic1', 1)
        p12 = create_partition('topic1', 2)
        p20 = create_partition('topic2', 0)
        p21 = create_partition('topic2', 1)
        p30 = create_partition('topic3', 0)
        p31 = create_partition('topic3', 1)
        b1 = create_broker('b1', [p10, p11, p20])
        b2 = create_broker('b2', [p12, p21, p30, p31])
        b3 = create_broker('b3', [])
        rg = ReplicationGroup('rg', set([b1, b2, b3]))

        over_loaded = [b1, b2]
        under_loaded = [b3]

        target = rg._get_target_brokers(
            over_loaded,
            under_loaded,
            rg.generate_sibling_distance(),
        )

        # b3 is the best broker fit because of number of partition
        # Both p10 and p11 are a good fit. p20 can't be considered because it is
        # already in b3.
        assert target == (b2, b3, p30) or target == (b2, b3, p31)
Ejemplo n.º 3
0
    def test_get_target_brokers_3(self, create_partition):
        p10 = create_partition('topic1', 0)
        p11 = create_partition('topic1', 1)
        p12 = create_partition('topic1', 2)
        p20 = create_partition('topic2', 0)
        p21 = create_partition('topic2', 1)
        p30 = create_partition('topic3', 0)
        p31 = create_partition('topic3', 1)
        b1 = create_broker('b1', [p10, p11, p20])
        b2 = create_broker('b2', [p12, p21, p30, p31])
        b3 = create_broker('b3', [])
        rg = ReplicationGroup('rg', set([b1, b2, b3]))

        over_loaded = [b1, b2]
        under_loaded = [b3]

        target = rg._get_target_brokers(
            over_loaded,
            under_loaded,
            rg.generate_sibling_distance(),
        )

        # b3 is the best broker fit because of number of partition
        # Both p10 and p11 are a good fit. p20 can't be considered because it is
        # already in b3.
        assert target == (b2, b3, p30) or target == (b2, b3, p31)
Ejemplo n.º 4
0
    def test_generate_sibling_count(self):
        t1 = Topic('topic1', 2)
        t2 = Topic('topic2', 2)
        t3 = Topic('topic3', 1)
        p10 = create_and_attach_partition(t1, 0)
        p11 = create_and_attach_partition(t1, 1)
        p12 = create_and_attach_partition(t1, 2)
        p20 = create_and_attach_partition(t2, 0)
        p21 = create_and_attach_partition(t2, 1)
        p22 = create_and_attach_partition(t2, 2)
        p30 = create_and_attach_partition(t3, 0)
        p31 = create_and_attach_partition(t3, 1)
        b1 = create_broker('b1', [p10, p11, p20, p21, p30, p31])
        b2 = create_broker('b2', [p12, p21, p22])
        b3 = create_broker('b3', [p10, p11, p22])
        rg = ReplicationGroup('rg', set([b1, b2, b3]))

        expected = {
            b1: {
                b2: {
                    t1: 1,
                    t2: 0,
                    t3: 2
                },
                b3: {
                    t1: 0,
                    t2: 1,
                    t3: 2
                }
            },
            b2: {
                b1: {
                    t1: -1,
                    t2: 0,
                    t3: -2
                },
                b3: {
                    t1: -1,
                    t2: 1,
                    t3: 0
                }
            },
            b3: {
                b1: {
                    t1: 0,
                    t2: -1,
                    t3: -2
                },
                b2: {
                    t1: 1,
                    t2: -1,
                    t3: 0
                }
            },
        }
        actual = rg.generate_sibling_distance()

        assert dict(actual) == expected
Ejemplo n.º 5
0
    def test__get_target_brokers_1(self, create_partition):
        p10 = create_partition('topic1', 0, replication_factor=2)
        p11 = create_partition('topic1', 1, replication_factor=2)
        p20 = create_partition('topic2', 0, replication_factor=2)
        p30 = create_partition('topic3', 0)
        b1 = create_broker('b1', [p10, p11, p20, p30])
        b2 = create_broker('b2', [p10, p20])
        rg = ReplicationGroup('rg', set([b1, b2]))

        over_loaded = [b1]
        under_loaded = [b2]
        target = rg._get_target_brokers(
            over_loaded,
            under_loaded,
            rg.generate_sibling_distance(),
        )

        # p30 is the best fit because topic3 doesn't have any partition in
        # broker 2
        assert target == (b1, b2, p30) or target == (b1, b2, p11)
Ejemplo n.º 6
0
    def test__get_target_brokers_1(self, create_partition):
        p10 = create_partition('topic1', 0, replication_factor=2)
        p11 = create_partition('topic1', 1, replication_factor=2)
        p20 = create_partition('topic2', 0, replication_factor=2)
        p30 = create_partition('topic3', 0)
        b1 = create_broker('b1', [p10, p11, p20, p30])
        b2 = create_broker('b2', [p10, p20])
        rg = ReplicationGroup('rg', set([b1, b2]))

        over_loaded = [b1]
        under_loaded = [b2]
        target = rg._get_target_brokers(
            over_loaded,
            under_loaded,
            rg.generate_sibling_distance(),
        )

        # p30 is the best fit because topic3 doesn't have any partition in
        # broker 2
        assert target == (b1, b2, p30) or target == (b1, b2, p11)