卡桑德拉和加特林之间的冲突

Conflict between Cassandra and Gatling

我开始使用具有此 Maven 依赖项的 gatling

    <dependency>
        <groupId>io.gatling.highcharts</groupId>
        <artifactId>gatling-charts-highcharts</artifactId>
        <version>2.2.5</version>
        <scope>test</scope>
    </dependency>

但是我的 Cassandra 组件使用了这个依赖项后出现了问题

    <dependency>
        <groupId>com.datastax.cassandra</groupId>
        <artifactId>cassandra-driver-core</artifactId>
        <version>3.2.0</version>
        <exclusions>
            <exclusion>
                <artifactId>slf4j-api</artifactId>
                <groupId>org.slf4j</groupId>
            </exclusion>

        </exclusions>
    </dependency>

当我查看日志时,我可以看到此异常

INFO  2017-04-25T14:31:43,119 []                                       [com.datastax.driver.core.GuavaCompatibility] Detected Guava < 19 in the classpath, using legacy compatibility layer
INFO  2017-04-25T14:31:44,000 []                                       [com.datastax.driver.core.Native] Could not load JNR C Library, native system calls through this library will not be available (set this logger level to DEBUG to see the full stack trace).
INFO  2017-04-25T14:31:44,000 []                                       [com.datastax.driver.core.ClockFactory] Using java.lang.System clock to generate timestamps.
WARN  2017-04-25T14:31:44,789 []                                       [com.datastax.driver.core.NettyUtil] Found Netty's native epoll transport, but not running on linux-based operating system. Using NIO instead.
WARN  2017-04-25T14:31:46,457 []                                       [io.netty.util.concurrent.DefaultPromise] An exception was thrown by com.datastax.driver.core.Connection.operationComplete()
java.lang.NullPointerException
    at io.netty.channel.group.DefaultChannelGroup.add(DefaultChannelGroup.java:146) ~[netty-transport-4.1.5.Final.jar:4.1.5.Final]
    at io.netty.channel.group.DefaultChannelGroup.add(DefaultChannelGroup.java:42) ~[netty-transport-4.1.5.Final.jar:4.1.5.Final]
    at com.datastax.driver.core.Connection.operationComplete(Connection.java:161) ~[cassandra-driver-core-3.2.0.jar:?]
    at com.datastax.driver.core.Connection.operationComplete(Connection.java:148) ~[cassandra-driver-core-3.2.0.jar:?]
    at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:514) [netty-common-4.1.5.Final.jar:4.1.5.Final]
    at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:488) [netty-common-4.1.5.Final.jar:4.1.5.Final]
    at io.netty.util.concurrent.DefaultPromise.access[=12=]0(DefaultPromise.java:34) [netty-common-4.1.5.Final.jar:4.1.5.Final]
    at io.netty.util.concurrent.DefaultPromise.run(DefaultPromise.java:438) [netty-common-4.1.5.Final.jar:4.1.5.Final]
    at io.netty.util.concurrent.GlobalEventExecutor$TaskRunner.run(GlobalEventExecutor.java:233) [netty-common-4.1.5.Final.jar:4.1.5.Final]
    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144) [netty-common-4.1.5.Final.jar:4.1.5.Final]

知道如何解决这个冲突吗?

此致。

貌似冲突是gatling需要netty 4.1,驱动需要netty 4.0。您可以通过使用驱动程序的阴影版本并从驱动程序中明确排除 netty 依赖项来解决此问题。来自 docs page:

<dependency>
    <groupId>com.datastax.cassandra</groupId>
    <artifactId>cassandra-driver-core</artifactId>
    <version>3.2.0</version>
    <classifier>shaded</classifier>
    <!-- Because the shaded JAR uses the original POM, you still need
        to exclude this dependency explicitly: -->
    <exclusions>
        <exclusion>
        <groupId>io.netty</groupId>
        <artifactId>*</artifactId>
        </exclusion>
    </exclusions>
</dependency>

前段时间我们在项目中遇到了同样的问题。经过调查,我们发现了冲突的 netty 版本。 将 shaded netty jar 添加到 datastax 驱动依赖导致 Linux 系统出现问题,因为在这种情况下,shaded netty jar 在 Linux 系统上不使用本机 epoll 传输。 我们刚刚从 datastax 驱动程序依赖项中删除了 shaded 分类器,但为 netty 添加了排除项:

<dependency>
   <groupId>com.datastax.cassandra</groupId>
   <artifactId>cassandra-driver-core</artifactId>
   <version>3.1.2</version>
   <exclusions>
     <exclusion>
        <groupId>io.netty</groupId>
        <artifactId>*</artifactId>
     </exclusion>
   </exclusions>
</dependency>

它适用于 Linux 和 Windows 系统。但我们很幸运,我们的 netty 版本与 datastax 驱动程序版本兼容。