Search in sources :

Example 41 with DirectRowSet

use of org.apache.drill.exec.physical.rowSet.DirectRowSet in project drill by apache.

the class TestOAuthProcess method testGetDataWithAuthentication.

@Test
public void testGetDataWithAuthentication() {
    String url = hostname + "/update_oath2_authtoken?code=ABCDEF";
    Request request = new Request.Builder().url(url).build();
    try (MockWebServer server = startServer()) {
        server.enqueue(new MockResponse().setResponseCode(200).setBody(ACCESS_TOKEN_RESPONSE));
        Response response = httpClient.newCall(request).execute();
        // Verify that the request succeeded w/o error
        assertEquals(200, response.code());
        // Verify that the access and refresh tokens were saved
        PersistentTokenTable tokenTable = ((HttpStoragePlugin) cluster.storageRegistry().getPlugin("localOauth")).getTokenRegistry().getTokenTable("localOauth");
        assertEquals("you_have_access", tokenTable.getAccessToken());
        assertEquals("refresh_me", tokenTable.getRefreshToken());
        // Now execute a query and get query results.
        server.enqueue(new MockResponse().setResponseCode(200).setBody(TEST_JSON_RESPONSE_WITH_DATATYPES));
        String sql = "SELECT * FROM localOauth.test";
        DirectRowSet results = queryBuilder().sql(sql).rowSet();
        TupleMetadata expectedSchema = new SchemaBuilder().add("col_1", MinorType.FLOAT8, DataMode.OPTIONAL).add("col_2", MinorType.BIGINT, DataMode.OPTIONAL).add("col_3", MinorType.VARCHAR, DataMode.OPTIONAL).build();
        RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(1.0, 2, "3.0").addRow(4.0, 5, "6.0").build();
        RowSetUtilities.verify(expected, results);
    } catch (Exception e) {
        logger.debug(e.getMessage());
        fail();
    }
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) ClusterFixtureBuilder(org.apache.drill.test.ClusterFixtureBuilder) Request(okhttp3.Request) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) IOException(java.io.IOException) Response(okhttp3.Response) MockResponse(okhttp3.mockwebserver.MockResponse) RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) MockWebServer(okhttp3.mockwebserver.MockWebServer) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) PersistentTokenTable(org.apache.drill.exec.oauth.PersistentTokenTable) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test)

Example 42 with DirectRowSet

use of org.apache.drill.exec.physical.rowSet.DirectRowSet in project drill by apache.

the class TestOAuthProcess method testGetDataWithTokenRefresh.

@Test
public void testGetDataWithTokenRefresh() {
    String url = hostname + "/update_oath2_authtoken?code=ABCDEF";
    Request request = new Request.Builder().url(url).build();
    try (MockWebServer server = startServer()) {
        server.enqueue(new MockResponse().setResponseCode(200).setBody(ACCESS_TOKEN_RESPONSE));
        Response response = httpClient.newCall(request).execute();
        // Verify that the request succeeded w/o error
        assertEquals(200, response.code());
        // Verify that the access and refresh tokens were saved
        PersistentTokenTable tokenTable = ((HttpStoragePlugin) cluster.storageRegistry().getPlugin("localOauth")).getTokenRegistry().getTokenTable("localOauth");
        assertEquals("you_have_access", tokenTable.getAccessToken());
        assertEquals("refresh_me", tokenTable.getRefreshToken());
        // Now execute a query and get a refresh token
        // The API should return a 401 error.  This should trigger Drill to automatically
        // fire off a second call with the refresh token and then a third request with the
        // new access token to obtain the actual data.
        server.enqueue(new MockResponse().setResponseCode(401).setBody("Access Denied"));
        server.enqueue(new MockResponse().setResponseCode(200).setBody(REFRESH_TOKEN_RESPONSE));
        server.enqueue(new MockResponse().setResponseCode(200).setBody(TEST_JSON_RESPONSE_WITH_DATATYPES));
        String sql = "SELECT * FROM localOauth.test";
        DirectRowSet results = queryBuilder().sql(sql).rowSet();
        // Verify that the access and refresh tokens were saved
        assertEquals("token 2.0", tokenTable.getAccessToken());
        assertEquals("refresh 2.0", tokenTable.getRefreshToken());
        TupleMetadata expectedSchema = new SchemaBuilder().add("col_1", MinorType.FLOAT8, DataMode.OPTIONAL).add("col_2", MinorType.BIGINT, DataMode.OPTIONAL).add("col_3", MinorType.VARCHAR, DataMode.OPTIONAL).build();
        RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(1.0, 2, "3.0").addRow(4.0, 5, "6.0").build();
        RowSetUtilities.verify(expected, results);
    } catch (Exception e) {
        logger.debug(e.getMessage());
        fail();
    }
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) ClusterFixtureBuilder(org.apache.drill.test.ClusterFixtureBuilder) Request(okhttp3.Request) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) IOException(java.io.IOException) Response(okhttp3.Response) MockResponse(okhttp3.mockwebserver.MockResponse) RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) MockWebServer(okhttp3.mockwebserver.MockWebServer) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) PersistentTokenTable(org.apache.drill.exec.oauth.PersistentTokenTable) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test)

Aggregations

DirectRowSet (org.apache.drill.exec.physical.rowSet.DirectRowSet)42 Test (org.junit.Test)40 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)39 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)39 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)39 RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)35 ClusterTest (org.apache.drill.test.ClusterTest)33 QuerySummary (org.apache.drill.test.QueryBuilder.QuerySummary)25 JdbcStorageTest (org.apache.drill.categories.JdbcStorageTest)21 RowSetReader (org.apache.drill.exec.physical.rowSet.RowSetReader)8 EvfTest (org.apache.drill.categories.EvfTest)7 MockResponse (okhttp3.mockwebserver.MockResponse)3 MockWebServer (okhttp3.mockwebserver.MockWebServer)3 UserRemoteException (org.apache.drill.common.exceptions.UserRemoteException)3 IOException (java.io.IOException)2 Request (okhttp3.Request)2 Response (okhttp3.Response)2 PersistentTokenTable (org.apache.drill.exec.oauth.PersistentTokenTable)2 ClusterFixtureBuilder (org.apache.drill.test.ClusterFixtureBuilder)2 BigDecimal (java.math.BigDecimal)1