Search in sources :

Example 1 with PRESTO_USER

use of com.facebook.presto.client.PrestoHeaders.PRESTO_USER in project presto by prestodb.

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> queryInfos = client.execute(prepareGet().setUri(uriBuilderFrom(server.getBaseUrl()).replacePath("/v1/query").build()).build(), createJsonResponseHandler(listJsonCodec(BasicQueryInfo.class)));
        if ((queryInfos.size() == 2) && queryInfos.stream().allMatch(info -> info.getState() == RUNNING)) {
            break;
        }
    }
}
Also used : JsonCodec(com.facebook.airlift.json.JsonCodec) Assert.assertEquals(com.facebook.presto.testing.assertions.Assert.assertEquals) Builder.preparePost(com.facebook.airlift.http.client.Request.Builder.preparePost) TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) QueryResults(com.facebook.presto.client.QueryResults) Test(org.testng.annotations.Test) JettyHttpClient(com.facebook.airlift.http.client.jetty.JettyHttpClient) JsonCodec.listJsonCodec(com.facebook.airlift.json.JsonCodec.listJsonCodec) UnexpectedResponseException(com.facebook.airlift.http.client.UnexpectedResponseException) JsonResponseHandler.createJsonResponseHandler(com.facebook.airlift.http.client.JsonResponseHandler.createJsonResponseHandler) StaticBodyGenerator.createStaticBodyGenerator(com.facebook.airlift.http.client.StaticBodyGenerator.createStaticBodyGenerator) AfterClass(org.testng.annotations.AfterClass) TpchPlugin(com.facebook.presto.tpch.TpchPlugin) RUNNING(com.facebook.presto.execution.QueryState.RUNNING) PRESTO_USER(com.facebook.presto.client.PrestoHeaders.PRESTO_USER) UTF_8(java.nio.charset.StandardCharsets.UTF_8) BeforeClass(org.testng.annotations.BeforeClass) Assert.assertNotNull(org.testng.Assert.assertNotNull) JsonCodec.jsonCodec(com.facebook.airlift.json.JsonCodec.jsonCodec) HttpClient(com.facebook.airlift.http.client.HttpClient) Closeables.closeQuietly(com.facebook.airlift.testing.Closeables.closeQuietly) HttpUriBuilder.uriBuilderFrom(com.facebook.airlift.http.client.HttpUriBuilder.uriBuilderFrom) List(java.util.List) Request(com.facebook.airlift.http.client.Request) Assert.assertTrue(org.testng.Assert.assertTrue) Builder.prepareGet(com.facebook.airlift.http.client.Request.Builder.prepareGet) Request(com.facebook.airlift.http.client.Request) QueryResults(com.facebook.presto.client.QueryResults) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

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