【问题标题】:Exception when using cassandra-unit to test cassandra使用 cassandra-unit 测试 cassandra 时出现异常
【发布时间】:2014-01-20 23:14:09
【问题描述】:

在我的 Java-Mavan-Spring 项目中,我使用 cassandra unit 来尝试测试我的 DAO。

我在类路径中创建了 2 个文件:

  1. 描述我的初始数据的简单 XML
  2. cassandra 配置文件 (cassandra.yaml)

这是我的测试类:

public class UserProfilingCassandraDaoUTest extends BaseJunitTestCase {

    @Rule
    public CassandraUnit cassandraUnit = new CassandraUnit(new ClassPathXmlDataSet("cassandraTestValues.xml"), "cassandra.yaml", "127.0.0.1");

    private HectorCassandraConnection connection;

    @Before
    public void init() throws Exception {
    connection = Mockito.mock(HectorCassandraConnection.class);
    Mockito.when(connection.getKeyspace()).thenReturn(cassandraUnit.keyspace);
    }

    @Test
    public void shouldHaveLoadTestDataSet() throws Exception {
    Assert.assertNotNull(cassandraUnit.keyspace);
    Assert.assertEquals(cassandraUnit.keyspace.getKeyspaceName(), "rtb");
    }

    @Test
    public void getUserStatsTest() {
      // Some Test
    }
}

这是我的 cassandraTestValues.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<keyspace xmlns="http://xml.dataset.cassandraunit.org">
    <name>rtb</name>
    <columnFamilies>
        <columnFamily>
            <name>my_column_family</name>
            <keyType>UTF8Type</keyType>
            <comparatorType>UTF8Type</comparatorType>
            <defaultColumnValueType>UTF8Type</defaultColumnValueType>
            <row>
                <key>12345__678_910</key>
                <column>
                    <name>Col1</name>
                    <value>6</value>
                </column>
                <column>
                    <name>Col2</name>
                    <value>6</value>
                </column>
                <column>
                    <name>Col3</name>
                    <value>3</value>
                </column>
            </row>
        </columnFamily>
    </columnFamilies>
</keyspace>

当我运行测试时,我得到了this logthis error

我已经尝试了好几个小时来解决这个问题,但都没有成功。 有什么想法吗?

【问题讨论】:

    标签: unit-testing cassandra


    【解决方案1】:

    这有点令人难过,但是将 cassandra-unit 版本从 1.2.0.1 更改为 1.0.3.1,它就像一个魅力。 我通过将this project 导入到我的工作区得到了解决方案。导入的项目运行良好,在对两者进行比较后发现版本之间的差异是导致问题的原因。

    此外,后来的maven版本都没有工作,这意味着1.0.3.1之后出现的所有版本都失败了(1.2.0.1、1.1.2.1、1.1.1.3、1.1.1.2、1.1.1.1、1.1。 0.1)。

    我希望这可以为将来的某个人节省一些时间.. 这确实花了我一段时间。

    【讨论】:

      猜你喜欢
      • 2013-10-16
      • 2018-11-11
      • 2013-05-15
      • 2014-06-07
      • 2020-04-12
      • 1970-01-01
      • 2016-06-02
      • 2016-08-27
      • 2014-07-02
      相关资源
      最近更新 更多