Example #1
0
    def test_listen_port(self):
        """
        The test case to test the server
        created by NodeSamplerServer class.
        :return:
        """

        def start_server():
            self.node_sampler_server.start()

        server_thread = Thread(target=start_server)
        server_thread.setDaemon(True)
        server_thread.start()

        proxy = ServerProxy("http://localhost:8000")
        service_a = Service(name="$$service_a$$",
                            check_methods=TEST_METHOD,
                            ip=TEST_IP)
        service_b = Service(name="$$service_b$$",
                            check_methods=TEST_METHOD,
                            ip=TEST_IP)
        service_c = Service(name="$$service_c$$",
                            check_methods=TEST_METHOD,
                            ip=TEST_IP)
        fake_services = [service_a, service_b, service_c]
        self.assertEquals(
            proxy.sample(fake_services), 1,
            "NodeSamplerServer cannot create object.")
Example #2
0
    def connect(self, ip, group, port, node_services):
        log = LOG()
        log_root = log.root()

        url = "http://" + ip + ":" + port
        log_root.debug(
            "Sent from Master-node_services: %s -url: %s -group: %s " %
            (node_services, url, group))

        proxy = ServerProxy(url)
        raw_node_result = proxy.sample(node_services)
        log_root.info(
            "Raw Info received from Sampler:  %s" % raw_node_result)
        return raw_node_result
Example #3
0
    def test_sample_server(self):
        """
        This test case to test sampler response.
        :return:
        """
        fake_uri = "http://localhost:8000/"
        proxy = ServerProxy(fake_uri)

        dict_service_a = {"name": "$$test_service_a$$",
                          "ip": TEST_IP,
                          "check_methods": TEST_METHOD}
        dict_service_b = {"name": "$$test_service_b$$",
                          "ip": TEST_IP,
                          "check_methods": TEST_METHOD}

        fake_services = [dict_service_a, dict_service_b]
        self.assertEquals(proxy.sample(fake_services), 1,
                          "Failed to return result from sampler.")