use of org.springframework.data.cassandra.CassandraConnectionFailureException in project spring-data-cassandra by spring-projects.
the class CassandraTemplateUnitTests method selectShouldTranslateException.
// DATACASS-292
@Test
void selectShouldTranslateException() {
when(resultSet.iterator()).thenThrow(new NoNodeAvailableException());
try {
template.select("SELECT * FROM users", User.class);
fail("Missing CassandraConnectionFailureException");
} catch (CassandraConnectionFailureException e) {
assertThat(e).hasRootCauseInstanceOf(NoNodeAvailableException.class);
}
}
use of org.springframework.data.cassandra.CassandraConnectionFailureException in project spring-data-cassandra by spring-projects.
the class AsyncCqlTemplateUnitTests method queryCqlShouldTranslateExceptions.
// DATACASS-292
@Test
void queryCqlShouldTranslateExceptions() throws Exception {
TestResultSetFuture resultSetFuture = TestResultSetFuture.failed(new NoNodeAvailableException());
when(session.executeAsync(any(Statement.class))).thenReturn(resultSetFuture);
ListenableFuture<Boolean> future = template.query("UPDATE user SET a = 'b';", (AsyncResultSetExtractor<Boolean>) it -> new AsyncResult<>(it.wasApplied()));
try {
future.get();
fail("Missing CassandraConnectionFailureException");
} catch (ExecutionException e) {
assertThat(e).hasCauseInstanceOf(CassandraConnectionFailureException.class).hasMessageContaining("No node was available");
}
}
use of org.springframework.data.cassandra.CassandraConnectionFailureException in project spring-data-cassandra by spring-projects.
the class CqlTemplateUnitTests method queryCqlShouldTranslateExceptions.
// DATACASS-292
@Test
void queryCqlShouldTranslateExceptions() {
when(session.execute(any(Statement.class))).thenThrow(new NoNodeAvailableException());
try {
template.query("UPDATE user SET a = 'b';", ResultSet::wasApplied);
fail("Missing CassandraConnectionFailureException");
} catch (CassandraConnectionFailureException e) {
assertThat(e).hasMessageContaining("No node was available");
}
}
use of org.springframework.data.cassandra.CassandraConnectionFailureException in project spring-data-cassandra by spring-projects.
the class CqlTemplateUnitTests method queryPreparedStatementCreatorAndBinderShouldTranslateExecutionExceptions.
// DATACASS-292
@Test
void queryPreparedStatementCreatorAndBinderShouldTranslateExecutionExceptions() {
when(session.execute(boundStatement)).thenThrow(new NoNodeAvailableException());
try {
template.query(session -> preparedStatement, ps -> {
ps.bind("a", "b");
return boundStatement;
}, rs -> rs);
fail("Missing CassandraConnectionFailureException");
} catch (CassandraConnectionFailureException e) {
assertThat(e).hasCauseInstanceOf(NoNodeAvailableException.class);
}
}
use of org.springframework.data.cassandra.CassandraConnectionFailureException in project spring-data-cassandra by spring-projects.
the class CqlTemplateUnitTests method executeCqlShouldTranslateExceptions.
// DATACASS-292
@Test
void executeCqlShouldTranslateExceptions() {
when(session.execute(any(Statement.class))).thenThrow(new NoNodeAvailableException());
try {
template.execute("UPDATE user SET a = 'b';");
fail("Missing CassandraConnectionFailureException");
} catch (CassandraConnectionFailureException e) {
assertThat(e).hasMessageContaining("No node was available");
}
}
Aggregations