diff --git a/cassandra/pom.xml b/cassandra/pom.xml index 91ba86bbc0e..e4e53309ebf 100644 --- a/cassandra/pom.xml +++ b/cassandra/pom.xml @@ -37,8 +37,6 @@ 1.9.8 - 5.12.1 - 4.3.1.0 ${scala.2.12.version} 2.12 @@ -137,26 +135,17 @@ - net.java.dev.jna - jna - ${jna.version} + org.testcontainers + cassandra test - org.cassandraunit - cassandra-unit - ${cassandra.unit.version} - test - - - com.datastax.oss - java-driver-core - - + org.testcontainers + junit-jupiter + test - org.mockito mockito-core diff --git a/cassandra/src/test/java/org/apache/zeppelin/cassandra/CassandraInterpreterTest.java b/cassandra/src/test/java/org/apache/zeppelin/cassandra/CassandraInterpreterTest.java index 8a6cce4ee9e..4426d47d00e 100644 --- a/cassandra/src/test/java/org/apache/zeppelin/cassandra/CassandraInterpreterTest.java +++ b/cassandra/src/test/java/org/apache/zeppelin/cassandra/CassandraInterpreterTest.java @@ -27,13 +27,13 @@ import org.apache.zeppelin.interpreter.InterpreterContext; import org.apache.zeppelin.interpreter.InterpreterResult; import org.apache.zeppelin.interpreter.InterpreterResult.Code; -import org.cassandraunit.CQLDataLoader; -import org.cassandraunit.dataset.cql.ClassPathCQLDataSet; -import org.cassandraunit.utils.EmbeddedCassandraServerHelper; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.testcontainers.containers.CassandraContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -65,28 +65,40 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; -public class CassandraInterpreterTest { // extends AbstractCassandraUnit4CQLTestCase { +@Testcontainers +public class CassandraInterpreterTest { private static final String ARTISTS_TABLE = "zeppelin.artists"; private static volatile CassandraInterpreter interpreter; + private static CqlSession session; + private final InterpreterContext intrContext = InterpreterContext.builder() .setParagraphTitle("Paragraph1") .build(); + @Container + public static CassandraContainer cassandra = + new CassandraContainer<>("cassandra:4.1.3"); + @BeforeAll - public static synchronized void setUp() throws IOException, InterruptedException { - System.setProperty("cassandra.skip_wait_for_gossip_to_settle", "0"); - System.setProperty("cassandra.load_ring_state", "false"); - System.setProperty("cassandra.initial_token", "0"); - System.setProperty("cassandra.num_tokens", "nil"); - System.setProperty("cassandra.allocate_tokens_for_local_replication_factor", "nil"); - EmbeddedCassandraServerHelper.startEmbeddedCassandra(); - CqlSession session = EmbeddedCassandraServerHelper.getSession(); - new CQLDataLoader(session).load(new ClassPathCQLDataSet("prepare_all.cql", "zeppelin")); + public static synchronized void setUp() throws IOException { + session = CqlSession.builder() + .addContactPoint(java.net.InetSocketAddress.createUnresolved( + cassandra.getHost(), cassandra.getMappedPort(9042))) + .withLocalDatacenter("datacenter1") + .build(); + + String cql = IOUtils.resourceToString("/prepare_all.cql", StandardCharsets.UTF_8); + for (String stmt : cql.split(";")) { + String trimmed = stmt.trim(); + if (!trimmed.isEmpty()) { + session.execute(trimmed); + } + } Properties properties = new Properties(); - properties.setProperty(CASSANDRA_CLUSTER_NAME, EmbeddedCassandraServerHelper.getClusterName()); + properties.setProperty(CASSANDRA_CLUSTER_NAME, "Test Cluster"); properties.setProperty(CASSANDRA_COMPRESSION_PROTOCOL, "NONE"); properties.setProperty(CASSANDRA_CREDENTIALS_USERNAME, "none"); properties.setProperty(CASSANDRA_CREDENTIALS_PASSWORD, "none"); @@ -111,9 +123,9 @@ public static synchronized void setUp() throws IOException, InterruptedException properties.setProperty(CASSANDRA_SOCKET_READ_TIMEOUT_MILLIS, "12000"); properties.setProperty(CASSANDRA_SOCKET_TCP_NO_DELAY, "true"); - properties.setProperty(CASSANDRA_HOSTS, EmbeddedCassandraServerHelper.getHost()); + properties.setProperty(CASSANDRA_HOSTS, cassandra.getHost()); properties.setProperty(CASSANDRA_PORT, - Integer.toString(EmbeddedCassandraServerHelper.getNativeTransportPort())); + Integer.toString(cassandra.getMappedPort(9042))); properties.setProperty("datastax-java-driver.advanced.connection.pool.local.size", "1"); interpreter = new CassandraInterpreter(properties); interpreter.open(); @@ -122,6 +134,9 @@ public static synchronized void setUp() throws IOException, InterruptedException @AfterAll public static void tearDown() { interpreter.close(); + if (session != null) { + session.close(); + } } @Test @@ -333,7 +348,7 @@ void should_execute_statement_with_timestamp_option() throws Exception { String statement2 = "@timestamp=15\n" + "INSERT INTO zeppelin.ts(key,val) VALUES('k','v2');"; - CqlSession session = EmbeddedCassandraServerHelper.getSession(); + CqlSession session = CassandraInterpreterTest.session; // Insert v1 with current timestamp interpreter.interpret(statement1, intrContext); System.out.println("going to read data from zeppelin.ts;"); @@ -562,14 +577,17 @@ void should_display_statistics_for_non_select_statement() { // When final InterpreterResult actual = interpreter.interpret(query, intrContext); - final int port = EmbeddedCassandraServerHelper.getNativeTransportPort(); - final String address = EmbeddedCassandraServerHelper.getHost(); + final int port = cassandra.getMappedPort(9042); + final String address = cassandra.getHost(); // Then final String expected = rawResult.replaceAll("TRIED_HOSTS", address + ":" + port) .replaceAll("QUERIED_HOSTS", address + ":" + port); assertEquals(Code.SUCCESS, actual.code()); - assertEquals(expected, reformatHtml(actual.message().get(0).getData())); + // JDK 17+ renders unresolved InetSocketAddress as "host/:port" + String actualHtml = reformatHtml(actual.message().get(0).getData()) + .replaceAll(address + "/<unresolved>:", address + ":"); + assertEquals(expected, actualHtml); } @Test diff --git a/cassandra/src/test/resources/scalate/DescribeKeyspace_live_data.html b/cassandra/src/test/resources/scalate/DescribeKeyspace_live_data.html index 8d721ef2338..ed67b250cd3 100644 --- a/cassandra/src/test/resources/scalate/DescribeKeyspace_live_data.html +++ b/cassandra/src/test/resources/scalate/DescribeKeyspace_live_data.html @@ -1 +1 @@ -


  live_data

ReplicationDurable Writes
{'class' : 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor' : '1'}false

Tables
Column TypeColumn NameData Type
pk1uuid
pk2int
my_static1text
my_static2text
 clustering1timestamp
 clustering2int
 clustering3text
entries_indexed_mapmap<int, text>
indexed1text
indexed2int
key_indexed_mapmap<int, text>
my_listlist<text>
my_mapmap<int, text>
my_udtfrozen<live_data.address>
my_udt_listfrozen<list<frozen<live_data.address>>>
simpledouble

 complex_table's indices

NameTarget
clustering2idxclustering2
idx1indexed1
idx2indexed2
keys_map_idxkeys(key_indexed_map)
pk2idxpk2
Column TypeColumn NameData Type
sensor_iduuid
monthint
characteristicsmap<text, text>
model_numbertext
providertext
 datetimestamp
valuedouble
Column TypeColumn NameData Type
station_iduuid
sensorsfrozen<map<uuid, frozen<live_data.geolocation>>>

User Defined Types
Column NameData Type
numberint
streettext
zipint
citytext
countrytext
Column NameData Type
latitudedouble
longitudedouble
\ No newline at end of file +


  live_data

ReplicationDurable Writes
{'class' : 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor' : '1'}false

Tables
Column TypeColumn NameData Type
pk1uuid
pk2int
my_static1text
my_static2text
 clustering1timestamp
 clustering2int
 clustering3text
entries_indexed_mapmap<int, text>
indexed1text
indexed2int
key_indexed_mapmap<int, text>
my_listlist<text>
my_mapmap<int, text>
my_udtfrozen<live_data.address>
my_udt_listfrozen<list<frozen<live_data.address>>>
simpledouble

 complex_table's indices

NameTarget
clustering2idxclustering2
idx1indexed1
idx2indexed2
keys_map_idxkeys(key_indexed_map)
pk2idxpk2
Column TypeColumn NameData Type
sensor_iduuid
monthint
characteristicsmap<text, text>
model_numbertext
providertext
 datetimestamp
valuedouble
Column TypeColumn NameData Type
station_iduuid
sensorsfrozen<map<uuid, frozen<live_data.geolocation>>>

User Defined Types
Column NameData Type
numberint
streettext
zipint
citytext
countrytext
Column NameData Type
latitudedouble
longitudedouble
\ No newline at end of file diff --git a/cassandra/src/test/resources/scalate/DescribeTable_live_data_complex_table.html b/cassandra/src/test/resources/scalate/DescribeTable_live_data_complex_table.html index b31dc11ee55..09cb963f474 100644 --- a/cassandra/src/test/resources/scalate/DescribeTable_live_data_complex_table.html +++ b/cassandra/src/test/resources/scalate/DescribeTable_live_data_complex_table.html @@ -1 +1 @@ -


 complex_table

Column TypeColumn NameData Type
pk1uuid
pk2int
my_static1text
my_static2text
 clustering1timestamp
 clustering2int
 clustering3text
entries_indexed_mapmap<int, text>
indexed1text
indexed2int
key_indexed_mapmap<int, text>
my_listlist<text>
my_mapmap<int, text>
my_udtfrozen<live_data.address>
my_udt_listfrozen<list<frozen<live_data.address>>>
simpledouble

 complex_table's indices

NameTarget
clustering2idxclustering2
idx1indexed1
idx2indexed2
keys_map_idxkeys(key_indexed_map)
pk2idxpk2
\ No newline at end of file +


 complex_table

Column TypeColumn NameData Type
pk1uuid
pk2int
my_static1text
my_static2text
 clustering1timestamp
 clustering2int
 clustering3text
entries_indexed_mapmap<int, text>
indexed1text
indexed2int
key_indexed_mapmap<int, text>
my_listlist<text>
my_mapmap<int, text>
my_udtfrozen<live_data.address>
my_udt_listfrozen<list<frozen<live_data.address>>>
simpledouble

 complex_table's indices

NameTarget
clustering2idxclustering2
idx1indexed1
idx2indexed2
keys_map_idxkeys(key_indexed_map)
pk2idxpk2
\ No newline at end of file diff --git a/cassandra/src/test/resources/scalate/NoResultWithExecutionInfo.html b/cassandra/src/test/resources/scalate/NoResultWithExecutionInfo.html index bd713adad2e..f15b05dcaee 100644 --- a/cassandra/src/test/resources/scalate/NoResultWithExecutionInfo.html +++ b/cassandra/src/test/resources/scalate/NoResultWithExecutionInfo.html @@ -1 +1 @@ -
No Result      
InformationValue
StatementCREATE TABLE IF NOT EXISTS no_select(id int PRIMARY KEY);
Tried Hostslocalhost:9142
Queried Hostslocalhost:9142
Schema in Agreementtrue
\ No newline at end of file +
No Result      
InformationValue
StatementCREATE TABLE IF NOT EXISTS no_select(id int PRIMARY KEY);
Tried HostsTRIED_HOSTS
Queried HostsQUERIED_HOSTS
Schema in Agreementtrue
\ No newline at end of file diff --git a/pom.xml b/pom.xml index 9e021cbfc6f..a8e8a7f8f88 100644 --- a/pom.xml +++ b/pom.xml @@ -450,6 +450,13 @@ test + + org.testcontainers + cassandra + ${testcontainers.version} + test + + org.apache.hadoop hadoop-client-api