Search in sources :

Example 16 with FailsafeValueInSingleWindow

use of org.apache.beam.sdk.values.FailsafeValueInSingleWindow in project beam by apache.

the class BigQueryServicesImplTest method testInsertQuotaExceededRetry.

/**
 * Tests that {@link DatasetServiceImpl#insertAll} retries quota exceeded attempts.
 */
@Test
public void testInsertQuotaExceededRetry() throws Exception {
    TableReference ref = new TableReference().setProjectId("project").setDatasetId("dataset").setTableId("table");
    List<FailsafeValueInSingleWindow<TableRow, TableRow>> rows = new ArrayList<>();
    rows.add(wrapValue(new TableRow()));
    // First response is 403 quota exceeded, second response has valid payload.
    setupMockResponses(response -> {
        when(response.getStatusCode()).thenReturn(403);
        when(response.getContentType()).thenReturn(Json.MEDIA_TYPE);
        when(response.getContent()).thenReturn(toStream(errorWithReasonAndStatus("quotaExceeded", 403)));
    }, response -> {
        when(response.getContentType()).thenReturn(Json.MEDIA_TYPE);
        when(response.getStatusCode()).thenReturn(200);
        when(response.getContent()).thenReturn(toStream(new TableDataInsertAllResponse()));
    });
    DatasetServiceImpl dataService = new DatasetServiceImpl(bigquery, null, PipelineOptionsFactory.create());
    dataService.insertAll(ref, rows, null, BackOffAdapter.toGcpBackOff(TEST_BACKOFF.backoff()), TEST_BACKOFF, new MockSleeper(), InsertRetryPolicy.alwaysRetry(), null, null, false, false, false, null);
    verifyAllResponsesAreRead();
    expectedLogs.verifyInfo("BigQuery insertAll error, retrying:");
    verifyWriteMetricWasSet("project", "dataset", "table", "quotaexceeded", 1);
}
Also used : TableReference(com.google.api.services.bigquery.model.TableReference) DatasetServiceImpl(org.apache.beam.sdk.io.gcp.bigquery.BigQueryServicesImpl.DatasetServiceImpl) TableRow(com.google.api.services.bigquery.model.TableRow) TableDataInsertAllResponse(com.google.api.services.bigquery.model.TableDataInsertAllResponse) ArrayList(java.util.ArrayList) FailsafeValueInSingleWindow(org.apache.beam.sdk.values.FailsafeValueInSingleWindow) MockSleeper(com.google.api.client.testing.util.MockSleeper) Test(org.junit.Test)

Aggregations

TableReference (com.google.api.services.bigquery.model.TableReference)16 DatasetServiceImpl (org.apache.beam.sdk.io.gcp.bigquery.BigQueryServicesImpl.DatasetServiceImpl)16 FailsafeValueInSingleWindow (org.apache.beam.sdk.values.FailsafeValueInSingleWindow)16 Test (org.junit.Test)16 MockSleeper (com.google.api.client.testing.util.MockSleeper)15 TableRow (com.google.api.services.bigquery.model.TableRow)15 TableDataInsertAllResponse (com.google.api.services.bigquery.model.TableDataInsertAllResponse)14 ArrayList (java.util.ArrayList)8 ValueInSingleWindow (org.apache.beam.sdk.values.ValueInSingleWindow)8 Matchers.containsString (org.hamcrest.Matchers.containsString)8 ErrorProto (com.google.api.services.bigquery.model.ErrorProto)7 InsertErrors (com.google.api.services.bigquery.model.TableDataInsertAllResponse.InsertErrors)7 TableDataList (com.google.api.services.bigquery.model.TableDataList)4 GoogleJsonError (com.google.api.client.googleapis.json.GoogleJsonError)3 ErrorInfo (com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo)3 GoogleJsonErrorContainer (com.google.api.client.googleapis.json.GoogleJsonErrorContainer)3 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)3 HttpResponseException (com.google.api.client.http.HttpResponseException)3 LowLevelHttpResponse (com.google.api.client.http.LowLevelHttpResponse)3 GenericJson (com.google.api.client.json.GenericJson)3