Skip to content

Commit be49698

Browse files
authored
Upgrade Boltkit to 4.1. Adding BoltKit Test for NOOP message. (#703)
1 parent c476e0a commit be49698

File tree

8 files changed

+232
-121
lines changed

8 files changed

+232
-121
lines changed

driver/src/test/java/org/neo4j/driver/integration/RoutingDriverBoltKitTest.java

Lines changed: 129 additions & 107 deletions
Large diffs are not rendered by default.

driver/src/test/java/org/neo4j/driver/internal/DirectDriverBoltKitTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,24 @@ void shouldServerWithBoltV3NotSupportMultiDb() throws Throwable
544544
}
545545
}
546546

547+
@Test
548+
void shouldBeAbleHandleNOOPsDuringRunCypher() throws Exception
549+
{
550+
StubServer server = StubServer.start( "noop.script", 9001 );
551+
URI uri = URI.create( "bolt://127.0.0.1:9001" );
552+
553+
try ( Driver driver = GraphDatabase.driver( uri, INSECURE_CONFIG ) )
554+
{
555+
try ( Session session = driver.session() )
556+
{
557+
List<String> names = session.run( "MATCH (n) RETURN n.name" ).list( rec -> rec.get( 0 ).asString() );
558+
assertEquals( asList( "Foo", "Bar", "Baz" ), names );
559+
}
560+
}
561+
562+
assertThat( server.exitStatus(), equalTo( 0 ) );
563+
}
564+
547565
private static void testTxCloseErrorPropagation( String script, Consumer<Transaction> txAction, String expectedErrorMessage )
548566
throws Exception
549567
{

driver/src/test/java/org/neo4j/driver/util/StubServer.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,16 @@ public class StubServer
5151
// This may be thrown if the driver has not been closed properly
5252
public static class ForceKilled extends Exception {}
5353

54-
private static final String BOLT_STUB_COMMAND = "boltstub";
54+
private static final String BOLT_COMMAND = "bolt";
55+
private static final String BOLT_STUB_COMMAND = "stub";
5556

5657
private Process process;
5758

5859
private StubServer( String script, int port ) throws IOException, InterruptedException
5960
{
6061
List<String> command = new ArrayList<>();
61-
command.addAll( singletonList( BOLT_STUB_COMMAND ) );
62-
command.addAll( asList( Integer.toString( port ), script ) );
62+
command.addAll( asList( BOLT_COMMAND, BOLT_STUB_COMMAND ) );
63+
command.addAll( asList( "-l", "localhost:" + port, script ) );
6364
ProcessBuilder server = new ProcessBuilder().command( command );
6465
process = server.start();
6566
startReadingOutput( process );
@@ -72,7 +73,7 @@ public static StubServer start( String resource, int port ) throws IOException,
7273
return new StubServer( resource(resource), port );
7374
}
7475

75-
public int exitStatus() throws InterruptedException, ForceKilled
76+
public int exitStatus() throws InterruptedException
7677
{
7778
sleep( 500 ); // wait for a moment to allow disconnection to occur
7879
try
@@ -83,19 +84,26 @@ public int exitStatus() throws InterruptedException, ForceKilled
8384
{
8485
// not exited yet
8586
exit();
86-
throw new ForceKilled();
8787
}
88+
return -1;
8889
}
8990

9091
public static Config.ConfigBuilder insecureBuilder()
9192
{
9293
return Config.builder().withoutEncryption().withLogging( none() );
9394
}
9495

95-
private void exit() throws InterruptedException
96+
private void exit()
9697
{
9798
process.destroy();
98-
process.waitFor();
99+
try
100+
{
101+
process.waitFor();
102+
}
103+
catch ( InterruptedException ex )
104+
{
105+
throw new RuntimeException( "Interrupted whilst waiting for forced stub shutdown", ex);
106+
}
99107
}
100108

101109
private static String resource( String fileName )
@@ -113,7 +121,7 @@ private static boolean boltKitAvailable()
113121
try
114122
{
115123
// run 'help' command to see if boltstub is available
116-
Process process = new ProcessBuilder( BOLT_STUB_COMMAND, "-h" ).start();
124+
Process process = new ProcessBuilder( "bolt" ).start();
117125
int exitCode = process.waitFor();
118126
return exitCode == 0;
119127
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2002-2020 "Neo4j,"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.neo4j.driver.util;
20+
21+
import java.io.IOException;
22+
import java.util.List;
23+
import java.util.concurrent.CopyOnWriteArrayList;
24+
25+
public class StubServerController
26+
{
27+
private final List<StubServer> currentStubServers = new CopyOnWriteArrayList<>();
28+
29+
public StubServer startStub( String script, int port) throws IOException, InterruptedException
30+
{
31+
StubServer server = StubServer.start( script, port );
32+
currentStubServers.add( server );
33+
return server;
34+
}
35+
36+
public void reset()
37+
{
38+
for ( StubServer server : currentStubServers )
39+
{
40+
try
41+
{
42+
server.exitStatus();
43+
}
44+
catch ( InterruptedException e )
45+
{
46+
throw new RuntimeException( "Interrupted whilst waiting for stub shutdown", e);
47+
}
48+
currentStubServers.remove( server );
49+
}
50+
51+
}
52+
}

driver/src/test/resources/acquire_endpoints_v3_point_to_empty_router_and_exit.script

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,3 @@ C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"addre
88
S: SUCCESS {"fields": ["ttl", "servers"]}
99
RECORD [9223372036854775807, [{"addresses": ["127.0.0.1:9010"],"role": "WRITE"}, {"addresses": ["127.0.0.1:9011"], "role": "READ"},{"addresses": ["127.0.0.1:9004"], "role": "ROUTE"}]]
1010
SUCCESS {}
11-
C: RESET
12-
S: SUCCESS {}
13-
<EXIT>

driver/src/test/resources/acquire_endpoints_v3_three_servers_and_exit.script

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
!: AUTO RESET
33
!: AUTO HELLO
44
!: AUTO GOODBYE
5+
!: AUTO BEGIN
56

67
C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"address": "my.virtual.host:8080"}} {}
78
PULL_ALL
89
S: SUCCESS {"fields": ["ttl", "servers"]}
910
RECORD [9223372036854775807, [{"addresses": ["127.0.0.1:9001"],"role": "WRITE"}, {"addresses": ["127.0.0.1:9002","127.0.0.1:9003"], "role": "READ"},{"addresses": ["127.0.0.1:9001","127.0.0.1:9002","127.0.0.1:9003"], "role": "ROUTE"}]]
1011
SUCCESS {}
11-
C: RESET
12-
S: SUCCESS {}
1312
<EXIT>

driver/src/test/resources/noop.script

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
!: BOLT 4.1
2+
!: AUTO RESET
3+
!: AUTO HELLO
4+
!: AUTO GOODBYE
5+
6+
C: RUN "MATCH (n) RETURN n.name" {} {}
7+
PULL { "n": 1000 }
8+
S: SUCCESS {"fields": ["n.name"]}
9+
<NOOP>
10+
RECORD ["Foo"]
11+
<NOOP>
12+
RECORD ["Bar"]
13+
<NOOP>
14+
<NOOP>
15+
RECORD ["Baz"]
16+
SUCCESS {}

driver/src/test/resources/reset_error.script

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
!: BOLT 3
22
!: AUTO HELLO
33
!: AUTO GOODBYE
4-
!: AUTO RESET
54

65
C: RUN "RETURN 42 AS answer" {} {}
76
PULL_ALL

0 commit comments

Comments
 (0)