DATACASS-304 - CqlTemplate.doExecute does not translate Cassandra Exceptions.

This commit is contained in:
John Blum
2016-07-01 17:44:37 -07:00
parent ab73021187
commit 570d71a905
4 changed files with 59 additions and 23 deletions

View File

@@ -30,6 +30,7 @@ import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.cassandra.support.CassandraExceptionTranslator;
import org.springframework.cassandra.support.exception.CassandraReadTimeoutException;
import org.springframework.cassandra.support.exception.CassandraUncategorizedException;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
@@ -38,6 +39,7 @@ import com.datastax.driver.core.ConsistencyLevel;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.exceptions.DriverException;
import com.datastax.driver.core.exceptions.ReadTimeoutException;
import com.datastax.driver.core.querybuilder.Select;
@@ -80,8 +82,11 @@ public class CqlTemplateUnitTests {
verify(mockSession, times(1)).execute(eq("test"));
}
/**
* @see <a href="https://jira.spring.io/browse/DATACASS-304">DATACASS-304</a>
*/
@Test
public void doExecuteInSessionCallbackTranslatesException() {
public void doExecuteInSessionCallbackTranslatesToCassandraException() {
exception.expect(CassandraReadTimeoutException.class);
exception.expectCause(org.hamcrest.Matchers.isA(ReadTimeoutException.class));
@@ -92,6 +97,38 @@ public class CqlTemplateUnitTests {
});
}
/**
* @see <a href="https://jira.spring.io/browse/DATACASS-304">DATACASS-304</a>
*/
@Test
public void doExecuteInSessionCallbackTranslatesToCassandraUncategorizedException() {
exception.expect(CassandraUncategorizedException.class);
exception.expectCause(org.hamcrest.Matchers.isA(DriverException.class));
exception.expectMessage(containsString("test"));
template.doExecute(new SessionCallback<String>() {
@Override public String doInSession(Session session) throws DataAccessException {
throw new DriverException("test");
}
});
}
/**
* @see <a href="https://jira.spring.io/browse/DATACASS-304">DATACASS-304</a>
*/
@Test
public void doExecuteInSessionCallbackTranslatesToCassandraUncategorizedDataAccessException() {
exception.expect(CassandraUncategorizedDataAccessException.class);
exception.expectCause(org.hamcrest.Matchers.isA(Error.class));
exception.expectMessage(containsString("test"));
template.doExecute(new SessionCallback<String>() {
@Override public String doInSession(Session session) throws DataAccessException {
throw new Error("test");
}
});
}
@Test
public void doExecuteWithNullSessionCallbackThrowsIllegalArgumentException() {
exception.expect(IllegalArgumentException.class);