1

首先,为什么我要使用不同的键空间?因为我想写 JUnit Test,但是我需要另一个 keyspace 来测试。我正在使用 Spring MVC。我使用在春天自动装配的 hectorTemplate。

<!--  cassandra configuration -->
    <bean id="cassandraHostConfigurator" class="me.prettyprint.cassandra.service.CassandraHostConfigurator">
        <constructor-arg value="${cassandra.url}" />
    </bean>

    <bean id="cluster" class="me.prettyprint.cassandra.service.ThriftCluster">
        <constructor-arg value="${cassandra.cluster}" />
        <constructor-arg ref="cassandraHostConfigurator" />
    </bean>

    <bean id="consistencyLevelPolicy" class="me.prettyprint.cassandra.model.ConfigurableConsistencyLevel">
       <property name="defaultReadConsistencyLevel" value="${cassandra.defaultReadConsistencyLevel}"></property>
       <property name="defaultWriteConsistencyLevel" value="${cassandra.defaultWriteConsistencyLevel}"></property>
    </bean>

    <bean id="keyspace" class="me.prettyprint.hector.api.factory.HFactory" factory-method="createKeyspace">
        <constructor-arg value="${cassandra.keyspace}" />
        <constructor-arg ref="cluster" />
        <constructor-arg ref="consistencyLevelPolicy" />
    </bean>

    <bean id="hectorTemplate" class="me.prettyprint.cassandra.service.spring.HectorTemplateImpl">
        <property name="cluster" ref="cluster" />
        <property name="keyspace" ref="keyspace" />
        <property name="replicationStrategyClass" value="org.apache.cassandra.locator.SimpleStrategy" />
        <property name="replicationFactor" value="1" />
    </bean>

所以我应该怎么做才能添加另一个键空间?感谢您的帮助。(nn)!!!!

4

1 回答 1

0
<!-- Keyspace1 -->

 <bean id="keyspace1" class="me.prettyprint.hector.api.factory.HFactory" factory-method="createKeyspace">
        <constructor-arg value="${cassandra.keyspace1}" />
        <constructor-arg ref="cluster" />
        <constructor-arg ref="consistencyLevelPolicy" />
    </bean>

    <bean id="hectorTemplate1" class="me.prettyprint.cassandra.service.spring.HectorTemplateImpl">
        <property name="cluster" ref="cluster" />
        <property name="keyspace" ref="keyspace1" />
        <property name="replicationStrategyClass" value="org.apache.cassandra.locator.SimpleStrategy" />
        <property name="replicationFactor" value="1" />
    </bean>


<!-- Keyspace2 -->

 <bean id="keyspace2" class="me.prettyprint.hector.api.factory.HFactory" factory-method="createKeyspace">
        <constructor-arg value="${cassandra.keyspace2}" />
        <constructor-arg ref="cluster" />
        <constructor-arg ref="consistencyLevelPolicy" />
    </bean>

    <bean id="hectorTemplate2" class="me.prettyprint.cassandra.service.spring.HectorTemplateImpl">
        <property name="cluster" ref="cluster" />
        <property name="keyspace" ref="keyspace2" />
        <property name="replicationStrategyClass" value="org.apache.cassandra.locator.SimpleStrategy" />
        <property name="replicationFactor" value="1" />
    </bean>

对于 JUnit 测试,您应该使用相同的键空间并使用嵌入式Cassandra。在这里检查。没有理由仅仅为了测试而创建另一个键空间。

于 2013-09-15T11:06:01.143 回答