Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.facebook.presto.server;
 
 
 import java.net.URI;
 import java.util.List;
 
 import static com.facebook.presto.client.PrestoHeaders.PRESTO_CATALOG;
 import static com.facebook.presto.client.PrestoHeaders.PRESTO_SCHEMA;
 import static com.facebook.presto.client.PrestoHeaders.PRESTO_SESSION;
 import static com.facebook.presto.client.PrestoHeaders.PRESTO_SOURCE;
 import static com.facebook.presto.client.PrestoHeaders.PRESTO_USER;
 import static io.airlift.http.client.JsonResponseHandler.createJsonResponseHandler;
 import static io.airlift.http.client.Request.Builder.prepareGet;
 import static io.airlift.http.client.Request.Builder.preparePost;
 import static io.airlift.http.client.StaticBodyGenerator.createStaticBodyGenerator;
 import static io.airlift.http.client.StatusResponseHandler.createStatusResponseHandler;
 import static io.airlift.json.JsonCodec.jsonCodec;
 import static java.nio.charset.StandardCharsets.UTF_8;
 import static javax.ws.rs.core.Response.Status.OK;
 import static org.testng.Assert.assertEquals;
 
 @Test(singleThreaded = true)
 public class TestServer
 {
     private TestingPrestoServer server;
     private HttpClient client;
 
     @BeforeMethod
     public void setup()
             throws Exception
     {
          = new TestingPrestoServer();
          = new JettyHttpClient();
     }
 
     @SuppressWarnings("deprecation")
     @AfterMethod
     public void teardown()
     {
         Closeables.closeQuietly();
         Closeables.closeQuietly();
     }
 
     @Test
     public void testServerStarts()
             throws Exception
     {
         StatusResponseHandler.StatusResponse response = .execute(
                 prepareGet().setUri(.resolve("/v1/query")).build(),
                 createStatusResponseHandler());
 
         assertEquals(response.getStatusCode(), .getStatusCode());
     }
 
     @Test
     public void testQuery()
             throws Exception
     {
         // start query
         Request request = preparePost()
                 .setUri(uriFor("/v1/statement"))
                 .setBodyGenerator(createStaticBodyGenerator("show catalogs"))
                 .setHeader("user")
                 .setHeader("source")
                 .setHeader("catalog")
                 .setHeader("schema")
                 .addHeader("system-name=system-value")
                 .addHeader("catalog.name=catalog-value")
                 .addHeader("catalog2.name=catalog2-value")
                 .build();
 
        QueryResults queryResults = .execute(requestcreateJsonResponseHandler(jsonCodec(QueryResults.class)));
        // get the query info
        QueryInfo queryInfo = .getQueryManager().getQueryInfo(new QueryId(queryResults.getId()));
        // verify session properties
        assertEquals(queryInfo.getSession().getSystemProperties(), ImmutableMap.of("system-name""system-value"));
        assertEquals(queryInfo.getSession().getCatalogProperties(), ImmutableMap.of(
                "catalog", ImmutableMap.of("name""catalog-value"),
                "catalog2", ImmutableMap.of("name""catalog2-value")));
        ImmutableList.Builder<List<Object>> data = ImmutableList.builder();
        if (queryResults.getData() != null) {
            data.addAll(queryResults.getData());
        }
        while (queryResults.getNextUri() != null) {
            queryResults = .execute(prepareGet().setUri(queryResults.getNextUri()).build(), createJsonResponseHandler(jsonCodec(QueryResults.class)));
            if (queryResults.getData() != null) {
                data.addAll(queryResults.getData());
            }
        }
        // no catalogs in a the server by default
        List<List<Object>> rows = data.build();
        assertEquals(rows.size(), 0);
    }
    public URI uriFor(String path)
    {
        return HttpUriBuilder.uriBuilderFrom(.getBaseUrl()).replacePath(path).build();
    }
New to GrepCode? Check out our FAQ X