使用CassandraUnit与Astyanax的依赖性问题 [英] Dependency trouble using CassandraUnit with Astyanax

查看:641
本文介绍了使用CassandraUnit与Astyanax的依赖性问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SessionDaoCassandraImpl类,使用Astyanax从Cassandra读取数据,我想用嵌入式Cassandra服务器测试。 CassandraUnit 似乎完美的,但我遇到了异常

I have a SessionDaoCassandraImpl class that reads data from Cassandra using Astyanax that I would like to test with an embedded Cassandra server. CassandraUnit seems perfect to do so but I am running into an exception

ERROR - 2012-11-21 14:54:34,754 - AbstractCassandraDaemon.activate(370) | Exception encountered during startup
java.lang.NoSuchMethodError: com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap$Builder.maximumWeightedCapacity(I)Lcom/googlecode/concurrentlinkedhashmap/ConcurrentLinkedHashMap$Builder;
    at org.apache.cassandra.cache.ConcurrentLinkedHashCache.create(ConcurrentLinkedHashCache.java:70)

该异常被记录这里,但我不明白我今天能做些什么来解决它。

That exception is documented here but I fail to understand what I can do today to get around it.

这里是我使用的pom依赖:

Here are the pom dependencies I used:

  ...

      <dependency>
        <groupId>org.cassandraunit</groupId>
        <artifactId>cassandra-unit</artifactId>
        <version>1.1.1.1</version>  
        <!-- <version>1.1.0.1</version> --> 
        <!-- version 1.1.0.1 leads to java.lang.NoSuchMethodError:  
        com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap$Builder.maximumWeightedCapacity -->      
        <!-- <version>0.8.0.2.4</version> -->
        <!-- version 0.8.0.2.4 leads to ERROR - 2012-11-21 14:28:45,774 - 
        DatabaseDescriptor.loadYaml(479) | Fatal configuration error error -->      
        <scope>test</scope>
    </dependency>

  ...



我得到相同的异常,无论我使用1.1。 1.1或1.1.0.1。

I get the same exception whether I use 1.1.1.1 or 1.1.0.1.



我尝试的内容


我也尝试添加排除负责异常的类,重新添加最新版本1.3.1作为另一个依赖:


Things I tried

I also tried to add an exclusion of the class responsible for the exception, re-adding the latest version 1.3.1 as another dependency:

  ...  

    <dependency>
        <groupId>org.cassandraunit</groupId>
        <artifactId>cassandra-unit</artifactId>
        <version>1.1.1.1</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>com.googlecode.concurrentlinkedhashmap</groupId>
                <artifactId>concurrentlinkedhashmap-lru</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.googlecode.concurrentlinkedhashmap</groupId>
        <artifactId>concurrentlinkedhashmap-lru</artifactId>
        <version>1.3.1</version>
    </dependency>
   ...

这对于异常没有帮助。

下面是运行EmbeddedCassandraServerHelper.startEmbeddedCassandra()时生成异常的代码:

Here is the code that generates the exception as soon as I run EmbeddedCassandraServerHelper.startEmbeddedCassandra();

import java.io.IOException;

import org.apache.cassandra.config.ConfigurationException;
import org.apache.thrift.transport.TTransportException;
import org.cassandraunit.DataLoader;
import org.cassandraunit.dataset.xml.ClassPathXmlDataSet;
import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
import org.junit.Before;
import org.junit.Test;

import com.netflix.astyanax.AstyanaxContext;
import com.netflix.astyanax.Keyspace;
import com.netflix.astyanax.connectionpool.NodeDiscoveryType;
import com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl;
import com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor;
import com.netflix.astyanax.impl.AstyanaxConfigurationImpl;
import com.netflix.astyanax.thrift.ThriftFamilyFactory;

public class SessionDaoCassandraTestIT {

  private SessionDaoCassandraImpl sessionDao;

  @Before
  public void init() throws TTransportException, IOException,
  InterruptedException, ConfigurationException {

    EmbeddedCassandraServerHelper.startEmbeddedCassandra();
    final DataLoader dataLoader = new DataLoader("Test Cluster", "localhost:9171");
    dataLoader.load(new ClassPathXmlDataSet("cassandraDataSet.xml"));

    /* Doing this below instead of extending AbstractCassandraUnit4TestCase because
     * getDataSet.getKeySpace() returns a Hector keyspace but we want to use Astyanax
     * instead */

    /* Code below inspired from
     * http://pio-tech.blogspot.com/2012/07/unitintegration-testing-with-maven-and.html */
    final AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
    .forCluster("Test Cluster")
    .forKeyspace("sessiondata")
    .withAstyanaxConfiguration(
            new AstyanaxConfigurationImpl()
            .setDiscoveryType(NodeDiscoveryType.NONE))
            .withConnectionPoolConfiguration(
                    new ConnectionPoolConfigurationImpl("testConnectionPool")
                    .setPort(9171).setMaxConnsPerHost(1)
                    .setSeeds("localhost:9171"))
                    .withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
                    .buildKeyspace(ThriftFamilyFactory.getInstance());
    context.start();
    final Keyspace keyspace = context.getEntity();
    sessionDao = new SessionDaoCassandraImpl(keyspace);

  }

  @Test
  public void shouldDisplayAccountFromSessionCreatedByDataLoader() {
    System.out.println(sessionDao.getSession("72b97796-b1b3-4220-ba03-ba7e9ecfe946").get().getAccount());
  }

}

最后,这里是my cassandraDataTest.xml:

Last, here is the beginning of my cassandraDataTest.xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<keyspace xmlns="http://xml.dataset.cassandraunit.org">
    <name>sessiondata</name>
    <columnFamilies>
        <columnFamily>
            <name>session</name>
            <keyType>UTF8Type</keyType>
            <comparatorType>UTF8Type</comparatorType>
            <defaultColumnValueType>UTF8Type</defaultColumnValueType>
            <row>
                <key>72b97796-b1b3-4220-ba03-ba7e9ecfe946</key>
                <column>
                    <name>account</name>
                    <value>account</value>
                </column>
 ...      


推荐答案

库我的项目正在使用调用旧版本的cassandra比1.1.1。
在pom中添加排除项解决了我的问题:

Turns out the astyanax library my project was using invoked an older version of cassandra than 1.1.1. Adding an exclusion in the pom solved my problem:

    <dependency>
        <groupId>com.netflix.astyanax</groupId>
        <artifactId>astyanax</artifactId>
        <version>1.0.4</version>
        <exclusions>
            <exclusion>
                <groupId>org.apache.cassandra</groupId>
                <artifactId>cassandra-all</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

这篇关于使用CassandraUnit与Astyanax的依赖性问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆