def test_multiple_query_plans(self):
     hosts = [0, 1, 2, 3]
     policy = RoundRobinPolicy()
     policy.populate(None, hosts)
     for i in xrange(20):
         qplan = list(policy.make_query_plan())
         self.assertEqual(sorted(qplan), hosts)
Exemplo n.º 2
0
 def test_multiple_query_plans(self):
     hosts = [0, 1, 2, 3]
     policy = RoundRobinPolicy()
     policy.populate(None, hosts)
     for i in xrange(20):
         qplan = list(policy.make_query_plan())
         self.assertEqual(sorted(qplan), hosts)
Exemplo n.º 3
0
 def test_status_updates(self):
     hosts = [0, 1, 2, 3]
     policy = RoundRobinPolicy()
     policy.populate(None, hosts)
     policy.on_down(0)
     policy.on_remove(1)
     policy.on_up(4)
     policy.on_add(5)
     qplan = list(policy.make_query_plan())
     self.assertEqual(sorted(qplan), [2, 3, 4, 5])
Exemplo n.º 4
0
    def test_no_live_nodes(self):
        hosts = [0, 1, 2, 3]
        policy = RoundRobinPolicy()
        policy.populate(None, hosts)

        for i in range(4):
            policy.on_down(i)

        query_plan = list(policy.make_query_plan())
        self.assertEqual(query_plan, [])
 def test_status_updates(self):
     hosts = [0, 1, 2, 3]
     policy = RoundRobinPolicy()
     policy.populate(None, hosts)
     policy.on_down(0)
     policy.on_remove(1)
     policy.on_up(4)
     policy.on_add(5)
     qplan = list(policy.make_query_plan())
     self.assertEqual(sorted(qplan), [2, 3, 4, 5])
Exemplo n.º 6
0
    def test_no_live_nodes(self):
        hosts = [0, 1, 2, 3]
        policy = RoundRobinPolicy()
        policy.populate(None, hosts)

        for i in range(4):
            policy.on_down(i)

        query_plan = list(policy.make_query_plan())
        self.assertEqual(query_plan, [])
Exemplo n.º 7
0
    def test_thread_safety(self):
        hosts = range(100)
        policy = RoundRobinPolicy()
        policy.populate(None, hosts)

        def check_query_plan():
            for i in range(100):
                qplan = list(policy.make_query_plan())
                self.assertEqual(sorted(qplan), hosts)

        threads = [Thread(target=check_query_plan) for i in range(4)]
        map(lambda t: t.start(), threads)
        map(lambda t: t.join(), threads)
Exemplo n.º 8
0
    def test_no_live_nodes(self):
        """
        Ensure query plan for a downed cluster will execute without errors
        """
        hosts = [0, 1, 2, 3]
        policy = RoundRobinPolicy()
        policy.populate(None, hosts)

        for i in range(4):
            policy.on_down(i)

        qplan = list(policy.make_query_plan())
        self.assertEqual(qplan, [])
    def test_thread_safety(self):
        hosts = range(100)
        policy = RoundRobinPolicy()
        policy.populate(None, hosts)

        def check_query_plan():
            for i in range(100):
                qplan = list(policy.make_query_plan())
                self.assertEqual(sorted(qplan), hosts)

        threads = [Thread(target=check_query_plan) for i in range(4)]
        map(lambda t: t.start(), threads)
        map(lambda t: t.join(), threads)
Exemplo n.º 10
0
    def test_no_live_nodes(self):
        """
        Ensure query plan for a downed cluster will execute without errors
        """
        hosts = [0, 1, 2, 3]
        policy = RoundRobinPolicy()
        policy.populate(None, hosts)

        for i in range(4):
            policy.on_down(i)

        qplan = list(policy.make_query_plan())
        self.assertEqual(qplan, [])
Exemplo n.º 11
0
    def test_thread_safety_during_modification(self):
        hosts = range(100)
        policy = RoundRobinPolicy()
        policy.populate(None, hosts)

        errors = []

        def check_query_plan():
            try:
                for i in xrange(100):
                    list(policy.make_query_plan())
            except Exception as exc:
                errors.append(exc)

        def host_up():
            for i in xrange(1000):
                policy.on_up(randint(0, 99))

        def host_down():
            for i in xrange(1000):
                policy.on_down(randint(0, 99))

        threads = []
        for i in range(5):
            threads.append(Thread(target=check_query_plan))
            threads.append(Thread(target=host_up))
            threads.append(Thread(target=host_down))

        # make the GIL switch after every instruction, maximizing
        # the chance of race conditions
        check = six.PY2 or '__pypy__' in sys.builtin_module_names
        if check:
            original_interval = sys.getcheckinterval()
        else:
            original_interval = sys.getswitchinterval()

        try:
            if check:
                sys.setcheckinterval(0)
            else:
                sys.setswitchinterval(0.0001)
            map(lambda t: t.start(), threads)
            map(lambda t: t.join(), threads)
        finally:
            if check:
                sys.setcheckinterval(original_interval)
            else:
                sys.setswitchinterval(original_interval)

        if errors:
            self.fail("Saw errors: %s" % (errors,))
Exemplo n.º 12
0
    def test_thread_safety_during_modification(self):
        hosts = range(100)
        policy = RoundRobinPolicy()
        policy.populate(None, hosts)

        errors = []

        def check_query_plan():
            try:
                for i in xrange(100):
                    list(policy.make_query_plan())
            except Exception as exc:
                errors.append(exc)

        def host_up():
            for i in xrange(1000):
                policy.on_up(randint(0, 99))

        def host_down():
            for i in xrange(1000):
                policy.on_down(randint(0, 99))

        threads = []
        for i in range(5):
            threads.append(Thread(target=check_query_plan))
            threads.append(Thread(target=host_up))
            threads.append(Thread(target=host_down))

        # make the GIL switch after every instruction, maximizing
        # the chance of race conditions
        check = six.PY2 or '__pypy__' in sys.builtin_module_names
        if check:
            original_interval = sys.getcheckinterval()
        else:
            original_interval = sys.getswitchinterval()

        try:
            if check:
                sys.setcheckinterval(0)
            else:
                sys.setswitchinterval(0.0001)
            map(lambda t: t.start(), threads)
            map(lambda t: t.join(), threads)
        finally:
            if check:
                sys.setcheckinterval(original_interval)
            else:
                sys.setswitchinterval(original_interval)

        if errors:
            self.fail("Saw errors: %s" % (errors, ))
Exemplo n.º 13
0
 def test_single_host(self):
     policy = RoundRobinPolicy()
     policy.populate(None, [0])
     qplan = list(policy.make_query_plan())
     self.assertEqual(qplan, [0])
Exemplo n.º 14
0
 def test_basic(self):
     hosts = [0, 1, 2, 3]
     policy = RoundRobinPolicy()
     policy.populate(None, hosts)
     qplan = list(policy.make_query_plan())
     self.assertEqual(sorted(qplan), hosts)
 def test_single_host(self):
     policy = RoundRobinPolicy()
     policy.populate(None, [0])
     qplan = list(policy.make_query_plan())
     self.assertEqual(qplan, [0])
 def test_basic(self):
     hosts = [0, 1, 2, 3]
     policy = RoundRobinPolicy()
     policy.populate(None, hosts)
     qplan = list(policy.make_query_plan())
     self.assertEqual(sorted(qplan), hosts)