Search in sources :

Example 1 with NoNodeAvailableException

use of com.datastax.oss.driver.api.core.NoNodeAvailableException in project java-driver by datastax.

the class NodeTargetingIT method should_fail_if_node_is_not_connected.

@Test
public void should_fail_if_node_is_not_connected() {
    // given a statement with node explicitly set that for which we have no active pool.
    Node node4 = getNode(4);
    Statement statement = SimpleStatement.newInstance("select * system.local").setNode(node4);
    try {
        // when statement is executed
        SESSION_RULE.session().execute(statement);
        fail("Query should have failed");
    } catch (NoNodeAvailableException e) {
        assertThat(e.getAllErrors()).isEmpty();
    } catch (AllNodesFailedException e) {
        // its also possible that the query is tried.  This can happen if the node was marked
        // down, but not all connections have been closed yet.  In this case, just verify that
        // the expected host failed.
        assertThat(e.getAllErrors().size()).isEqualTo(1);
        assertThat(e.getAllErrors()).containsOnlyKeys(node4);
    }
}
Also used : AllNodesFailedException(com.datastax.oss.driver.api.core.AllNodesFailedException) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) Statement(com.datastax.oss.driver.api.core.cql.Statement) Node(com.datastax.oss.driver.api.core.metadata.Node) BoundNode(com.datastax.oss.simulacron.server.BoundNode) NoNodeAvailableException(com.datastax.oss.driver.api.core.NoNodeAvailableException) Test(org.junit.Test)

Aggregations

AllNodesFailedException (com.datastax.oss.driver.api.core.AllNodesFailedException)1 NoNodeAvailableException (com.datastax.oss.driver.api.core.NoNodeAvailableException)1 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)1 Statement (com.datastax.oss.driver.api.core.cql.Statement)1 Node (com.datastax.oss.driver.api.core.metadata.Node)1 BoundNode (com.datastax.oss.simulacron.server.BoundNode)1 Test (org.junit.Test)1