Skip to content

[ZEPPELIN-6221] Optimize Neo4jCypherInterpreterTest performance by reusing interpreter instance #4983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import org.apache.zeppelin.interpreter.InterpreterResult.Code;
import org.apache.zeppelin.interpreter.graph.GraphResult;
import org.apache.zeppelin.tabledata.Node;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.MethodOrderer;
import org.neo4j.driver.Driver;
Expand All @@ -51,11 +51,12 @@

@Testcontainers
@TestMethodOrder(MethodOrderer.MethodName.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class Neo4jCypherInterpreterTest {

private Neo4jCypherInterpreter interpreter;
private static Neo4jCypherInterpreter interpreter;

private InterpreterContext context;
private static InterpreterContext context;

@Container
public static Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("neo4j:4.1.1")
Expand Down Expand Up @@ -86,27 +87,27 @@ public static void setUpNeo4jServer() {
}
}

@BeforeEach
public void setUpZeppelin() {
@BeforeAll
public static void setUpZeppelin() {
Properties p = new Properties();
p.setProperty(Neo4jConnectionManager.NEO4J_SERVER_URL, neo4jContainer.getBoltUrl());
p.setProperty(Neo4jConnectionManager.NEO4J_AUTH_TYPE, Neo4jAuthType.NONE.toString());
p.setProperty(Neo4jConnectionManager.NEO4J_MAX_CONCURRENCY, "50");
p.setProperty(Neo4jCypherInterpreter.NEO4J_MULTI_STATEMENT, "false");
interpreter = new Neo4jCypherInterpreter(p);
interpreter.open();
context = InterpreterContext.builder()
.setInterpreterOut(new InterpreterOutput())
.build();
}

@AfterEach
public void tearDownZeppelin() throws Exception {
@AfterAll
public static void tearDownZeppelin() throws Exception {
interpreter.close();
}

@Test
void testTableWithArray() {
interpreter.open();
InterpreterResult result = interpreter.interpret(
"return 'a' as colA, 'b' as colB, [1, 2, 3] as colC", context);
assertEquals(Code.SUCCESS, result.code());
Expand All @@ -124,15 +125,13 @@ void testTableWithArray() {

@Test
void testCreateIndex() {
interpreter.open();
InterpreterResult result = interpreter.interpret("CREATE INDEX ON :Person(name)", context);
assertEquals(Code.SUCCESS, result.code());
assertEquals(StringUtils.EMPTY, result.toString());
}

@Test
void testRenderTable() {
interpreter.open();
InterpreterResult result = interpreter.interpret("MATCH (n:Person) "
+ "WHERE n.name IN ['name1', 'name2', 'name3'] "
+ "RETURN n.name AS name, n.age AS age, "
Expand All @@ -147,7 +146,6 @@ void testRenderTable() {

@Test
void testRenderMap() {
interpreter.open();
final String jsonQuery =
"RETURN {key: \"value\", listKey: [{inner: \"Map1\"}, {inner: \"Map2\"}]} as object";
final String objectKey = "object.key";
Expand Down Expand Up @@ -234,7 +232,6 @@ void testRenderMap() {

@Test
void testRenderNetwork() {
interpreter.open();
InterpreterResult result = interpreter.interpret(
"MATCH (n)-[r:KNOWS]-(m) RETURN n, r, m LIMIT 1", context);
GraphResult.Graph graph = gson.fromJson(result.toString().replace(NETWORK_RESULT_PREFIX,
Expand All @@ -252,7 +249,6 @@ void testRenderNetwork() {

@Test
void testFallingQuery() {
interpreter.open();
final String errorMsgEmpty = "";
InterpreterResult result = interpreter.interpret(StringUtils.EMPTY, context);
assertEquals(Code.SUCCESS, result.code());
Expand Down