我在使用 Embedded Cassandra 进行 Spring 单元测试时遇到问题。问题是 Embedded Cassandra 和 My Cassandra Server 同时启动。如何确保在单元测试期间只有 Embedded Cassandra 启动。
我正在为 Cassandra 使用 spring-data。
我有以下 Spring 配置文件。
cassandra.contactpoints=xxx.yyy.1.42
cassandra.keyspace=dialoguedev
我的上下文文件
<?xml version='1.0'?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cassandra="http://www.springframework.org/schema/data/cassandra"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/cql http://www.springframework.org/schema/cql/spring-cql-1.0.xsd
http://www.springframework.org/schema/data/cassandra http://www.springframework.org/schema/data/cassandra/spring-cassandra-1.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<context:component-scan base-package="com.xxx.cassandra" />
<context:property-placeholder location="classpath:cassandra.properties" />
<cassandra:cluster contact-points="${cassandra.contactpoints}"
/>
<cassandra:session keyspace-name="${cassandra.keyspace}"
schema-action="RECREATE"
/>
<cassandra:mapping />
<cassandra:converter />
<cassandra:template />
<cassandra:repositories base-package="com.xxx.cassandra.repository" />
我的测试用例如下:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(value = {"classpath:cassandrabeans.xml"})
@TestExecutionListeners( { DependencyInjectionTestExecutionListener.class, CassandraUnitDependencyInjectionTestExecutionListener.class })
@EmbeddedCassandra
public class EventLogInsertTest extends AbstractCassandraIntegrationTest {
@Autowired
private EventLogEventRepository eventLogEventRepository;
@Autowired
private EventLogPersonRepository eventLogPersonRepository;
@Test
public void runAllTableInsertTest() throws Exception{
}
}