Search in sources :

Example 1 with PRESTO_USER

use of io.prestosql.client.PrestoHeaders.PRESTO_USER in project hetu-core by openlookeng.

the class TestQueryStateInfoResource method setup.

@BeforeClass
public void setup() {
    Request request1 = preparePost().setUri(uriBuilderFrom(server.getBaseUrl()).replacePath("/v1/statement").build()).setBodyGenerator(createStaticBodyGenerator(LONG_LASTING_QUERY, UTF_8)).setHeader(PRESTO_USER, "user1").build();
    queryResults = client.execute(request1, createJsonResponseHandler(QUERY_RESULTS_JSON_CODEC));
    client.execute(prepareGet().setUri(queryResults.getNextUri()).build(), createJsonResponseHandler(QUERY_RESULTS_JSON_CODEC));
    Request request2 = preparePost().setUri(uriBuilderFrom(server.getBaseUrl()).replacePath("/v1/statement").build()).setBodyGenerator(createStaticBodyGenerator(LONG_LASTING_QUERY, UTF_8)).setHeader(PRESTO_USER, "user2").build();
    QueryResults queryResults2 = client.execute(request2, createJsonResponseHandler(jsonCodec(QueryResults.class)));
    client.execute(prepareGet().setUri(queryResults2.getNextUri()).build(), createJsonResponseHandler(QUERY_RESULTS_JSON_CODEC));
    // queries are started in the background, so they may not all be immediately visible
    while (true) {
        List<BasicQueryInfo> queryInfos1 = client.execute(prepareGet().setUri(uriBuilderFrom(server.getBaseUrl()).replacePath("/v1/query").build()).setHeader(PRESTO_USER, "user1").build(), createJsonResponseHandler(listJsonCodec(BasicQueryInfo.class)));
        List<BasicQueryInfo> queryInfos2 = client.execute(prepareGet().setUri(uriBuilderFrom(server.getBaseUrl()).replacePath("/v1/query").build()).setHeader(PRESTO_USER, "user2").build(), createJsonResponseHandler(listJsonCodec(BasicQueryInfo.class)));
        if ((queryInfos1.size() == 1) && queryInfos1.stream().allMatch(info -> info.getState() == RUNNING) && (queryInfos2.size() == 1) && queryInfos2.stream().allMatch(info -> info.getState() == RUNNING)) {
            break;
        }
    }
}
Also used : HttpClient(io.airlift.http.client.HttpClient) Test(org.testng.annotations.Test) PRESTO_USER(io.prestosql.client.PrestoHeaders.PRESTO_USER) UnexpectedResponseException(io.airlift.http.client.UnexpectedResponseException) Assert.assertEquals(io.prestosql.testing.assertions.Assert.assertEquals) Request(io.airlift.http.client.Request) RUNNING(io.prestosql.execution.QueryState.RUNNING) AfterClass(org.testng.annotations.AfterClass) Builder.preparePost(io.airlift.http.client.Request.Builder.preparePost) Builder.prepareGet(io.airlift.http.client.Request.Builder.prepareGet) JettyHttpClient(io.airlift.http.client.jetty.JettyHttpClient) QueryResults(io.prestosql.client.QueryResults) Closeables.closeQuietly(io.airlift.testing.Closeables.closeQuietly) UTF_8(java.nio.charset.StandardCharsets.UTF_8) BeforeClass(org.testng.annotations.BeforeClass) TestingPrestoServer(io.prestosql.server.testing.TestingPrestoServer) Assert.assertNotNull(org.testng.Assert.assertNotNull) JsonCodec.jsonCodec(io.airlift.json.JsonCodec.jsonCodec) List(java.util.List) JsonCodec.listJsonCodec(io.airlift.json.JsonCodec.listJsonCodec) HttpUriBuilder.uriBuilderFrom(io.airlift.http.client.HttpUriBuilder.uriBuilderFrom) JsonResponseHandler.createJsonResponseHandler(io.airlift.http.client.JsonResponseHandler.createJsonResponseHandler) Assert.assertTrue(org.testng.Assert.assertTrue) StaticBodyGenerator.createStaticBodyGenerator(io.airlift.http.client.StaticBodyGenerator.createStaticBodyGenerator) JsonCodec(io.airlift.json.JsonCodec) TpchPlugin(io.prestosql.plugin.tpch.TpchPlugin) Request(io.airlift.http.client.Request) QueryResults(io.prestosql.client.QueryResults) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

HttpClient (io.airlift.http.client.HttpClient)1 HttpUriBuilder.uriBuilderFrom (io.airlift.http.client.HttpUriBuilder.uriBuilderFrom)1 JsonResponseHandler.createJsonResponseHandler (io.airlift.http.client.JsonResponseHandler.createJsonResponseHandler)1 Request (io.airlift.http.client.Request)1 Builder.prepareGet (io.airlift.http.client.Request.Builder.prepareGet)1 Builder.preparePost (io.airlift.http.client.Request.Builder.preparePost)1 StaticBodyGenerator.createStaticBodyGenerator (io.airlift.http.client.StaticBodyGenerator.createStaticBodyGenerator)1 UnexpectedResponseException (io.airlift.http.client.UnexpectedResponseException)1 JettyHttpClient (io.airlift.http.client.jetty.JettyHttpClient)1 JsonCodec (io.airlift.json.JsonCodec)1 JsonCodec.jsonCodec (io.airlift.json.JsonCodec.jsonCodec)1 JsonCodec.listJsonCodec (io.airlift.json.JsonCodec.listJsonCodec)1 Closeables.closeQuietly (io.airlift.testing.Closeables.closeQuietly)1 PRESTO_USER (io.prestosql.client.PrestoHeaders.PRESTO_USER)1 QueryResults (io.prestosql.client.QueryResults)1 RUNNING (io.prestosql.execution.QueryState.RUNNING)1 TpchPlugin (io.prestosql.plugin.tpch.TpchPlugin)1 TestingPrestoServer (io.prestosql.server.testing.TestingPrestoServer)1 Assert.assertEquals (io.prestosql.testing.assertions.Assert.assertEquals)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1