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

Commit d151e1d

Browse files
authored
Merge pull request #70 from praveenag/master
updated java driver to 1.1.0.
2 parents 9463bed + 78b6c77 commit d151e1d

File tree

6 files changed

+60
-34
lines changed

6 files changed

+60
-34
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ ext {
6565

6666
argparse4jVersion = '0.7.0'
6767
junitVersion = '4.12'
68-
neo4jJavaVersion = '1.1.0-M06'
68+
neo4jJavaVersion = '1.1.0'
6969
findbugsVersion = '3.0.0'
7070
jansiVersion = '1.13'
7171
jlineVersion = '2.14.2'

cypher-shell/src/main/java/org/neo4j/shell/state/BoltStateHandler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class BoltStateHandler implements TransactionHandler, Connector {
3030
protected Driver driver;
3131
protected Session session;
3232
protected Transaction tx = null;
33+
private String version;
3334

3435
public BoltStateHandler() {
3536
this(GraphDatabase::driver);
@@ -103,7 +104,9 @@ public void connect(@Nonnull ConnectionConfig connectionConfig) throws CommandEx
103104
driver = getDriver(connectionConfig, authToken);
104105
session = driver.session();
105106
// Bug in Java driver forces us to run a statement to make it actually connect
106-
session.run("RETURN 1").consume();
107+
StatementResult run = session.run( "RETURN 1" );
108+
this.version = run.summary().server().version();
109+
run.consume();
107110
} catch (Throwable t) {
108111
try {
109112
silentDisconnect();
@@ -118,7 +121,6 @@ public void connect(@Nonnull ConnectionConfig connectionConfig) throws CommandEx
118121
@Override
119122
public String getServerVersion() {
120123
if (isConnected()) {
121-
String version = session.server();
122124
if (version == null) {
123125
// On versions before 3.1.0-M09
124126
version = "";

cypher-shell/src/test/java/org/neo4j/shell/state/BoltStateHandlerTest.java

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.neo4j.driver.v1.Session;
1111
import org.neo4j.driver.v1.StatementResult;
1212
import org.neo4j.driver.v1.Transaction;
13+
import org.neo4j.driver.v1.summary.ResultSummary;
14+
import org.neo4j.driver.v1.summary.ServerInfo;
1315
import org.neo4j.shell.ConnectionConfig;
1416
import org.neo4j.shell.TriFunction;
1517
import org.neo4j.shell.exception.CommandException;
@@ -53,49 +55,46 @@ public Driver apply(String uri, AuthToken authToken, Config config) {
5355
return new FakeDriver() {
5456
@Override
5557
public Session session() {
56-
return new FakeSession() {
57-
@Override
58-
public String server() {
59-
return null;
60-
}
61-
};
58+
return new FakeSession();
6259
}
6360
};
6461
}
6562
};
6663
BoltStateHandler handler = new BoltStateHandler(provider);
67-
ConnectionConfig config = new ConnectionConfig( logger, "bolt://", "", -1, "", "", false);
64+
ConnectionConfig config = new ConnectionConfig(logger, "bolt://", "", -1, "", "", false);
6865
handler.connect(config);
6966

7067
assertEquals("", handler.getServerVersion());
7168
}
7269

7370
@Test
7471
public void versionIsNotEmptyAfterConnect() throws CommandException {
75-
RecordingDriverProvider provider = new RecordingDriverProvider() {
76-
@Override
77-
public Driver apply(String uri, AuthToken authToken, Config config) {
78-
super.apply(uri, authToken, config);
79-
return new FakeDriver() {
80-
@Override
81-
public Session session() {
82-
return new FakeSession() {
83-
@Override
84-
public String server() {
85-
return "Neo4j/9.4.1-ALPHA";
86-
}
87-
};
88-
}
89-
};
90-
}
91-
};
92-
BoltStateHandler handler = new BoltStateHandler(provider);
72+
Session sessionMock = mock(Session.class);
73+
StatementResult resultMock = mock(StatementResult.class);
74+
Driver driverMock = mock(Driver.class);
75+
76+
stubVersion(resultMock, "Neo4j/9.4.1-ALPHA");
77+
when(driverMock.session()).thenReturn(sessionMock);
78+
when(sessionMock.run("RETURN 1")).thenReturn(resultMock);
79+
80+
when(sessionMock.isOpen()).thenReturn(true);
81+
82+
BoltStateHandler handler = new BoltStateHandler((s, authToken, config) -> driverMock);
9383
ConnectionConfig config = new ConnectionConfig(logger, "bolt://", "", -1, "", "", false);
9484
handler.connect(config);
9585

9686
assertEquals("9.4.1-ALPHA", handler.getServerVersion());
9787
}
9888

89+
private void stubVersion(StatementResult resultMock, String value) {
90+
ResultSummary resultSummary = mock(ResultSummary.class);
91+
ServerInfo serverInfo = mock(ServerInfo.class);
92+
93+
when(resultSummary.server()).thenReturn(serverInfo);
94+
when(serverInfo.version()).thenReturn(value);
95+
when(resultMock.summary()).thenReturn(resultSummary);
96+
}
97+
9998
@Test
10099
public void closeTransactionAfterRollback() throws CommandException {
101100
boltStateHandler.connect();
@@ -117,13 +116,16 @@ public void exceptionsFromSilentDisconnectAreSuppressedToReportOriginalErrors()
117116
Driver mockedDriver = mock(Driver.class);
118117
Session session = mock(Session.class);
119118
StatementResult resultMock = mock(StatementResult.class);
119+
120120
RuntimeException originalException = new RuntimeException("original exception");
121121
RuntimeException thrownFromSilentDisconnect = new RuntimeException("exception from silent disconnect");
122122

123123
OfflineBoltStateHandler boltStateHandler = new OfflineBoltStateHandler(mockedDriver);
124124

125+
stubVersion(resultMock, "neo4j-version");
125126
when(mockedDriver.session()).thenReturn(session);
126127
when(session.run("RETURN 1")).thenReturn(resultMock);
128+
127129
when(resultMock.consume()).thenThrow(originalException);
128130
doThrow(thrownFromSilentDisconnect).when(session).close();
129131

@@ -229,6 +231,7 @@ public void resetSessionOnReset() throws Exception {
229231
Driver driverMock = mock(Driver.class);
230232
Transaction transactionMock = mock(Transaction.class);
231233

234+
stubVersion(resultMock, "neo4j-version");
232235
when(driverMock.session()).thenReturn(sessionMock);
233236
when(sessionMock.run("RETURN 1")).thenReturn(resultMock);
234237
when(sessionMock.isOpen()).thenReturn(true);
@@ -288,6 +291,7 @@ public void turnOnEncryptionIfRequested() throws CommandException {
288291
* Bolt state with faked bolt interactions
289292
*/
290293
private static class OfflineBoltStateHandler extends BoltStateHandler {
294+
291295
public OfflineBoltStateHandler(Driver driver) {
292296
super((uri, authToken, config) -> driver);
293297
}

cypher-shell/src/test/java/org/neo4j/shell/test/bolt/FakeResultSummary.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,23 @@ public long resultAvailableAfter(TimeUnit unit) {
6161
public long resultConsumedAfter(TimeUnit unit) {
6262
return 0;
6363
}
64+
65+
@Override
66+
public ServerInfo server()
67+
{
68+
return new ServerInfo()
69+
{
70+
@Override
71+
public String address()
72+
{
73+
throw new Util.NotImplementedYetException("Not implemented yet");
74+
}
75+
76+
@Override
77+
public String version()
78+
{
79+
return null;
80+
}
81+
};
82+
}
6483
}

cypher-shell/src/test/java/org/neo4j/shell/test/bolt/FakeSession.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ public void close() {
4040
open = false;
4141
}
4242

43-
@Override
44-
public String server() {
45-
return null;
46-
}
47-
4843
@Override
4944
public StatementResult run(String statementTemplate, Value parameters) {
5045
return FakeStatementResult.parseStatement(statementTemplate);

cypher-shell/src/test/java/org/neo4j/shell/test/bolt/FakeStatementResult.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
* A fake StatementResult with fake records and fake values
2020
*/
21-
public class FakeStatementResult implements StatementResult {
21+
class FakeStatementResult implements StatementResult {
2222

2323
private final List<Record> records;
2424
private int currentRecord = -1;
@@ -71,6 +71,12 @@ public ResultSummary consume() {
7171
return new FakeResultSummary();
7272
}
7373

74+
@Override
75+
public ResultSummary summary()
76+
{
77+
return new FakeResultSummary();
78+
}
79+
7480
/**
7581
* Supports fake parsing of very limited cypher statements, only for basic test purposes
7682
*/

0 commit comments

Comments
 (0)