コード例 #1
0
    def test_single_concurrent_member(self):
        handler_a = TestHandler(1)
        handler_b = TestHandler(1)

        service_name = "test"
        service_a = LeaderElectedService(self.client, service_name, ("127.0.0.1", 80), handler_a)
        service_path_a = service_a.join()

        # Just A
        assert_that(handler_a.await(5), is_(True))
        assert_that(handler_a.value, is_(1))
        assert_that(service_path_a, starts_with("/services/{0}/node-".format(service_name)))

        service_b = LeaderElectedService(self.client, service_name, ("127.0.0.1", 8080), handler_b)
        service_path_b = service_b.join()

        # B is still waiting to get membership (timeout after 1 second)
        assert_that(handler_b.await(1), is_(False))
        assert_that(handler_b.value, is_(0))
        assert_that(service_path_b, starts_with("/services/{0}/node-".format(service_name)))

        assert_that(service_path_a, not equal_to_ignoring_case(service_path_b))

        handler_a.calls = 0
        service_a.leave()

        # A left
        assert_that(handler_a.await(5), is_(True))
        assert_that(handler_a.value, is_(0))

        # B should have joined since A is gone
        assert_that(handler_b.await(5), is_(True))
        assert_that(handler_b.value, is_(1))
コード例 #2
0
    def test_leave(self):
        handler = TestHandler(1)

        service_name = "test"
        service = LeaderElectedService(self.client, service_name, ("127.0.0.1", 80), handler)
        service_path = service.join()

        assert_that(handler.await(5), is_(True))
        assert_that(handler.value, is_(1))

        handler.calls = 0
        service.leave()

        assert_that(handler.await(5), is_(True))
        assert_that(handler.value, is_(0))
        assert_that(service_path, starts_with("/services/{0}/node-".format(service_name)))
コード例 #3
0
    def test_leave(self):
        handler = TestHandler(1)

        service_name = "test"
        service = LeaderElectedService(self.client, service_name,
                                       ("127.0.0.1", 80), handler)
        service_path = service.join()

        assert_that(handler. await (5), is_(True))
        assert_that(handler.value, is_(1))

        handler.calls = 0
        service.leave()

        assert_that(handler. await (5), is_(True))
        assert_that(handler.value, is_(0))
        assert_that(service_path,
                    starts_with("/services/{0}/node-".format(service_name)))
コード例 #4
0
    def test_single_concurrent_member(self):
        handler_a = TestHandler(1)
        handler_b = TestHandler(1)

        service_name = "test"
        service_a = LeaderElectedService(self.client, service_name,
                                         ("127.0.0.1", 80), handler_a)
        service_path_a = service_a.join()

        # Just A
        assert_that(handler_a. await (5), is_(True))
        assert_that(handler_a.value, is_(1))
        assert_that(service_path_a,
                    starts_with("/services/{0}/node-".format(service_name)))

        service_b = LeaderElectedService(self.client, service_name,
                                         ("127.0.0.1", 8080), handler_b)
        service_path_b = service_b.join()

        # B is still waiting to get membership (timeout after 1 second)
        assert_that(handler_b. await (1), is_(False))
        assert_that(handler_b.value, is_(0))
        assert_that(service_path_b,
                    starts_with("/services/{0}/node-".format(service_name)))

        assert_that(service_path_a, not equal_to_ignoring_case(service_path_b))

        handler_a.calls = 0
        service_a.leave()

        # A left
        assert_that(handler_a. await (5), is_(True))
        assert_that(handler_a.value, is_(0))

        # B should have joined since A is gone
        assert_that(handler_b. await (5), is_(True))
        assert_that(handler_b.value, is_(1))