Search in sources :

Example 6 with DatasetServiceImpl

use of org.apache.beam.sdk.io.gcp.bigquery.BigQueryServicesImpl.DatasetServiceImpl in project beam by apache.

the class BigQueryUtilTest method testInsertAll.

@Test
public void testInsertAll() throws Exception, IOException {
    // Build up a list of indices to fail on each invocation. This should result in
    // 5 calls to insertAll.
    List<List<Long>> errorsIndices = new ArrayList<>();
    errorsIndices.add(Arrays.asList(0L, 5L, 10L, 15L, 20L));
    errorsIndices.add(Arrays.asList(0L, 2L, 4L));
    errorsIndices.add(Arrays.asList(0L, 2L));
    errorsIndices.add(new ArrayList<Long>());
    onInsertAll(errorsIndices);
    TableReference ref = BigQueryHelpers.parseTableSpec("project:dataset.table");
    DatasetServiceImpl datasetService = new DatasetServiceImpl(mockClient, options, 5);
    List<ValueInSingleWindow<TableRow>> rows = new ArrayList<>();
    List<String> ids = new ArrayList<>();
    for (int i = 0; i < 25; ++i) {
        rows.add(ValueInSingleWindow.of(rawRow("foo", 1234), GlobalWindow.TIMESTAMP_MAX_VALUE, GlobalWindow.INSTANCE, PaneInfo.ON_TIME_AND_ONLY_FIRING));
        ids.add(new String());
    }
    long totalBytes = 0;
    try {
        totalBytes = datasetService.insertAll(ref, rows, ids, InsertRetryPolicy.alwaysRetry(), null);
    } finally {
        verifyInsertAll(5);
        // Each of the 25 rows is 23 bytes: "{f=[{v=foo}, {v=1234}]}"
        assertEquals("Incorrect byte count", 25L * 23L, totalBytes);
    }
}
Also used : DatasetServiceImpl(org.apache.beam.sdk.io.gcp.bigquery.BigQueryServicesImpl.DatasetServiceImpl) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) TableReference(com.google.api.services.bigquery.model.TableReference) Matchers.anyLong(org.mockito.Matchers.anyLong) ValueInSingleWindow(org.apache.beam.sdk.values.ValueInSingleWindow) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) List(java.util.List) TableDataList(com.google.api.services.bigquery.model.TableDataList) Test(org.junit.Test)

Aggregations

TableReference (com.google.api.services.bigquery.model.TableReference)6 DatasetServiceImpl (org.apache.beam.sdk.io.gcp.bigquery.BigQueryServicesImpl.DatasetServiceImpl)6 ValueInSingleWindow (org.apache.beam.sdk.values.ValueInSingleWindow)6 Test (org.junit.Test)6 MockSleeper (com.google.api.client.testing.util.MockSleeper)5 TableDataInsertAllResponse (com.google.api.services.bigquery.model.TableDataInsertAllResponse)5 TableRow (com.google.api.services.bigquery.model.TableRow)5 InsertErrors (com.google.api.services.bigquery.model.TableDataInsertAllResponse.InsertErrors)3 ArrayList (java.util.ArrayList)3 ErrorProto (com.google.api.services.bigquery.model.ErrorProto)2 TableDataList (com.google.api.services.bigquery.model.TableDataList)1 ImmutableList (com.google.common.collect.ImmutableList)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.anyLong (org.mockito.Matchers.anyLong)1 Matchers.anyString (org.mockito.Matchers.anyString)1