Ejemplo n.º 1
0
    def test_druid_returns_error(self):
        # given
        client = AsyncPyDruid("http://localhost:%s" % (self.get_http_port(), ),
                              "druid/v2/fail_request")

        # when / then
        with pytest.raises(IOError):
            yield client.topn(datasource="testdatasource",
                              granularity="all",
                              intervals="2015-12-29/pt1h",
                              aggregations={"count": doublesum("count")},
                              dimension="user_name",
                              metric="count",
                              filter=Dimension("user_lang") == "en",
                              threshold=1,
                              context={"timeout": 1000})
Ejemplo n.º 2
0
    def test_druid_returns_error(self):
        # given
        client = AsyncPyDruid("http://localhost:%s" % (self.get_http_port(), ),
                              "druid/v2/fail_request")

        # when / then
        with pytest.raises(IOError):
            yield client.topn(
                    datasource="testdatasource",
                    granularity="all",
                    intervals="2015-12-29/pt1h",
                    aggregations={"count": doublesum("count")},
                    dimension="user_name",
                    metric="count",
                    filter=Dimension("user_lang") == "en",
                    threshold=1,
                    context={"timeout": 1000})
Ejemplo n.º 3
0
    def test_client_allows_to_export_last_query(self):
        # given
        client = AsyncPyDruid("http://localhost:%s" % (self.get_http_port(), ),
                              "druid/v2/return_results")
        yield client.topn(datasource="testdatasource",
                          granularity="all",
                          intervals="2015-12-29/pt1h",
                          aggregations={"count": doublesum("count")},
                          dimension="user_name",
                          metric="count",
                          filter=Dimension("user_lang") == "en",
                          threshold=1,
                          context={"timeout": 1000})

        # when / then
        # assert that last_query.export_tsv method was called (it should throw an exception, given empty path)
        with pytest.raises(TypeError):
            client.export_tsv(None)
Ejemplo n.º 4
0
    def test_client_allows_passing_default_parameters(self):
        # given
        client = AsyncPyDruid("http://localhost:%s" % (self.get_http_port(), ),
                              "druid/v2/return_results",
                              defaults=dict(request_timeout=120))
        top = yield client.topn(datasource="testdatasource",
                                granularity="all",
                                intervals="2015-12-29/pt1h",
                                aggregations={"count": doublesum("count")},
                                dimension="user_name",
                                metric="count",
                                filter=Dimension("user_lang") == "en",
                                threshold=1,
                                context={"timeout": 1000})

        # then
        self.assertIsNotNone(top)
        self.assertEqual(len(top.result), 1)
        self.assertEqual(len(top.result[0]['result']), 1)
Ejemplo n.º 5
0
    def test_client_allows_to_export_last_query(self):
        # given
        client = AsyncPyDruid("http://localhost:%s" % (self.get_http_port(), ),
                              "druid/v2/return_results")
        yield client.topn(
                datasource="testdatasource",
                granularity="all",
                intervals="2015-12-29/pt1h",
                aggregations={"count": doublesum("count")},
                dimension="user_name",
                metric="count",
                filter=Dimension("user_lang") == "en",
                threshold=1,
                context={"timeout": 1000})

        # when / then
        # assert that last_query.export_tsv method was called (it should throw an exception, given empty path)
        with pytest.raises(TypeError):
            client.export_tsv(None)
Ejemplo n.º 6
0
    def test_druid_returns_results(self):
        # given
        client = AsyncPyDruid("http://localhost:%s" % (self.get_http_port(), ),
                              "druid/v2/return_results")

        # when
        top = yield client.topn(
                datasource="testdatasource",
                granularity="all",
                intervals="2015-12-29/pt1h",
                aggregations={"count": doublesum("count")},
                dimension="user_name",
                metric="count",
                filter=Dimension("user_lang") == "en",
                threshold=1,
                context={"timeout": 1000})

        # then
        self.assertIsNotNone(top)
        self.assertEqual(len(top.result), 1)
        self.assertEqual(len(top.result[0]['result']), 1)
Ejemplo n.º 7
0
 def __init__(self, address, port=8082):
     url = f"http://{address}:{port}"
     self.async_client = AsyncPyDruid(url, 'druid/v2/')
     self.client = PyDruid(url, 'druid/v2/')