Search in sources :

Example 6 with TableDataList

use of com.google.api.services.bigquery.model.TableDataList in project beam by apache.

the class BigQueryUtilTest method testTableGet.

@Test
public void testTableGet() throws InterruptedException, IOException {
    onTableGet(basicTableSchema());
    TableDataList dataList = new TableDataList().setTotalRows(0L);
    onTableList(dataList);
    BigQueryServicesImpl.DatasetServiceImpl services = new BigQueryServicesImpl.DatasetServiceImpl(mockClient, options);
    services.getTable(new TableReference().setProjectId("project").setDatasetId("dataset").setTableId("table"));
    verifyTableGet();
}
Also used : TableReference(com.google.api.services.bigquery.model.TableReference) DatasetServiceImpl(org.apache.beam.sdk.io.gcp.bigquery.BigQueryServicesImpl.DatasetServiceImpl) DatasetServiceImpl(org.apache.beam.sdk.io.gcp.bigquery.BigQueryServicesImpl.DatasetServiceImpl) TableDataList(com.google.api.services.bigquery.model.TableDataList) Test(org.junit.Test)

Example 7 with TableDataList

use of com.google.api.services.bigquery.model.TableDataList in project beam by apache.

the class BigQueryServicesImplTest method testIsTableEmptySucceeds.

@Test
public void testIsTableEmptySucceeds() throws Exception {
    TableReference tableRef = new TableReference().setProjectId("projectId").setDatasetId("datasetId").setTableId("tableId");
    TableDataList testDataList = new TableDataList().setRows(ImmutableList.of(new TableRow()));
    // First response is 403 rate limited, second response has valid payload.
    when(response.getContentType()).thenReturn(Json.MEDIA_TYPE);
    when(response.getStatusCode()).thenReturn(403).thenReturn(200);
    when(response.getContent()).thenReturn(toStream(errorWithReasonAndStatus("rateLimitExceeded", 403))).thenReturn(toStream(testDataList));
    BigQueryServicesImpl.DatasetServiceImpl datasetService = new BigQueryServicesImpl.DatasetServiceImpl(bigquery, PipelineOptionsFactory.create());
    assertFalse(datasetService.isTableEmpty(tableRef, BackOff.ZERO_BACKOFF, Sleeper.DEFAULT));
    verify(response, times(2)).getStatusCode();
    verify(response, times(2)).getContent();
    verify(response, times(2)).getContentType();
}
Also used : TableReference(com.google.api.services.bigquery.model.TableReference) DatasetServiceImpl(org.apache.beam.sdk.io.gcp.bigquery.BigQueryServicesImpl.DatasetServiceImpl) DatasetServiceImpl(org.apache.beam.sdk.io.gcp.bigquery.BigQueryServicesImpl.DatasetServiceImpl) TableRow(com.google.api.services.bigquery.model.TableRow) TableDataList(com.google.api.services.bigquery.model.TableDataList) Test(org.junit.Test)

Aggregations

TableDataList (com.google.api.services.bigquery.model.TableDataList)7 Test (org.junit.Test)6 TableRow (com.google.api.services.bigquery.model.TableRow)4 TableReference (com.google.api.services.bigquery.model.TableReference)2 DatasetServiceImpl (org.apache.beam.sdk.io.gcp.bigquery.BigQueryServicesImpl.DatasetServiceImpl)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1