Skip to content

Upgrade Boltkit to 4.1. Adding BoltKit Test for NOOP message. #703

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

Merged
merged 3 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,24 @@ void shouldServerWithBoltV3NotSupportMultiDb() throws Throwable
}
}

@Test
void shouldBeAbleHandleNOOPsDuringRunCypher() throws Exception
{
StubServer server = StubServer.start( "noop.script", 9001 );
URI uri = URI.create( "bolt://127.0.0.1:9001" );

try ( Driver driver = GraphDatabase.driver( uri, INSECURE_CONFIG ) )
{
try ( Session session = driver.session() )
{
List<String> names = session.run( "MATCH (n) RETURN n.name" ).list( rec -> rec.get( 0 ).asString() );
assertEquals( asList( "Foo", "Bar", "Baz" ), names );
}
}

assertThat( server.exitStatus(), equalTo( 0 ) );
}

private static void testTxCloseErrorPropagation( String script, Consumer<Transaction> txAction, String expectedErrorMessage )
throws Exception
{
Expand Down
24 changes: 16 additions & 8 deletions driver/src/test/java/org/neo4j/driver/util/StubServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ public class StubServer
// This may be thrown if the driver has not been closed properly
public static class ForceKilled extends Exception {}

private static final String BOLT_STUB_COMMAND = "boltstub";
private static final String BOLT_COMMAND = "bolt";
private static final String BOLT_STUB_COMMAND = "stub";

private Process process;

private StubServer( String script, int port ) throws IOException, InterruptedException
{
List<String> command = new ArrayList<>();
command.addAll( singletonList( BOLT_STUB_COMMAND ) );
command.addAll( asList( Integer.toString( port ), script ) );
command.addAll( asList( BOLT_COMMAND, BOLT_STUB_COMMAND ) );
command.addAll( asList( "-l", "localhost:" + port, script ) );
ProcessBuilder server = new ProcessBuilder().command( command );
process = server.start();
startReadingOutput( process );
Expand All @@ -72,7 +73,7 @@ public static StubServer start( String resource, int port ) throws IOException,
return new StubServer( resource(resource), port );
}

public int exitStatus() throws InterruptedException, ForceKilled
public int exitStatus() throws InterruptedException
{
sleep( 500 ); // wait for a moment to allow disconnection to occur
try
Expand All @@ -83,19 +84,26 @@ public int exitStatus() throws InterruptedException, ForceKilled
{
// not exited yet
exit();
throw new ForceKilled();
}
return -1;
}

public static Config.ConfigBuilder insecureBuilder()
{
return Config.builder().withoutEncryption().withLogging( none() );
}

private void exit() throws InterruptedException
private void exit()
{
process.destroy();
process.waitFor();
try
{
process.waitFor();
}
catch ( InterruptedException ex )
{
throw new RuntimeException( "Interrupted whilst waiting for forced stub shutdown", ex);
}
}

private static String resource( String fileName )
Expand All @@ -113,7 +121,7 @@ private static boolean boltKitAvailable()
try
{
// run 'help' command to see if boltstub is available
Process process = new ProcessBuilder( BOLT_STUB_COMMAND, "-h" ).start();
Process process = new ProcessBuilder( "bolt" ).start();
int exitCode = process.waitFor();
return exitCode == 0;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2002-2020 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.neo4j.driver.util;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class StubServerController
{
private final List<StubServer> currentStubServers = new CopyOnWriteArrayList<>();

public StubServer startStub( String script, int port) throws IOException, InterruptedException
{
StubServer server = StubServer.start( script, port );
currentStubServers.add( server );
return server;
}

public void reset()
{
for ( StubServer server : currentStubServers )
{
try
{
server.exitStatus();
}
catch ( InterruptedException e )
{
throw new RuntimeException( "Interrupted whilst waiting for stub shutdown", e);
}
currentStubServers.remove( server );
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,3 @@ C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"addre
S: SUCCESS {"fields": ["ttl", "servers"]}
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"}]]
SUCCESS {}
C: RESET
S: SUCCESS {}
<EXIT>
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
!: AUTO RESET
!: AUTO HELLO
!: AUTO GOODBYE
!: AUTO BEGIN

C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"address": "my.virtual.host:8080"}} {}
PULL_ALL
S: SUCCESS {"fields": ["ttl", "servers"]}
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"}]]
SUCCESS {}
C: RESET
S: SUCCESS {}
<EXIT>
16 changes: 16 additions & 0 deletions driver/src/test/resources/noop.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
!: BOLT 4.1
!: AUTO RESET
!: AUTO HELLO
!: AUTO GOODBYE

C: RUN "MATCH (n) RETURN n.name" {} {}
PULL { "n": 1000 }
S: SUCCESS {"fields": ["n.name"]}
<NOOP>
RECORD ["Foo"]
<NOOP>
RECORD ["Bar"]
<NOOP>
<NOOP>
RECORD ["Baz"]
SUCCESS {}
1 change: 0 additions & 1 deletion driver/src/test/resources/reset_error.script
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
!: BOLT 3
!: AUTO HELLO
!: AUTO GOODBYE
!: AUTO RESET

C: RUN "RETURN 42 AS answer" {} {}
PULL_ALL
Expand Down