コード例 #1
0
ファイル: test_partitioner.py プロジェクト: ciena/afkak
    def test_partition(self):
        parts = [1, 2, 3, 4, 5, 6]
        p = RoundRobinPartitioner(None, parts)

        for part in parts:
            self.assertEqual(part, p.partition("key", parts))

        for part in parts:
            self.assertEqual(part, p.partition("key", parts))

        # Make sure updates work
        parts = [1, 2, 3, 4, 5, 6, 7, 8, 9]
        for part in parts:
            self.assertEqual(part, p.partition("key", parts))

        for part in parts:
            self.assertEqual(part, p.partition("key", parts))
コード例 #2
0
ファイル: test_partitioner.py プロジェクト: zsuzhengdu/afkak
    def test_set_random_start(self):
        RoundRobinPartitioner.set_random_start(True)
        self.assertTrue(RoundRobinPartitioner.randomStart)
        parts = [1, 2, 3, 4, 5, 6, 7, 8, 19, 20, 30]
        # Try a number of times and check the distribution of the start
        firstParts = defaultdict(lambda: 0)
        trycount = 10000
        for i in xrange(trycount):
            p1 = RoundRobinPartitioner(None, parts)
            firstParts[p1.partition(None, parts)] += 1

        self.assertLess(std(firstParts.values()), trycount / 100)

        RoundRobinPartitioner.set_random_start(False)
        self.assertFalse(RoundRobinPartitioner.randomStart)
        p2 = RoundRobinPartitioner(None, parts)
        self.assertFalse(p2.randomStart)
        for part in parts:
            self.assertEqual(part, p2.partition(None, parts))
コード例 #3
0
ファイル: test_partitioner.py プロジェクト: ciena/afkak
    def test_set_random_start(self):
        RoundRobinPartitioner.set_random_start(True)
        self.assertTrue(RoundRobinPartitioner.randomStart)
        parts = [1, 2, 3, 4, 5, 6, 7, 8, 19, 20, 30]
        # Try a number of times and check the distribution of the start
        firstParts = defaultdict(lambda: 0)
        trycount = 10000
        for _i in range(trycount):
            p1 = RoundRobinPartitioner(None, parts)
            firstParts[p1.partition(None, parts)] += 1

        self.assertLess(std(firstParts.values()), trycount/100)

        RoundRobinPartitioner.set_random_start(False)
        self.assertFalse(RoundRobinPartitioner.randomStart)
        p2 = RoundRobinPartitioner(None, parts)
        self.assertFalse(p2.randomStart)
        for part in parts:
            self.assertEqual(part, p2.partition(None, parts))
コード例 #4
0
ファイル: test_partitioner.py プロジェクト: zsuzhengdu/afkak
    def test_partition(self):
        parts = [1, 2, 3, 4, 5, 6]
        p = RoundRobinPartitioner(None, parts)

        for part in parts:
            self.assertEqual(part, p.partition("key", parts))

        for part in parts:
            self.assertEqual(part, p.partition("key", parts))

        # Make sure updates work
        parts = [1, 2, 3, 4, 5, 6, 7, 8, 9]
        for part in parts:
            self.assertEqual(part, p.partition("key", parts))

        for part in parts:
            self.assertEqual(part, p.partition("key", parts))
コード例 #5
0
ファイル: test_partitioner.py プロジェクト: zsuzhengdu/afkak
 def test_repr(self):
     parts = [1, 3, 5, 7]
     p = RoundRobinPartitioner(None, parts)
     self.assertEqual(p.__repr__(),
                      '<RoundRobinPartitioner False:[1, 3, 5, 7]>')
コード例 #6
0
ファイル: test_partitioner.py プロジェクト: zsuzhengdu/afkak
 def test_constructor(self):
     parts = [1, 2, 3, 4, 5, 6]
     p = RoundRobinPartitioner(None, parts)
     self.assertEqual(parts, p.partitions)
コード例 #7
0
ファイル: test_partitioner.py プロジェクト: ciena/afkak
 def test_repr(self):
     parts = [1, 3, 5, 7]
     p = RoundRobinPartitioner(None, parts)
     self.assertEqual(p.__repr__(),
                      '<RoundRobinPartitioner False:[1, 3, 5, 7]>')