将 CassandraUnit 与 Astyanax 结合使用时出现依赖性问题

2024-05-04

我有一个 SessionDaoCassandraImpl 类,它使用 Astyanax 从 Cassandra 读取数据,我想使用嵌入式 Cassandra 服务器进行测试。卡桑德拉单元 https://github.com/jsevellec/cassandra-unit这样做似乎很完美,但我遇到了异常

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)

该异常已记录在案here http://mail-archives.apache.org/mod_mbox/cassandra-commits/201206.mbox/%3C1754923128.8168.1339517923307.JavaMail.jiratomcat@issues-vm%3E但我不明白今天我能做些什么来解决这个问题。

以下是我使用的 pom 依赖项:

  ...

      <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,我都会遇到相同的异常。


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(); 后立即生成异常的代码;

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());
  }

}

最后,这是我的 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>
 ...      

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

    <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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将 CassandraUnit 与 Astyanax 结合使用时出现依赖性问题 的相关文章

随机推荐

  • Shiny + downloadHandler + Openxlsx 不生成xlsx文件

    我试图通过 Openxlsx 包生成一个 xlsx 文件 其中包含文件内的反应名称和标头 输入变量为 ASL 1 和 Year 1 要保存在文件中的对象是反应表 tab 1 它是由应用程序生成的 没有任何问题 但是当我尝试下载它时 浏览器
  • Oracle PL/SQL 块的语法图是否错误?

    我怀疑 a 的语法图plsql block如中给出的Oracle 数据库 PL SQL 语言参考对于 Release 2 来说是错误的 以供参考 这是当前的链接 http download oracle com docs cd E11882
  • 当用户点击无框架 pygame 窗口时如何移动它?

    我想创建一个没有框架的 pygame 窗口 当用户单击它并移动鼠标时该窗口会移动 我尝试了这个脚本 但是当我单击窗口时 打印 0 而不是 1 我的脚本有问题 coding utf 8 import pygame from pygame lo
  • 更改流程布局的 itemSize 后单元格大小未更新

    在我的应用程序中 我有一个全屏分页集合视图 每个单元格也需要全屏 因此集合视图布局的项目大小需要与视图控制器的视图边界大小相同 为此 在viewDidLayoutSubviews我只是设置了项目大小 它就按预期工作了 当我呈现这个屏幕时 v
  • ionic 2 从 json 填充选择选项

    我正在尝试动态填充ion select带有 json 对象的下拉列表 我的 html 组件如下所示
  • Active Directory:获取用户所属的组

    我想找到用户所属的组列表 我尝试了几种解决方案http www codeproject com KB system everythingInAD aspx http www codeproject com KB system everyth
  • 如何在java hashset中查找并返回对象

    根据 HashSet javadoc HashSet contains 仅返回布尔值 如何在 hashSet 中 查找 对象并修改它 它不是原始数据类型 我看到 HashTable 有一个 get 方法 但我更喜欢使用该集合 您可以删除一个
  • 将 POSIXct 日期值更改为每周的第一天

    我想计算平均值Dist每周使用这些数据 如下 同时保留使用POSIXct时间课 df lt structure list IndID structure c 1L 1L 1L 1L 1L 1L 1L 1L 1L 1L 1L 1L 1L 1L
  • 如何将一个窗格连接到另一个窗格

    如何将输出连接到paneWithList PaneWithList其上有一个监听器JList以便将所选行输出到控制台 我怎样才能将该输出定向到JTextPane关于输出 Could PaneWithList触发一个事件Main拿起 会属性更
  • 使用 RSelenium 下载嵌入到框架中的文件

    我正在参与一个项目 其中有一个网页 我需要单击该网页才能获取 pdf 文件 该文件出现在同一页面内的新窗口中 我认为是 iframe 然后我需要单击一个按钮来下载文件 我正在使用的代码如下 library wdman library RSe
  • Firebase Auth:如何检测 Firebase 尝试自动登录当前用户?

    我在用着firebase auth onAuthStateChanged 在浏览器中检测用户是否已登录 并在每个页面上加载 firebase 尝试登录当前用户 可能基于 IndexDB 中存储的令牌 我需要检测 firebase 何时尝试自
  • 与 ssh2_connect() 断开连接

    我已经使用 ssh2 连接ssh2 connect到服务器 但我没有看到任何方法在联机帮助页中 http php net ssh2 connect我应该如何结束连接 我不太喜欢在断开连接之前等待脚本结束 我可以用吗fclose 这听起来不对
  • 淡化背景但不淡化文本

    我已经对 div 应用了 CSS 淡入 淡出解决方案 在很大程度上我对此感到满意 但是我只想将其应用于背景 而不是文本 我需要文本始终完全不透明 参见示例 http jsfiddle net howiepaul gUAPV 33 http
  • bash 调整图像尺寸以适合特定大小

    我到处搜索但找不到这个问题的答案 我想精确输出一个文件夹中的所有图像 大小为 50Kb 并保持原始的宽高比 I tried ImageMagick并将大小调整为 250x250 例如 但它对我不起作用 它所做的是更改第一个尺寸并适应另一个尺
  • 在 R 中使用 NA 计算栅格数据的变异函数

    Summary 我有一个包含 NA 值的栅格数据集 并且想要计算它的变异函数 忽略 NA 我怎样才能做到这一点 我有一个图像 已使用以下命令加载到 R 中readGDAL函数 存储为im 为了使其可重复 结果dput图像上可在https g
  • 有用的库存 SQL 数据集吗?

    有谁知道有哪些资源可以提供优质 有用的股票数据集 例如 我下载了一个包含美国所有州 城市和邮政编码的 SQL 脚本 这在最近的一个应用程序中节省了我很多时间 我希望能够按地理位置进行查找 你们中有人知道其他可以免费下载的有用数据集吗 例如
  • Struts 未处理的异常 - 没有为操作定义结果 - Struts Spring 和 hibernate 集成

    实际上 我正在致力于在在线考试项目上实现 Struts Spring 和 Hibernate 集成 但是当我在 JSP 页面中提交值时 它会抛出以下错误 Struts 问题报告 Struts has detected an unhandle
  • 配置错误:无法链接到 boost_system

    我正在尝试在 Debian 上安装一个软件包 足球模拟器 2d 当我进入目录并运行时 configure 我得到以下信息 reza debian soccer rcssserver 15 0 1 configure checking for
  • 显示不同表中的名称而不是 ID

    我有 2 张桌子 Category带主键ID和列Name Employee带主键ID和列Category id Note Category id现在显示ID正确地 我想展示Name代替ID对于输出Employee Attempt categ
  • 将 CassandraUnit 与 Astyanax 结合使用时出现依赖性问题

    我有一个 SessionDaoCassandraImpl 类 它使用 Astyanax 从 Cassandra 读取数据 我想使用嵌入式 Cassandra 服务器进行测试 卡桑德拉单元 https github com jsevellec