java - 使用 CassandraUnit 时出错 : Dataset not found

标签 java unit-testing cassandra

我正在尝试使用 CassandraUnit java 库对 Cassandra 进行单元测试。遵循https://github.com/jsevellec/cassandra-unit/wiki/How-to-use-it-in-your-code#load-data-from-a-data-set中的选项2(确切的代码)它应该从 ExtendedDataSet.xml 加载数据。它给了我这个错误。

org.cassandraunit.dataset.ParseException: Dataset not found

at org.cassandraunit.dataset.xml.AbstractXmlDataSet.<init>(AbstractXmlDataSet.java:39)
at org.cassandraunit.dataset.xml.ClassPathXmlDataSet.<init>(ClassPathXmlDataSet.java:10)
at com.visa.util.recordstore.cassandra.AutomaticallyStartAndLoadExtendedDataSetTest.getDataSet(AutomaticallyStartAndLoadExtendedDataSetTest.java:17)
at org.cassandraunit.AbstractCassandraUnit4TestCase.<init>(AbstractCassandraUnit4TestCase.java:19)
at com.visa.util.recordstore.cassandra.AutomaticallyStartAndLoadExtendedDataSetTest.<init>(AutomaticallyStartAndLoadExtendedDataSetTest.java:13)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:209)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:258)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:255)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

如果重要的话,请使用 cassandra-unit-3.0.0.1.jar、cassandra-driver-core-3.0.0.jar。

我已将extendedDataSet.xml 放置在类路径中。有什么建议来修复此异常吗?

更新: 代码:

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;

import org.cassandraunit.dataset.IDataSet;
import org.cassandraunit.dataset.xml.ClassPathXmlDataSet;
import org.junit.Test;

public class AutomaticallyStartAndLoadExtendedDataSetTest extends       AbstractCassandraUnit4TestCase {

@Override
public IDataSet getDataSet() {
        return new ClassPathXmlDataSet("extendedDataSet.xml");
}

@Test
public void shouldHaveLoadAnExtendDataSet() throws Exception {
    //here, a Cassandra server is started and your data from extendedDataSet.xml has been loaded
    // you can query or do what you want
    assertThat(getKeyspace(), notNullValue());
    assertThat(getKeyspace().getKeyspaceName(), is("otherKeyspaceName"));
}

}

最佳答案

我也遇到了这个问题,发现配置的 CQL 文件已移动到其他位置。修复配置为我解决了问题。

关于java - 使用 CassandraUnit 时出错 : Dataset not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37082616/

相关文章:

java - 如何处理带有 4xx/5xx 状态代码的 HTTP 响应,Java servlet/HttpURLConnection

java - 带字符串的 switch 不仅仅是语法糖吗?

android - 单元测试协程 runBlockingTest : This job has not completed yet

angularjs - Karma 错误 - Chrome 没有在 60000 毫秒内捕获,杀死

java - javafx 转换的当前圆位置

java - 有什么方法可以优化这个java代码吗?

c# - 如何使用 xunit test 比较两个列表

algorithm - 解释 Merkle 树用于最终一致性

python - Shared Cassandra Session 失去连接,应用必须重启

scala - InvalidRequestException(为什么 :empid cannot be restricted by more than one relation if it includes an Equal)