Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions cassandra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
<scalate.version>1.9.8</scalate.version>

<!-- test library versions -->
<jna.version>5.12.1</jna.version>
<cassandra.unit.version>4.3.1.0</cassandra.unit.version>

<scala.version>${scala.2.12.version}</scala.version>
<scala.binary.version>2.12</scala.binary.version>
Expand Down Expand Up @@ -137,26 +135,17 @@
</dependency>

<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>${jna.version}</version>
<groupId>org.testcontainers</groupId>
<artifactId>cassandra</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.cassandraunit</groupId>
<artifactId>cassandra-unit</artifactId>
<version>${cassandra.unit.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-core</artifactId>
</exclusion>
</exclusions>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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;");
Expand Down Expand Up @@ -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/<unresolved>:port"
String actualHtml = reformatHtml(actual.message().get(0).getData())
.replaceAll(address + "/&lt;unresolved&gt;:", address + ":");
assertEquals(expected, actualHtml);
}

@Test
Expand Down

Large diffs are not rendered by default.

Loading
Loading