@Override public RetryResult beforeEval(Exception exception) { if (exception instanceof DatastoreException) { DatastoreException e = getInnerException((DatastoreException) exception); if (e.getCode() == ABORTED_CODE || e.getReason() != null && e.getReason().equals("ABORTED")) { return Interceptor.RetryResult.RETRY; } } return Interceptor.RetryResult.CONTINUE_EVALUATION; }
fail("Expecting a failure"); } catch (DatastoreException expected) { assertEquals(4, ((DatastoreException) expected.getCause()).getCode());
@Test public void testDatastoreException() throws Exception { DatastoreException exception = new DatastoreException(10, "message", "ABORTED"); assertEquals(10, exception.getCode()); assertEquals("ABORTED", exception.getReason()); assertEquals("message", exception.getMessage()); assertEquals(4, exception.getCode()); assertEquals("DEADLINE_EXCEEDED", exception.getReason()); assertEquals("message", exception.getMessage()); assertEquals(14, exception.getCode()); assertEquals("UNAVAILABLE", exception.getReason()); assertEquals("message", exception.getMessage()); assertEquals(2, exception.getCode()); assertEquals("INTERNAL", exception.getReason()); assertEquals("message", exception.getMessage()); assertEquals(DatastoreException.UNKNOWN_CODE, exception.getCode()); assertNull(exception.getReason()); assertEquals("socketTimeoutMessage", exception.getMessage()); assertEquals(2, exception.getCode()); assertEquals("INTERNAL", exception.getReason()); assertEquals("message", exception.getMessage());
fail("Expecting a failure"); } catch (DatastoreException expected) { assertEquals(3, ((DatastoreException) expected.getCause()).getCode());
@Override public RetryResult beforeEval(Exception exception) { if (exception instanceof DatastoreException) { DatastoreException e = getInnerException((DatastoreException) exception); if (e.getCode() == ABORTED_CODE || e.getReason() != null && e.getReason().equals("ABORTED")) { return Interceptor.RetryResult.RETRY; } } return Interceptor.RetryResult.CONTINUE_EVALUATION; }
public boolean isConflict() { if (getCause() != null && getCause() instanceof DatastoreException) { DatastoreException datastoreException = (DatastoreException) getCause(); return datastoreException.getCode() == 10; } else { return false; } }
/** * Wraps the given DatastoreException into an {@link EntityManagerException} or a subclass of * {@link EntityManagerException}. * * @param exp * the DatastoreException * @return An {@link EntityManagerException} or a subclass of {@link EntityManagerException}. */ static EntityManagerException wrap(DatastoreException exp) { switch (exp.getCode()) { case ERROR_CODE_ENTITY_NOT_FOUND: return new EntityNotFoundException(exp); case ERROR_CODE_ENTITY_ALREADY_EXISTS: return new EntityAlreadyExistsException(exp); default: return new EntityManagerException(exp); } }