예제 #1
0
    def test_empty_server_list_update(self):
        http_client_factory = HttpClientFactory(None, {})

        http_client_factory.update_upstream('nn', 'max_tries=10 | server=172.17.0.1:2800')
        self.assertEqual(1, len(http_client_factory.upstreams))

        http_client_factory.update_upstream('nn', '|')
        self.assertEqual(0, len(http_client_factory.upstreams))
예제 #2
0
    def test_retry_policy(self):
        http_client_factory = HttpClientFactory(None, {})

        http_client_factory.update_upstream(
            'nn',
            'retry_policy=http_503,non_idempotent_503|server=172.17.0.1:2800')
        upstream = http_client_factory.upstreams.get('nn')
        self.assertEqual({503: True}, upstream.retry_policy.statuses)
예제 #3
0
파일: app.py 프로젝트: curlup/frontik-1
    def __init__(self, **settings):
        self.start_time = time.time()

        tornado_settings = settings.get('tornado_settings')
        if tornado_settings is None:
            tornado_settings = {}

        self.config = self.application_config()
        self.app = settings.get('app')
        self.app_root = settings.get('app_root')

        self.xml = frontik.producers.xml_producer.XMLProducerFactory(self)
        self.json = frontik.producers.json_producer.JsonProducerFactory(self)

        self.http_client_factory = HttpClientFactory(
            self, getattr(self.config, 'http_upstreams', {}))

        self.router = FrontikRouter(self)

        core_handlers = [
            (r'/version/?', VersionHandler),
            (r'/status/?', StatusHandler),
            (r'.*', self.router),
        ]

        if options.debug:
            core_handlers.insert(0, (r'/pydevd/?', PydevdHandler))

        super().__init__(core_handlers, **tornado_settings)
        self.available_integrations, self.default_init_futures = integrations.load_integrations(
            self)
        self.transforms.insert(0, partial(DebugTransform, self))
예제 #4
0
    def test_init_from_config(self):
        http_client_factory = HttpClientFactory(
            None, {
                'nn': {
                    'config': {
                        'max_tries': 10,
                        'max_fails': 100,
                        'request_timeout_sec': 0.1,
                        'connect_timeout_sec': 1.3,
                        'max_timeout_tries': 4
                    },
                    'servers': [{
                        'server': '172.17.0.1:2800'
                    }]
                }
            })

        upstream = http_client_factory.upstreams.get('nn')

        self.assertEqual(10, upstream.max_tries)
        self.assertEqual(100, upstream.max_fails)
        self.assertEqual(10, upstream.fail_timeout)
        self.assertEqual(1.3, upstream.connect_timeout)
        self.assertEqual(0.1, upstream.request_timeout)
        self.assertEqual(4, upstream.max_timeout_tries)

        self.assertEqual(1, len(upstream.servers))
        self.assertEqual('172.17.0.1:2800', upstream.servers[0].address)
예제 #5
0
    def test_from_config_string(self):
        http_client_factory = HttpClientFactory(None, {})

        http_client_factory.update_upstream(
            'nn',
            'max_tries=10 fail_timeout_sec=1 max_fails=30 request_timeout_sec=0.2 '
            'connect_timeout_sec=1 max_timeout_tries=2 |'
            'server=172.17.0.1:2800')
        upstream = http_client_factory.upstreams.get('nn')

        self.assertEqual(10, upstream.max_tries)
        self.assertEqual(30, upstream.max_fails)
        self.assertEqual(1, upstream.fail_timeout)
        self.assertEqual(1, upstream.connect_timeout)
        self.assertEqual(0.2, upstream.request_timeout)
        self.assertEqual(2, upstream.max_timeout_tries)

        self.assertEqual(1, len(upstream.servers))
        self.assertEqual('172.17.0.1:2800', upstream.servers[0].address)
예제 #6
0
    def test_from_config_string(self):
        http_client_factory = HttpClientFactory(None, {})

        http_client_factory.update_upstream(
            'nn',
            'max_tries=10 fail_timeout_sec=1 max_fails=30 request_timeout_sec=0.2 '
            'connect_timeout_sec=1 max_timeout_tries=2 |'
            'server=172.17.0.1:2800')
        upstream = http_client_factory.upstreams.get('nn')

        self.assertEqual(10, upstream.max_tries)
        self.assertEqual(30, upstream.max_fails)
        self.assertEqual(1, upstream.fail_timeout)
        self.assertEqual(1, upstream.connect_timeout)
        self.assertEqual(0.2, upstream.request_timeout)
        self.assertEqual(2, upstream.max_timeout_tries)

        self.assertEqual(1, len(upstream.servers))
        self.assertEqual('172.17.0.1:2800', upstream.servers[0].address)
예제 #7
0
    def test_empty_server_list_update(self):
        http_client_factory = HttpClientFactory(None, {})

        http_client_factory.update_upstream(
            'nn', 'max_tries=10 | server=172.17.0.1:2800')
        self.assertEqual(1, len(http_client_factory.upstreams))

        http_client_factory.update_upstream('nn', '|')
        self.assertEqual(0, len(http_client_factory.upstreams))
예제 #8
0
    def test_empty_server_list_init(self):
        http_client_factory = HttpClientFactory(None, {})

        http_client_factory.update_upstream('nn', '|')
        self.assertEqual(0, len(http_client_factory.upstreams))
예제 #9
0
    def test_retry_policy(self):
        http_client_factory = HttpClientFactory(None, {})

        http_client_factory.update_upstream('nn', 'retry_policy=http_503,non_idempotent_503|server=172.17.0.1:2800')
        upstream = http_client_factory.upstreams.get('nn')
        self.assertEqual({503: True}, upstream.retry_policy.statuses)
예제 #10
0
    def test_empty_server_list_init(self):
        http_client_factory = HttpClientFactory(None, {})

        http_client_factory.update_upstream('nn', '|')
        self.assertEqual(0, len(http_client_factory.upstreams))