无法在EmbeddedCassandra中为JUnit创建密钥空间

时间:2019-05-30 07:35:11

标签: junit spring-junit cassandraunit

我用cassandra作为DB编写JUnits。

Iam使用EmbeddedCassandra与cassandra-unit-spring库版本3.1.1.0进行JUnit测试。

但是,当我启动EmbeddedCassandra服务器时。无法加载CQL,表明键空间不存在。

@BeforeClass
public static void setup()
{

    try
    {


        EmbeddedCassandraServerHelper.startEmbeddedCassandra("another-cassandra.yaml", 20000);
        Cluster cluster = Cluster.builder().addContactPoints("localhost").withPort(9000).build();
        Session session = cluster.connect();


        session.execute("CREATE KEYSPACE mosaickeyspace WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 1}");
        session.execute("USE mosaickeyspace");

        final CQLDataLoader cqlDataLoader = new CQLDataLoader(session);
        cqlDataLoader.load(new ClassPathCQLDataSet("create-table.cql", false, true, "mosaickeyspace"));




    }
    catch(Exception excp)
    {
        LOGGER.info("Error in setup ", excp);
        System.out.println(excp.getStackTrace());

    }

}

我尝试将查询更改为大写,还尝试使用注释驱动的@EmbeddedCassandra服务器,但没有成功。

以下是我得到的错误

com.datastax.driver.core.exceptions.InvalidConfigurationInQueryException: Keyspace mosaickeyspace doesn't exist
    at com.datastax.driver.core.exceptions.InvalidConfigurationInQueryException.copy(InvalidConfigurationInQueryException.java:38)
    at com.datastax.driver.core.exceptions.InvalidConfigurationInQueryException.copy(InvalidConfigurationInQueryException.java:27)
    at com.datastax.driver.core.DriverThrowables.propagateCause(DriverThrowables.java:35)
    at com.datastax.driver.core.DefaultResultSetFuture.getUninterruptibly(DefaultResultSetFuture.java:293)
    at com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:58)
    at com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:39)
    at org.cassandraunit.CQLDataLoader.load(CQLDataLoader.java:36)
    at com.girnarsoft.mosaic.UserServiceTest.setup(UserServiceTest.java:100)
    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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

0 个答案:

没有答案