首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Cassandra Embedded时的NoHostAvailableException

使用Cassandra Embedded时的NoHostAvailableException
EN

Stack Overflow用户
提问于 2019-01-30 03:57:46
回答 1查看 758关注 0票数 0

我有一个spring boot应用程序,它使用spring-data-cassandra。我正在尝试使用嵌入式Cassandra为这个应用程序编写集成测试。

下面是我使用的依赖项:

代码语言:javascript
复制
testCompile('org.springframework.boot:spring-boot-starter-test') {
       exclude group: 'junit'
   }
   testCompile("org.junit.jupiter:junit-jupiter-api:5.3.2")
   testRuntime("org.junit.jupiter:junit-jupiter-engine:5.3.2")
   testCompile("org.mockito:mockito-junit-jupiter:2.23.4")
   testCompile group: 'org.cassandraunit', name: 'cassandra-unit-spring', version: '3.5.0.1'

下面是测试代码:

代码语言:javascript
复制
import org.cassandraunit.spring.CassandraDataSet;
import org.cassandraunit.spring.CassandraUnitTestExecutionListener;
import org.cassandraunit.spring.EmbeddedCassandra;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@ContextConfiguration
@TestExecutionListeners(
        listeners = CassandraUnitTestExecutionListener.class,
        mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS)
@CassandraDataSet(value = "dataset.cql", keyspace = "key_space")
@EmbeddedCassandra
@ActiveProfiles("test")
@SpringBootTest
@ExtendWith(SpringExtension.class)
public class IntegrationTest {

    @Test
    public void test() {
        System.out.println("Test");
    }
}

然而,当我运行应用程序时,我得到了以下错误:

com.datastax.driver.core.exceptions.NoHostAvailableException

这意味着默认的Cassandra嵌入式配置不起作用!

EN

回答 1

Stack Overflow用户

发布于 2019-01-31 01:22:13

我不是cassandra-unit方面的专家,但我可以向您推荐一个替代库:https://github.com/nosan/embedded-cassandra

代码语言:javascript
复制
@SpringBootTest
@EmbeddedCassandra(scripts = "...", replace = EmbeddedCassandra.Replace.NONE /*use auto-configured cluster */)
@ExtendWith(SpringExtension.class)
public class EmbeddedCassandraTests {

    @Test
    public void testMe() {

    }

}

希望这能帮到你。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54428737

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档