使用CassandraUnit时出错:找不到数据集

时间:2016-05-06 23:05:32

标签: 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"));
}

}

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

此问题的主要原因是cql文件的路径错误!