@Test(groups = "short", dataProvider = "connectionErrors") public void should_retry_on_connection_error_if_statement_idempotent( ClosedConnectionConfig.CloseType closeType) { simulateError(1, closed_connection, new ClosedConnectionConfig(closeType)); simulateError(2, closed_connection, new ClosedConnectionConfig(closeType)); simulateError(3, closed_connection, new ClosedConnectionConfig(closeType)); try { session.execute(new SimpleStatement("mock query").setIdempotent(true)); Fail.fail("expected a TransportException"); } catch (NoHostAvailableException e) { assertThat(e.getErrors().keySet()) .hasSize(3) .containsOnly( host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress()); assertThat(e.getErrors().values()).hasOnlyElementsOfType(TransportException.class); } assertOnRequestErrorWasCalled(3, TransportException.class); assertThat(errors.getRetries().getCount()).isEqualTo(3); assertThat(errors.getConnectionErrors().getCount()).isEqualTo(3); assertThat(errors.getIgnoresOnConnectionError().getCount()).isEqualTo(0); assertThat(errors.getRetriesOnConnectionError().getCount()).isEqualTo(3); assertQueried(1, 1); assertQueried(2, 1); assertQueried(3, 1); }
@Test(groups = "short", dataProvider = "serverSideErrors") public void should_try_next_host_on_server_side_error( Result error, Class<? extends DriverException> exception) { simulateError(1, error); simulateError(2, error); simulateError(3, error); try { query(); Fail.fail("expected a NoHostAvailableException"); } catch (NoHostAvailableException e) { assertThat(e.getErrors().keySet()) .hasSize(3) .containsOnly( host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress()); assertThat(e.getErrors().values()).hasOnlyElementsOfType(exception); } assertOnRequestErrorWasCalled(3, exception); assertThat(errors.getOthers().getCount()).isEqualTo(3); assertThat(errors.getRetries().getCount()).isEqualTo(3); assertThat(errors.getRetriesOnOtherErrors().getCount()).isEqualTo(3); assertQueried(1, 1); assertQueried(2, 1); assertQueried(3, 1); }
@SuppressWarnings("UnusedParameters") @Test(groups = "short", dataProvider = "serverSideErrors") public void should_retry_on_server_error_if_statement_idempotent( Result error, Class<? extends DriverException> exception) { simulateError(1, error); simulateError(2, error); simulateError(3, error); try { session.execute(new SimpleStatement("mock query").setIdempotent(true)); fail("expected a NoHostAvailableException"); } catch (NoHostAvailableException e) { assertThat(e.getErrors().keySet()) .hasSize(3) .containsOnly( host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress()); assertThat(e.getErrors().values()).hasOnlyElementsOfType(exception); } assertOnRequestErrorWasCalled(3, exception); assertThat(errors.getOthers().getCount()).isEqualTo(3); assertThat(errors.getRetries().getCount()).isEqualTo(3); assertThat(errors.getRetriesOnOtherErrors().getCount()).isEqualTo(3); assertQueried(1, 1); assertQueried(2, 1); assertQueried(3, 1); }
@Test(groups = "short", dataProvider = "connectionErrors") public void should_try_next_host_on_connection_error(ClosedConnectionConfig.CloseType closeType) { simulateError(1, closed_connection, new ClosedConnectionConfig(closeType)); simulateError(2, closed_connection, new ClosedConnectionConfig(closeType)); simulateError(3, closed_connection, new ClosedConnectionConfig(closeType)); try { query(); Fail.fail("expected a NoHostAvailableException"); } catch (NoHostAvailableException e) { assertThat(e.getErrors().keySet()) .hasSize(3) .containsOnly( host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress()); assertThat(e.getErrors().values()).hasOnlyElementsOfType(TransportException.class); } assertOnRequestErrorWasCalled(3, TransportException.class); assertThat(errors.getRetries().getCount()).isEqualTo(3); assertThat(errors.getConnectionErrors().getCount()).isEqualTo(3); assertThat(errors.getIgnoresOnConnectionError().getCount()).isEqualTo(0); assertThat(errors.getRetriesOnConnectionError().getCount()).isEqualTo(3); assertQueried(1, 1); assertQueried(2, 1); assertQueried(3, 1); }
/** * Ensures that when handling a connection error caused by the connection closing during a request * in a way described by {@link #connectionErrors} that the next host is tried. * * @param closeType The way the connection should be closed during the request. */ @Test(groups = "short", dataProvider = "connectionErrors") public void should_try_next_host_on_connection_error(ClosedConnectionConfig.CloseType closeType) { simulateError(1, closed_connection, new ClosedConnectionConfig(closeType)); simulateError(2, closed_connection, new ClosedConnectionConfig(closeType)); simulateError(3, closed_connection, new ClosedConnectionConfig(closeType)); try { query(); Fail.fail("expected a TransportException"); } catch (NoHostAvailableException e) { assertThat(e.getErrors().keySet()) .hasSize(3) .containsOnly( host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress()); assertThat(e.getErrors().values()).hasOnlyElementsOfType(TransportException.class); } assertOnRequestErrorWasCalled(3, TransportException.class); assertThat(errors.getRetries().getCount()).isEqualTo(3); assertThat(errors.getConnectionErrors().getCount()).isEqualTo(3); assertThat(errors.getIgnoresOnConnectionError().getCount()).isEqualTo(0); assertThat(errors.getRetriesOnConnectionError().getCount()).isEqualTo(3); assertQueried(1, 1); assertQueried(2, 1); assertQueried(3, 1); }
.containsOnly( host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress()); assertThat(e.getErrors().values()).hasOnlyElementsOfType(exception);
host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress()); assertThat(e.getErrors().values()) .hasOnlyElementsOfType(OperationTimedOutException.class) .extractingResultOf("getMessage") .containsOnlyOnce(
host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress()); assertThat(e.getErrors().values()) .hasOnlyElementsOfType(OperationTimedOutException.class) .extractingResultOf("getMessage") .containsOnlyOnce(
@Test(groups = "short", dataProvider = "serverSideErrors") public void should_try_next_host_on_server_side_error( Result error, Class<? extends DriverException> exception) { simulateError(1, error); simulateError(2, error); simulateError(3, error); try { query(); Fail.fail("expected a NoHostAvailableException"); } catch (NoHostAvailableException e) { assertThat(e.getErrors().keySet()) .hasSize(3) .containsOnly( host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress()); assertThat(e.getErrors().values()).hasOnlyElementsOfType(exception); } assertOnRequestErrorWasCalled(3, exception); assertThat(errors.getOthers().getCount()).isEqualTo(3); assertThat(errors.getRetries().getCount()).isEqualTo(3); assertThat(errors.getRetriesOnOtherErrors().getCount()).isEqualTo(3); assertQueried(1, 1); assertQueried(2, 1); assertQueried(3, 1); }
@SuppressWarnings("UnusedParameters") @Test(groups = "short", dataProvider = "serverSideErrors") public void should_retry_on_server_error_if_statement_idempotent( Result error, Class<? extends DriverException> exception) { simulateError(1, error); simulateError(2, error); simulateError(3, error); try { session.execute(new SimpleStatement("mock query").setIdempotent(true)); fail("expected a NoHostAvailableException"); } catch (NoHostAvailableException e) { assertThat(e.getErrors().keySet()) .hasSize(3) .containsOnly( host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress()); assertThat(e.getErrors().values()).hasOnlyElementsOfType(exception); } assertOnRequestErrorWasCalled(3, exception); assertThat(errors.getOthers().getCount()).isEqualTo(3); assertThat(errors.getRetries().getCount()).isEqualTo(3); assertThat(errors.getRetriesOnOtherErrors().getCount()).isEqualTo(3); assertQueried(1, 1); assertQueried(2, 1); assertQueried(3, 1); }
@Test(groups = "short", dataProvider = "connectionErrors") public void should_try_next_host_on_connection_error(ClosedConnectionConfig.CloseType closeType) { simulateError(1, closed_connection, new ClosedConnectionConfig(closeType)); simulateError(2, closed_connection, new ClosedConnectionConfig(closeType)); simulateError(3, closed_connection, new ClosedConnectionConfig(closeType)); try { query(); Fail.fail("expected a NoHostAvailableException"); } catch (NoHostAvailableException e) { assertThat(e.getErrors().keySet()) .hasSize(3) .containsOnly( host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress()); assertThat(e.getErrors().values()).hasOnlyElementsOfType(TransportException.class); } assertOnRequestErrorWasCalled(3, TransportException.class); assertThat(errors.getRetries().getCount()).isEqualTo(3); assertThat(errors.getConnectionErrors().getCount()).isEqualTo(3); assertThat(errors.getIgnoresOnConnectionError().getCount()).isEqualTo(0); assertThat(errors.getRetriesOnConnectionError().getCount()).isEqualTo(3); assertQueried(1, 1); assertQueried(2, 1); assertQueried(3, 1); }
@Test(groups = "short", dataProvider = "connectionErrors") public void should_retry_on_connection_error_if_statement_idempotent( ClosedConnectionConfig.CloseType closeType) { simulateError(1, closed_connection, new ClosedConnectionConfig(closeType)); simulateError(2, closed_connection, new ClosedConnectionConfig(closeType)); simulateError(3, closed_connection, new ClosedConnectionConfig(closeType)); try { session.execute(new SimpleStatement("mock query").setIdempotent(true)); Fail.fail("expected a TransportException"); } catch (NoHostAvailableException e) { assertThat(e.getErrors().keySet()) .hasSize(3) .containsOnly( host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress()); assertThat(e.getErrors().values()).hasOnlyElementsOfType(TransportException.class); } assertOnRequestErrorWasCalled(3, TransportException.class); assertThat(errors.getRetries().getCount()).isEqualTo(3); assertThat(errors.getConnectionErrors().getCount()).isEqualTo(3); assertThat(errors.getIgnoresOnConnectionError().getCount()).isEqualTo(0); assertThat(errors.getRetriesOnConnectionError().getCount()).isEqualTo(3); assertQueried(1, 1); assertQueried(2, 1); assertQueried(3, 1); }
/** * Ensures that when handling a connection error caused by the connection closing during a request * in a way described by {@link #connectionErrors} that the next host is tried. * * @param closeType The way the connection should be closed during the request. */ @Test(groups = "short", dataProvider = "connectionErrors") public void should_try_next_host_on_connection_error(ClosedConnectionConfig.CloseType closeType) { simulateError(1, closed_connection, new ClosedConnectionConfig(closeType)); simulateError(2, closed_connection, new ClosedConnectionConfig(closeType)); simulateError(3, closed_connection, new ClosedConnectionConfig(closeType)); try { query(); Fail.fail("expected a TransportException"); } catch (NoHostAvailableException e) { assertThat(e.getErrors().keySet()) .hasSize(3) .containsOnly( host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress()); assertThat(e.getErrors().values()).hasOnlyElementsOfType(TransportException.class); } assertOnRequestErrorWasCalled(3, TransportException.class); assertThat(errors.getRetries().getCount()).isEqualTo(3); assertThat(errors.getConnectionErrors().getCount()).isEqualTo(3); assertThat(errors.getIgnoresOnConnectionError().getCount()).isEqualTo(0); assertThat(errors.getRetriesOnConnectionError().getCount()).isEqualTo(3); assertQueried(1, 1); assertQueried(2, 1); assertQueried(3, 1); }
.containsOnly( host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress()); assertThat(e.getErrors().values()).hasOnlyElementsOfType(exception);
host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress()); assertThat(e.getErrors().values()) .hasOnlyElementsOfType(OperationTimedOutException.class) .extractingResultOf("getMessage") .containsOnlyOnce(
host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress()); assertThat(e.getErrors().values()) .hasOnlyElementsOfType(OperationTimedOutException.class) .extractingResultOf("getMessage") .containsOnlyOnce(