use of com.google.api.client.testing.http.MockLowLevelHttpResponse in project beam by apache.
the class GcsUtilTest method testFileSizeWhenFileNotFoundNonBatch.
@Test
public void testFileSizeWhenFileNotFoundNonBatch() throws Exception {
MockLowLevelHttpResponse notFoundResponse = new MockLowLevelHttpResponse();
notFoundResponse.setContent("");
notFoundResponse.setStatusCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
MockHttpTransport mockTransport = new MockHttpTransport.Builder().setLowLevelHttpResponse(notFoundResponse).build();
GcsOptions pipelineOptions = gcsOptionsWithTestCredential();
GcsUtil gcsUtil = pipelineOptions.getGcsUtil();
gcsUtil.setStorageClient(new Storage(mockTransport, Transport.getJsonFactory(), null));
thrown.expect(FileNotFoundException.class);
gcsUtil.fileSize(GcsPath.fromComponents("testbucket", "testobject"));
}
use of com.google.api.client.testing.http.MockLowLevelHttpResponse in project beam by apache.
the class RetryHttpRequestInitializerTest method createMockResponseWithStatusCode.
MockLowLevelHttpResponse[] createMockResponseWithStatusCode(int... statusCodes) {
MockLowLevelHttpResponse[] responses = new MockLowLevelHttpResponse[statusCodes.length];
for (int i = 0; i < statusCodes.length; ++i) {
MockLowLevelHttpResponse response = mock(MockLowLevelHttpResponse.class);
when(response.getStatusCode()).thenReturn(statusCodes[i]);
responses[i] = response;
}
return responses;
}
use of com.google.api.client.testing.http.MockLowLevelHttpResponse in project beam by apache.
the class RetryHttpRequestInitializerTest method testErrorCodeForbidden.
/**
* Tests that a non-retriable error is not retried.
*/
@Test
public void testErrorCodeForbidden() throws IOException {
MockLowLevelHttpResponse[] responses = createMockResponseWithStatusCode(// Non-retryable error.
403, // Shouldn't happen.
200);
when(mockLowLevelRequest.execute()).thenReturn(responses[0], responses[1]);
try {
Storage.Buckets.Get result = storage.buckets().get("test");
HttpResponse response = result.executeUnparsed();
assertNotNull(response);
} catch (HttpResponseException e) {
assertThat(e.getMessage(), Matchers.containsString("403"));
}
verify(mockHttpResponseInterceptor).interceptResponse(any(HttpResponse.class));
verify(mockLowLevelRequest, atLeastOnce()).addHeader(anyString(), anyString());
verify(mockLowLevelRequest).setTimeout(anyInt(), anyInt());
verify(mockLowLevelRequest).setWriteTimeout(anyInt());
verify(mockLowLevelRequest).execute();
verify(responses[0], atLeastOnce()).getStatusCode();
verify(responses[1], never()).getStatusCode();
expectedLogs.verifyWarn("Request failed with code 403");
}
Aggregations