@Override public WriteTimeoutException copy() { return new WriteTimeoutException( getAddress(), getMessage(), this, getConsistencyLevel(), getWriteType(), getReceivedAcknowledgements(), getRequiredAcknowledgements()); }
@Test(groups = "unit") public void should_create_proper_write_timeout_exception() { WriteTimeoutException e = new WriteTimeoutException(address1, LOCAL_QUORUM, WriteType.BATCH, 2, 3); assertThat(e.getMessage()) .isEqualTo( "Cassandra timeout during BATCH write query at consistency LOCAL_QUORUM (3 replica were required but only 2 acknowledged the write)"); assertThat(e.getConsistencyLevel()).isEqualTo(LOCAL_QUORUM); assertThat(e.getReceivedAcknowledgements()).isEqualTo(2); assertThat(e.getRequiredAcknowledgements()).isEqualTo(3); assertThat(e.getWriteType()).isEqualTo(WriteType.BATCH); assertThat(e.getAddress()).isEqualTo(address1); assertThat(e.getHost()).isEqualTo(address1.getAddress()); e = e.copy(address2); assertThat(e.getMessage()) .isEqualTo( "Cassandra timeout during BATCH write query at consistency LOCAL_QUORUM (3 replica were required but only 2 acknowledged the write)"); assertThat(e.getConsistencyLevel()).isEqualTo(LOCAL_QUORUM); assertThat(e.getReceivedAcknowledgements()).isEqualTo(2); assertThat(e.getRequiredAcknowledgements()).isEqualTo(3); assertThat(e.getWriteType()).isEqualTo(WriteType.BATCH); assertThat(e.getAddress()).isEqualTo(address2); assertThat(e.getHost()).isEqualTo(address2.getAddress()); } }
@Test(groups = "short") public void should_throw_proper_write_timeout_exception() { simulateError(1, write_request_timeout); try { query(); fail("expected a WriteTimeoutException"); } catch (WriteTimeoutException e) { assertThat(e.getMessage()) .isEqualTo( "Cassandra timeout during SIMPLE write query at consistency LOCAL_ONE (1 replica were required but only 0 acknowledged the write)"); assertThat(e.getConsistencyLevel()).isEqualTo(LOCAL_ONE); assertThat(e.getReceivedAcknowledgements()).isEqualTo(0); assertThat(e.getRequiredAcknowledgements()).isEqualTo(1); assertThat(e.getWriteType()).isEqualTo(WriteType.SIMPLE); assertThat(e.getAddress()).isEqualTo(host1.getSocketAddress()); assertThat(e.getHost()).isEqualTo(host1.getAddress()); } }
/** * Create a copy of this exception with a nicer stack trace, and including the coordinator address * that caused this exception to be raised. * * <p>This method is mainly intended for internal use by the driver and exists mainly because: * * <ol> * <li>the original exception was decoded from a response frame and at that time, the * coordinator address was not available; and * <li>the newly-created exception will refer to the current thread in its stack trace, which * generally yields a more user-friendly stack trace that the original one. * </ol> * * @param address The full address of the host that caused this exception to be thrown. * @return a copy/clone of this exception, but with the given host address instead of the original * one. */ public WriteTimeoutException copy(InetSocketAddress address) { return new WriteTimeoutException( address, getMessage(), this, getConsistencyLevel(), getWriteType(), getReceivedAcknowledgements(), getRequiredAcknowledgements()); } }
statement, wte.getConsistencyLevel(), wte.getWriteType(), wte.getRequiredAcknowledgements(), wte.getReceivedAcknowledgements(),
@Override public DriverException copy() { return new WriteTimeoutException(getMessage(), this, getConsistencyLevel(), getWriteType(), getReceivedAcknowledgements(), getRequiredAcknowledgements()); } }
@Test public void handle_WTEThrownInSimpleWriteInBatchExecution_ShouldThrowRetriableExecutionException() { // Arrange configureBehavior(); mutations = prepareConditionalPuts(); WriteTimeoutException e = mock(WriteTimeoutException.class); when(e.getWriteType()).thenReturn(WriteType.SIMPLE); when(session.execute(any(Statement.class))).thenThrow(e); // Act Assert assertThatThrownBy( () -> { batch.handle(mutations); }) .isInstanceOf(RetriableExecutionException.class) .hasCause(e); }
@Test public void handle_WTEThrownInLoggingInBatchExecution_ShouldThrowRetriableExecutionException() { // Arrange configureBehavior(); mutations = prepareConditionalPuts(); WriteTimeoutException e = mock(WriteTimeoutException.class); when(e.getWriteType()).thenReturn(WriteType.BATCH_LOG); when(session.execute(any(Statement.class))).thenThrow(e); // Act Assert assertThatThrownBy( () -> { batch.handle(mutations); }) .isInstanceOf(RetriableExecutionException.class) .hasCause(e); }
@Test public void handle_WTEThrownInCasInBatchExecution_ShouldThrowRetriableExecutionException() { // Arrange configureBehavior(); mutations = prepareConditionalPuts(); WriteTimeoutException e = mock(WriteTimeoutException.class); when(e.getWriteType()).thenReturn(WriteType.CAS); when(session.execute(any(Statement.class))).thenThrow(e); // Act Assert assertThatThrownBy( () -> { batch.handle(mutations); }) .isInstanceOf(RetriableExecutionException.class) .hasCause(e); }
@Test public void handle_WTEThrownInMutationInBatchExecution_ShouldExecuteProperly() { // Arrange configureBehavior(); mutations = prepareConditionalPuts(); WriteTimeoutException e = mock(WriteTimeoutException.class); when(e.getWriteType()).thenReturn(WriteType.BATCH); when(session.execute(any(Statement.class))).thenThrow(e); // Act Assert assertThatCode( () -> { batch.handle(mutations); }) .doesNotThrowAnyException(); }
@Override public WriteTimeoutException copy() { return new WriteTimeoutException( getAddress(), getMessage(), this, getConsistencyLevel(), getWriteType(), getReceivedAcknowledgements(), getRequiredAcknowledgements() ); }
@Override public WriteTimeoutException copy() { return new WriteTimeoutException( getAddress(), getMessage(), this, getConsistencyLevel(), getWriteType(), getReceivedAcknowledgements(), getRequiredAcknowledgements() ); }
@Override public WriteTimeoutException copy() { return new WriteTimeoutException( getAddress(), getMessage(), this, getConsistencyLevel(), getWriteType(), getReceivedAcknowledgements(), getRequiredAcknowledgements() ); }
@Test(groups = "short") public void should_throw_proper_write_timeout_exception() { simulateError(1, write_request_timeout); try { query(); fail("expected a WriteTimeoutException"); } catch (WriteTimeoutException e) { assertThat(e.getMessage()) .isEqualTo( "Cassandra timeout during SIMPLE write query at consistency LOCAL_ONE (1 replica were required but only 0 acknowledged the write)"); assertThat(e.getConsistencyLevel()).isEqualTo(LOCAL_ONE); assertThat(e.getReceivedAcknowledgements()).isEqualTo(0); assertThat(e.getRequiredAcknowledgements()).isEqualTo(1); assertThat(e.getWriteType()).isEqualTo(WriteType.SIMPLE); assertThat(e.getAddress()).isEqualTo(host1.getSocketAddress()); assertThat(e.getHost()).isEqualTo(host1.getAddress()); } }
@Test public void handle_PutWithoutConditionGivenAndWTEWithSimpleThrown_ShouldThrowProperExecutionException() throws ExecutionException { // Arrange put = preparePutWithClusteringKey(); spy = prepareSpiedInsertStatementHandler(); WriteTimeoutException toThrow = mock(WriteTimeoutException.class); when(toThrow.getWriteType()).thenReturn(WriteType.SIMPLE); doThrow(toThrow).when(spy).handleInternal(put); // Act Assert assertThatThrownBy( () -> { spy.handle(put); }) .isInstanceOf(RetriableExecutionException.class) .hasCause(toThrow); }
@Test(groups = "unit") public void should_create_proper_write_timeout_exception() { WriteTimeoutException e = new WriteTimeoutException(address1, LOCAL_QUORUM, WriteType.BATCH, 2, 3); assertThat(e.getMessage()) .isEqualTo( "Cassandra timeout during BATCH write query at consistency LOCAL_QUORUM (3 replica were required but only 2 acknowledged the write)"); assertThat(e.getConsistencyLevel()).isEqualTo(LOCAL_QUORUM); assertThat(e.getReceivedAcknowledgements()).isEqualTo(2); assertThat(e.getRequiredAcknowledgements()).isEqualTo(3); assertThat(e.getWriteType()).isEqualTo(WriteType.BATCH); assertThat(e.getAddress()).isEqualTo(address1); assertThat(e.getHost()).isEqualTo(address1.getAddress()); e = e.copy(address2); assertThat(e.getMessage()) .isEqualTo( "Cassandra timeout during BATCH write query at consistency LOCAL_QUORUM (3 replica were required but only 2 acknowledged the write)"); assertThat(e.getConsistencyLevel()).isEqualTo(LOCAL_QUORUM); assertThat(e.getReceivedAcknowledgements()).isEqualTo(2); assertThat(e.getRequiredAcknowledgements()).isEqualTo(3); assertThat(e.getWriteType()).isEqualTo(WriteType.BATCH); assertThat(e.getAddress()).isEqualTo(address2); assertThat(e.getHost()).isEqualTo(address2.getAddress()); } }
/** * Create a copy of this exception with a nicer stack trace, and including the coordinator * address that caused this exception to be raised. * <p/> * This method is mainly intended for internal use by the driver and exists mainly because: * <ol> * <li>the original exception was decoded from a response frame * and at that time, the coordinator address was not available; and</li> * <li>the newly-created exception will refer to the current thread in its stack trace, * which generally yields a more user-friendly stack trace that the original one.</li> * </ol> * * @param address The full address of the host that caused this exception to be thrown. * @return a copy/clone of this exception, but with the given host address instead of the original one. */ public WriteTimeoutException copy(InetSocketAddress address) { return new WriteTimeoutException( address, getMessage(), this, getConsistencyLevel(), getWriteType(), getReceivedAcknowledgements(), getRequiredAcknowledgements() ); }
/** * Create a copy of this exception with a nicer stack trace, and including the coordinator * address that caused this exception to be raised. * <p/> * This method is mainly intended for internal use by the driver and exists mainly because: * <ol> * <li>the original exception was decoded from a response frame * and at that time, the coordinator address was not available; and</li> * <li>the newly-created exception will refer to the current thread in its stack trace, * which generally yields a more user-friendly stack trace that the original one.</li> * </ol> * * @param address The full address of the host that caused this exception to be thrown. * @return a copy/clone of this exception, but with the given host address instead of the original one. */ public WriteTimeoutException copy(InetSocketAddress address) { return new WriteTimeoutException( address, getMessage(), this, getConsistencyLevel(), getWriteType(), getReceivedAcknowledgements(), getRequiredAcknowledgements() ); }
@Test public void handle_WTEWithCasThrown_ShouldThrowProperExecutionException() throws ExecutionException { // Arrange put = preparePutWithClusteringKey(); put.withCondition(new PutIfNotExists()); spy = prepareSpiedInsertStatementHandler(); WriteTimeoutException toThrow = mock(WriteTimeoutException.class); when(toThrow.getWriteType()).thenReturn(WriteType.CAS); doThrow(toThrow).when(spy).handleInternal(put); // Act Assert assertThatThrownBy( () -> { spy.handle(put); }) .isInstanceOf(RetriableExecutionException.class) .hasCause(toThrow); }
@Test public void handle_PutWithConditionGivenAndWTEWithSimpleThrown_ShouldThrowProperExecutionException() throws ExecutionException { // Arrange put = preparePutWithClusteringKey(); put.withCondition(new PutIfNotExists()); spy = prepareSpiedInsertStatementHandler(); WriteTimeoutException toThrow = mock(WriteTimeoutException.class); when(toThrow.getWriteType()).thenReturn(WriteType.SIMPLE); doThrow(toThrow).when(spy).handleInternal(put); // Act Assert assertThatThrownBy( () -> { spy.handle(put); }) .isInstanceOf(ReadRepairableExecutionException.class) .hasCause(toThrow); }