forked from testcontainers/testcontainers-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Issue-2179] Add JDBC binding to Cassandra module
Many enterprise environments require a JDBC connection to Cassandra for integration into legacy systems. This patch changes the parent of the CassandraContainer to JdbcDatabaseContainer and optionally allows enables the 'native api' (thrift-over-rcp) used by many JDBC driver implementations. A new test was added - testCassandraJdbcQuery(). == Status This code isn't ready for merge - it's being offered for review. It loosely corresponds to my work on Friday creating a local fork that integrates into our existing environment where we were already using JDBC connections to Cassandra servers. That fork works so I know this fork is very close to working. Of particular note is the log line ``` INFO [main] 2019-12-14 21:31:33,520 ThriftServer.java:116 - Binding thrift service to /0.0.0.0:9160 ``` since that indicates that the server is listening to the RPC port required by the JDBC driver. == Remaining Work testcontainers#1 The connection attempt fails with ``` Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: localhost/127.0.0.1:32862 (com.datastax.driver.core.exceptions.TransportException: [localhost/127.0.0.1:32862] Channel has been closed)) at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:268) at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:107) at com.datastax.driver.core.Cluster$Manager.negotiateProtocolVersionAndConnect(Cluster.java:1813) at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1726) at com.datastax.driver.core.Cluster.init(Cluster.java:214) at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:387) at com.datastax.driver.core.Cluster.connect(Cluster.java:338) at com.github.adejanovski.cassandra.jdbc.SessionHolder.createSession(SessionHolder.java:201) ... 36 more ``` however I know that the same JDBC driver works elsewhere. It may be something as simple as a missing datastax jar. == Remaining Work testcontainers#2 The test includes calls to `cassandraContainer.setWaitStrategy()`. Neither seems to have any effect. In the other fork I only saw a wait strategy used was when I explicitly set the waitStrategy value in the constructor.
- Loading branch information
1 parent
ef96100
commit 3c6ec94
Showing
6 changed files
with
256 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
description = "TestContainers :: Cassandra" | ||
|
||
dependencies { | ||
compile project(":database-commons") | ||
compile project(":jdbc") | ||
compile "com.datastax.cassandra:cassandra-driver-core:3.7.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>org.testcontainers</artifactId> | ||
<groupId>cassandra-2179</groupId> | ||
<version>pr-2179</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>cassandra</name> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.6.0</version> | ||
<configuration> | ||
<fork>true</fork> | ||
<meminitial>256m</meminitial> | ||
<maxmem>1024m</maxmem> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
<encoding>UTF-8</encoding> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<properties> | ||
<testcontainers.version>1.12.3</testcontainers.version> | ||
<datastax.version>3.8.0</datastax.version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>testcontainers-bom</artifactId> | ||
<version>${testcontainers.version}</version> | ||
<scope>import</scope> | ||
<type>pom</type> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<!-- Dependencies --> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>database-commons</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>jdbc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<version>2.6</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.8</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.rnorth.duct-tape</groupId> | ||
<artifactId>duct-tape</artifactId> | ||
<version>1.0.7</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.datastax.cassandra</groupId> | ||
<artifactId>cassandra-driver-core</artifactId> | ||
<version>${datastax.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.datastax.cassandra</groupId> | ||
<artifactId>cassandra-driver-mapping</artifactId> | ||
<version>${datastax.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.datastax.cassandra</groupId> | ||
<artifactId>cassandra-driver-extras</artifactId> | ||
<version>${datastax.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.github.adejanovski</groupId> | ||
<artifactId>cassandra-jdbc-wrapper</artifactId> | ||
<version>3.1.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...les/cassandra/src/main/java/org/testcontainers/containers/CassandraContainerProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.testcontainers.containers; | ||
|
||
import org.testcontainers.containers.JdbcDatabaseContainer; | ||
import org.testcontainers.containers.JdbcDatabaseContainerProvider; | ||
|
||
/** | ||
* Implementation of JdbcDatabaseContainerProvider for Cassandra. | ||
*/ | ||
public class CassandraContainerProvider extends JdbcDatabaseContainerProvider { | ||
@Override | ||
public boolean supports(String databaseType) { | ||
return databaseType.equals(CassandraContainer.NAME); | ||
} | ||
|
||
@Override | ||
public JdbcDatabaseContainer newInstance() { | ||
return newInstance(CassandraContainer.DEFAULT_TAG); | ||
} | ||
|
||
@Override | ||
public JdbcDatabaseContainer newInstance(String tag) { | ||
return new CassandraContainer(CassandraContainer.IMAGE + ":" + tag); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters