You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by pd...@apache.org on 2023/09/11 07:00:55 UTC
[zeppelin] branch master updated: [ZEPPELIN-5955] migrate cassandra (#4649)
This is an automated email from the ASF dual-hosted git repository.
pdallig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push:
new 5eb9824587 [ZEPPELIN-5955] migrate cassandra (#4649)
5eb9824587 is described below
commit 5eb9824587b210fba8744d3819e25b63cb039072
Author: Philipp Dallig <ph...@gmail.com>
AuthorDate: Mon Sep 11 09:00:48 2023 +0200
[ZEPPELIN-5955] migrate cassandra (#4649)
---
cassandra/pom.xml | 7 -
.../cassandra/CassandraInterpreterTest.java | 747 ++++++++++-----------
.../zeppelin/cassandra/InterpreterLogicTest.java | 348 +++++-----
3 files changed, 548 insertions(+), 554 deletions(-)
diff --git a/cassandra/pom.xml b/cassandra/pom.xml
index 7962c4aa01..f7c87855e3 100644
--- a/cassandra/pom.xml
+++ b/cassandra/pom.xml
@@ -164,13 +164,6 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
-
- <dependency>
- <groupId>org.assertj</groupId>
- <artifactId>assertj-core</artifactId>
- <scope>test</scope>
- </dependency>
-
</dependencies>
<build>
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 7923fe4eba..8a6cce4ee9 100644
--- a/cassandra/src/test/java/org/apache/zeppelin/cassandra/CassandraInterpreterTest.java
+++ b/cassandra/src/test/java/org/apache/zeppelin/cassandra/CassandraInterpreterTest.java
@@ -30,10 +30,10 @@ 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.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
+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 java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -61,18 +61,20 @@ import static org.apache.zeppelin.cassandra.CassandraInterpreter.CASSANDRA_SOCKE
import static org.apache.zeppelin.cassandra.CassandraInterpreter.CASSANDRA_SOCKET_READ_TIMEOUT_MILLIS;
import static org.apache.zeppelin.cassandra.CassandraInterpreter.CASSANDRA_SOCKET_TCP_NO_DELAY;
import static org.apache.zeppelin.cassandra.CassandraInterpreter.CASSANDRA_SPECULATIVE_EXECUTION_POLICY;
-import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-public class CassandraInterpreterTest { //extends AbstractCassandraUnit4CQLTestCase {
+public class CassandraInterpreterTest { // extends AbstractCassandraUnit4CQLTestCase {
private static final String ARTISTS_TABLE = "zeppelin.artists";
private static volatile CassandraInterpreter interpreter;
private final InterpreterContext intrContext = InterpreterContext.builder()
- .setParagraphTitle("Paragraph1")
- .build();
+ .setParagraphTitle("Paragraph1")
+ .build();
- @BeforeClass
+ @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");
@@ -111,44 +113,43 @@ public class CassandraInterpreterTest { //extends AbstractCassandraUnit4CQLTestC
properties.setProperty(CASSANDRA_HOSTS, EmbeddedCassandraServerHelper.getHost());
properties.setProperty(CASSANDRA_PORT,
- Integer.toString(EmbeddedCassandraServerHelper.getNativeTransportPort()));
+ Integer.toString(EmbeddedCassandraServerHelper.getNativeTransportPort()));
properties.setProperty("datastax-java-driver.advanced.connection.pool.local.size", "1");
interpreter = new CassandraInterpreter(properties);
interpreter.open();
}
- @AfterClass
+ @AfterAll
public static void tearDown() {
interpreter.close();
}
@Test
- public void should_create_cluster_and_session_upon_call_to_open(){
- assertThat(interpreter.session).isNotNull();
- assertThat(interpreter.helper).isNotNull();
+ void should_create_cluster_and_session_upon_call_to_open() {
+ assertNotNull(interpreter.session);
+ assertNotNull(interpreter.helper);
}
@Test
- public void should_set_custom_option() {
- assertThat(interpreter.session).isNotNull();
+ void should_set_custom_option() {
+ assertNotNull(interpreter.session);
DriverExecutionProfile config = interpreter.session.getContext()
- .getConfig().getDefaultProfile();
- assertThat(config.getInt(DefaultDriverOption.CONNECTION_POOL_LOCAL_SIZE, 10))
- .isEqualTo(1);
+ .getConfig().getDefaultProfile();
+ assertEquals(1, config.getInt(DefaultDriverOption.CONNECTION_POOL_LOCAL_SIZE, 10));
}
@Test
- public void should_interpret_simple_select() {
- //Given
+ void should_interpret_simple_select() {
+ // Given
- //When
+ // When
final InterpreterResult actual = interpreter.interpret("SELECT * FROM " + ARTISTS_TABLE +
- " LIMIT 10;", intrContext);
+ " LIMIT 10;", intrContext);
- //Then
- assertThat(actual).isNotNull();
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(actual.message().get(0).getData()).isEqualTo("name\tborn\tcountry\tdied\tgender\t" +
+ // Then
+ assertNotNull(actual);
+ assertEquals(Code.SUCCESS, actual.code());
+ assertEquals("name\tborn\tcountry\tdied\tgender\t" +
"styles\ttype\n" +
"Bogdan Raczynski\t1977-01-01\tPoland\tnull\tMale\t" +
"[Dance, Electro]\tPerson\n" +
@@ -163,48 +164,48 @@ public class CassandraInterpreterTest { //extends AbstractCassandraUnit4CQLTestC
"[Rock, Pop, Classic]\tPerson\n" +
"Los Paranoias\tnull\tUnknown\tnull\tnull\t[Unknown]\tnull\n" +
"…And You Will Know Us by the Trail of Dead\t1994-01-01\tUSA\tnull\tnull\t" +
- "[Rock, Pop, Classic]\tGroup\n");
+ "[Rock, Pop, Classic]\tGroup\n", actual.message().get(0).getData());
}
@Test
- public void should_interpret_select_statement() {
- //Given
+ void should_interpret_select_statement() {
+ // Given
- //When
+ // When
final InterpreterResult actual = interpreter.interpret("SELECT * FROM " + ARTISTS_TABLE +
- " LIMIT 2;", intrContext);
+ " LIMIT 2;", intrContext);
- //Then
- assertThat(actual).isNotNull();
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(actual.message().get(0).getData())
- .isEqualTo("name\tborn\tcountry\tdied\tgender\tstyles\ttype\n" +
+ // Then
+ assertNotNull(actual);
+ assertEquals(Code.SUCCESS, actual.code());
+ assertEquals("name\tborn\tcountry\tdied\tgender\tstyles\ttype\n" +
"Bogdan Raczynski\t1977-01-01\tPoland\tnull\tMale\t" +
"[Dance, Electro]\tPerson\n" +
- "Krishna Das\t1947-05-31\tUSA\tnull\tMale\t[Unknown]\tPerson\n");
+ "Krishna Das\t1947-05-31\tUSA\tnull\tMale\t[Unknown]\tPerson\n",
+ actual.message().get(0).getData());
}
@Test
- public void should_interpret_select_statement_with_cql_format() {
- //When
+ void should_interpret_select_statement_with_cql_format() {
+ // When
intrContext.getLocalProperties().put("outputFormat", "cql");
final InterpreterResult actual = interpreter.interpret(
- "SELECT * FROM " + ARTISTS_TABLE + " LIMIT 2;", intrContext);
+ "SELECT * FROM " + ARTISTS_TABLE + " LIMIT 2;", intrContext);
intrContext.getLocalProperties().remove("outputFormat");
- //Then
- assertThat(actual).isNotNull();
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(actual.message().get(0).getData())
- .isEqualTo("name\tborn\tcountry\tdied\tgender\tstyles\ttype\n" +
- "'Bogdan Raczynski'\t'1977-01-01'\t'Poland'\tnull\t'Male'\t" +
- "['Dance','Electro']\t'Person'\n" +
- "'Krishna Das'\t'1947-05-31'\t'USA'\tnull\t'Male'\t['Unknown']\t'Person'\n");
+ // Then
+ assertNotNull(actual);
+ assertEquals(Code.SUCCESS, actual.code());
+ assertEquals("name\tborn\tcountry\tdied\tgender\tstyles\ttype\n" +
+ "'Bogdan Raczynski'\t'1977-01-01'\t'Poland'\tnull\t'Male'\t" +
+ "['Dance','Electro']\t'Person'\n" +
+ "'Krishna Das'\t'1947-05-31'\t'USA'\tnull\t'Male'\t['Unknown']\t'Person'\n",
+ actual.message().get(0).getData());
}
@Test
- public void should_interpret_select_statement_with_formatting_options() {
- //When
+ void should_interpret_select_statement_with_formatting_options() {
+ // When
Map<String, String> props = intrContext.getLocalProperties();
props.put("outputFormat", "human");
props.put("locale", "de_DE");
@@ -216,7 +217,7 @@ public class CassandraInterpreterTest { //extends AbstractCassandraUnit4CQLTestC
props.put("dateFormat", "EEEE, d MMMM yy");
props.put("timezone", "Etc/GMT+2");
String query =
- "select date,time,timestamp,dec,double,float,tuple,udt from zeppelin.test_format;";
+ "select date,time,timestamp,dec,double,float,tuple,udt from zeppelin.test_format;";
final InterpreterResult actual = interpreter.interpret(query, intrContext);
props.remove("outputFormat");
props.remove("locale");
@@ -228,616 +229,612 @@ public class CassandraInterpreterTest { //extends AbstractCassandraUnit4CQLTestC
props.remove("dateFormat");
props.remove("timezone");
- //Then
- assertThat(actual).isNotNull();
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
+ // Then
+ assertNotNull(actual);
+ assertEquals(Code.SUCCESS, actual.code());
String expected = "date\ttime\ttimestamp\tdec\tdouble\tfloat\ttuple\tudt\n" +
- "Dienstag, 29 Januar 19\t04:05\t06/16/20 21:59\t123562352352,12346\t10,0153\t20,03\t" +
- "(1, text, 10)\t{id: 1, t: text, lst: [1, 2, 3]}\n";
- assertThat(actual.message().get(0).getData()).isEqualTo(expected);
+ "Dienstag, 29 Januar 19\t04:05\t06/16/20 21:59\t123562352352,12346\t10,0153\t20,03\t" +
+ "(1, text, 10)\t{id: 1, t: text, lst: [1, 2, 3]}\n";
+ assertEquals(expected, actual.message().get(0).getData());
}
@Test
- public void should_interpret_multiple_statements_with_single_line_logged_batch() {
- //Given
+ void should_interpret_multiple_statements_with_single_line_logged_batch() {
+ // Given
String statements = "CREATE TABLE IF NOT EXISTS zeppelin.albums(\n" +
- " title text PRIMARY KEY,\n" +
- " artist text,\n" +
- " year int\n" +
- ");\n" +
- "BEGIN BATCH" +
- " INSERT INTO zeppelin.albums(title,artist,year) " +
- "VALUES('The Impossible Dream EP','Carter the Unstoppable Sex Machine',1992);" +
- " INSERT INTO zeppelin.albums(title,artist,year) " +
- "VALUES('The Way You Are','Tears for Fears',1983);" +
- " INSERT INTO zeppelin.albums(title,artist,year) " +
- "VALUES('Primitive','Soulfly',2003);" +
- "APPLY BATCH;\n" +
- "SELECT * FROM zeppelin.albums;";
- //When
+ " title text PRIMARY KEY,\n" +
+ " artist text,\n" +
+ " year int\n" +
+ ");\n" +
+ "BEGIN BATCH" +
+ " INSERT INTO zeppelin.albums(title,artist,year) " +
+ "VALUES('The Impossible Dream EP','Carter the Unstoppable Sex Machine',1992);" +
+ " INSERT INTO zeppelin.albums(title,artist,year) " +
+ "VALUES('The Way You Are','Tears for Fears',1983);" +
+ " INSERT INTO zeppelin.albums(title,artist,year) " +
+ "VALUES('Primitive','Soulfly',2003);" +
+ "APPLY BATCH;\n" +
+ "SELECT * FROM zeppelin.albums;";
+ // When
final InterpreterResult actual = interpreter.interpret(statements, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(actual.message().get(0).getData()).isEqualTo("title\tartist\tyear\n" +
- "The Impossible Dream EP\tCarter the Unstoppable Sex Machine\t1992\n" +
- "The Way You Are\tTears for Fears\t1983\n" +
- "Primitive\tSoulfly\t2003\n");
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
+ assertEquals("title\tartist\tyear\n" +
+ "The Impossible Dream EP\tCarter the Unstoppable Sex Machine\t1992\n" +
+ "The Way You Are\tTears for Fears\t1983\n" +
+ "Primitive\tSoulfly\t2003\n", actual.message().get(0).getData());
}
@Test
- public void should_throw_statement_not_having_semi_colon() {
- //Given
+ void should_throw_statement_not_having_semi_colon() {
+ // Given
String statement = "SELECT * zeppelin.albums";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(statement, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.ERROR);
- assertThat(actual.message().get(0).getData())
- .contains("Error parsing input:\n" +
- "\t'SELECT * zeppelin.albums'\n" +
- "Did you forget to add ; (semi-colon) at the end of each CQL statement ?");
+ // Then
+ assertEquals(Code.ERROR, actual.code());
+ assertTrue(actual.message().get(0).getData().contains("Error parsing input:\n" +
+ "\t'SELECT * zeppelin.albums'\n" +
+ "Did you forget to add ; (semi-colon) at the end of each CQL statement ?"),
+ actual.message().get(0).getData());
}
@Test
- public void should_validate_statement() {
- //Given
+ void should_validate_statement() {
+ // Given
String statement = "SELECT * zeppelin.albums;";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(statement, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.ERROR);
+ // Then
+ assertEquals(Code.ERROR, actual.code());
String s = "line 1:9 mismatched input 'zeppelin' expecting K_FROM (SELECT * [zeppelin]...)";
- assertThat(actual.message().get(0).getData())
- .contains(s);
+ assertTrue(actual.message().get(0).getData().contains(s), actual.message().get(0).getData());
}
@Test
- public void should_execute_statement_with_consistency_option() {
- //Given
+ void should_execute_statement_with_consistency_option() {
+ // Given
String statement = "@consistency=THREE\n" +
- "SELECT * FROM zeppelin.artists LIMIT 1;";
+ "SELECT * FROM zeppelin.artists LIMIT 1;";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(statement, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.ERROR);
- assertThat(actual.message().get(0).getData())
- .contains("Not enough replicas available for query at consistency THREE (3 required " +
- "but only 1 alive)");
+ // Then
+ assertEquals(Code.ERROR, actual.code());
+ assertTrue(actual.message().get(0).getData()
+ .contains("Not enough replicas available for query at consistency THREE (3 required " +
+ "but only 1 alive)"),
+ actual.message().get(0).getData());
}
@Test
- public void should_execute_statement_with_serial_consistency_option() {
- //Given
+ void should_execute_statement_with_serial_consistency_option() {
+ // Given
String statement = "@serialConsistency=SERIAL\n" +
- "SELECT * FROM zeppelin.artists LIMIT 1;";
+ "SELECT * FROM zeppelin.artists LIMIT 1;";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(statement, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
}
@Test
- public void should_execute_statement_with_timestamp_option() throws Exception {
- //Given
+ void should_execute_statement_with_timestamp_option() throws Exception {
+ // Given
String statement1 = "INSERT INTO zeppelin.ts(key,val) VALUES('k','v1');";
String statement2 = "@timestamp=15\n" +
- "INSERT INTO zeppelin.ts(key,val) VALUES('k','v2');";
+ "INSERT INTO zeppelin.ts(key,val) VALUES('k','v2');";
CqlSession session = EmbeddedCassandraServerHelper.getSession();
// Insert v1 with current timestamp
interpreter.interpret(statement1, intrContext);
System.out.println("going to read data from zeppelin.ts;");
session.execute("SELECT val FROM zeppelin.ts LIMIT 1")
- .forEach(x -> System.out.println("row " + x ));
+ .forEach(x -> System.out.println("row " + x));
Thread.sleep(1);
- //When
+ // When
// Insert v2 with past timestamp
interpreter.interpret(statement2, intrContext);
System.out.println("going to read data from zeppelin.ts;");
session.execute("SELECT val FROM zeppelin.ts LIMIT 1")
- .forEach(x -> System.out.println("row " + x ));
+ .forEach(x -> System.out.println("row " + x));
final String actual = session.execute("SELECT val FROM zeppelin.ts LIMIT 1").one()
- .getString("val");
+ .getString("val");
- //Then
- assertThat(actual).isEqualTo("v1");
+ // Then
+ assertEquals("v1", actual);
}
@Test
- public void should_execute_statement_with_request_timeout() {
- //Given
+ void should_execute_statement_with_request_timeout() {
+ // Given
String statement = "@requestTimeOut=10000000\n" +
- "SELECT * FROM zeppelin.artists;";
+ "SELECT * FROM zeppelin.artists;";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(statement, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
}
@Test
- public void should_execute_prepared_and_bound_statements() {
- //Given
+ void should_execute_prepared_and_bound_statements() {
+ // Given
String queries = "@prepare[ps]=INSERT INTO zeppelin.prepared(key,val) VALUES(?,?)\n" +
- "@prepare[select]=SELECT * FROM zeppelin.prepared WHERE key=:key\n" +
- "@bind[ps]='myKey','myValue'\n" +
- "@bind[select]='myKey'";
+ "@prepare[select]=SELECT * FROM zeppelin.prepared WHERE key=:key\n" +
+ "@bind[ps]='myKey','myValue'\n" +
+ "@bind[select]='myKey'";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(queries, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(actual.message().get(0).getData()).isEqualTo("key\tval\n" +
- "myKey\tmyValue\n");
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
+ assertEquals("key\tval\nmyKey\tmyValue\n", actual.message().get(0).getData());
}
@Test
- public void should_execute_bound_statement() {
- //Given
+ void should_execute_bound_statement() {
+ // Given
String queries = "@prepare[users_insert]=INSERT INTO zeppelin.users" +
- "(login,firstname,lastname,addresses,location)" +
- "VALUES(:login,:fn,:ln,:addresses,:loc)\n" +
- "@bind[users_insert]='jdoe','John','DOE'," +
- "{street_number: 3, street_name: 'Beverly Hills Bld', zip_code: 90209," +
- " country: 'USA', extra_info: ['Right on the hills','Next to the post box']," +
- " phone_numbers: {'home': 2016778524, 'office': 2015790847}}," +
- "('USA', 90209, 'Beverly Hills')\n" +
- "SELECT * FROM zeppelin.users WHERE login='jdoe';";
- //When
+ "(login,firstname,lastname,addresses,location)" +
+ "VALUES(:login,:fn,:ln,:addresses,:loc)\n" +
+ "@bind[users_insert]='jdoe','John','DOE'," +
+ "{street_number: 3, street_name: 'Beverly Hills Bld', zip_code: 90209," +
+ " country: 'USA', extra_info: ['Right on the hills','Next to the post box']," +
+ " phone_numbers: {'home': 2016778524, 'office': 2015790847}}," +
+ "('USA', 90209, 'Beverly Hills')\n" +
+ "SELECT * FROM zeppelin.users WHERE login='jdoe';";
+ // When
final InterpreterResult actual = interpreter.interpret(queries, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(actual.message().get(0).getData()).isEqualTo(
- "login\taddresses\tage\tdeceased\tfirstname\tlast_update\tlastname\tlocation\n" +
- "jdoe\t" +
- "{street_number: 3, street_name: Beverly Hills Bld, zip_code: 90209, " +
- "country: USA, extra_info: [Right on the hills, Next to the post box], " +
- "phone_numbers: {home: 2016778524, office: 2015790847}}\tnull\t" +
- "null\t" +
- "John\t" +
- "null\t" +
- "DOE\t" +
- "(USA, 90209, Beverly Hills)\n");
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
+ assertEquals("login\taddresses\tage\tdeceased\tfirstname\tlast_update\tlastname\tlocation\n" +
+ "jdoe\t" +
+ "{street_number: 3, street_name: Beverly Hills Bld, zip_code: 90209, " +
+ "country: USA, extra_info: [Right on the hills, Next to the post box], " +
+ "phone_numbers: {home: 2016778524, office: 2015790847}}\tnull\t" +
+ "null\t" +
+ "John\t" +
+ "null\t" +
+ "DOE\t" +
+ "(USA, 90209, Beverly Hills)\n", actual.message().get(0).getData());
}
@Test
- public void should_exception_when_executing_unknown_bound_statement() {
- //Given
+ void should_exception_when_executing_unknown_bound_statement() {
+ // Given
String queries = "@bind[select_users]='jdoe'";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(queries, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.ERROR);
- assertThat(actual.message().get(0).getData())
- .isEqualTo("The statement 'select_users' can not be bound to values. " +
- "Are you sure you did prepare it with @prepare[select_users] ?");
+ // Then
+ assertEquals(Code.ERROR, actual.code());
+ assertEquals("The statement 'select_users' can not be bound to values. " +
+ "Are you sure you did prepare it with @prepare[select_users] ?",
+ actual.message().get(0).getData());
}
@Test
- public void should_extract_variable_from_statement() {
- //Given
+ void should_extract_variable_from_statement() {
+ // Given
AngularObjectRegistry angularObjectRegistry = new AngularObjectRegistry("cassandra", null);
GUI gui = new GUI();
gui.textbox("login", "hsue");
gui.textbox("age", "27");
InterpreterContext intrContext = InterpreterContext.builder()
- .setParagraphTitle("Paragraph1")
- .setAngularObjectRegistry(angularObjectRegistry)
- .setGUI(gui)
- .build();
+ .setParagraphTitle("Paragraph1")
+ .setAngularObjectRegistry(angularObjectRegistry)
+ .setGUI(gui)
+ .build();
String queries = "@prepare[test_insert_with_variable]=" +
- "INSERT INTO zeppelin.users(login,firstname,lastname,age) VALUES(?,?,?,?)\n" +
- "@bind[test_insert_with_variable]='{{login=hsue}}','Helen','SUE',{{age=27}}\n" +
- "SELECT firstname,lastname,age FROM zeppelin.users WHERE login='hsue';";
- //When
+ "INSERT INTO zeppelin.users(login,firstname,lastname,age) VALUES(?,?,?,?)\n" +
+ "@bind[test_insert_with_variable]='{{login=hsue}}','Helen','SUE',{{age=27}}\n" +
+ "SELECT firstname,lastname,age FROM zeppelin.users WHERE login='hsue';";
+ // When
final InterpreterResult actual = interpreter.interpret(queries, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(actual.message().get(0).getData()).isEqualTo("firstname\tlastname\tage\n" +
- "Helen\tSUE\t27\n");
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
+ assertEquals("firstname\tlastname\tage\nHelen\tSUE\t27\n", actual.message().get(0).getData());
}
@Test
- public void should_just_prepare_statement() {
- //Given
+ void should_just_prepare_statement() {
+ // Given
String queries = "@prepare[just_prepare]=SELECT name,country,styles " +
- "FROM zeppelin.artists LIMIT 3";
+ "FROM zeppelin.artists LIMIT 3";
final String expected = reformatHtml(
- readTestResource("/scalate/NoResult.html"));
+ readTestResource("/scalate/NoResult.html"));
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(queries, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(reformatHtml(actual.message().get(0).getData())).isEqualTo(expected);
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
+ assertEquals(expected, reformatHtml(actual.message().get(0).getData()));
}
@Test
- public void should_execute_bound_statement_with_no_bound_value() {
- //Given
+ void should_execute_bound_statement_with_no_bound_value() {
+ // Given
String queries = "@prepare[select_no_bound_value]=SELECT name,country,styles " +
- "FROM zeppelin.artists LIMIT 3\n" +
- "@bind[select_no_bound_value]";
+ "FROM zeppelin.artists LIMIT 3\n" +
+ "@bind[select_no_bound_value]";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(queries, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(actual.message().get(0).getData()).isEqualTo("name\tcountry\tstyles\n" +
- "Bogdan Raczynski\tPoland\t[Dance, Electro]\n" +
- "Krishna Das\tUSA\t[Unknown]\n" +
- "Sheryl Crow\tUSA\t[Classic, Rock, Country, Blues, Pop, Folk]\n");
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
+ assertEquals("name\tcountry\tstyles\n" +
+ "Bogdan Raczynski\tPoland\t[Dance, Electro]\n" +
+ "Krishna Das\tUSA\t[Unknown]\n" +
+ "Sheryl Crow\tUSA\t[Classic, Rock, Country, Blues, Pop, Folk]\n",
+ actual.message().get(0).getData());
}
@Test
- public void should_parse_date_value() {
- //Given
+ void should_parse_date_value() {
+ // Given
String queries = "@prepare[parse_date]=INSERT INTO zeppelin.users(login,last_update) " +
- "VALUES(?,?)\n" +
- "@bind[parse_date]='last_update','2015-07-30 12:00:01'\n" +
- "SELECT last_update FROM zeppelin.users WHERE login='last_update';";
- //When
+ "VALUES(?,?)\n" +
+ "@bind[parse_date]='last_update','2015-07-30 12:00:01'\n" +
+ "SELECT last_update FROM zeppelin.users WHERE login='last_update';";
+ // When
final InterpreterResult actual = interpreter.interpret(queries, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(actual.message().get(0).getData()).contains("last_update\n2015-07-30T12:00:01.000Z");
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
+ assertTrue(actual.message().get(0).getData().contains("last_update\n2015-07-30T12:00:01.000Z"),
+ actual.message().get(0).getData());
}
@Test
- public void should_bind_null_value() {
- //Given
+ void should_bind_null_value() {
+ // Given
String queries = "@prepare[bind_null]=INSERT INTO zeppelin.users(login,firstname,lastname) " +
- "VALUES(?,?,?)\n" +
- "@bind[bind_null]='bind_null',null,'NULL'\n" +
- "SELECT firstname,lastname FROM zeppelin.users WHERE login='bind_null';";
- //When
+ "VALUES(?,?,?)\n" +
+ "@bind[bind_null]='bind_null',null,'NULL'\n" +
+ "SELECT firstname,lastname FROM zeppelin.users WHERE login='bind_null';";
+ // When
final InterpreterResult actual = interpreter.interpret(queries, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(actual.message().get(0).getData()).isEqualTo("firstname\tlastname\n" +
- "null\tNULL\n");
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
+ assertEquals("firstname\tlastname\nnull\tNULL\n", actual.message().get(0).getData());
}
@Test
- public void should_bind_boolean_value() {
- //Given
+ void should_bind_boolean_value() {
+ // Given
String queries = "@prepare[bind_boolean]=INSERT INTO zeppelin.users(login,deceased) " +
- "VALUES(?,?)\n" +
- "@bind[bind_boolean]='bind_bool',false\n" +
- "SELECT login,deceased FROM zeppelin.users WHERE login='bind_bool';";
- //When
+ "VALUES(?,?)\n" +
+ "@bind[bind_boolean]='bind_bool',false\n" +
+ "SELECT login,deceased FROM zeppelin.users WHERE login='bind_bool';";
+ // When
final InterpreterResult actual = interpreter.interpret(queries, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(actual.message().get(0).getData()).isEqualTo("login\tdeceased\n" +
- "bind_bool\tfalse\n");
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
+ assertEquals("login\tdeceased\nbind_bool\tfalse\n", actual.message().get(0).getData());
}
@Test
- public void should_fail_when_executing_a_removed_prepared_statement() {
- //Given
+ void should_fail_when_executing_a_removed_prepared_statement() {
+ // Given
String prepareFirst = "@prepare[to_be_removed]=INSERT INTO zeppelin.users(login,deceased) " +
- "VALUES(?,?)";
+ "VALUES(?,?)";
interpreter.interpret(prepareFirst, intrContext);
String removePrepared = "@remove_prepare[to_be_removed]\n" +
- "@bind[to_be_removed]='bind_bool'";
+ "@bind[to_be_removed]='bind_bool'";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(removePrepared, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.ERROR);
- assertThat(actual.message().get(0).getData()).isEqualTo("The statement 'to_be_removed' can " +
- "not be bound to values. Are you sure you did prepare it with " +
- "@prepare[to_be_removed] ?");
+ // Then
+ assertEquals(Code.ERROR, actual.code());
+ assertEquals("The statement 'to_be_removed' can " +
+ "not be bound to values. Are you sure you did prepare it with " +
+ "@prepare[to_be_removed] ?", actual.message().get(0).getData());
}
@Test
- public void should_display_statistics_for_non_select_statement() {
- //Given
+ void should_display_statistics_for_non_select_statement() {
+ // Given
String query = "USE zeppelin;\nCREATE TABLE IF NOT EXISTS no_select(id int PRIMARY KEY);";
final String rawResult = reformatHtml(readTestResource(
- "/scalate/NoResultWithExecutionInfo.html"));
+ "/scalate/NoResultWithExecutionInfo.html"));
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
final int port = EmbeddedCassandraServerHelper.getNativeTransportPort();
final String address = EmbeddedCassandraServerHelper.getHost();
- //Then
+ // Then
final String expected = rawResult.replaceAll("TRIED_HOSTS", address + ":" + port)
- .replaceAll("QUERIED_HOSTS", address + ":" + port);
+ .replaceAll("QUERIED_HOSTS", address + ":" + port);
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(reformatHtml(actual.message().get(0).getData())).isEqualTo(expected);
+ assertEquals(Code.SUCCESS, actual.code());
+ assertEquals(expected, reformatHtml(actual.message().get(0).getData()));
}
@Test
- public void should_error_and_display_stack_trace() {
- //Given
+ void should_error_and_display_stack_trace() {
+ // Given
String query = "@consistency=THREE\n" +
- "SELECT * FROM zeppelin.users LIMIT 3;";
- //When
+ "SELECT * FROM zeppelin.users LIMIT 3;";
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.ERROR);
- assertThat(actual.message().get(0).getData())
- .contains("All 1 node(s) tried for the query failed");
+ // Then
+ assertEquals(Code.ERROR, actual.code());
+ assertTrue(
+ actual.message().get(0).getData().contains("All 1 node(s) tried for the query failed"),
+ actual.message().get(0).getData());
}
@Test
- public void should_describe_cluster() {
- //Given
+ void should_describe_cluster() {
+ // Given
String query = "DESCRIBE CLUSTER;";
final String expected = reformatHtml(
- readTestResource("/scalate/DescribeCluster.html"));
+ readTestResource("/scalate/DescribeCluster.html"));
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(reformatHtml(actual.message().get(0).getData())).isEqualTo(expected);
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
+ assertEquals(expected, reformatHtml(actual.message().get(0).getData()));
}
@Test
- public void should_describe_keyspaces() {
- //Given
+ void should_describe_keyspaces() {
+ // Given
String query = "DESCRIBE KEYSPACES;";
final String expected = reformatHtml(
- readTestResource("/scalate/DescribeKeyspaces.html"));
+ readTestResource("/scalate/DescribeKeyspaces.html"));
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(reformatHtml(actual.message().get(0).getData())).isEqualTo(expected);
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
+ assertEquals(expected, reformatHtml(actual.message().get(0).getData()));
}
@Test
- public void should_describe_keyspace() {
- //Given
+ void should_describe_keyspace() {
+ // Given
String query = "DESCRIBE KEYSPACE live_data;";
final String expected = reformatHtml(
- readTestResource("/scalate/DescribeKeyspace_live_data.html"));
+ readTestResource("/scalate/DescribeKeyspace_live_data.html"));
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(reformatHtml(actual.message().get(0).getData())).isEqualTo(expected);
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
+ assertEquals(expected, reformatHtml(actual.message().get(0).getData()));
}
@Test
- @Ignore
- //TODO(n.a.) activate test when using Java 8 and C* 3.x
- public void should_describe_function() throws Exception {
- //Given
+ @Disabled("TODO(n.a.) activate test when using Java 8 and C* 3.x")
+ void should_describe_function() throws Exception {
+ // Given
Properties properties = new Properties();
properties.setProperty(CASSANDRA_HOSTS, "127.0.0.1");
- properties.setProperty(CASSANDRA_PORT, "9042");
+ properties.setProperty(CASSANDRA_PORT, "9042");
Interpreter interpreter = new CassandraInterpreter(properties);
interpreter.open();
String createFunction = "CREATE FUNCTION zeppelin.maxof(val1 int,val2 int) " +
- "RETURNS NULL ON NULL INPUT " +
- "RETURNS int " +
- "LANGUAGE java " +
- "AS $$" +
- " return Math.max(val1, val2);\n" +
- "$$;";
+ "RETURNS NULL ON NULL INPUT " +
+ "RETURNS int " +
+ "LANGUAGE java " +
+ "AS $$" +
+ " return Math.max(val1, val2);\n" +
+ "$$;";
interpreter.interpret(createFunction, intrContext);
String query = "DESCRIBE FUNCTION zeppelin.maxOf;";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(actual.message()).isEqualTo("xxxxx");
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
+ assertEquals("xxxxx", actual.message());
}
@Test
- @Ignore
- //TODO(n.a.) activate test when using Java 8 and C* 3.x
- public void should_describe_aggregate() throws Exception {
- //Given
+ @Disabled("TODO(n.a.) activate test when using Java 8 and C* 3.x")
+ void should_describe_aggregate() throws Exception {
+ // Given
Properties properties = new Properties();
properties.setProperty(CASSANDRA_HOSTS, "127.0.0.1");
- properties.setProperty(CASSANDRA_PORT, "9042");
+ properties.setProperty(CASSANDRA_PORT, "9042");
Interpreter interpreter = new CassandraInterpreter(properties);
interpreter.open();
final String query = "DESCRIBE AGGREGATES;";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
}
@Test
- @Ignore
- //TODO(n.a.) activate test when using Java 8 and C* 3.x
- public void should_describe_materialized_view() throws Exception {
- //Given
+ @Disabled("TODO(n.a.) activate test when using Java 8 and C* 3.x")
+ void should_describe_materialized_view() throws Exception {
+ // Given
Properties properties = new Properties();
properties.setProperty(CASSANDRA_HOSTS, "127.0.0.1");
- properties.setProperty(CASSANDRA_PORT, "9042");
+ properties.setProperty(CASSANDRA_PORT, "9042");
Interpreter interpreter = new CassandraInterpreter(properties);
interpreter.open();
final String query = "DESCRIBE MATERIALIZED VIEWS;";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
}
@Test
- public void should_describe_table() {
- //Given
+ void should_describe_table() {
+ // Given
String query = "DESCRIBE TABLE live_data.complex_table;";
final String expected = reformatHtml(
- readTestResource("/scalate/DescribeTable_live_data_complex_table.html"));
+ readTestResource("/scalate/DescribeTable_live_data_complex_table.html"));
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(reformatHtml(actual.message().get(0).getData())).isEqualTo(expected);
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
+ assertEquals(expected, reformatHtml(actual.message().get(0).getData()));
}
@Test
- public void should_describe_udt() {
- //Given
+ void should_describe_udt() {
+ // Given
String query = "DESCRIBE TYPE live_data.address;";
final String expected = reformatHtml(
- readTestResource("/scalate/DescribeType_live_data_address.html"));
+ readTestResource("/scalate/DescribeType_live_data_address.html"));
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(reformatHtml(actual.message().get(0).getData())).isEqualTo(expected);
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
+ assertEquals(expected, reformatHtml(actual.message().get(0).getData()));
}
@Test
- public void should_describe_udt_withing_logged_in_keyspace() {
- //Given
+ void should_describe_udt_withing_logged_in_keyspace() {
+ // Given
String query = "USE live_data;\n" +
- "DESCRIBE TYPE address;";
+ "DESCRIBE TYPE address;";
final String expected = reformatHtml(readTestResource(
- "/scalate/DescribeType_live_data_address_within_current_keyspace.html"));
+ "/scalate/DescribeType_live_data_address_within_current_keyspace.html"));
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(reformatHtml(actual.message().get(0).getData())).isEqualTo(expected);
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
+ assertEquals(expected, reformatHtml(actual.message().get(0).getData()));
}
@Test
- public void should_describe_all_tables() {
- //Given
+ void should_describe_all_tables() {
+ // Given
String query = "DESCRIBE TABLES;";
final String expected = reformatHtml(readTestResource(
- "/scalate/DescribeTables.html"));
+ "/scalate/DescribeTables.html"));
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(reformatHtml(actual.message().get(0).getData())).isEqualTo(expected);
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
+ assertEquals(expected, reformatHtml(actual.message().get(0).getData()));
}
@Test
- public void should_describe_all_udts() {
- //Given
+ void should_describe_all_udts() {
+ // Given
String query = "DESCRIBE TYPES;";
final String expected = reformatHtml(readTestResource(
- "/scalate/DescribeTypes.html"));
+ "/scalate/DescribeTypes.html"));
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(reformatHtml(actual.message().get(0).getData())).isEqualTo(expected);
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
+ assertEquals(expected, reformatHtml(actual.message().get(0).getData()));
}
-
@Test
- public void should_error_describing_non_existing_table() {
- //Given
+ void should_error_describing_non_existing_table() {
+ // Given
String query = "USE system;\n" +
- "DESCRIBE TABLE complex_table;";
+ "DESCRIBE TABLE complex_table;";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.ERROR);
- assertThat(actual.message().get(0).getData())
- .contains("Cannot find table system.complex_table");
+ // Then
+ assertEquals(Code.ERROR, actual.code());
+ assertTrue(actual.message().get(0).getData().contains("Cannot find table system.complex_table"),
+ actual.message().get(0).getData());
}
@Test
- public void should_error_describing_non_existing_udt() {
- //Given
+ void should_error_describing_non_existing_udt() {
+ // Given
String query = "USE system;\n" +
- "DESCRIBE TYPE address;";
+ "DESCRIBE TYPE address;";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.ERROR);
- assertThat(actual.message().get(0).getData()).contains("Cannot find type system.address");
+ // Then
+ assertEquals(Code.ERROR, actual.code());
+ assertTrue(actual.message().get(0).getData().contains("Cannot find type system.address"),
+ actual.message().get(0).getData());
}
@Test
- public void should_show_help() {
- //Given
+ void should_show_help() {
+ // Given
String query = "HELP;";
final String expected = reformatHtml(readTestResource("/scalate/Help.html"));
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
- assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(reformatHtml(actual.message().get(0).getData())).contains(expected);
+ // Then
+ assertEquals(Code.SUCCESS, actual.code());
+ assertTrue(reformatHtml(actual.message().get(0).getData()).contains(expected),
+ reformatHtml(actual.message().get(0).getData()));
}
private static String reformatHtml(String rawHtml) {
- return rawHtml
- .replaceAll("\\s*\n\\s*", "")
- .replaceAll(">\\s+<", "><")
- .replaceAll("(?s)data-target=\"#[a-f0-9-]+(?:_asCQL|_indices_asCQL)?\"", "")
- .replaceAll("(?s)id=\"[a-f0-9-]+(?:_asCQL|_indices_asCQL)?\"", "")
- .replaceAll("AND memtable_flush_period_in_ms = 0", "")
- .trim();
+ return rawHtml
+ .replaceAll("\\s*\n\\s*", "")
+ .replaceAll(">\\s+<", "><")
+ .replaceAll("(?s)data-target=\"#[a-f0-9-]+(?:_asCQL|_indices_asCQL)?\"", "")
+ .replaceAll("(?s)id=\"[a-f0-9-]+(?:_asCQL|_indices_asCQL)?\"", "")
+ .replaceAll("AND memtable_flush_period_in_ms = 0", "")
+ .trim();
}
private static String readTestResource(String testResource) {
try {
return IOUtils.toString(
- CassandraInterpreterTest.class.getResourceAsStream(testResource),
- StandardCharsets.UTF_8);
+ CassandraInterpreterTest.class.getResourceAsStream(testResource),
+ StandardCharsets.UTF_8);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
diff --git a/cassandra/src/test/java/org/apache/zeppelin/cassandra/InterpreterLogicTest.java b/cassandra/src/test/java/org/apache/zeppelin/cassandra/InterpreterLogicTest.java
index f0d8334db3..c7f952c7d9 100644
--- a/cassandra/src/test/java/org/apache/zeppelin/cassandra/InterpreterLogicTest.java
+++ b/cassandra/src/test/java/org/apache/zeppelin/cassandra/InterpreterLogicTest.java
@@ -22,12 +22,17 @@ import static com.datastax.oss.driver.api.core.ConsistencyLevel.ONE;
import static com.datastax.oss.driver.api.core.ConsistencyLevel.QUORUM;
import static com.datastax.oss.driver.api.core.ConsistencyLevel.SERIAL;
import static com.datastax.oss.driver.api.core.cql.BatchType.UNLOGGED;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.eq;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import static java.util.Arrays.asList;
@@ -37,16 +42,8 @@ import com.datastax.oss.driver.api.core.cql.BatchStatement;
import com.datastax.oss.driver.api.core.cql.BatchableStatement;
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.ArgumentCaptor;
-import org.mockito.Captor;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
@@ -71,320 +68,327 @@ import org.apache.zeppelin.display.GUI;
import org.apache.zeppelin.display.ui.OptionInput.ParamOption;
import org.apache.zeppelin.interpreter.InterpreterContext;
import org.apache.zeppelin.interpreter.InterpreterException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-@RunWith(MockitoJUnitRunner.class)
-public class InterpreterLogicTest {
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
+class InterpreterLogicTest {
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private InterpreterContext intrContext;
-
- @Mock
private CqlSession session;
- final InterpreterLogic helper = new InterpreterLogic(session, new Properties());
+ @BeforeEach
+ public void setup() {
+ intrContext = mock(InterpreterContext.class, Answers.RETURNS_DEEP_STUBS);
+ session = mock(CqlSession.class);
+ }
- @Captor
- ArgumentCaptor<ParamOption[]> optionsCaptor;
+ final InterpreterLogic helper = new InterpreterLogic(session, new Properties());
@Test
- public void should_parse_input_string_block() {
- //Given
+ void should_parse_input_string_block() {
+ // Given
String input = "SELECT * FROM users LIMIT 10;";
- //When
+ // When
final List<AnyBlock> anyBlocks = this.toJavaList(helper.parseInput(input));
- //Then
- assertThat(anyBlocks).hasSize(1);
- assertThat(anyBlocks.get(0)).isInstanceOf(SimpleStm.class);
+ // Then
+ assertEquals(1, anyBlocks.size());
+ assertTrue(anyBlocks.get(0) instanceof SimpleStm);
}
@Test
- public void should_parse_input_string_block_with_comment_dash() {
- //Given
+ void should_parse_input_string_block_with_comment_dash() {
+ // Given
String input = "SELECT * FROM users LIMIT 10; -- this is a comment";
- //When
+ // When
final List<AnyBlock> anyBlocks = this.toJavaList(helper.parseInput(input));
- //Then
- assertThat(anyBlocks).hasSize(2);
- assertThat(anyBlocks.get(0)).isInstanceOf(SimpleStm.class);
- assertThat(anyBlocks.get(1)).isInstanceOf(TextBlockHierarchy.Comment.class);
+ // Then
+ assertEquals(2, anyBlocks.size());
+ assertTrue(anyBlocks.get(0) instanceof SimpleStm);
+ assertTrue(anyBlocks.get(1) instanceof TextBlockHierarchy.Comment);
}
@Test
- public void should_parse_input_string_block_with_comment_slash() {
- //Given
+ void should_parse_input_string_block_with_comment_slash() {
+ // Given
String input = "SELECT * FROM users LIMIT 10; // this is a comment";
- //When
+ // When
final List<AnyBlock> anyBlocks = this.toJavaList(helper.parseInput(input));
- //Then
- assertThat(anyBlocks).hasSize(2);
- assertThat(anyBlocks.get(0)).isInstanceOf(SimpleStm.class);
- assertThat(anyBlocks.get(1)).isInstanceOf(TextBlockHierarchy.Comment.class);
+ // Then
+ assertEquals(2, anyBlocks.size());
+ assertTrue(anyBlocks.get(0) instanceof SimpleStm);
+ assertTrue(anyBlocks.get(1) instanceof TextBlockHierarchy.Comment);
}
@Test
- public void should_exception_while_parsing_input() {
- //Given
+ void should_exception_while_parsing_input() {
+ // Given
String input = "SELECT * FROM users LIMIT 10";
- //When
- expectedException.expect(InterpreterException.class);
- expectedException.expectMessage("Error parsing input:\n" +
- "\t'SELECT * FROM users LIMIT 10'\n" +
- "Did you forget to add ; (semi-colon) at the end of each CQL statement ?");
+ // When
+ InterpreterException ex = assertThrows(InterpreterException.class, () -> {
+ helper.parseInput(input);
+ });
+
+ assertEquals("Error parsing input:\n" +
+ "\t'SELECT * FROM users LIMIT 10'\n" +
+ "Did you forget to add ; (semi-colon) at the end of each CQL statement ?", ex.getMessage());
- helper.parseInput(input);
}
@Test
- public void should_extract_variable_and_default_value() {
- //Given
+ void should_extract_variable_and_default_value() {
+ // Given
AngularObjectRegistry angularObjectRegistry = new AngularObjectRegistry("cassandra", null);
when(intrContext.getAngularObjectRegistry()).thenReturn(angularObjectRegistry);
when(intrContext.getGui().textbox("table", "zeppelin.demo")).thenReturn("zeppelin.demo");
when(intrContext.getGui().textbox("id", "'John'")).thenReturn("'John'");
- //When
+ // When
final String actual = helper.maybeExtractVariables(
- "SELECT * FROM {{table=zeppelin.demo}} WHERE id={{id='John'}}", intrContext);
+ "SELECT * FROM {{table=zeppelin.demo}} WHERE id={{id='John'}}", intrContext);
- //Then
- assertThat(actual).isEqualTo("SELECT * FROM zeppelin.demo WHERE id='John'");
+ // Then
+ assertEquals("SELECT * FROM zeppelin.demo WHERE id='John'", actual);
}
@Test
- public void should_extract_variable_and_choices() {
- //Given
+ void should_extract_variable_and_choices() {
+ // Given
AngularObjectRegistry angularObjectRegistry = new AngularObjectRegistry("cassandra", null);
when(intrContext.getAngularObjectRegistry()).thenReturn(angularObjectRegistry);
- when(intrContext.getGui().select(eq("name"), optionsCaptor.capture(), eq("'Paul'")))
- .thenReturn("'Jack'");
-
- //When
+ ArgumentCaptor<ParamOption[]> optionsCaptor = ArgumentCaptor.forClass(ParamOption[].class);
+ when(intrContext.getGui().select(any(), any(), any())).thenReturn("'Jack'");
+ // When
final String actual = helper.maybeExtractVariables(
- "SELECT * FROM zeppelin.artists WHERE name={{name='Paul'|'Jack'|'Smith'}}",
- intrContext);
-
- //Then
- assertThat(actual).isEqualTo("SELECT * FROM zeppelin.artists WHERE name='Jack'");
+ "SELECT * FROM zeppelin.artists WHERE name={{name='Paul'|'Jack'|'Smith'}}",
+ intrContext);
+ verify(intrContext.getGui()).select(eq("name"), optionsCaptor.capture(), eq("'Paul'"));
+ // Then
+ assertEquals("SELECT * FROM zeppelin.artists WHERE name='Jack'", actual);
final List<ParamOption> paramOptions = asList(optionsCaptor.getValue());
- assertThat(paramOptions.get(0).getValue()).isEqualTo("'Paul'");
- assertThat(paramOptions.get(1).getValue()).isEqualTo("'Jack'");
- assertThat(paramOptions.get(2).getValue()).isEqualTo("'Smith'");
+ assertEquals("'Paul'", paramOptions.get(0).getValue());
+ assertEquals("'Jack'", paramOptions.get(1).getValue());
+ assertEquals("'Smith'", paramOptions.get(2).getValue());
}
@Test
- public void should_extract_no_variable() {
- //Given
+ void should_extract_no_variable() {
+ // Given
GUI gui = mock(GUI.class);
when(intrContext.getGui()).thenReturn(gui);
- //When
+ // When
final String actual = helper.maybeExtractVariables("SELECT * FROM zeppelin.demo", intrContext);
- //Then
- verifyZeroInteractions(gui);
- assertThat(actual).isEqualTo("SELECT * FROM zeppelin.demo");
+ // Then
+ verifyNoInteractions(gui);
+ assertEquals("SELECT * FROM zeppelin.demo", actual);
}
@Test
- public void should_extract_variable_from_angular_object_registry() {
- //Given
+ void should_extract_variable_from_angular_object_registry() {
+ // Given
AngularObjectRegistry angularObjectRegistry = new AngularObjectRegistry("cassandra", null);
angularObjectRegistry.add("id", "from_angular_registry", "noteId", "paragraphId");
when(intrContext.getAngularObjectRegistry()).thenReturn(angularObjectRegistry);
when(intrContext.getNoteId()).thenReturn("noteId");
when(intrContext.getParagraphId()).thenReturn("paragraphId");
- //When
+ // When
final String actual = helper.maybeExtractVariables(
- "SELECT * FROM zeppelin.demo WHERE id='{{id=John}}'", intrContext);
+ "SELECT * FROM zeppelin.demo WHERE id='{{id=John}}'", intrContext);
- //Then
- assertThat(actual).isEqualTo("SELECT * FROM zeppelin.demo WHERE id='from_angular_registry'");
+ // Then
+ assertEquals("SELECT * FROM zeppelin.demo WHERE id='from_angular_registry'", actual);
verify(intrContext, never()).getGui();
}
@Test
public void should_error_if_incorrect_variable_definition() {
- //Given
-
- //When
- expectedException.expect(ParsingException.class);
- expectedException.expectMessage("Invalid bound variable definition for " +
- "'{{table?zeppelin.demo}}' in 'SELECT * FROM {{table?zeppelin.demo}} " +
- "WHERE id={{id='John'}}'. It should be of form 'variable=defaultValue'");
+ // Given
+
+ // When
+ ParsingException thrown = assertThrows(ParsingException.class, () -> {
+ // Then
+ helper.maybeExtractVariables("SELECT * FROM {{table?zeppelin.demo}} WHERE id={{id='John'}}",
+ intrContext);
+ });
+ assertEquals("Invalid bound variable definition for " +
+ "'{{table?zeppelin.demo}}' in 'SELECT * FROM {{table?zeppelin.demo}} " +
+ "WHERE id={{id='John'}}'. It should be of form 'variable=defaultValue' " +
+ "or 'variable=value1|value2|...|valueN'",
+ thrown.getMessage());
- //Then
- helper.maybeExtractVariables("SELECT * FROM {{table?zeppelin.demo}} WHERE id={{id='John'}}",
- intrContext);
}
@Test
- public void should_extract_consistency_option() {
- //Given
+ void should_extract_consistency_option() {
+ // Given
List<QueryParameters> options = Arrays.asList(new Consistency(ALL),
- new Consistency(ONE));
+ new Consistency(ONE));
- //When
+ // When
final CassandraQueryOptions actual = helper.extractQueryOptions(toScalaList(options));
- //Then
- assertThat(actual.consistency().get()).isEqualTo(ALL);
+ // Then
+ assertEquals(ALL, actual.consistency().get());
}
@Test
- public void should_extract_serial_consistency_option() {
- //Given
+ void should_extract_serial_consistency_option() {
+ // Given
List<QueryParameters> options = Arrays.asList(new SerialConsistency(SERIAL),
- new SerialConsistency(LOCAL_SERIAL));
+ new SerialConsistency(LOCAL_SERIAL));
- //When
+ // When
final CassandraQueryOptions actual = helper.extractQueryOptions(toScalaList(options));
- //Then
- assertThat(actual.serialConsistency().get()).isEqualTo(SERIAL);
+ // Then
+ assertEquals(SERIAL, actual.serialConsistency().get());
}
@Test
- public void should_extract_timestamp_option() {
- //Given
+ void should_extract_timestamp_option() {
+ // Given
List<QueryParameters> options = Arrays.asList(new Timestamp(123L),
- new Timestamp(456L));
+ new Timestamp(456L));
- //When
+ // When
final CassandraQueryOptions actual = helper.extractQueryOptions(toScalaList(options));
- //Then
- assertThat(actual.timestamp().get()).isEqualTo(123L);
+ // Then
+ assertEquals(123L, actual.timestamp().get());
}
@Test
- public void should_extract_request_timeout_option() {
- //Given
+ void should_extract_request_timeout_option() {
+ // Given
List<QueryParameters> options = Collections.singletonList(new RequestTimeOut(100));
- //When
+ // When
final CassandraQueryOptions actual = helper.extractQueryOptions(toScalaList(options));
- //Then
- assertThat(actual.requestTimeOut().get()).isEqualTo(100);
+ // Then
+ assertEquals(100, actual.requestTimeOut().get());
}
@Test
- public void should_generate_simple_statement() {
- //Given
+ void should_generate_simple_statement() {
+ // Given
String input = "SELECT * FROM users LIMIT 10;";
CassandraQueryOptions options = new CassandraQueryOptions(Option.apply(QUORUM),
- Option.empty(),
- Option.empty(),
- Option.empty(),
- Option.empty());
+ Option.empty(),
+ Option.empty(),
+ Option.empty(),
+ Option.empty());
- //When
+ // When
final SimpleStatement actual = helper.generateSimpleStatement(new SimpleStm(input), options,
- intrContext);
+ intrContext);
- //Then
- assertThat(actual).isNotNull();
- assertThat(actual.getQuery()).isEqualTo("SELECT * FROM users LIMIT 10;");
- assertThat(actual.getConsistencyLevel()).isSameAs(QUORUM);
+ // Then
+ assertNotNull(actual);
+ assertEquals("SELECT * FROM users LIMIT 10;", actual.getQuery());
+ assertSame(QUORUM, actual.getConsistencyLevel());
}
@Test
- public void should_generate_batch_statement() {
- //Given
+ void should_generate_batch_statement() {
+ // Given
SimpleStatement st1 = SimpleStatement.newInstance("SELECT * FROM users LIMIT 10;");
SimpleStatement st2 = SimpleStatement.newInstance("INSERT INTO users(id) VALUES(10);");
SimpleStatement st3 = SimpleStatement.newInstance(
- "UPDATE users SET name = 'John DOE' WHERE id=10;");
+ "UPDATE users SET name = 'John DOE' WHERE id=10;");
CassandraQueryOptions options = new CassandraQueryOptions(Option.apply(QUORUM),
- Option.empty(),
- Option.empty(),
- Option.empty(),
- Option.empty());
+ Option.empty(),
+ Option.empty(),
+ Option.empty(),
+ Option.empty());
- //When
+ // When
BatchStatement actual = helper.generateBatchStatement(UNLOGGED, options,
- toScalaList(asList(st1, st2, st3)));
+ toScalaList(asList(st1, st2, st3)));
- //Then
- assertThat(actual).isNotNull();
+ // Then
+ assertNotNull(actual);
List<BatchableStatement> statements = new ArrayList<>();
- for (BatchableStatement b: actual) {
+ for (BatchableStatement b : actual) {
statements.add(b);
}
- assertThat(statements).hasSize(3);
- assertThat(statements.get(0)).isSameAs(st1);
- assertThat(statements.get(1)).isSameAs(st2);
- assertThat(statements.get(2)).isSameAs(st3);
- assertThat(actual.getConsistencyLevel()).isSameAs(QUORUM);
+ assertEquals(3, statements.size());
+ assertSame(st1, statements.get(0));
+ assertSame(st2, statements.get(1));
+ assertSame(st3, statements.get(2));
+ assertSame(QUORUM, actual.getConsistencyLevel());
}
@Test
- public void should_parse_bound_values() {
- //Given
+ void should_parse_bound_values() {
+ // Given
String bs = "'jdoe',32,'John DOE',null, true, '2014-06-12 34:00:34'";
- //When
+ // When
final List<String> actual = this.toJavaList(helper.parseBoundValues("ps", bs));
- //Then
- assertThat(actual).containsExactly("'jdoe'", "32", "'John DOE'",
- "null", "true", "2014-06-12 34:00:34");
+ // Then
+ assertEquals("'jdoe'", actual.get(0));
+ assertEquals("32", actual.get(1));
+ assertEquals("'John DOE'", actual.get(2));
+ assertEquals("null", actual.get(3));
+ assertEquals("true", actual.get(4));
+ assertEquals("2014-06-12 34:00:34", actual.get(5));
}
@Test
- public void should_parse_simple_date() {
- //Given
+ void should_parse_simple_date() {
+ // Given
String dateString = "2015-07-30 12:00:01";
- //When
+ // When
final Instant actual = helper.parseDate(dateString);
- //Then
+ // Then
ZonedDateTime dt = actual.atZone(ZoneOffset.UTC);
- assertThat(dt.getLong(ChronoField.YEAR_OF_ERA)).isEqualTo(2015);
- assertThat(dt.getLong(ChronoField.MONTH_OF_YEAR)).isEqualTo(7);
- assertThat(dt.getLong(ChronoField.DAY_OF_MONTH)).isEqualTo(30);
- assertThat(dt.getLong(ChronoField.HOUR_OF_DAY)).isEqualTo(12);
- assertThat(dt.getLong(ChronoField.MINUTE_OF_HOUR)).isEqualTo(0);
- assertThat(dt.getLong(ChronoField.SECOND_OF_MINUTE)).isEqualTo(1);
+ assertEquals(2015, dt.getLong(ChronoField.YEAR_OF_ERA));
+ assertEquals(7, dt.getLong(ChronoField.MONTH_OF_YEAR));
+ assertEquals(30, dt.getLong(ChronoField.DAY_OF_MONTH));
+ assertEquals(12, dt.getLong(ChronoField.HOUR_OF_DAY));
+ assertEquals(0, dt.getLong(ChronoField.MINUTE_OF_HOUR));
+ assertEquals(1, dt.getLong(ChronoField.SECOND_OF_MINUTE));
}
@Test
- public void should_parse_accurate_date() {
- //Given
+ void should_parse_accurate_date() {
+ // Given
String dateString = "2015-07-30 12:00:01.123";
- //When
+ // When
final Instant actual = helper.parseDate(dateString);
- //Then
+ // Then
ZonedDateTime dt = actual.atZone(ZoneOffset.UTC);
- assertThat(dt.getLong(ChronoField.YEAR_OF_ERA)).isEqualTo(2015);
- assertThat(dt.getLong(ChronoField.MONTH_OF_YEAR)).isEqualTo(7);
- assertThat(dt.getLong(ChronoField.DAY_OF_MONTH)).isEqualTo(30);
- assertThat(dt.getLong(ChronoField.HOUR_OF_DAY)).isEqualTo(12);
- assertThat(dt.getLong(ChronoField.MINUTE_OF_HOUR)).isEqualTo(0);
- assertThat(dt.getLong(ChronoField.SECOND_OF_MINUTE)).isEqualTo(1);
- assertThat(dt.getLong(ChronoField.MILLI_OF_SECOND)).isEqualTo(123);
+ assertEquals(2015, dt.getLong(ChronoField.YEAR_OF_ERA));
+ assertEquals(7, dt.getLong(ChronoField.MONTH_OF_YEAR));
+ assertEquals(30, dt.getLong(ChronoField.DAY_OF_MONTH));
+ assertEquals(12, dt.getLong(ChronoField.HOUR_OF_DAY));
+ assertEquals(0, dt.getLong(ChronoField.MINUTE_OF_HOUR));
+ assertEquals(1, dt.getLong(ChronoField.SECOND_OF_MINUTE));
+ assertEquals(123, dt.getLong(ChronoField.MILLI_OF_SECOND));
}
- private <A> scala.collection.immutable.List<A> toScalaList(java.util.List<A> list) {
+ private <A> scala.collection.immutable.List<A> toScalaList(java.util.List<A> list) {
return scala.collection.JavaConversions.collectionAsScalaIterable(list).toList();
}
- private <A> java.util.List<A> toJavaList(scala.collection.immutable.List<A> list){
+ private <A> java.util.List<A> toJavaList(scala.collection.immutable.List<A> list) {
return scala.collection.JavaConversions.seqAsJavaList(list);
}
}