Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit 3ab0ee3

Browse files
authored
Merge pull request #141 from fickludd/stream-results
Stream results of autocommit queries
2 parents ea28065 + 73c843e commit 3ab0ee3

29 files changed

+736
-470
lines changed

cypher-shell/src/integration-test/java/org/neo4j/shell/MainIntegrationTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.neo4j.shell.cli.CliArgs;
55
import org.neo4j.shell.log.AnsiLogger;
66
import org.neo4j.shell.log.Logger;
7+
import org.neo4j.shell.prettyprint.PrettyConfig;
78

89
import java.io.ByteArrayInputStream;
910
import java.io.ByteArrayOutputStream;
@@ -32,8 +33,7 @@ public void connectInteractivelyPromptsOnWrongAuthentication() throws Exception
3233
cliArgs.setPassword( "", "" );
3334

3435
Logger logger = new AnsiLogger(cliArgs.getDebugMode());
35-
logger.setFormat(cliArgs.getFormat());
36-
36+
PrettyConfig prettyConfig = new PrettyConfig(cliArgs);
3737
ConnectionConfig connectionConfig = new ConnectionConfig(
3838
cliArgs.getScheme(),
3939
cliArgs.getHost(),
@@ -42,7 +42,7 @@ public void connectInteractivelyPromptsOnWrongAuthentication() throws Exception
4242
cliArgs.getPassword(),
4343
cliArgs.getEncryption());
4444

45-
CypherShell shell = new CypherShell(logger);
45+
CypherShell shell = new CypherShell(logger, prettyConfig);
4646

4747
// when
4848
assertEquals("", connectionConfig.username());
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.neo4j.shell;
2+
3+
import org.neo4j.shell.prettyprint.LinePrinter;
4+
import org.neo4j.shell.prettyprint.OutputFormatter;
5+
6+
public class StringLinePrinter implements LinePrinter {
7+
8+
private StringBuilder sb = new StringBuilder();
9+
10+
@Override
11+
public void printOut(String line) {
12+
sb.append(line).append(OutputFormatter.NEWLINE);
13+
}
14+
15+
public void clear() {
16+
sb.setLength(0);
17+
}
18+
19+
public String output() {
20+
return sb.toString();
21+
}
22+
}

cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellFailureIntegrationTest.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,25 @@
55
import org.junit.Rule;
66
import org.junit.Test;
77
import org.junit.rules.ExpectedException;
8-
98
import org.neo4j.driver.v1.exceptions.AuthenticationException;
109
import org.neo4j.shell.ConnectionConfig;
1110
import org.neo4j.shell.CypherShell;
11+
import org.neo4j.shell.StringLinePrinter;
1212
import org.neo4j.shell.cli.Format;
1313
import org.neo4j.shell.exception.CommandException;
14-
import org.neo4j.shell.log.Logger;
15-
16-
import static org.mockito.Mockito.doReturn;
17-
import static org.mockito.Mockito.mock;
14+
import org.neo4j.shell.prettyprint.PrettyConfig;
1815

1916
public class CypherShellFailureIntegrationTest {
2017
@Rule
2118
public final ExpectedException thrown = ExpectedException.none();
2219

23-
private Logger logger = mock(Logger.class);
20+
private StringLinePrinter linePrinter = new StringLinePrinter();
2421
private CypherShell shell;
2522

2623
@Before
2724
public void setUp() throws Exception {
28-
doReturn(Format.VERBOSE).when(logger).getFormat();
29-
30-
shell = new CypherShell(logger);
25+
linePrinter.clear();
26+
shell = new CypherShell(linePrinter, new PrettyConfig(Format.VERBOSE, true, 1000));
3127
}
3228

3329
@Test

cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellPlainIntegrationTest.java

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,28 @@
66
import org.junit.Rule;
77
import org.junit.Test;
88
import org.junit.rules.ExpectedException;
9-
import org.mockito.ArgumentCaptor;
109
import org.neo4j.shell.ConnectionConfig;
1110
import org.neo4j.shell.CypherShell;
11+
import org.neo4j.shell.StringLinePrinter;
1212
import org.neo4j.shell.cli.Format;
1313
import org.neo4j.shell.exception.CommandException;
14-
import org.neo4j.shell.log.Logger;
15-
16-
import java.util.List;
14+
import org.neo4j.shell.prettyprint.PrettyConfig;
1715

1816
import static org.hamcrest.CoreMatchers.containsString;
1917
import static org.hamcrest.MatcherAssert.assertThat;
20-
import static org.mockito.Mockito.doReturn;
21-
import static org.mockito.Mockito.mock;
22-
import static org.mockito.Mockito.times;
23-
import static org.mockito.Mockito.verify;
18+
import static org.neo4j.shell.prettyprint.OutputFormatter.NEWLINE;
2419

2520
public class CypherShellPlainIntegrationTest {
2621
@Rule
2722
public final ExpectedException thrown = ExpectedException.none();
2823

29-
private Logger logger = mock(Logger.class);
24+
private StringLinePrinter linePrinter = new StringLinePrinter();
3025
private CypherShell shell;
3126

3227
@Before
3328
public void setUp() throws Exception {
34-
doReturn(Format.PLAIN).when(logger).getFormat();
35-
shell = new CypherShell(logger);
29+
linePrinter.clear();
30+
shell = new CypherShell(linePrinter, new PrettyConfig(Format.PLAIN, true, 1000));
3631
shell.connect(new ConnectionConfig("bolt://", "localhost", 7687, "neo4j", "neo", true));
3732
}
3833

@@ -46,14 +41,11 @@ public void periodicCommitWorks() throws CommandException {
4641
shell.execute("USING PERIODIC COMMIT\n" +
4742
"LOAD CSV FROM 'https://neo4j.com/docs/cypher-refcard/3.2/csv/artists.csv' AS line\n" +
4843
"CREATE (:Artist {name: line[1], year: toInt(line[2])});");
44+
linePrinter.clear();
4945

5046
shell.execute("MATCH (a:Artist) WHERE a.name = 'Europe' RETURN a.name");
5147

52-
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
53-
verify(logger, times(2)).printOut(captor.capture());
54-
55-
List<String> queryResult = captor.getAllValues();
56-
assertThat(queryResult.get(1), containsString("Europe"));
48+
assertThat(linePrinter.output(), containsString("a.name"+ NEWLINE+"\"Europe\""));
5749
}
5850

5951
@Test
@@ -62,11 +54,7 @@ public void cypherWithProfileStatements() throws CommandException {
6254
shell.execute("CYPHER RUNTIME=INTERPRETED PROFILE RETURN null");
6355

6456
//then
65-
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
66-
verify(logger, times(1)).printOut(captor.capture());
67-
68-
List<String> result = captor.getAllValues();
69-
String actual = result.get(0);
57+
String actual = linePrinter.output();
7058
// This assertion checks everything except for time and cypher
7159
assertThat(actual, containsString("Plan: \"PROFILE\""));
7260
assertThat(actual, containsString("Statement: \"READ_ONLY\""));
@@ -84,11 +72,7 @@ public void cypherWithExplainStatements() throws CommandException {
8472
shell.execute("CYPHER RUNTIME=INTERPRETED EXPLAIN RETURN null");
8573

8674
//then
87-
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
88-
verify(logger, times(1)).printOut(captor.capture());
89-
90-
List<String> result = captor.getAllValues();
91-
String actual = result.get(0);
75+
String actual = linePrinter.output();
9276
// This assertion checks everything except for time and cypher
9377
assertThat(actual, containsString("Plan: \"EXPLAIN\""));
9478
assertThat(actual, containsString("Statement: \"READ_ONLY\""));

0 commit comments

Comments
 (0)