Search in sources :

Example 1 with SplitReadStreamRequest

use of com.google.cloud.bigquery.storage.v1.SplitReadStreamRequest in project beam by apache.

the class BigQueryServicesImplTest method testSplitReadStreamSetsRequestCountMetricOnError.

@Test
public void testSplitReadStreamSetsRequestCountMetricOnError() throws InterruptedException, IOException {
    BigQueryServices.StorageClient client = mock(BigQueryServicesImpl.StorageClientImpl.class);
    SplitReadStreamRequest request = null;
    StatusCode statusCode = new StatusCode() {

        @Override
        public Code getCode() {
            return Code.RESOURCE_EXHAUSTED;
        }

        @Override
        public Object getTransportCode() {
            return null;
        }
    };
    when(client.splitReadStream(request)).thenThrow(new ApiException("Resource Exhausted", null, statusCode, // Mock implementation.
    false));
    // Real implementation.
    when(client.splitReadStream(any(), any())).thenCallRealMethod();
    thrown.expect(ApiException.class);
    thrown.expectMessage("Resource Exhausted");
    client.splitReadStream(request, "myproject:mydataset.mytable");
    verifyReadMetricWasSet("myproject", "mydataset", "mytable", "resource_exhausted", 1);
}
Also used : SplitReadStreamRequest(com.google.cloud.bigquery.storage.v1.SplitReadStreamRequest) StatusCode(com.google.api.gax.rpc.StatusCode) ApiException(com.google.api.gax.rpc.ApiException) Test(org.junit.Test)

Example 2 with SplitReadStreamRequest

use of com.google.cloud.bigquery.storage.v1.SplitReadStreamRequest in project beam by apache.

the class BigQueryServicesImplTest method testSplitReadStreamSetsRequestCountMetric.

@Test
public void testSplitReadStreamSetsRequestCountMetric() throws InterruptedException, IOException {
    BigQueryServices.StorageClient client = mock(BigQueryServicesImpl.StorageClientImpl.class);
    SplitReadStreamRequest request = null;
    when(client.splitReadStream(request)).thenReturn(// Mock implementation.
    SplitReadStreamResponse.newBuilder().build());
    // Real implementation.
    when(client.splitReadStream(any(), any())).thenCallRealMethod();
    client.splitReadStream(request, "myproject:mydataset.mytable");
    verifyReadMetricWasSet("myproject", "mydataset", "mytable", "ok", 1);
}
Also used : SplitReadStreamRequest(com.google.cloud.bigquery.storage.v1.SplitReadStreamRequest) Test(org.junit.Test)

Aggregations

SplitReadStreamRequest (com.google.cloud.bigquery.storage.v1.SplitReadStreamRequest)2 Test (org.junit.Test)2 ApiException (com.google.api.gax.rpc.ApiException)1 StatusCode (com.google.api.gax.rpc.StatusCode)1