Search in sources :

Example 6 with Sleeper

use of com.google.api.client.util.Sleeper in project beam by apache.

the class RetryHttpRequestInitializerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    HttpTransport lowLevelTransport = new HttpTransport() {

        @Override
        protected LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
            return mockLowLevelRequest;
        }
    };
    // Retry initializer will pass through to credential, since we can have
    // only a single HttpRequestInitializer, and we use multiple Credential
    // types in the SDK, not all of which allow for retry configuration.
    RetryHttpRequestInitializer initializer = new RetryHttpRequestInitializer(new MockNanoClock(), new Sleeper() {

        @Override
        public void sleep(long millis) throws InterruptedException {
        }
    }, Arrays.asList(418), mockHttpResponseInterceptor);
    storage = new Storage.Builder(lowLevelTransport, jsonFactory, initializer).setApplicationName("test").build();
}
Also used : MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) Storage(com.google.api.services.storage.Storage) Matchers.anyString(org.mockito.Matchers.anyString) Sleeper(com.google.api.client.util.Sleeper) Before(org.junit.Before)

Example 7 with Sleeper

use of com.google.api.client.util.Sleeper 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);
    // 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()));
    verify(response, times(1)).getStatusCode();
    verify(response, times(1)).getContent();
    verify(response, times(1)).getContentType();
    expectedLogs.verifyNotLogged("Started BigQuery job");
}
Also used : JobReference(com.google.api.services.bigquery.model.JobReference) FastNanoClockAndSleeper(org.apache.beam.sdk.util.FastNanoClockAndSleeper) MockSleeper(com.google.api.client.testing.util.MockSleeper) FastNanoClockAndSleeper(org.apache.beam.sdk.util.FastNanoClockAndSleeper) Sleeper(com.google.api.client.util.Sleeper) Job(com.google.api.services.bigquery.model.Job) ApiErrorExtractor(com.google.cloud.hadoop.util.ApiErrorExtractor) Test(org.junit.Test)

Aggregations

Sleeper (com.google.api.client.util.Sleeper)7 Job (com.google.api.services.bigquery.model.Job)4 FastNanoClockAndSleeper (org.apache.beam.sdk.util.FastNanoClockAndSleeper)4 Test (org.junit.Test)4 MockSleeper (com.google.api.client.testing.util.MockSleeper)3 JobReference (com.google.api.services.bigquery.model.JobReference)3 ApiErrorExtractor (com.google.cloud.hadoop.util.ApiErrorExtractor)3 BackOff (com.google.api.client.util.BackOff)2 IOException (java.io.IOException)2 HttpTransport (com.google.api.client.http.HttpTransport)1 MockHttpTransport (com.google.api.client.testing.http.MockHttpTransport)1 NanoClock (com.google.api.client.util.NanoClock)1 JobStatus (com.google.api.services.bigquery.model.JobStatus)1 Job (com.google.api.services.dataflow.model.Job)1 JobMessage (com.google.api.services.dataflow.model.JobMessage)1 Storage (com.google.api.services.storage.Storage)1 MonitoringUtil (org.apache.beam.runners.dataflow.util.MonitoringUtil)1 Instant (org.joda.time.Instant)1 Before (org.junit.Before)1 Matchers.anyString (org.mockito.Matchers.anyString)1