本文整理汇总了Java中com.google.api.client.util.Sleeper类的典型用法代码示例。如果您正苦于以下问题:Java Sleeper类的具体用法?Java Sleeper怎么用?Java Sleeper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Sleeper类属于com.google.api.client.util包,在下文中一共展示了Sleeper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getProjectNumber
import com.google.api.client.util.Sleeper; //导入依赖的package包/类
/**
* Returns the project number or throws an error if the project does not
* exist or has other access errors.
*/
private static long getProjectNumber(
String projectId,
CloudResourceManager crmClient,
BackOff backoff,
Sleeper sleeper) throws IOException {
CloudResourceManager.Projects.Get getProject =
crmClient.projects().get(projectId);
try {
Project project = ResilientOperation.retry(
ResilientOperation.getGoogleRequestCallable(getProject),
backoff,
RetryDeterminer.SOCKET_ERRORS,
IOException.class,
sleeper);
return project.getProjectNumber();
} catch (Exception e) {
throw new IOException("Unable to get project number", e);
}
}
示例2: setUp
import com.google.api.client.util.Sleeper; //导入依赖的package包/类
@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 /* I'm a teapot */), mockHttpResponseInterceptor);
storage = new Storage.Builder(lowLevelTransport, jsonFactory, initializer)
.setApplicationName("test").build();
}
示例3: dryRunQuery
import com.google.api.client.util.Sleeper; //导入依赖的package包/类
@Override
public JobStatistics dryRunQuery(String projectId, JobConfigurationQuery queryConfig)
throws InterruptedException, IOException {
Job job = new Job()
.setConfiguration(new JobConfiguration()
.setQuery(queryConfig)
.setDryRun(true));
return executeWithRetries(
client.jobs().insert(projectId, job),
String.format(
"Unable to dry run query: %s, aborting after %d retries.",
queryConfig, MAX_RPC_RETRIES),
Sleeper.DEFAULT,
createDefaultBackoff(),
ALWAYS_RETRY).getStatistics();
}
示例4: getTable
import com.google.api.client.util.Sleeper; //导入依赖的package包/类
@VisibleForTesting
@Nullable
Table getTable(TableReference ref, BackOff backoff, Sleeper sleeper)
throws IOException, InterruptedException {
try {
return executeWithRetries(
client.tables().get(ref.getProjectId(), ref.getDatasetId(), ref.getTableId()),
String.format(
"Unable to get table: %s, aborting after %d retries.",
ref.getTableId(), MAX_RPC_RETRIES),
sleeper,
backoff,
DONT_RETRY_NOT_FOUND);
} catch (IOException e) {
if (errorExtractor.itemNotFound(e)) {
return null;
}
throw e;
}
}
示例5: createDataset
import com.google.api.client.util.Sleeper; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* <p>Tries executing the RPC for at most {@code MAX_RPC_RETRIES} times until it succeeds.
*
* @throws IOException if it exceeds {@code MAX_RPC_RETRIES} attempts.
*/
@Override
public void createDataset(
String projectId,
String datasetId,
@Nullable String location,
@Nullable String description,
@Nullable Long defaultTableExpirationMs)
throws IOException, InterruptedException {
createDataset(
projectId,
datasetId,
location,
description,
defaultTableExpirationMs,
Sleeper.DEFAULT,
createDefaultBackoff());
}
示例6: patchTableDescription
import com.google.api.client.util.Sleeper; //导入依赖的package包/类
@Override
public Table patchTableDescription(TableReference tableReference,
@Nullable String tableDescription)
throws IOException, InterruptedException {
Table table = new Table();
table.setDescription(tableDescription);
return executeWithRetries(
client.tables().patch(
tableReference.getProjectId(),
tableReference.getDatasetId(),
tableReference.getTableId(),
table),
String.format(
"Unable to patch table description: %s, aborting after %d retries.",
tableReference, MAX_RPC_RETRIES),
Sleeper.DEFAULT,
createDefaultBackoff(),
ALWAYS_RETRY);
}
示例7: executeWithRetries
import com.google.api.client.util.Sleeper; //导入依赖的package包/类
@VisibleForTesting
static <T> T executeWithRetries(
AbstractGoogleClientRequest<T> request,
String errorMessage,
Sleeper sleeper,
BackOff backoff,
SerializableFunction<IOException, Boolean> shouldRetry)
throws IOException, InterruptedException {
Exception lastException = null;
do {
try {
return request.execute();
} catch (IOException e) {
lastException = e;
if (!shouldRetry.apply(e)) {
break;
}
LOG.info("Ignore the error and retry the request.", e);
}
} while (nextBackOff(sleeper, backoff));
throw new IOException(
errorMessage,
lastException);
}
示例8: testStartLoadJobSucceeds
import com.google.api.client.util.Sleeper; //导入依赖的package包/类
/**
* 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);
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()));
verify(response, times(1)).getStatusCode();
verify(response, times(1)).getContent();
verify(response, times(1)).getContentType();
expectedLogs.verifyInfo(String.format("Started BigQuery job: %s", jobRef));
}
示例9: testStartLoadJobSucceedsAlreadyExists
import com.google.api.client.util.Sleeper; //导入依赖的package包/类
/**
* 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);
when(response.getStatusCode()).thenReturn(409); // 409 means already exists
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");
}
示例10: testStartLoadJobRetry
import com.google.api.client.util.Sleeper; //导入依赖的package包/类
/**
* 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.
when(response.getContentType()).thenReturn(Json.MEDIA_TYPE);
when(response.getStatusCode()).thenReturn(403).thenReturn(200);
when(response.getContent())
.thenReturn(toStream(errorWithReasonAndStatus("rateLimitExceeded", 403)))
.thenReturn(toStream(testJob));
Sleeper sleeper = new FastNanoClockAndSleeper();
JobServiceImpl.startJob(
testJob, new ApiErrorExtractor(), bigquery, sleeper,
BackOffAdapter.toGcpBackOff(FluentBackoff.DEFAULT.backoff()));
verify(response, times(2)).getStatusCode();
verify(response, times(2)).getContent();
verify(response, times(2)).getContentType();
}
示例11: testPollJobSucceeds
import com.google.api.client.util.Sleeper; //导入依赖的package包/类
/**
* Tests that {@link BigQueryServicesImpl.JobServiceImpl#pollJob} succeeds.
*/
@Test
public void testPollJobSucceeds() throws IOException, InterruptedException {
Job testJob = new Job();
testJob.setStatus(new JobStatus().setState("DONE"));
when(response.getContentType()).thenReturn(Json.MEDIA_TYPE);
when(response.getStatusCode()).thenReturn(200);
when(response.getContent()).thenReturn(toStream(testJob));
BigQueryServicesImpl.JobServiceImpl jobService =
new BigQueryServicesImpl.JobServiceImpl(bigquery);
JobReference jobRef = new JobReference()
.setProjectId("projectId")
.setJobId("jobId");
Job job = jobService.pollJob(jobRef, Sleeper.DEFAULT, BackOff.ZERO_BACKOFF);
assertEquals(testJob, job);
verify(response, times(1)).getStatusCode();
verify(response, times(1)).getContent();
verify(response, times(1)).getContentType();
}
示例12: testPollJobFailed
import com.google.api.client.util.Sleeper; //导入依赖的package包/类
/**
* Tests that {@link BigQueryServicesImpl.JobServiceImpl#pollJob} fails.
*/
@Test
public void testPollJobFailed() throws IOException, InterruptedException {
Job testJob = new Job();
testJob.setStatus(new JobStatus().setState("DONE").setErrorResult(new ErrorProto()));
when(response.getContentType()).thenReturn(Json.MEDIA_TYPE);
when(response.getStatusCode()).thenReturn(200);
when(response.getContent()).thenReturn(toStream(testJob));
BigQueryServicesImpl.JobServiceImpl jobService =
new BigQueryServicesImpl.JobServiceImpl(bigquery);
JobReference jobRef = new JobReference()
.setProjectId("projectId")
.setJobId("jobId");
Job job = jobService.pollJob(jobRef, Sleeper.DEFAULT, BackOff.ZERO_BACKOFF);
assertEquals(testJob, job);
verify(response, times(1)).getStatusCode();
verify(response, times(1)).getContent();
verify(response, times(1)).getContentType();
}
示例13: testPollJobUnknown
import com.google.api.client.util.Sleeper; //导入依赖的package包/类
/**
* Tests that {@link BigQueryServicesImpl.JobServiceImpl#pollJob} returns UNKNOWN.
*/
@Test
public void testPollJobUnknown() throws IOException, InterruptedException {
Job testJob = new Job();
testJob.setStatus(new JobStatus());
when(response.getContentType()).thenReturn(Json.MEDIA_TYPE);
when(response.getStatusCode()).thenReturn(200);
when(response.getContent()).thenReturn(toStream(testJob));
BigQueryServicesImpl.JobServiceImpl jobService =
new BigQueryServicesImpl.JobServiceImpl(bigquery);
JobReference jobRef = new JobReference()
.setProjectId("projectId")
.setJobId("jobId");
Job job = jobService.pollJob(jobRef, Sleeper.DEFAULT, BackOff.STOP_BACKOFF);
assertEquals(null, job);
verify(response, times(1)).getStatusCode();
verify(response, times(1)).getContent();
verify(response, times(1)).getContentType();
}
示例14: testGetJobSucceeds
import com.google.api.client.util.Sleeper; //导入依赖的package包/类
@Test
public void testGetJobSucceeds() throws Exception {
Job testJob = new Job();
testJob.setStatus(new JobStatus());
when(response.getContentType()).thenReturn(Json.MEDIA_TYPE);
when(response.getStatusCode()).thenReturn(200);
when(response.getContent()).thenReturn(toStream(testJob));
BigQueryServicesImpl.JobServiceImpl jobService =
new BigQueryServicesImpl.JobServiceImpl(bigquery);
JobReference jobRef = new JobReference()
.setProjectId("projectId")
.setJobId("jobId");
Job job = jobService.getJob(jobRef, Sleeper.DEFAULT, BackOff.ZERO_BACKOFF);
assertEquals(testJob, job);
verify(response, times(1)).getStatusCode();
verify(response, times(1)).getContent();
verify(response, times(1)).getContentType();
}
示例15: testGetJobNotFound
import com.google.api.client.util.Sleeper; //导入依赖的package包/类
@Test
public void testGetJobNotFound() throws Exception {
when(response.getContentType()).thenReturn(Json.MEDIA_TYPE);
when(response.getStatusCode()).thenReturn(404);
BigQueryServicesImpl.JobServiceImpl jobService =
new BigQueryServicesImpl.JobServiceImpl(bigquery);
JobReference jobRef = new JobReference()
.setProjectId("projectId")
.setJobId("jobId");
Job job = jobService.getJob(jobRef, Sleeper.DEFAULT, BackOff.ZERO_BACKOFF);
assertEquals(null, job);
verify(response, times(1)).getStatusCode();
verify(response, times(1)).getContent();
verify(response, times(1)).getContentType();
}