use of org.apache.beam.sdk.extensions.gcp.util.FastNanoClockAndSleeper in project beam by apache.
the class BigQueryServicesImplTest method testStartLoadJobRetry.
/**
* Tests that {@link BigQueryServicesImpl.JobServiceImpl#startLoadJob} succeeds with a retry.
*/
@Test
public void testStartLoadJobRetry() throws IOException, InterruptedException {
Job testJob = new Job();
JobReference jobRef = new JobReference();
jobRef.setJobId("jobId");
jobRef.setProjectId("projectId");
testJob.setJobReference(jobRef);
// First response is 403 rate limited, 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("rateLimitExceeded", 403)));
}, response -> {
when(response.getContentType()).thenReturn(Json.MEDIA_TYPE);
when(response.getStatusCode()).thenReturn(200);
when(response.getContent()).thenReturn(toStream(testJob));
});
Sleeper sleeper = new FastNanoClockAndSleeper();
JobServiceImpl.startJob(testJob, new ApiErrorExtractor(), bigquery, sleeper, BackOffAdapter.toGcpBackOff(FluentBackoff.DEFAULT.backoff()));
verifyAllResponsesAreRead();
}
use of org.apache.beam.sdk.extensions.gcp.util.FastNanoClockAndSleeper in project beam by apache.
the class BigQueryServicesImplTest method testStartLoadJobSucceeds.
/**
* Tests that {@link BigQueryServicesImpl.JobServiceImpl#startLoadJob} succeeds.
*/
@Test
public void testStartLoadJobSucceeds() throws IOException, InterruptedException {
Job testJob = new Job();
JobReference jobRef = new JobReference();
jobRef.setJobId("jobId");
jobRef.setProjectId("projectId");
testJob.setJobReference(jobRef);
setupMockResponses(response -> {
when(response.getContentType()).thenReturn(Json.MEDIA_TYPE);
when(response.getStatusCode()).thenReturn(200);
when(response.getContent()).thenReturn(toStream(testJob));
});
Sleeper sleeper = new FastNanoClockAndSleeper();
JobServiceImpl.startJob(testJob, new ApiErrorExtractor(), bigquery, sleeper, BackOffAdapter.toGcpBackOff(FluentBackoff.DEFAULT.backoff()));
verifyAllResponsesAreRead();
expectedLogs.verifyInfo(String.format("Started BigQuery job: %s", jobRef));
}
use of org.apache.beam.sdk.extensions.gcp.util.FastNanoClockAndSleeper in project beam by apache.
the class BigQueryServicesImplTest method testStartLoadJobSucceedsAlreadyExists.
/**
* Tests that {@link BigQueryServicesImpl.JobServiceImpl#startLoadJob} succeeds with an already
* exist job.
*/
@Test
public void testStartLoadJobSucceedsAlreadyExists() throws IOException, InterruptedException {
Job testJob = new Job();
JobReference jobRef = new JobReference();
jobRef.setJobId("jobId");
jobRef.setProjectId("projectId");
testJob.setJobReference(jobRef);
setupMockResponses(response -> {
// 409 means already exists
when(response.getStatusCode()).thenReturn(409);
});
Sleeper sleeper = new FastNanoClockAndSleeper();
JobServiceImpl.startJob(testJob, new ApiErrorExtractor(), bigquery, sleeper, BackOffAdapter.toGcpBackOff(FluentBackoff.DEFAULT.backoff()));
verifyAllResponsesAreRead();
expectedLogs.verifyNotLogged("Started BigQuery job");
}
Aggregations