Java 类com.google.appengine.api.datastore.DatastoreFailureException 实例源码
项目:nomulus
文件:WhoisServerTest.java
@Test
public void testRun_retryOnTransientFailure() throws Exception {
persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4"));
WhoisServer server = newWhoisServer("ns1.cat.lol");
WhoisResponse expectedResponse =
server.whoisReader.readCommand(server.input, clock.nowUtc()).executeQuery(clock.nowUtc());
WhoisReader mockReader = mock(WhoisReader.class);
WhoisCommand mockCommand = mock(WhoisCommand.class);
when(mockReader.readCommand(any(Reader.class), any(DateTime.class))).thenReturn(mockCommand);
when(mockCommand.executeQuery(any(DateTime.class)))
.thenThrow(new DatastoreFailureException("Expected transient exception #1"))
.thenThrow(new DatastoreTimeoutException("Expected transient exception #2"))
.thenReturn(expectedResponse);
server.whoisReader = mockReader;
server.run();
assertThat(response.getPayload()).isEqualTo(loadFile("whois_server_nameserver.txt"));
}
项目:appengine-java-vm-runtime
文件:VmApiProxyDelegateTest.java
public void testAPIExceptionWrapping() {
VmApiProxyDelegate delegate = new VmApiProxyDelegate(createMockHttpClient());
RuntimeException exception = delegate.constructApiException("logservice", "a");
assertEquals(LogServiceException.class, exception.getClass());
assertEquals("RCP Failure for API call: logservice a", exception.getMessage());
exception = delegate.constructApiException("modules", "b");
assertEquals(ModulesException.class, exception.getClass());
assertEquals("RCP Failure for API call: modules b", exception.getMessage());
exception = delegate.constructApiException("datastore_v3", "c");
assertEquals(DatastoreFailureException.class, exception.getClass());
assertEquals("RCP Failure for API call: datastore_v3 c", exception.getMessage());
exception = delegate.constructApiException("barf", "d");
assertEquals(ApiProxy.RPCFailedException.class, exception.getClass());
assertEquals(
"The remote RPC to the application server failed for the call barf.d().",
exception.getMessage());
}
项目:nomulus
文件:Ofy.java
/**
* Transact with commit logs and retry with exponential backoff.
*
* <p>This method is broken out from {@link #transactNew(Work)} for testing purposes.
*/
@VisibleForTesting
<R> R transactCommitLoggedWork(CommitLoggedWork<R> work) {
long baseRetryMillis = getBaseOfyRetryDuration().getMillis();
for (long attempt = 0, sleepMillis = baseRetryMillis;
true;
attempt++, sleepMillis *= 2) {
try {
ofy().transactNew(work);
return work.getResult();
} catch (TransientFailureException
| TimestampInversionException
| DatastoreTimeoutException
| DatastoreFailureException e) {
// TransientFailureExceptions come from task queues and always mean nothing committed.
// TimestampInversionExceptions are thrown by our code and are always retryable as well.
// However, Datastore exceptions might get thrown even if the transaction succeeded.
if ((e instanceof DatastoreTimeoutException || e instanceof DatastoreFailureException)
&& checkIfAlreadySucceeded(work)) {
return work.getResult();
}
if (attempt == NUM_RETRIES) {
throw e; // Give up.
}
sleeper.sleepUninterruptibly(Duration.millis(sleepMillis));
logger.infofmt(e, "Retrying %s, attempt %s", e.getClass().getSimpleName(), attempt);
}
}
}
项目:appengine-java-vm-runtime
文件:VmApiProxyDelegate.java
RuntimeException constructApiException(String packageName, String methodName) {
String message = "RCP Failure for API call: " + packageName + " " + methodName;
switch (packageName) {
case "taskqueue":
return new TransientFailureException(message);
case "app_identity_service":
return new AppIdentityServiceFailureException(message);
case "blobstore":
return new BlobstoreFailureException(message);
case "channel":
return new ChannelFailureException(message);
case "images":
return new ImagesServiceFailureException(message);
case "logservice":
return constructException(
LogServiceException.class.getName(), message, packageName, methodName);
case "memcache":
return new MemcacheServiceException(message);
case "modules":
return constructException(
ModulesException.class.getName(), message, packageName, methodName);
case "search":
return new SearchException(message);
case "user":
return new UserServiceFailureException(message);
case "xmpp":
return new XMPPFailureException(message);
default:
// Cover all datastore versions:
if (packageName.startsWith("datastore")) {
return new DatastoreFailureException(message);
} else {
return new RPCFailedException(packageName, methodName);
}
}
}
项目:nomulus
文件:OfyTest.java
@Test
public void testTransactNewReadOnly_datastoreFailureException_retries() {
doReadOnlyRetryTest(new DatastoreFailureException(""));
}