). I added Cassandra-Unit to my test dependencies but having an issue on no host connection.
com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: localhost/127.0.0.1 ([localhost/127.0.0.1] Cannot connect)) at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:186)
at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:81)
at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:812)
at com.datastax.driver.core.Cluster$Manager.access$100(Cluster.java:739)
at com.datastax.driver.core.Cluster.<init>(Cluster.java:82)
at com.datastax.driver.core.Cluster.<init>(Cluster.java:67)
at com.datastax.driver.core.Cluster$Builder.build(Cluster.java:708)
at org.springframework.cassandra.config.CassandraCqlClusterFactoryBean.afterPropertiesSet(CassandraCqlClusterFactoryBean.java:186)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)
Here is an example of one of my tests:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"/testApplicationContext.xml", "/cassandraTestContext.xml"
})
@TestExecutionListeners({
CassandraUnitTestExecutionListener.class, DependencyInjectionTestExecutionListener.class
})
@CassandraDataSet(value = {
"foo.cql"
})
@EmbeddedCassandra
public class FooServiceImplTest {
@Autowired
private IFooService service;
/**
* Tests saving foo data.
*/
@Test
public final void save() {
FooKey key = new FooKey();
Foo foo = new Foo(key);
// Saves the foo using TypedIdCassandraRepository in the back-end
foo = service.save(foo);
Assert.assertNotNull("Failed to save the foo", foo);
}
}
Here is my test configuration setup:
@Configuration
@EnableCassandraRepositories(basePackages = "com.foo.db.repository")
public class TestCassandraConfiguration extends AbstractCassandraConfiguration {
@Override
protected final String getKeyspaceName() {
return "test";
}
}
I'm obviously missing something between using Spring Data Cassandra and Cassandra Unit. I felt that I must be using Spring Data Cassandra wrong with Cassandra Unit and in the task in JIRA, there is a mention that Spring Data Cassandra is using Cassandra Unit but I couldn't find a test that looked similar to the one I had mentioned.