@Override public ResultSet answer(InvocationOnMock invocationOnMock) throws Throwable { // Let the main thread know we are blocked cqlBlocked.countDown(); // Wait for the main thread to give the signal to raise the connection exception raiseConnectionException.await(); // Raise the exception throw new OperationException("simulated cassandra exception"); } });
@Override public OperationResult<R> execute() throws ConnectionException { ConnectionException lastException = null; retry.begin(); do { try { return executeOp(); } catch (RuntimeException ex) { lastException = new OperationException(ex); } catch (ConnectionException ex) { if (ex instanceof IsRetryableException) lastException = ex; else throw ex; } } while (retry.allowRetry()); throw lastException; }
@SuppressWarnings("ThrowableResultOfMethodCallIgnored") @Test public void testNegativeHealthCheck() throws Exception { when(_astyanaxStatement.execute()).thenThrow(new OperationException("simulated cassandra exception")); when(_clock.millis()).thenReturn(1478789200000L); HealthCheck.Result result = _healthCheck.execute(); assertFalse(result.isHealthy()); assertTrue(result.getError() instanceof OperationException); }
throw new OperationException("simulated cassandra exception");