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

Commit 25bc451

Browse files
committed
Fix getting server version and database name on failure
When the ping query fails, e.g. on credentials expired exception, we still need to get the server version. - Add handling of empty version string
1 parent 2efa050 commit 25bc451

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,8 @@ private void reconnect(boolean keepBookmark) {
164164
driver.verifyConnectivity();
165165

166166
SessionConfig.Builder builder = SessionConfig.builder();
167-
builder.withDefaultAccessMode( AccessMode.WRITE );
168-
if ( !ABSENT_DB_NAME.equals( activeDatabaseNameAsSetByUser ) )
169-
{
167+
builder.withDefaultAccessMode(AccessMode.WRITE);
168+
if (!ABSENT_DB_NAME.equals(activeDatabaseNameAsSetByUser)) {
170169
builder.withDatabase( activeDatabaseNameAsSetByUser );
171170
}
172171
if (session != null && keepBookmark) {
@@ -184,9 +183,17 @@ private void reconnect(boolean keepBookmark) {
184183

185184
resetActualDbName(); // Set this to null first in case run throws an exception
186185
StatementResult run = session.run(query);
187-
ResultSummary summary = run.consume();
188-
this.version = summary.server().version();
189-
updateActualDbName(summary);
186+
ResultSummary summary = null;
187+
try {
188+
summary = run.consume();
189+
} finally {
190+
// Since run.consume() can throw the first time we have to go through this extra hoop to get the summary
191+
if (summary == null) {
192+
summary = run.consume();
193+
}
194+
this.version = summary.server().version();
195+
updateActualDbName(summary);
196+
}
190197
}
191198

192199
@Nonnull

cypher-shell/src/main/java/org/neo4j/shell/util/Versions.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public static Version version(String version) {
2626
if (version == null) {
2727
throw new AssertionError("null is not a valid version string");
2828
}
29+
if (version.isEmpty()) {
30+
return new Version(0, 0, 0);
31+
}
2932
//remove -alpha, and -beta etc
3033
int offset = version.indexOf("-");
3134
if (offset > 0) {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.neo4j.shell.util;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertEquals;
6+
7+
public class VersionsTest
8+
{
9+
@Test
10+
public void shouldWorkForEmptyString() throws Exception {
11+
assertEquals(0, Versions.version("").compareTo(Versions.version("0.0.0")));
12+
assertEquals(0, Versions.majorVersion(""));
13+
assertEquals(0, Versions.minorVersion(""));
14+
assertEquals(0, Versions.patch(""));
15+
}
16+
17+
@Test
18+
public void shouldWorkForReleaseVersion() throws Exception {
19+
String versionString = "3.4.5";
20+
assertEquals(0, Versions.version(versionString).compareTo(Versions.version("3.4.5")));
21+
assertEquals(3, Versions.majorVersion(versionString));
22+
assertEquals(4, Versions.minorVersion(versionString));
23+
assertEquals(5, Versions.patch(versionString));
24+
}
25+
26+
@Test
27+
public void shouldWorkForPreReleaseVersion() throws Exception {
28+
String versionString = "3.4.55-beta99";
29+
assertEquals(0, Versions.version(versionString).compareTo(Versions.version("3.4.55")));
30+
assertEquals(3, Versions.majorVersion(versionString));
31+
assertEquals(4, Versions.minorVersion(versionString));
32+
assertEquals(55, Versions.patch(versionString));
33+
}
34+
}

0 commit comments

Comments
 (0)