com.google.appengine.api.datastore.DatastoreFailureException Java Examples
The following examples show how to use
com.google.appengine.api.datastore.DatastoreFailureException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WhoisActionTest.java From nomulus with Apache License 2.0 | 6 votes |
@Test public void testRun_retryOnTransientFailure() throws Exception { persistResource(loadRegistrar("TheRegistrar").asBuilder().setUrl("http://my.fake.url").build()); persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")); WhoisAction action = newWhoisAction("ns1.cat.lol"); WhoisResponse expectedResponse = action .whoisReader .readCommand(action.input, false, clock.nowUtc()) .executeQuery(clock.nowUtc()); WhoisReader mockReader = mock(WhoisReader.class); WhoisCommand mockCommand = mock(WhoisCommand.class); when(mockReader.readCommand(any(Reader.class), eq(false), 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); action.whoisReader = mockReader; action.run(); assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_nameserver.txt")); }
Example #2
Source File: VmApiProxyDelegateTest.java From appengine-java-vm-runtime with Apache License 2.0 | 6 votes |
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()); }
Example #3
Source File: Ofy.java From nomulus with Apache License 2.0 | 5 votes |
/** * 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.run(); return null; }); 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.atInfo().withCause(e).log( "Retrying %s, attempt %d", e.getClass().getSimpleName(), attempt); } } }
Example #4
Source File: VmApiProxyDelegate.java From appengine-java-vm-runtime with Apache License 2.0 | 5 votes |
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); } } }
Example #5
Source File: OfyTest.java From nomulus with Apache License 2.0 | 4 votes |
@Test public void testTransactNewReadOnly_datastoreFailureException_retries() { doReadOnlyRetryTest(new DatastoreFailureException("")); }