@Test(groups = "short") public void should_fail_if_host_is_not_connected() { // given a statement with host explicitly set that for which we have no active pool. Host host4 = TestUtils.findHost(cluster, 4); Statement statement = new SimpleStatement("select * system.local").setHost(host4); try { // when statement is executed session.execute(statement); fail("Query should have failed"); } catch (NoHostAvailableException e) { // then the request should fail with a NHAE and no host was tried. assertThat(e.getErrors()).isEmpty(); } finally { verifyNoLbpInteractions(); } } }
@Test(groups = "short") public void should_use_host_on_statement() { for (int i = 0; i < 10; i++) { int hostIndex = i % 3 + 1; Host host = TestUtils.findHost(cluster, hostIndex); // given a statement with host explicitly set. Statement statement = new SimpleStatement("select * system.local").setHost(host); // when statement is executed ResultSet result = session.execute(statement); // then the query should have been sent to the configured host. assertThat(result.getExecutionInfo().getQueriedHost()).isSameAs(host); verifyNoLbpInteractions(); } }
@Test(groups = "short") public void should_fail_if_host_fails_query() { String query = "mock"; sCluster .node(1) .primingClient() .prime( PrimingRequest.queryBuilder() .withQuery(query) .withThen(then().withResult(Result.unavailable)) .build()); // given a statement with a host configured to fail the given query. Host host1 = TestUtils.findHost(cluster, 1); Statement statement = new SimpleStatement(query).setHost(host1); try { // when statement is executed an error should be raised. session.execute(statement); fail("Query should have failed"); } catch (NoHostAvailableException e) { // then the request should fail with a NHAE and no host was tried. assertThat(e.getErrors()).hasSize(1); assertThat(e.getErrors().values().iterator().next()).isInstanceOf(UnavailableException.class); } finally { verifyNoLbpInteractions(); } }
@Test(groups = "short") public void should_fail_if_host_is_not_connected() { // given a statement with host explicitly set that for which we have no active pool. Host host4 = TestUtils.findHost(cluster, 4); Statement statement = new SimpleStatement("select * system.local").setHost(host4); try { // when statement is executed session.execute(statement); fail("Query should have failed"); } catch (NoHostAvailableException e) { // then the request should fail with a NHAE and no host was tried. assertThat(e.getErrors()).isEmpty(); } finally { verifyNoLbpInteractions(); } } }
@Test(groups = "short") public void should_use_host_on_statement() { for (int i = 0; i < 10; i++) { int hostIndex = i % 3 + 1; Host host = TestUtils.findHost(cluster, hostIndex); // given a statement with host explicitly set. Statement statement = new SimpleStatement("select * system.local").setHost(host); // when statement is executed ResultSet result = session.execute(statement); // then the query should have been sent to the configured host. assertThat(result.getExecutionInfo().getQueriedHost()).isSameAs(host); verifyNoLbpInteractions(); } }
@Test(groups = "short") public void should_fail_if_host_fails_query() { String query = "mock"; sCluster .node(1) .primingClient() .prime( PrimingRequest.queryBuilder() .withQuery(query) .withThen(then().withResult(Result.unavailable)) .build()); // given a statement with a host configured to fail the given query. Host host1 = TestUtils.findHost(cluster, 1); Statement statement = new SimpleStatement(query).setHost(host1); try { // when statement is executed an error should be raised. session.execute(statement); fail("Query should have failed"); } catch (NoHostAvailableException e) { // then the request should fail with a NHAE and no host was tried. assertThat(e.getErrors()).hasSize(1); assertThat(e.getErrors().values().iterator().next()).isInstanceOf(UnavailableException.class); } finally { verifyNoLbpInteractions(); } }