diff --git a/community/bolt/src/main/java/org/neo4j/bolt/messaging/BoltResponseMessageWriter.java b/community/bolt/src/main/java/org/neo4j/bolt/messaging/BoltResponseMessageWriter.java new file mode 100644 index 0000000000000..48fff98bd8936 --- /dev/null +++ b/community/bolt/src/main/java/org/neo4j/bolt/messaging/BoltResponseMessageWriter.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2002-2018 "Neo4j," + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.bolt.messaging; + +import java.io.IOException; + +/** + * Interface defining simple encoders for each defined + * Bolt response message. + */ +public interface BoltResponseMessageWriter +{ + void write( ResponseMessage message ) throws IOException; +} diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/message/ResponseMessage.java b/community/bolt/src/main/java/org/neo4j/bolt/messaging/ResponseMessage.java similarity index 78% rename from community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/message/ResponseMessage.java rename to community/bolt/src/main/java/org/neo4j/bolt/messaging/ResponseMessage.java index cf51e3acaccf4..bd7f1eb8bdbc8 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/message/ResponseMessage.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/messaging/ResponseMessage.java @@ -17,13 +17,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.neo4j.bolt.v1.messaging.message; - -import java.io.IOException; - -import org.neo4j.bolt.v1.messaging.BoltResponseMessageHandler; +package org.neo4j.bolt.messaging; public interface ResponseMessage { - void dispatch( BoltResponseMessageHandler consumer ) throws IOException; + byte signature(); } diff --git a/community/bolt/src/main/java/org/neo4j/bolt/messaging/ResponseMessageEncoder.java b/community/bolt/src/main/java/org/neo4j/bolt/messaging/ResponseMessageEncoder.java new file mode 100644 index 0000000000000..96c5b34cc4f49 --- /dev/null +++ b/community/bolt/src/main/java/org/neo4j/bolt/messaging/ResponseMessageEncoder.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2002-2018 "Neo4j," + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.bolt.messaging; + +import java.io.IOException; + +public interface ResponseMessageEncoder +{ + void encode( Neo4jPack.Packer packer, T message ) throws IOException; +} diff --git a/community/bolt/src/main/java/org/neo4j/bolt/runtime/BoltResponseHandler.java b/community/bolt/src/main/java/org/neo4j/bolt/runtime/BoltResponseHandler.java index 68b80dd56e614..320ff61c29881 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/runtime/BoltResponseHandler.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/runtime/BoltResponseHandler.java @@ -40,5 +40,4 @@ public interface BoltResponseHandler /** Called when the operation is completed. */ void onFinish(); - } diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/BoltProtocolV1.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/BoltProtocolV1.java index cede3eff35312..e29b2865000d5 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/BoltProtocolV1.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/BoltProtocolV1.java @@ -33,7 +33,7 @@ import org.neo4j.bolt.transport.pipeline.MessageAccumulator; import org.neo4j.bolt.transport.pipeline.MessageDecoder; import org.neo4j.bolt.v1.messaging.BoltRequestMessageReaderV1; -import org.neo4j.bolt.v1.messaging.BoltResponseMessageWriter; +import org.neo4j.bolt.v1.messaging.BoltResponseMessageWriterV1; import org.neo4j.bolt.v1.messaging.Neo4jPackV1; import org.neo4j.bolt.v1.runtime.BoltStateMachineFactory; import org.neo4j.kernel.impl.logging.LogService; @@ -91,7 +91,7 @@ public long version() public static BoltRequestMessageReader createBoltMessageReaderV1( BoltChannel channel, Neo4jPack neo4jPack, BoltConnection connection, LogService logging ) { - BoltResponseMessageWriter responseWriter = new BoltResponseMessageWriter( neo4jPack, connection.output(), logging, channel.log() ); + BoltResponseMessageWriterV1 responseWriter = new BoltResponseMessageWriterV1( neo4jPack, connection.output(), logging, channel.log() ); return new BoltRequestMessageReaderV1( connection, responseWriter, channel.log(), logging ); } } diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/BoltRequestMessageReaderV1.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/BoltRequestMessageReaderV1.java index 99c6f35dddd11..692ce24f56198 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/BoltRequestMessageReaderV1.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/BoltRequestMessageReaderV1.java @@ -27,48 +27,49 @@ import org.neo4j.bolt.messaging.RequestMessageDecoder; import org.neo4j.bolt.runtime.BoltConnection; import org.neo4j.bolt.runtime.BoltResponseHandler; -import org.neo4j.bolt.v1.messaging.decoder.AckFailureDecoder; -import org.neo4j.bolt.v1.messaging.decoder.DiscardAllDecoder; -import org.neo4j.bolt.v1.messaging.decoder.InitDecoder; -import org.neo4j.bolt.v1.messaging.decoder.PullAllDecoder; -import org.neo4j.bolt.v1.messaging.decoder.ResetDecoder; -import org.neo4j.bolt.v1.messaging.decoder.RunDecoder; +import org.neo4j.bolt.v1.messaging.decoder.AckFailureMessageDecoder; +import org.neo4j.bolt.messaging.BoltResponseMessageWriter; +import org.neo4j.bolt.v1.messaging.decoder.DiscardAllMessageDecoder; +import org.neo4j.bolt.v1.messaging.decoder.InitMessageDecoder; +import org.neo4j.bolt.v1.messaging.decoder.PullAllMessageDecoder; +import org.neo4j.bolt.v1.messaging.decoder.ResetMessageDecoder; +import org.neo4j.bolt.v1.messaging.decoder.RunMessageDecoder; import org.neo4j.kernel.impl.logging.LogService; import org.neo4j.logging.Log; public class BoltRequestMessageReaderV1 extends BoltRequestMessageReader { - public BoltRequestMessageReaderV1( BoltConnection connection, BoltResponseMessageHandler responseMessageHandler, + public BoltRequestMessageReaderV1( BoltConnection connection, BoltResponseMessageWriter responseMessageWriter, BoltMessageLogger messageLogger, LogService logService ) { super( connection, - newSimpleResponseHandler( connection, responseMessageHandler, logService ), - buildDecoders( connection, responseMessageHandler, messageLogger, logService ), + newSimpleResponseHandler( connection, responseMessageWriter, logService ), + buildDecoders( connection, responseMessageWriter, messageLogger, logService ), messageLogger ); } - private static List buildDecoders( BoltConnection connection, BoltResponseMessageHandler responseMessageHandler, + private static List buildDecoders( BoltConnection connection, BoltResponseMessageWriter responseMessageWriter, BoltMessageLogger messageLogger, LogService logService ) { - BoltResponseHandler initHandler = newSimpleResponseHandler( connection, responseMessageHandler, logService ); - BoltResponseHandler runHandler = newSimpleResponseHandler( connection, responseMessageHandler, logService ); - BoltResponseHandler resultHandler = new ResultHandler( responseMessageHandler, connection, internalLog( logService ) ); - BoltResponseHandler defaultHandler = newSimpleResponseHandler( connection, responseMessageHandler, logService ); + BoltResponseHandler initHandler = newSimpleResponseHandler( connection, responseMessageWriter, logService ); + BoltResponseHandler runHandler = newSimpleResponseHandler( connection, responseMessageWriter, logService ); + BoltResponseHandler resultHandler = new ResultHandler( responseMessageWriter, connection, internalLog( logService ) ); + BoltResponseHandler defaultHandler = newSimpleResponseHandler( connection, responseMessageWriter, logService ); return Arrays.asList( - new InitDecoder( initHandler, messageLogger ), - new AckFailureDecoder( defaultHandler, messageLogger ), - new ResetDecoder( connection, defaultHandler, messageLogger ), - new RunDecoder( runHandler, messageLogger ), - new DiscardAllDecoder( resultHandler, messageLogger ), - new PullAllDecoder( resultHandler, messageLogger ) + new InitMessageDecoder( initHandler, messageLogger ), + new AckFailureMessageDecoder( defaultHandler, messageLogger ), + new ResetMessageDecoder( connection, defaultHandler, messageLogger ), + new RunMessageDecoder( runHandler, messageLogger ), + new DiscardAllMessageDecoder( resultHandler, messageLogger ), + new PullAllMessageDecoder( resultHandler, messageLogger ) ); } private static BoltResponseHandler newSimpleResponseHandler( BoltConnection connection, - BoltResponseMessageHandler responseMessageHandler, LogService logService ) + BoltResponseMessageWriter responseMessageWriter, LogService logService ) { - return new MessageProcessingHandler( responseMessageHandler, connection, internalLog( logService ) ); + return new MessageProcessingHandler( responseMessageWriter, connection, internalLog( logService ) ); } private static Log internalLog( LogService logService ) diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageWriter.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageWriter.java deleted file mode 100644 index c1a7e4a6b0d73..0000000000000 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageWriter.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2002-2018 "Neo4j," - * Neo4j Sweden AB [http://neo4j.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.bolt.v1.messaging; - -import java.io.IOException; - -import org.neo4j.bolt.logging.BoltMessageLogger; -import org.neo4j.bolt.messaging.Neo4jPack; -import org.neo4j.bolt.messaging.PackProvider; -import org.neo4j.bolt.v1.packstream.PackOutput; -import org.neo4j.cypher.result.QueryResult; -import org.neo4j.function.ThrowingAction; -import org.neo4j.kernel.api.exceptions.Status; -import org.neo4j.kernel.impl.logging.LogService; -import org.neo4j.logging.Log; -import org.neo4j.values.AnyValue; -import org.neo4j.values.virtual.MapValue; - -import static org.neo4j.bolt.v1.messaging.BoltResponseMessage.FAILURE; -import static org.neo4j.bolt.v1.messaging.BoltResponseMessage.IGNORED; -import static org.neo4j.bolt.v1.messaging.BoltResponseMessage.RECORD; -import static org.neo4j.bolt.v1.messaging.BoltResponseMessage.SUCCESS; - -/** - * Writer for Bolt request messages to be sent to a {@link Neo4jPack.Packer}. - */ -public class BoltResponseMessageWriter implements BoltResponseMessageHandler -{ - private final PackOutput output; - private final Neo4jPack.Packer packer; - private final BoltMessageLogger messageLogger; - private final Log log; - - public BoltResponseMessageWriter( PackProvider packerProvider, PackOutput output, LogService logService, - BoltMessageLogger messageLogger ) - { - this.output = output; - this.packer = packerProvider.newPacker( output ); - this.messageLogger = messageLogger; - this.log = logService.getInternalLog( getClass() ); - } - - @Override - public void onRecord( QueryResult.Record item ) throws IOException - { - packCompleteMessageOrFail( RECORD, () -> - { - AnyValue[] fields = item.fields(); - packer.packStructHeader( 1, RECORD.signature() ); - packer.packListHeader( fields.length ); - for ( AnyValue field : fields ) - { - packer.pack( field ); - } - } ); - } - - @Override - public void onSuccess( MapValue metadata ) throws IOException - { - packCompleteMessageOrFail( SUCCESS, () -> - { - packer.packStructHeader( 1, SUCCESS.signature() ); - packer.pack( metadata ); - } ); - - messageLogger.logSuccess( () -> metadata ); - } - - @Override - public void onIgnored() throws IOException - { - packCompleteMessageOrFail( IGNORED, () -> - { - packer.packStructHeader( 0, IGNORED.signature() ); - } ); - - messageLogger.logIgnored(); - } - - @Override - public void onFailure( Status status, String errorMessage ) throws IOException - { - packCompleteMessageOrFail( FAILURE, () -> - { - packer.packStructHeader( 1, FAILURE.signature() ); - packer.packMapHeader( 2 ); - - packer.pack( "code" ); - packer.pack( status.code().serialize() ); - - packer.pack( "message" ); - packer.pack( errorMessage ); - } ); - - messageLogger.logFailure( status ); - } - - @Override - public void onFatal( Status status, String errorMessage ) throws IOException - { - messageLogger.serverError( "FATAL", status); - onFailure( status, errorMessage ); - flush(); - } - - public void flush() throws IOException - { - packer.flush(); - } - - private void packCompleteMessageOrFail( BoltResponseMessage message, ThrowingAction action ) throws IOException - { - boolean packingFailed = true; - output.beginMessage(); - try - { - action.apply(); - packingFailed = false; - output.messageSucceeded(); - } - catch ( Throwable error ) - { - if ( packingFailed ) - { - // packing failed, there might be some half-written data in the output buffer right now - // notify output about the failure so that it cleans up the buffer - output.messageFailed(); - log.error( "Failed to write full %s message because: %s", message, error.getMessage() ); - } - throw error; - } - } -} diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageWriterV1.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageWriterV1.java new file mode 100644 index 0000000000000..4f3776afb46fd --- /dev/null +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageWriterV1.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2002-2018 "Neo4j," + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.bolt.v1.messaging; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.neo4j.bolt.logging.BoltMessageLogger; +import org.neo4j.bolt.messaging.BoltIOException; +import org.neo4j.bolt.messaging.BoltResponseMessageWriter; +import org.neo4j.bolt.messaging.Neo4jPack; +import org.neo4j.bolt.messaging.PackProvider; +import org.neo4j.bolt.messaging.ResponseMessage; +import org.neo4j.bolt.messaging.ResponseMessageEncoder; +import org.neo4j.bolt.v1.messaging.encoder.FailureMessageEncoder; +import org.neo4j.bolt.v1.messaging.encoder.IgnoredMessageEncoder; +import org.neo4j.bolt.v1.messaging.encoder.RecordMessageEncoder; +import org.neo4j.bolt.v1.messaging.encoder.SuccessMessageEncoder; +import org.neo4j.bolt.v1.messaging.response.FailureMessage; +import org.neo4j.bolt.v1.messaging.response.FatalFailureMessage; +import org.neo4j.bolt.v1.messaging.response.IgnoredMessage; +import org.neo4j.bolt.v1.messaging.response.RecordMessage; +import org.neo4j.bolt.v1.messaging.response.SuccessMessage; +import org.neo4j.bolt.v1.packstream.PackOutput; +import org.neo4j.kernel.api.exceptions.Status; +import org.neo4j.kernel.impl.logging.LogService; +import org.neo4j.logging.Log; + +import static java.lang.Integer.toHexString; +import static java.lang.String.format; + +/** + * Writer for Bolt request messages to be sent to a {@link Neo4jPack.Packer}. + */ +public class BoltResponseMessageWriterV1 implements BoltResponseMessageWriter +{ + private final PackOutput output; + private final Neo4jPack.Packer packer; + private final Log log; + private final Map encoders; + + public BoltResponseMessageWriterV1( PackProvider packerProvider, PackOutput output, LogService logService, + BoltMessageLogger messageLogger ) + { + this.output = output; + this.packer = packerProvider.newPacker( output ); + this.log = logService.getInternalLog( getClass() ); + this.encoders = registerEncoders( messageLogger ); + } + + private Map registerEncoders( BoltMessageLogger messageLogger ) + { + Map encoders = new HashMap<>(); + encoders.put( SuccessMessage.SIGNATURE, new SuccessMessageEncoder( messageLogger ) ); + encoders.put( RecordMessage.SIGNATURE, new RecordMessageEncoder() ); + encoders.put( IgnoredMessage.SIGNATURE, new IgnoredMessageEncoder( messageLogger ) ); + encoders.put( FailureMessage.SIGNATURE, new FailureMessageEncoder( messageLogger ) ); + return encoders; + } + + @Override + public void write( ResponseMessage message ) throws IOException + { + packCompleteMessageOrFail( message ); + if ( message instanceof FatalFailureMessage ) + { + flush(); + } + } + + public void flush() throws IOException + { + packer.flush(); + } + + private void packCompleteMessageOrFail( ResponseMessage message ) throws IOException + { + boolean packingFailed = true; + output.beginMessage(); + try + { + ResponseMessageEncoder encoder = encoders.get( message.signature() ); + if ( encoder == null ) + { + throw new BoltIOException( Status.Request.InvalidFormat, + format( "Message signature %s is not supported in this protocol version.", toHexString( message.signature() ) ) ); + } + encoder.encode( packer, message ); + packingFailed = false; + output.messageSucceeded(); + } + catch ( Throwable error ) + { + if ( packingFailed ) + { + // packing failed, there might be some half-written data in the output buffer right now + // notify output about the failure so that it cleans up the buffer + output.messageFailed(); + log.error( "Failed to write full %s message because: %s", message.signature(), error.getMessage() ); + } + throw error; + } + } +} diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/MessageProcessingHandler.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/MessageProcessingHandler.java index e5d73725adf66..41ef50265d35e 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/MessageProcessingHandler.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/MessageProcessingHandler.java @@ -27,6 +27,10 @@ import org.neo4j.bolt.runtime.BoltResponseHandler; import org.neo4j.bolt.runtime.BoltResult; import org.neo4j.bolt.runtime.Neo4jError; +import org.neo4j.bolt.messaging.BoltResponseMessageWriter; +import org.neo4j.bolt.v1.messaging.response.FailureMessage; +import org.neo4j.bolt.v1.messaging.response.FatalFailureMessage; +import org.neo4j.bolt.v1.messaging.response.SuccessMessage; import org.neo4j.bolt.v1.packstream.PackOutputClosedException; import org.neo4j.kernel.api.exceptions.Status; import org.neo4j.logging.Log; @@ -34,23 +38,25 @@ import org.neo4j.values.virtual.MapValue; import org.neo4j.values.virtual.MapValueBuilder; +import static org.neo4j.bolt.v1.messaging.response.IgnoredMessage.IGNORED_MESSAGE; + class MessageProcessingHandler implements BoltResponseHandler { // Errors that are expected when the client disconnects mid-operation - private static final Set CLIENT_MID_OP_DISCONNECT_ERRORS = new HashSet<>( Arrays.asList( - Status.Transaction.Terminated, Status.Transaction.LockClientStopped ) ); + private static final Set CLIENT_MID_OP_DISCONNECT_ERRORS = + new HashSet<>( Arrays.asList( Status.Transaction.Terminated, Status.Transaction.LockClientStopped ) ); private final MapValueBuilder metadata = new MapValueBuilder(); protected final Log log; protected final BoltConnection connection; - protected final BoltResponseMessageHandler handler; + protected final BoltResponseMessageWriter messageWriter; private Neo4jError error; private boolean ignored; - MessageProcessingHandler( BoltResponseMessageHandler handler, BoltConnection connection, Log logger ) + MessageProcessingHandler( BoltResponseMessageWriter messageWriter, BoltConnection connection, Log logger ) { - this.handler = handler; + this.messageWriter = messageWriter; this.connection = connection; this.log = logger; } @@ -85,15 +91,15 @@ public void onFinish() { if ( ignored ) { - handler.onIgnored(); + messageWriter.write( IGNORED_MESSAGE ); } else if ( error != null ) { - publishError( handler, error ); + publishError( messageWriter, error ); } else { - handler.onSuccess( getMetadata() ); + messageWriter.write( new SuccessMessage( getMetadata() ) ); } } catch ( Throwable e ) @@ -119,17 +125,17 @@ private void clearState() metadata.clear(); } - private void publishError( BoltResponseMessageHandler out, Neo4jError error ) + private void publishError( BoltResponseMessageWriter messageWriter, Neo4jError error ) { try { if ( error.isFatal() ) { - out.onFatal( error.status(), error.message() ); + messageWriter.write( new FatalFailureMessage( error.status(), error.message() ) ); } else { - out.onFailure( error.status(), error.message() ); + messageWriter.write( new FailureMessage( error.status(), error.message() ) ); } } catch ( PackOutputClosedException e ) @@ -143,9 +149,8 @@ private void publishError( BoltResponseMessageHandler out, Neo4jError error ) if ( CLIENT_MID_OP_DISCONNECT_ERRORS.contains( error.status() ) ) { log.warn( "Client %s disconnected while query was running. Session has been cleaned up. " + - "This can be caused by temporary network problems, but if you see this often, " + - "ensure your applications are properly waiting for operations to complete before exiting.", - e.clientAddress() ); + "This can be caused by temporary network problems, but if you see this often, " + + "ensure your applications are properly waiting for operations to complete before exiting.", e.clientAddress() ); return; } diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/ResultHandler.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/ResultHandler.java index e573df67fb8d2..5c4a7bed48336 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/ResultHandler.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/ResultHandler.java @@ -21,13 +21,15 @@ import org.neo4j.bolt.runtime.BoltConnection; import org.neo4j.bolt.runtime.BoltResult; +import org.neo4j.bolt.messaging.BoltResponseMessageWriter; +import org.neo4j.bolt.v1.messaging.response.RecordMessage; import org.neo4j.cypher.result.QueryResult; import org.neo4j.logging.Log; import org.neo4j.values.AnyValue; class ResultHandler extends MessageProcessingHandler { - ResultHandler( BoltResponseMessageHandler handler, BoltConnection connection, Log log ) + ResultHandler( BoltResponseMessageWriter handler, BoltConnection connection, Log log ) { super( handler, connection, log ); } @@ -42,7 +44,7 @@ public void visit( QueryResult.Record record ) throws Exception { if ( pull ) { - handler.onRecord( record ); + messageWriter.write( new RecordMessage( record ) ); } } diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/AckFailureDecoder.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/AckFailureMessageDecoder.java similarity index 83% rename from community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/AckFailureDecoder.java rename to community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/AckFailureMessageDecoder.java index 4c9107649a5f4..a50b99a0e4fa5 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/AckFailureDecoder.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/AckFailureMessageDecoder.java @@ -26,14 +26,14 @@ import org.neo4j.bolt.messaging.RequestMessage; import org.neo4j.bolt.messaging.RequestMessageDecoder; import org.neo4j.bolt.runtime.BoltResponseHandler; -import org.neo4j.bolt.v1.messaging.message.AckFailure; +import org.neo4j.bolt.v1.messaging.request.AckFailureMessage; -public class AckFailureDecoder implements RequestMessageDecoder +public class AckFailureMessageDecoder implements RequestMessageDecoder { private final BoltResponseHandler responseHandler; private final BoltMessageLogger messageLogger; - public AckFailureDecoder( BoltResponseHandler responseHandler, BoltMessageLogger messageLogger ) + public AckFailureMessageDecoder( BoltResponseHandler responseHandler, BoltMessageLogger messageLogger ) { this.responseHandler = responseHandler; this.messageLogger = messageLogger; @@ -42,7 +42,7 @@ public AckFailureDecoder( BoltResponseHandler responseHandler, BoltMessageLogger @Override public int signature() { - return AckFailure.SIGNATURE; + return AckFailureMessage.SIGNATURE; } @Override @@ -55,6 +55,6 @@ public BoltResponseHandler responseHandler() public RequestMessage decode( Neo4jPack.Unpacker unpacker ) throws IOException { messageLogger.logAckFailure(); - return AckFailure.INSTANCE; + return AckFailureMessage.INSTANCE; } } diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/DiscardAllDecoder.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/DiscardAllMessageDecoder.java similarity index 83% rename from community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/DiscardAllDecoder.java rename to community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/DiscardAllMessageDecoder.java index 83034219f0bb4..963d39fdbd0e6 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/DiscardAllDecoder.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/DiscardAllMessageDecoder.java @@ -26,14 +26,14 @@ import org.neo4j.bolt.messaging.RequestMessage; import org.neo4j.bolt.messaging.RequestMessageDecoder; import org.neo4j.bolt.runtime.BoltResponseHandler; -import org.neo4j.bolt.v1.messaging.message.DiscardAll; +import org.neo4j.bolt.v1.messaging.request.DiscardAllMessage; -public class DiscardAllDecoder implements RequestMessageDecoder +public class DiscardAllMessageDecoder implements RequestMessageDecoder { private final BoltResponseHandler responseHandler; private final BoltMessageLogger messageLogger; - public DiscardAllDecoder( BoltResponseHandler responseHandler, BoltMessageLogger messageLogger ) + public DiscardAllMessageDecoder( BoltResponseHandler responseHandler, BoltMessageLogger messageLogger ) { this.responseHandler = responseHandler; this.messageLogger = messageLogger; @@ -42,7 +42,7 @@ public DiscardAllDecoder( BoltResponseHandler responseHandler, BoltMessageLogger @Override public int signature() { - return DiscardAll.SIGNATURE; + return DiscardAllMessage.SIGNATURE; } @Override @@ -55,6 +55,6 @@ public BoltResponseHandler responseHandler() public RequestMessage decode( Neo4jPack.Unpacker unpacker ) throws IOException { messageLogger.logDiscardAll(); - return DiscardAll.INSTANCE; + return DiscardAllMessage.INSTANCE; } } diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/InitDecoder.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/InitMessageDecoder.java similarity index 87% rename from community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/InitDecoder.java rename to community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/InitMessageDecoder.java index 9c0e3a81b91a4..9d56a9ee78d7e 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/InitDecoder.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/InitMessageDecoder.java @@ -28,15 +28,15 @@ import org.neo4j.bolt.messaging.RequestMessage; import org.neo4j.bolt.messaging.RequestMessageDecoder; import org.neo4j.bolt.runtime.BoltResponseHandler; -import org.neo4j.bolt.v1.messaging.message.Init; +import org.neo4j.bolt.v1.messaging.request.InitMessage; import org.neo4j.values.virtual.MapValue; -public class InitDecoder implements RequestMessageDecoder +public class InitMessageDecoder implements RequestMessageDecoder { private final BoltResponseHandler responseHandler; private final BoltMessageLogger messageLogger; - public InitDecoder( BoltResponseHandler responseHandler, BoltMessageLogger messageLogger ) + public InitMessageDecoder( BoltResponseHandler responseHandler, BoltMessageLogger messageLogger ) { this.responseHandler = responseHandler; this.messageLogger = messageLogger; @@ -45,7 +45,7 @@ public InitDecoder( BoltResponseHandler responseHandler, BoltMessageLogger messa @Override public int signature() { - return Init.SIGNATURE; + return InitMessage.SIGNATURE; } @Override @@ -60,7 +60,7 @@ public RequestMessage decode( Neo4jPack.Unpacker unpacker ) throws IOException String userAgent = unpacker.unpackString(); Map authToken = readAuthToken( unpacker ); messageLogger.logInit( userAgent ); - return new Init( userAgent, authToken ); + return new InitMessage( userAgent, authToken ); } private static Map readAuthToken( Neo4jPack.Unpacker unpacker ) throws IOException diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/PullAllDecoder.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/PullAllMessageDecoder.java similarity index 83% rename from community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/PullAllDecoder.java rename to community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/PullAllMessageDecoder.java index 838ae4d2d4bfe..7cf43062fd016 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/PullAllDecoder.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/PullAllMessageDecoder.java @@ -26,14 +26,14 @@ import org.neo4j.bolt.messaging.RequestMessage; import org.neo4j.bolt.messaging.RequestMessageDecoder; import org.neo4j.bolt.runtime.BoltResponseHandler; -import org.neo4j.bolt.v1.messaging.message.PullAll; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; -public class PullAllDecoder implements RequestMessageDecoder +public class PullAllMessageDecoder implements RequestMessageDecoder { private final BoltResponseHandler responseHandler; private final BoltMessageLogger messageLogger; - public PullAllDecoder( BoltResponseHandler responseHandler, BoltMessageLogger messageLogger ) + public PullAllMessageDecoder( BoltResponseHandler responseHandler, BoltMessageLogger messageLogger ) { this.responseHandler = responseHandler; this.messageLogger = messageLogger; @@ -42,7 +42,7 @@ public PullAllDecoder( BoltResponseHandler responseHandler, BoltMessageLogger me @Override public int signature() { - return PullAll.SIGNATURE; + return PullAllMessage.SIGNATURE; } @Override @@ -55,6 +55,6 @@ public BoltResponseHandler responseHandler() public RequestMessage decode( Neo4jPack.Unpacker unpacker ) throws IOException { messageLogger.logPullAll(); - return PullAll.INSTANCE; + return PullAllMessage.INSTANCE; } } diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/ResetDecoder.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/ResetMessageDecoder.java similarity index 84% rename from community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/ResetDecoder.java rename to community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/ResetMessageDecoder.java index 7f3b309f3147c..901bfb8526d26 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/ResetDecoder.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/ResetMessageDecoder.java @@ -27,15 +27,15 @@ import org.neo4j.bolt.messaging.RequestMessageDecoder; import org.neo4j.bolt.runtime.BoltConnection; import org.neo4j.bolt.runtime.BoltResponseHandler; -import org.neo4j.bolt.v1.messaging.message.Reset; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; -public class ResetDecoder implements RequestMessageDecoder +public class ResetMessageDecoder implements RequestMessageDecoder { private final BoltConnection connection; private final BoltResponseHandler responseHandler; private final BoltMessageLogger messageLogger; - public ResetDecoder( BoltConnection connection, BoltResponseHandler responseHandler, BoltMessageLogger messageLogger ) + public ResetMessageDecoder( BoltConnection connection, BoltResponseHandler responseHandler, BoltMessageLogger messageLogger ) { this.connection = connection; this.responseHandler = responseHandler; @@ -45,7 +45,7 @@ public ResetDecoder( BoltConnection connection, BoltResponseHandler responseHand @Override public int signature() { - return Reset.SIGNATURE; + return ResetMessage.SIGNATURE; } @Override @@ -60,6 +60,6 @@ public RequestMessage decode( Neo4jPack.Unpacker unpacker ) throws IOException messageLogger.clientEvent( "INTERRUPT" ); messageLogger.logReset(); connection.interrupt(); - return Reset.INSTANCE; + return ResetMessage.INSTANCE; } } diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/RunDecoder.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/RunMessageDecoder.java similarity index 84% rename from community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/RunDecoder.java rename to community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/RunMessageDecoder.java index 3b864f3fa677c..a9e15c429794b 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/RunDecoder.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/decoder/RunMessageDecoder.java @@ -26,15 +26,15 @@ import org.neo4j.bolt.messaging.RequestMessage; import org.neo4j.bolt.messaging.RequestMessageDecoder; import org.neo4j.bolt.runtime.BoltResponseHandler; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.values.virtual.MapValue; -public class RunDecoder implements RequestMessageDecoder +public class RunMessageDecoder implements RequestMessageDecoder { private final BoltResponseHandler responseHandler; private final BoltMessageLogger messageLogger; - public RunDecoder( BoltResponseHandler responseHandler, BoltMessageLogger messageLogger ) + public RunMessageDecoder( BoltResponseHandler responseHandler, BoltMessageLogger messageLogger ) { this.responseHandler = responseHandler; this.messageLogger = messageLogger; @@ -43,7 +43,7 @@ public RunDecoder( BoltResponseHandler responseHandler, BoltMessageLogger messag @Override public int signature() { - return Run.SIGNATURE; + return RunMessage.SIGNATURE; } @Override @@ -58,6 +58,6 @@ public RequestMessage decode( Neo4jPack.Unpacker unpacker ) throws IOException String statement = unpacker.unpackString(); MapValue params = unpacker.unpackMap(); messageLogger.logRun(); - return new Run( statement, params ); + return new RunMessage( statement, params ); } } diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/encoder/FailureMessageEncoder.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/encoder/FailureMessageEncoder.java new file mode 100644 index 0000000000000..7b8957a4efdeb --- /dev/null +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/encoder/FailureMessageEncoder.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2002-2018 "Neo4j," + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.bolt.v1.messaging.encoder; + +import java.io.IOException; + +import org.neo4j.bolt.logging.BoltMessageLogger; +import org.neo4j.bolt.messaging.Neo4jPack; +import org.neo4j.bolt.messaging.ResponseMessageEncoder; +import org.neo4j.bolt.v1.messaging.response.FailureMessage; +import org.neo4j.bolt.v1.messaging.response.FatalFailureMessage; + +public class FailureMessageEncoder implements ResponseMessageEncoder +{ + private BoltMessageLogger messageLogger; + + public FailureMessageEncoder( BoltMessageLogger messageLogger ) + { + this.messageLogger = messageLogger; + } + + @Override + public void encode( Neo4jPack.Packer packer, FailureMessage message ) throws IOException + { + if ( message instanceof FatalFailureMessage ) + { + messageLogger.serverError( "FATAL", message.status() ); + } + encodeFailure( message, packer ); + } + + private void encodeFailure( FailureMessage message, Neo4jPack.Packer packer ) throws IOException + { + packer.packStructHeader( 1, message.signature() ); + packer.packMapHeader( 2 ); + + packer.pack( "code" ); + packer.pack( message.status().code().serialize() ); + + packer.pack( "message" ); + packer.pack( message.message() ); + messageLogger.logFailure( message.status() ); + } +} diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/encoder/IgnoredMessageEncoder.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/encoder/IgnoredMessageEncoder.java new file mode 100644 index 0000000000000..ae6bc44d9ac1a --- /dev/null +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/encoder/IgnoredMessageEncoder.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2002-2018 "Neo4j," + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.bolt.v1.messaging.encoder; + +import java.io.IOException; + +import org.neo4j.bolt.logging.BoltMessageLogger; +import org.neo4j.bolt.messaging.Neo4jPack; +import org.neo4j.bolt.messaging.ResponseMessageEncoder; +import org.neo4j.bolt.v1.messaging.response.IgnoredMessage; + +public class IgnoredMessageEncoder implements ResponseMessageEncoder +{ + private final BoltMessageLogger messageLogger; + + public IgnoredMessageEncoder( BoltMessageLogger messageLogger ) + { + this.messageLogger = messageLogger; + } + + @Override + public void encode( Neo4jPack.Packer packer, IgnoredMessage message ) throws IOException + { + packer.packStructHeader( 0, message.signature() ); + messageLogger.logIgnored(); + } +} diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageHandler.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/encoder/RecordMessageEncoder.java similarity index 54% rename from community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageHandler.java rename to community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/encoder/RecordMessageEncoder.java index da2a005b2f8ff..74ed63f6e79e3 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageHandler.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/encoder/RecordMessageEncoder.java @@ -17,30 +17,26 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.neo4j.bolt.v1.messaging; +package org.neo4j.bolt.v1.messaging.encoder; import java.io.IOException; -import org.neo4j.cypher.result.QueryResult; -import org.neo4j.kernel.api.exceptions.Status; -import org.neo4j.values.virtual.MapValue; +import org.neo4j.bolt.messaging.Neo4jPack; +import org.neo4j.bolt.messaging.ResponseMessageEncoder; +import org.neo4j.bolt.v1.messaging.response.RecordMessage; +import org.neo4j.values.AnyValue; -/** - * Interface defining simple handler methods for each defined - * Bolt response message. - */ -public interface BoltResponseMessageHandler +public class RecordMessageEncoder implements ResponseMessageEncoder { - void onSuccess( MapValue metadata ) throws IOException; - - void onRecord( QueryResult.Record item ) throws IOException; - - void onIgnored() throws IOException; - - void onFailure( Status status, String errorMessage ) throws IOException; - - default void onFatal( Status status, String errorMessage ) throws IOException + @Override + public void encode( Neo4jPack.Packer packer, RecordMessage message ) throws IOException { - onFailure( status, errorMessage ); + AnyValue[] fields = message.fields(); + packer.packStructHeader( 1, message.signature() ); + packer.packListHeader( fields.length ); + for ( AnyValue field : fields ) + { + packer.pack( field ); + } } } diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/encoder/SuccessMessageEncoder.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/encoder/SuccessMessageEncoder.java new file mode 100644 index 0000000000000..9efc2265df21e --- /dev/null +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/encoder/SuccessMessageEncoder.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2002-2018 "Neo4j," + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.bolt.v1.messaging.encoder; + +import java.io.IOException; + +import org.neo4j.bolt.logging.BoltMessageLogger; +import org.neo4j.bolt.messaging.Neo4jPack; +import org.neo4j.bolt.messaging.ResponseMessageEncoder; +import org.neo4j.bolt.v1.messaging.response.SuccessMessage; + +public class SuccessMessageEncoder implements ResponseMessageEncoder +{ + private final BoltMessageLogger messageLogger; + + public SuccessMessageEncoder( BoltMessageLogger messageLogger ) + { + this.messageLogger = messageLogger; + } + + @Override + public void encode( Neo4jPack.Packer packer, SuccessMessage message ) throws IOException + { + packer.packStructHeader( 1, message.signature() ); + packer.pack( message.meta() ); + messageLogger.logSuccess( message::meta ); + } +} diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/message/AckFailure.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/request/AckFailureMessage.java similarity index 83% rename from community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/message/AckFailure.java rename to community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/request/AckFailureMessage.java index 1a46c514b0d05..c669066e517cf 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/message/AckFailure.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/request/AckFailureMessage.java @@ -17,17 +17,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.neo4j.bolt.v1.messaging.message; +package org.neo4j.bolt.v1.messaging.request; import org.neo4j.bolt.messaging.RequestMessage; -public class AckFailure implements RequestMessage +public class AckFailureMessage implements RequestMessage { public static final byte SIGNATURE = 0x0E; - public static final AckFailure INSTANCE = new AckFailure(); + public static final AckFailureMessage INSTANCE = new AckFailureMessage(); - private AckFailure() + private AckFailureMessage() { } diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/message/DiscardAll.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/request/DiscardAllMessage.java similarity index 83% rename from community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/message/DiscardAll.java rename to community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/request/DiscardAllMessage.java index 2720a9db3cfda..b58a7df62aec0 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/message/DiscardAll.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/request/DiscardAllMessage.java @@ -17,17 +17,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.neo4j.bolt.v1.messaging.message; +package org.neo4j.bolt.v1.messaging.request; import org.neo4j.bolt.messaging.RequestMessage; -public class DiscardAll implements RequestMessage +public class DiscardAllMessage implements RequestMessage { public static final byte SIGNATURE = 0x2F; - public static final DiscardAll INSTANCE = new DiscardAll(); + public static final DiscardAllMessage INSTANCE = new DiscardAllMessage(); - private DiscardAll() + private DiscardAllMessage() { } diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/message/Init.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/request/InitMessage.java similarity index 90% rename from community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/message/Init.java rename to community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/request/InitMessage.java index fef55a6090020..6de9cf22bd29d 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/message/Init.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/request/InitMessage.java @@ -17,7 +17,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.neo4j.bolt.v1.messaging.message; +package org.neo4j.bolt.v1.messaging.request; import java.util.Map; import java.util.Objects; @@ -26,14 +26,14 @@ import static java.util.Objects.requireNonNull; -public class Init implements RequestMessage +public class InitMessage implements RequestMessage { public static final byte SIGNATURE = 0x01; private final String userAgent; private final Map authToken; - public Init( String userAgent, Map authToken ) + public InitMessage( String userAgent, Map authToken ) { this.userAgent = requireNonNull( userAgent ); this.authToken = requireNonNull( authToken ); @@ -66,7 +66,7 @@ public boolean equals( Object o ) { return false; } - Init that = (Init) o; + InitMessage that = (InitMessage) o; return Objects.equals( userAgent, that.userAgent ) && Objects.equals( authToken, that.authToken ); } diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/message/Interrupt.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/request/InterruptSignal.java similarity index 83% rename from community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/message/Interrupt.java rename to community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/request/InterruptSignal.java index 29e0b2e7f95ee..5d25425df7a87 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/message/Interrupt.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/request/InterruptSignal.java @@ -17,15 +17,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.neo4j.bolt.v1.messaging.message; +package org.neo4j.bolt.v1.messaging.request; import org.neo4j.bolt.messaging.RequestMessage; -public class Interrupt implements RequestMessage +public class InterruptSignal implements RequestMessage { - public static final Interrupt INSTANCE = new Interrupt(); + public static final InterruptSignal INSTANCE = new InterruptSignal(); - private Interrupt() + private InterruptSignal() { } diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/message/PullAll.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/request/PullAllMessage.java similarity index 83% rename from community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/message/PullAll.java rename to community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/request/PullAllMessage.java index c70c772a36ae3..dd28355073611 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/message/PullAll.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/request/PullAllMessage.java @@ -17,17 +17,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.neo4j.bolt.v1.messaging.message; +package org.neo4j.bolt.v1.messaging.request; import org.neo4j.bolt.messaging.RequestMessage; -public class PullAll implements RequestMessage +public class PullAllMessage implements RequestMessage { public static final byte SIGNATURE = 0x3F; - public static final PullAll INSTANCE = new PullAll(); + public static final PullAllMessage INSTANCE = new PullAllMessage(); - private PullAll() + private PullAllMessage() { } diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/message/Reset.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/request/ResetMessage.java similarity index 84% rename from community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/message/Reset.java rename to community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/request/ResetMessage.java index a127837ed8dd5..1cf3ef3cb816d 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/message/Reset.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/request/ResetMessage.java @@ -17,17 +17,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.neo4j.bolt.v1.messaging.message; +package org.neo4j.bolt.v1.messaging.request; import org.neo4j.bolt.messaging.RequestMessage; -public class Reset implements RequestMessage +public class ResetMessage implements RequestMessage { public static final byte SIGNATURE = 0x0F; - public static final Reset INSTANCE = new Reset(); + public static final ResetMessage INSTANCE = new ResetMessage(); - private Reset() + private ResetMessage() { } diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/message/Run.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/request/RunMessage.java similarity index 89% rename from community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/message/Run.java rename to community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/request/RunMessage.java index 2da32f5439d88..d24c0be99eb54 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/message/Run.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/request/RunMessage.java @@ -17,7 +17,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.neo4j.bolt.v1.messaging.message; +package org.neo4j.bolt.v1.messaging.request; import java.util.Objects; @@ -27,19 +27,19 @@ import static java.util.Objects.requireNonNull; -public class Run implements RequestMessage +public class RunMessage implements RequestMessage { public static final byte SIGNATURE = 0x10; private final String statement; private final MapValue params; - public Run( String statement ) + public RunMessage( String statement ) { this( statement, VirtualValues.EMPTY_MAP ); } - public Run( String statement, MapValue params ) + public RunMessage( String statement, MapValue params ) { this.statement = requireNonNull( statement ); this.params = requireNonNull( params ); @@ -72,7 +72,7 @@ public boolean equals( Object o ) { return false; } - Run that = (Run) o; + RunMessage that = (RunMessage) o; return Objects.equals( statement, that.statement ) && Objects.equals( params, that.params ); } diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/message/FailureMessage.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/response/FailureMessage.java similarity index 88% rename from community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/message/FailureMessage.java rename to community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/response/FailureMessage.java index 505a3575df68d..ab04fe88e072c 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/message/FailureMessage.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/response/FailureMessage.java @@ -17,15 +17,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.neo4j.bolt.v1.messaging.message; +package org.neo4j.bolt.v1.messaging.response; -import java.io.IOException; - -import org.neo4j.bolt.v1.messaging.BoltResponseMessageHandler; +import org.neo4j.bolt.messaging.ResponseMessage; import org.neo4j.kernel.api.exceptions.Status; public class FailureMessage implements ResponseMessage { + public static final byte SIGNATURE = 0x7F; private final Status status; private final String message; @@ -46,9 +45,9 @@ public String message() } @Override - public void dispatch( BoltResponseMessageHandler consumer ) throws IOException + public byte signature() { - consumer.onFailure( status, message ); + return SIGNATURE; } @Override diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/response/FatalFailureMessage.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/response/FatalFailureMessage.java new file mode 100644 index 0000000000000..09edc687a30e1 --- /dev/null +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/response/FatalFailureMessage.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2002-2018 "Neo4j," + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.bolt.v1.messaging.response; + +import org.neo4j.kernel.api.exceptions.Status; + +public class FatalFailureMessage extends FailureMessage +{ + public FatalFailureMessage( Status status, String message ) + { + super( status, message ); + } +} diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/message/IgnoredMessage.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/response/IgnoredMessage.java similarity index 78% rename from community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/message/IgnoredMessage.java rename to community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/response/IgnoredMessage.java index 4c597eafa12bf..ecdff7b2c0821 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/message/IgnoredMessage.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/response/IgnoredMessage.java @@ -17,18 +17,23 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.neo4j.bolt.v1.messaging.message; +package org.neo4j.bolt.v1.messaging.response; -import java.io.IOException; - -import org.neo4j.bolt.v1.messaging.BoltResponseMessageHandler; +import org.neo4j.bolt.messaging.ResponseMessage; public class IgnoredMessage implements ResponseMessage { + public static final byte SIGNATURE = 0x7E; + public static final IgnoredMessage IGNORED_MESSAGE = new IgnoredMessage(); + + private IgnoredMessage() + { + } + @Override - public void dispatch( BoltResponseMessageHandler consumer ) throws IOException + public byte signature() { - consumer.onIgnored(); + return SIGNATURE; } @Override diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/message/RecordMessage.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/response/RecordMessage.java similarity index 84% rename from community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/message/RecordMessage.java rename to community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/response/RecordMessage.java index 01c4aa8b8111c..10fc6ade9e9ad 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/message/RecordMessage.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/response/RecordMessage.java @@ -17,15 +17,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.neo4j.bolt.v1.messaging.message; +package org.neo4j.bolt.v1.messaging.response; -import java.io.IOException; - -import org.neo4j.bolt.v1.messaging.BoltResponseMessageHandler; +import org.neo4j.bolt.messaging.ResponseMessage; import org.neo4j.cypher.result.QueryResult; +import org.neo4j.values.AnyValue; public class RecordMessage implements ResponseMessage { + public static final byte SIGNATURE = 0x71; private final QueryResult.Record value; public RecordMessage( QueryResult.Record record ) @@ -34,9 +34,9 @@ public RecordMessage( QueryResult.Record record ) } @Override - public void dispatch( BoltResponseMessageHandler consumer ) throws IOException + public byte signature() { - consumer.onRecord( value ); + return SIGNATURE; } @Override @@ -74,4 +74,9 @@ public QueryResult.Record record() { return value; } + + public AnyValue[] fields() + { + return value.fields(); + } } diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/message/SuccessMessage.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/response/SuccessMessage.java similarity index 86% rename from community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/message/SuccessMessage.java rename to community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/response/SuccessMessage.java index dd1fd9422be98..14a5b9ed49285 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/message/SuccessMessage.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/response/SuccessMessage.java @@ -17,15 +17,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.neo4j.bolt.v1.messaging.message; +package org.neo4j.bolt.v1.messaging.response; -import java.io.IOException; - -import org.neo4j.bolt.v1.messaging.BoltResponseMessageHandler; +import org.neo4j.bolt.messaging.ResponseMessage; import org.neo4j.values.virtual.MapValue; public class SuccessMessage implements ResponseMessage { + public static final byte SIGNATURE = 0x70; private final MapValue metadata; public SuccessMessage( MapValue metadata ) @@ -34,9 +33,9 @@ public SuccessMessage( MapValue metadata ) } @Override - public void dispatch( BoltResponseMessageHandler consumer ) throws IOException + public byte signature() { - consumer.onSuccess( metadata ); + return SIGNATURE; } @Override diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/BoltStateMachineV1.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/BoltStateMachineV1.java index 0930846247844..4f2a26afc67af 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/BoltStateMachineV1.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/BoltStateMachineV1.java @@ -37,7 +37,7 @@ import org.neo4j.bolt.runtime.StateMachineContext; import org.neo4j.bolt.runtime.StatementProcessor; import org.neo4j.bolt.v1.messaging.BoltStateMachineV1Context; -import org.neo4j.bolt.v1.messaging.message.Interrupt; +import org.neo4j.bolt.v1.messaging.request.InterruptSignal; import org.neo4j.graphdb.security.AuthorizationExpiredException; import org.neo4j.internal.kernel.api.exceptions.KernelException; import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; @@ -105,7 +105,7 @@ private void before( BoltResponseHandler handler ) throws BoltConnectionFatality } else if ( connectionState.isInterrupted() ) { - state = nextState( Interrupt.INSTANCE, context ); + state = nextState( InterruptSignal.INSTANCE, context ); } connectionState.setResponseHandler( handler ); } diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/ConnectedState.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/ConnectedState.java index f8083c8440cc2..e01bb7c3c0590 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/ConnectedState.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/ConnectedState.java @@ -28,7 +28,7 @@ import org.neo4j.bolt.runtime.StateMachineContext; import org.neo4j.bolt.runtime.StatementProcessor; import org.neo4j.bolt.security.auth.AuthenticationResult; -import org.neo4j.bolt.v1.messaging.message.Init; +import org.neo4j.bolt.v1.messaging.request.InitMessage; import org.neo4j.values.storable.Values; import static org.neo4j.kernel.api.security.AuthToken.PRINCIPAL; @@ -50,9 +50,9 @@ public class ConnectedState implements BoltStateMachineState public BoltStateMachineState process( RequestMessage message, StateMachineContext context ) throws BoltConnectionFatality { assertInitialized(); - if ( message instanceof Init ) + if ( message instanceof InitMessage ) { - return processInitMessage( (Init) message, context ); + return processInitMessage( (InitMessage) message, context ); } return null; } @@ -73,7 +73,7 @@ public void setFailedState( BoltStateMachineState failedState ) this.failedState = failedState; } - private BoltStateMachineState processInitMessage( Init message, StateMachineContext context ) throws BoltConnectionFatality + private BoltStateMachineState processInitMessage( InitMessage message, StateMachineContext context ) throws BoltConnectionFatality { String userAgent = message.userAgent(); Map authToken = message.authToken(); diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/FailedState.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/FailedState.java index 761837cce3104..3b3dd97354cd2 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/FailedState.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/FailedState.java @@ -23,12 +23,12 @@ import org.neo4j.bolt.runtime.BoltConnectionFatality; import org.neo4j.bolt.runtime.BoltStateMachineState; import org.neo4j.bolt.runtime.StateMachineContext; -import org.neo4j.bolt.v1.messaging.message.AckFailure; -import org.neo4j.bolt.v1.messaging.message.DiscardAll; -import org.neo4j.bolt.v1.messaging.message.Interrupt; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Reset; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.AckFailureMessage; +import org.neo4j.bolt.v1.messaging.request.DiscardAllMessage; +import org.neo4j.bolt.v1.messaging.request.InterruptSignal; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import static org.neo4j.util.Preconditions.checkState; @@ -53,16 +53,16 @@ public BoltStateMachineState process( RequestMessage message, StateMachineContex context.connectionState().markIgnored(); return this; } - if ( message instanceof AckFailure ) + if ( message instanceof AckFailureMessage ) { context.connectionState().resetPendingFailedAndIgnored(); return readyState; } - if ( message instanceof Reset ) + if ( message instanceof ResetMessage ) { return processResetMessage( context ); } - if ( message instanceof Interrupt ) + if ( message instanceof InterruptSignal ) { return interruptedState; } @@ -104,8 +104,8 @@ private void assertInitialized() private static boolean shouldIgnore( RequestMessage message ) { - return message instanceof Run || - message instanceof PullAll || - message instanceof DiscardAll; + return message instanceof RunMessage || + message instanceof PullAllMessage || + message instanceof DiscardAllMessage; } } diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/InterruptedState.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/InterruptedState.java index 5fbb06a789249..ab863af3c4079 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/InterruptedState.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/InterruptedState.java @@ -23,8 +23,8 @@ import org.neo4j.bolt.runtime.BoltConnectionFatality; import org.neo4j.bolt.runtime.BoltStateMachineState; import org.neo4j.bolt.runtime.StateMachineContext; -import org.neo4j.bolt.v1.messaging.message.Interrupt; -import org.neo4j.bolt.v1.messaging.message.Reset; +import org.neo4j.bolt.v1.messaging.request.InterruptSignal; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; import static org.neo4j.util.Preconditions.checkState; @@ -43,11 +43,11 @@ public class InterruptedState implements BoltStateMachineState public BoltStateMachineState process( RequestMessage message, StateMachineContext context ) throws BoltConnectionFatality { assertInitialized(); - if ( message instanceof Interrupt ) + if ( message instanceof InterruptSignal ) { return this; } - else if ( message instanceof Reset ) + else if ( message instanceof ResetMessage ) { if ( context.connectionState().decrementInterruptCounter() > 0 ) { diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/ReadyState.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/ReadyState.java index e81db8af549f0..7d47d1ca3f077 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/ReadyState.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/ReadyState.java @@ -24,9 +24,9 @@ import org.neo4j.bolt.runtime.BoltStateMachineState; import org.neo4j.bolt.runtime.StateMachineContext; import org.neo4j.bolt.runtime.StatementMetadata; -import org.neo4j.bolt.v1.messaging.message.Interrupt; -import org.neo4j.bolt.v1.messaging.message.Reset; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.InterruptSignal; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.graphdb.security.AuthorizationExpiredException; import org.neo4j.values.storable.Values; import org.neo4j.values.virtual.MapValue; @@ -52,15 +52,15 @@ public class ReadyState implements BoltStateMachineState public BoltStateMachineState process( RequestMessage message, StateMachineContext context ) throws BoltConnectionFatality { assertInitialized(); - if ( message instanceof Run ) + if ( message instanceof RunMessage ) { - return processRunMessage( (Run) message, context ); + return processRunMessage( (RunMessage) message, context ); } - if ( message instanceof Reset ) + if ( message instanceof ResetMessage ) { return processResetMessage( context ); } - if ( message instanceof Interrupt ) + if ( message instanceof InterruptSignal ) { return interruptedState; } @@ -88,7 +88,7 @@ public void setFailedState( BoltStateMachineState failedState ) this.failedState = failedState; } - private BoltStateMachineState processRunMessage( Run message, StateMachineContext context ) throws BoltConnectionFatality + private BoltStateMachineState processRunMessage( RunMessage message, StateMachineContext context ) throws BoltConnectionFatality { String statement = message.statement(); MapValue params = message.params(); diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/StreamingState.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/StreamingState.java index c53294721455a..ab1d52e2e2d98 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/StreamingState.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/runtime/StreamingState.java @@ -23,10 +23,10 @@ import org.neo4j.bolt.runtime.BoltConnectionFatality; import org.neo4j.bolt.runtime.BoltStateMachineState; import org.neo4j.bolt.runtime.StateMachineContext; -import org.neo4j.bolt.v1.messaging.message.DiscardAll; -import org.neo4j.bolt.v1.messaging.message.Interrupt; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Reset; +import org.neo4j.bolt.v1.messaging.request.DiscardAllMessage; +import org.neo4j.bolt.v1.messaging.request.InterruptSignal; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; import org.neo4j.graphdb.security.AuthorizationExpiredException; import static org.neo4j.util.Preconditions.checkState; @@ -46,19 +46,19 @@ public class StreamingState implements BoltStateMachineState public BoltStateMachineState process( RequestMessage message, StateMachineContext context ) throws BoltConnectionFatality { assertInitialized(); - if ( message instanceof PullAll ) + if ( message instanceof PullAllMessage ) { return processPullAllMessage( context ); } - if ( message instanceof DiscardAll ) + if ( message instanceof DiscardAllMessage ) { return processDiscardAllMessage( context ); } - if ( message instanceof Reset ) + if ( message instanceof ResetMessage ) { return processResetMessage( context ); } - if ( message instanceof Interrupt ) + if ( message instanceof InterruptSignal ) { return interruptedState; } diff --git a/community/bolt/src/test/java/org/neo4j/bolt/runtime/BoltConnectionReadLimiterTest.java b/community/bolt/src/test/java/org/neo4j/bolt/runtime/BoltConnectionReadLimiterTest.java index 16af843bef569..c1be634cc221d 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/runtime/BoltConnectionReadLimiterTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/runtime/BoltConnectionReadLimiterTest.java @@ -26,7 +26,7 @@ import java.util.Arrays; -import org.neo4j.bolt.v1.messaging.message.Init; +import org.neo4j.bolt.v1.messaging.request.InitMessage; import org.neo4j.bolt.v1.runtime.Job; import org.neo4j.logging.Log; @@ -49,7 +49,7 @@ public class BoltConnectionReadLimiterTest { - private static final Job job = machine -> machine.process( new Init( "INIT", emptyMap() ), nullResponseHandler() ); + private static final Job job = machine -> machine.process( new InitMessage( "INIT", emptyMap() ), nullResponseHandler() ); private BoltConnection connection; private EmbeddedChannel channel; private Log log; diff --git a/community/bolt/src/test/java/org/neo4j/bolt/testing/BoltMatchers.java b/community/bolt/src/test/java/org/neo4j/bolt/testing/BoltMatchers.java index 8523a0efc58c7..b2719892c7db7 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/testing/BoltMatchers.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/testing/BoltMatchers.java @@ -30,7 +30,7 @@ import org.neo4j.bolt.runtime.BoltStateMachine; import org.neo4j.bolt.runtime.BoltStateMachineState; import org.neo4j.bolt.runtime.StatementProcessor; -import org.neo4j.bolt.v1.messaging.message.Reset; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; import org.neo4j.bolt.v1.runtime.BoltStateMachineV1; import org.neo4j.bolt.v1.runtime.ReadyState; import org.neo4j.cypher.result.QueryResult; @@ -295,7 +295,7 @@ public boolean matches( final Object item ) final BoltResponseRecorder recorder = new BoltResponseRecorder(); try { - machine.process( Reset.INSTANCE, recorder ); + machine.process( ResetMessage.INSTANCE, recorder ); return recorder.responseCount() == 1 && inState( ReadyState.class ).matches( item ); } catch ( BoltConnectionFatality boltConnectionFatality ) diff --git a/community/bolt/src/test/java/org/neo4j/bolt/transport/pipeline/MessageDecoderTest.java b/community/bolt/src/test/java/org/neo4j/bolt/transport/pipeline/MessageDecoderTest.java index 5287108d867e7..b88e4a14d0b87 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/transport/pipeline/MessageDecoderTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/transport/pipeline/MessageDecoderTest.java @@ -46,14 +46,14 @@ import org.neo4j.bolt.runtime.Neo4jError; import org.neo4j.bolt.runtime.SynchronousBoltConnection; import org.neo4j.bolt.v1.messaging.BoltRequestMessageReaderV1; -import org.neo4j.bolt.v1.messaging.BoltResponseMessageHandler; +import org.neo4j.bolt.messaging.BoltResponseMessageWriter; import org.neo4j.bolt.v1.messaging.Neo4jPackV1; -import org.neo4j.bolt.v1.messaging.message.AckFailure; -import org.neo4j.bolt.v1.messaging.message.DiscardAll; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Reset; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.AckFailureMessage; +import org.neo4j.bolt.v1.messaging.request.DiscardAllMessage; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.bolt.v1.packstream.PackedOutputArray; import org.neo4j.bolt.v2.messaging.Neo4jPackV2; import org.neo4j.helpers.collection.MapUtil; @@ -123,10 +123,10 @@ public void shouldDispatchInit() throws Exception String userAgent = "Test/User Agent 1.0"; Map authToken = MapUtil.map( "scheme", "basic", "principal", "user", "credentials", "password" ); - channel.writeInbound( Unpooled.wrappedBuffer( serialize( packerUnderTest, new Init( userAgent, authToken ) ) ) ); + channel.writeInbound( Unpooled.wrappedBuffer( serialize( packerUnderTest, new InitMessage( userAgent, authToken ) ) ) ); channel.finishAndReleaseAll(); - verify( stateMachine ).process( eq( new Init( userAgent, authToken ) ), any() ); + verify( stateMachine ).process( eq( new InitMessage( userAgent, authToken ) ), any() ); } @Test @@ -136,10 +136,10 @@ public void shouldDispatchAckFailure() throws Exception SynchronousBoltConnection connection = new SynchronousBoltConnection( stateMachine ); channel = new EmbeddedChannel( newDecoder( connection ) ); - channel.writeInbound( Unpooled.wrappedBuffer( serialize( packerUnderTest, AckFailure.INSTANCE ) ) ); + channel.writeInbound( Unpooled.wrappedBuffer( serialize( packerUnderTest, AckFailureMessage.INSTANCE ) ) ); channel.finishAndReleaseAll(); - verify( stateMachine ).process( eq( AckFailure.INSTANCE ), any() ); + verify( stateMachine ).process( eq( AckFailureMessage.INSTANCE ), any() ); } @Test @@ -149,10 +149,10 @@ public void shouldDispatchReset() throws Exception SynchronousBoltConnection connection = new SynchronousBoltConnection( stateMachine ); channel = new EmbeddedChannel( newDecoder( connection ) ); - channel.writeInbound( Unpooled.wrappedBuffer( serialize( packerUnderTest, Reset.INSTANCE ) ) ); + channel.writeInbound( Unpooled.wrappedBuffer( serialize( packerUnderTest, ResetMessage.INSTANCE ) ) ); channel.finishAndReleaseAll(); - verify( stateMachine ).process( eq( Reset.INSTANCE ), any() ); + verify( stateMachine ).process( eq( ResetMessage.INSTANCE ), any() ); } @Test @@ -165,10 +165,10 @@ public void shouldDispatchRun() throws Exception String statement = "RETURN 1"; MapValue parameters = ValueUtils.asMapValue( MapUtil.map( "param1", 1, "param2", "2", "param3", true, "param4", 5.0 ) ); - channel.writeInbound( Unpooled.wrappedBuffer( serialize( packerUnderTest, new Run( statement, parameters ) ) ) ); + channel.writeInbound( Unpooled.wrappedBuffer( serialize( packerUnderTest, new RunMessage( statement, parameters ) ) ) ); channel.finishAndReleaseAll(); - verify( stateMachine ).process( eq( new Run( statement, parameters ) ), any() ); + verify( stateMachine ).process( eq( new RunMessage( statement, parameters ) ), any() ); } @Test @@ -178,10 +178,10 @@ public void shouldDispatchDiscardAll() throws Exception SynchronousBoltConnection connection = new SynchronousBoltConnection( stateMachine ); channel = new EmbeddedChannel( newDecoder( connection ) ); - channel.writeInbound( Unpooled.wrappedBuffer( serialize( packerUnderTest, DiscardAll.INSTANCE ) ) ); + channel.writeInbound( Unpooled.wrappedBuffer( serialize( packerUnderTest, DiscardAllMessage.INSTANCE ) ) ); channel.finishAndReleaseAll(); - verify( stateMachine ).process( eq( DiscardAll.INSTANCE ), any() ); + verify( stateMachine ).process( eq( DiscardAllMessage.INSTANCE ), any() ); } @Test @@ -191,10 +191,10 @@ public void shouldDispatchPullAll() throws Exception SynchronousBoltConnection connection = new SynchronousBoltConnection( stateMachine ); channel = new EmbeddedChannel( newDecoder( connection ) ); - channel.writeInbound( Unpooled.wrappedBuffer( serialize( packerUnderTest, PullAll.INSTANCE ) ) ); + channel.writeInbound( Unpooled.wrappedBuffer( serialize( packerUnderTest, PullAllMessage.INSTANCE ) ) ); channel.finishAndReleaseAll(); - verify( stateMachine ).process( eq( PullAll.INSTANCE ), any() ); + verify( stateMachine ).process( eq( PullAllMessage.INSTANCE ), any() ); } @Test @@ -207,7 +207,7 @@ public void shouldCallExternalErrorOnInitWithNullKeys() throws Exception String userAgent = "Test/User Agent 1.0"; Map authToken = MapUtil.map( "scheme", "basic", null, "user", "credentials", "password" ); - channel.writeInbound( Unpooled.wrappedBuffer( serialize( packerUnderTest, new Init( userAgent, authToken ) ) ) ); + channel.writeInbound( Unpooled.wrappedBuffer( serialize( packerUnderTest, new InitMessage( userAgent, authToken ) ) ) ); channel.finishAndReleaseAll(); verify( stateMachine ).handleExternalFailure( @@ -224,7 +224,7 @@ public void shouldCallExternalErrorOnInitWithDuplicateKeys() throws Exception // Generate INIT message with duplicate keys PackedOutputArray out = new PackedOutputArray(); Neo4jPack.Packer packer = packerUnderTest.newPacker( out ); - packer.packStructHeader( 2, Init.SIGNATURE ); + packer.packStructHeader( 2, InitMessage.SIGNATURE ); packer.pack( "Test/User Agent 1.0" ); packer.packMapHeader( 3 ); packer.pack( "scheme" ); @@ -330,7 +330,7 @@ public void shouldThrowOnUnknownStructType() throws Exception { PackedOutputArray out = new PackedOutputArray(); Neo4jPack.Packer packer = packerUnderTest.newPacker( out ); - packer.packStructHeader( 2, Run.SIGNATURE ); + packer.packStructHeader( 2, RunMessage.SIGNATURE ); packer.pack( "RETURN $x" ); packer.packMapHeader( 1 ); packer.pack( "x" ); @@ -350,7 +350,7 @@ public void shouldThrowOnUnknownStructType() throws Exception public void shouldLogContentOfTheMessageOnIOError() throws Exception { BoltConnection connection = mock( BoltConnection.class ); - BoltResponseMessageHandler responseMessageHandler = mock( BoltResponseMessageHandler.class ); + BoltResponseMessageWriter responseMessageHandler = mock( BoltResponseMessageWriter.class ); BoltRequestMessageReader requestMessageReader = new BoltRequestMessageReaderV1( connection, responseMessageHandler, NullBoltMessageLogger.getInstance(), NullLogService.getInstance() ); @@ -389,7 +389,7 @@ public void shouldLogContentOfTheMessageOnError() throws Exception channel = new EmbeddedChannel( new MessageDecoder( packerUnderTest::newUnpacker, requestMessageReader, logService ) ); - byte[] messageBytes = packMessageWithSignature( Run.SIGNATURE ); + byte[] messageBytes = packMessageWithSignature( RunMessage.SIGNATURE ); try { @@ -419,7 +419,7 @@ private void testUnpackableStructParametersWithKnownType( Neo4jPack packerForSer SynchronousBoltConnection connection = new SynchronousBoltConnection( stateMachine ); channel = new EmbeddedChannel( newDecoder( connection ) ); - channel.writeInbound( Unpooled.wrappedBuffer( serialize( packerForSerialization, new Run( statement, parameters ) ) ) ); + channel.writeInbound( Unpooled.wrappedBuffer( serialize( packerForSerialization, new RunMessage( statement, parameters ) ) ) ); channel.finishAndReleaseAll(); verify( stateMachine ).handleExternalFailure( eq( Neo4jError.from( Status.Statement.TypeError, expectedMessage ) ), any() ); @@ -447,7 +447,7 @@ private byte[] packMessageWithSignature( byte signature ) throws IOException private MessageDecoder newDecoder( BoltConnection connection ) { - BoltRequestMessageReader reader = new BoltRequestMessageReaderV1( connection, mock( BoltResponseMessageHandler.class ), + BoltRequestMessageReader reader = new BoltRequestMessageReaderV1( connection, mock( BoltResponseMessageWriter.class ), NullBoltMessageLogger.getInstance(), NullLogService.getInstance() ); return new MessageDecoder( packerUnderTest::newUnpacker, reader, NullLogService.getInstance() ); } diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltRequestMessageReaderV1Test.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltRequestMessageReaderV1Test.java index f04d7efba0f30..496294594650a 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltRequestMessageReaderV1Test.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltRequestMessageReaderV1Test.java @@ -27,12 +27,13 @@ import org.neo4j.bolt.messaging.RequestMessage; import org.neo4j.bolt.runtime.BoltStateMachine; import org.neo4j.bolt.runtime.SynchronousBoltConnection; -import org.neo4j.bolt.v1.messaging.message.AckFailure; -import org.neo4j.bolt.v1.messaging.message.DiscardAll; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Reset; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.messaging.BoltResponseMessageWriter; +import org.neo4j.bolt.v1.messaging.request.AckFailureMessage; +import org.neo4j.bolt.v1.messaging.request.DiscardAllMessage; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.bolt.v1.packstream.PackedInputArray; import org.neo4j.kernel.impl.logging.NullLogService; import org.neo4j.values.AnyValue; @@ -51,37 +52,37 @@ public class BoltRequestMessageReaderV1Test @Test void shouldDecodeInitMessage() throws Exception { - testMessageDecoding( new Init( "My driver", map( "one", 1L, "two", 2L ) ) ); + testMessageDecoding( new InitMessage( "My driver", map( "one", 1L, "two", 2L ) ) ); } @Test void shouldDecodeAckFailureMessage() throws Exception { - testMessageDecoding( AckFailure.INSTANCE ); + testMessageDecoding( AckFailureMessage.INSTANCE ); } @Test void shouldDecodeResetMessage() throws Exception { - testMessageDecoding( Reset.INSTANCE ); + testMessageDecoding( ResetMessage.INSTANCE ); } @Test void shouldDecodeRunMessage() throws Exception { - testMessageDecoding( new Run( "RETURN $answer", map( new String[]{"answer"}, new AnyValue[]{stringValue( "42" )} ) ) ); + testMessageDecoding( new RunMessage( "RETURN $answer", map( new String[]{"answer"}, new AnyValue[]{stringValue( "42" )} ) ) ); } @Test void shouldDecodeDiscardAllMessage() throws Exception { - testMessageDecoding( DiscardAll.INSTANCE ); + testMessageDecoding( DiscardAllMessage.INSTANCE ); } @Test void shouldDecodePullAllMessage() throws Exception { - testMessageDecoding( PullAll.INSTANCE ); + testMessageDecoding( PullAllMessage.INSTANCE ); } private static void testMessageDecoding( RequestMessage message ) throws Exception @@ -102,6 +103,6 @@ private static void testMessageDecoding( RequestMessage message ) throws Excepti private static BoltRequestMessageReader newReader( BoltStateMachine stateMachine ) { return new BoltRequestMessageReaderV1( new SynchronousBoltConnection( stateMachine ), - mock( BoltResponseMessageHandler.class ), NullBoltMessageLogger.getInstance(), NullLogService.getInstance() ); + mock( BoltResponseMessageWriter.class ), NullBoltMessageLogger.getInstance(), NullLogService.getInstance() ); } } diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltRequestMessageTest.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltRequestMessageTest.java index 1c6f0195ea7a3..b7c446f6df71e 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltRequestMessageTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltRequestMessageTest.java @@ -35,13 +35,14 @@ import org.neo4j.bolt.messaging.RequestMessage; import org.neo4j.bolt.runtime.BoltStateMachine; import org.neo4j.bolt.runtime.SynchronousBoltConnection; -import org.neo4j.bolt.v1.messaging.message.AckFailure; -import org.neo4j.bolt.v1.messaging.message.DiscardAll; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.RecordMessage; -import org.neo4j.bolt.v1.messaging.message.Reset; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.messaging.BoltResponseMessageWriter; +import org.neo4j.bolt.v1.messaging.request.AckFailureMessage; +import org.neo4j.bolt.v1.messaging.request.DiscardAllMessage; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.response.RecordMessage; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.bolt.v1.packstream.BufferedChannelOutput; import org.neo4j.bolt.v1.packstream.PackedInputArray; import org.neo4j.kernel.impl.logging.NullLogService; @@ -79,12 +80,12 @@ public class BoltRequestMessageTest @Test public void shouldHandleCommonMessages() throws Throwable { - assertSerializes( new Init( "MyClient/1.0", map( "scheme", "basic" ) ) ); - assertSerializes( AckFailure.INSTANCE ); - assertSerializes( Reset.INSTANCE ); - assertSerializes( new Run( "CREATE (n) RETURN åäö" ) ); - assertSerializes( DiscardAll.INSTANCE ); - assertSerializes( PullAll.INSTANCE ); + assertSerializes( new InitMessage( "MyClient/1.0", map( "scheme", "basic" ) ) ); + assertSerializes( AckFailureMessage.INSTANCE ); + assertSerializes( ResetMessage.INSTANCE ); + assertSerializes( new RunMessage( "CREATE (n) RETURN åäö" ) ); + assertSerializes( DiscardAllMessage.INSTANCE ); + assertSerializes( PullAllMessage.INSTANCE ); } @Test @@ -94,7 +95,7 @@ public void shouldHandleParameterizedStatements() throws Throwable MapValue parameters = ValueUtils.asMapValue( map( "n", 12L ) ); // When - Run msg = serializeAndDeserialize( new Run( "asd", parameters ) ); + RunMessage msg = serializeAndDeserialize( new RunMessage( "asd", parameters ) ); // Then MapValue params = msg.params(); @@ -165,7 +166,7 @@ public Void answer( InvocationOnMock invocationOnMock ) throws Throwable } } ).when( stateMachine ).process( any(), any() ); BoltRequestMessageReader reader = new BoltRequestMessageReaderV1( new SynchronousBoltConnection( stateMachine ), - mock( BoltResponseMessageHandler.class ), NullBoltMessageLogger.getInstance(), NullLogService.getInstance() ); + mock( BoltResponseMessageWriter.class ), NullBoltMessageLogger.getInstance(), NullLogService.getInstance() ); byte[] bytes = channel.getBytes(); String serialized = HexPrinter.hex( bytes ); diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltRequestMessageWriter.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltRequestMessageWriter.java index 4f94b883e3672..90cdb7697e9bf 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltRequestMessageWriter.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltRequestMessageWriter.java @@ -24,12 +24,12 @@ import org.neo4j.bolt.messaging.Neo4jPack; import org.neo4j.bolt.messaging.RequestMessage; -import org.neo4j.bolt.v1.messaging.message.AckFailure; -import org.neo4j.bolt.v1.messaging.message.DiscardAll; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Reset; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.AckFailureMessage; +import org.neo4j.bolt.v1.messaging.request.DiscardAllMessage; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.kernel.impl.util.ValueUtils; public class BoltRequestMessageWriter @@ -43,27 +43,27 @@ public BoltRequestMessageWriter( Neo4jPack.Packer packer ) public BoltRequestMessageWriter write( RequestMessage message ) throws IOException { - if ( message instanceof Init ) + if ( message instanceof InitMessage ) { - writeInit( (Init) message ); + writeInit( (InitMessage) message ); } - else if ( message instanceof AckFailure ) + else if ( message instanceof AckFailureMessage ) { writeAckFailure(); } - else if ( message instanceof Reset ) + else if ( message instanceof ResetMessage ) { writeReset(); } - else if ( message instanceof Run ) + else if ( message instanceof RunMessage ) { - writeRun( (Run) message ); + writeRun( (RunMessage) message ); } - else if ( message instanceof DiscardAll ) + else if ( message instanceof DiscardAllMessage ) { writeDiscardAll(); } - else if ( message instanceof PullAll ) + else if ( message instanceof PullAllMessage ) { writePullAll(); } @@ -74,11 +74,11 @@ else if ( message instanceof PullAll ) return this; } - private void writeInit( Init message ) + private void writeInit( InitMessage message ) { try { - packer.packStructHeader( 2, Init.SIGNATURE ); + packer.packStructHeader( 2, InitMessage.SIGNATURE ); packer.pack( message.userAgent() ); packer.pack( ValueUtils.asMapValue( message.authToken() ) ); } @@ -92,7 +92,7 @@ private void writeAckFailure() { try { - packer.packStructHeader( 0, AckFailure.SIGNATURE ); + packer.packStructHeader( 0, AckFailureMessage.SIGNATURE ); } catch ( IOException e ) { @@ -104,7 +104,7 @@ private void writeReset() { try { - packer.packStructHeader( 0, Reset.SIGNATURE ); + packer.packStructHeader( 0, ResetMessage.SIGNATURE ); } catch ( IOException e ) { @@ -112,11 +112,11 @@ private void writeReset() } } - private void writeRun( Run message ) + private void writeRun( RunMessage message ) { try { - packer.packStructHeader( 2, Run.SIGNATURE ); + packer.packStructHeader( 2, RunMessage.SIGNATURE ); packer.pack( message.statement() ); packer.pack( message.params() ); } @@ -130,7 +130,7 @@ private void writeDiscardAll() { try { - packer.packStructHeader( 0, DiscardAll.SIGNATURE ); + packer.packStructHeader( 0, DiscardAllMessage.SIGNATURE ); } catch ( IOException e ) { @@ -142,7 +142,7 @@ private void writePullAll() { try { - packer.packStructHeader( 0, PullAll.SIGNATURE ); + packer.packStructHeader( 0, PullAllMessage.SIGNATURE ); } catch ( IOException e ) { diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/BoltResponseMessage.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltResponseMessage.java similarity index 100% rename from community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/BoltResponseMessage.java rename to community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltResponseMessage.java diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageReader.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageReader.java index 94b509aeed627..f44b6693cd78e 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageReader.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageReader.java @@ -24,6 +24,11 @@ import org.neo4j.bolt.messaging.BoltIOException; import org.neo4j.bolt.messaging.Neo4jPack; import org.neo4j.bolt.runtime.Neo4jError; +import org.neo4j.bolt.messaging.BoltResponseMessageWriter; +import org.neo4j.bolt.v1.messaging.response.FailureMessage; +import org.neo4j.bolt.v1.messaging.response.IgnoredMessage; +import org.neo4j.bolt.v1.messaging.response.RecordMessage; +import org.neo4j.bolt.v1.messaging.response.SuccessMessage; import org.neo4j.bolt.v1.packstream.PackStream; import org.neo4j.kernel.api.exceptions.Status; import org.neo4j.values.AnyValue; @@ -41,7 +46,7 @@ public BoltResponseMessageReader( Neo4jPack.Unpacker unpacker ) this.unpacker = unpacker; } - public void read( BoltResponseMessageHandler handler ) throws IOException + public void read( BoltResponseMessageWriter messageWriter ) throws IOException { try { @@ -54,7 +59,7 @@ public void read( BoltResponseMessageHandler handler ) throws IOException { case SUCCESS: MapValue successMetadata = unpacker.unpackMap(); - handler.onSuccess( successMetadata ); + messageWriter.write( new SuccessMessage( successMetadata ) ); break; case RECORD: long length = unpacker.unpackListHeader(); @@ -63,10 +68,10 @@ public void read( BoltResponseMessageHandler handler ) throws IOException { fields[i] = unpacker.unpack(); } - handler.onRecord( record( fields ) ); + messageWriter.write( new RecordMessage( record( fields ) ) ); break; case IGNORED: - handler.onIgnored(); + messageWriter.write( IgnoredMessage.IGNORED_MESSAGE ); break; case FAILURE: MapValue failureMetadata = unpacker.unpackMap(); @@ -76,7 +81,7 @@ public void read( BoltResponseMessageHandler handler ) throws IOException String msg = failureMetadata.containsKey( "message" ) ? ((StringValue) failureMetadata.get( "message" )).stringValue() : ""; - handler.onFailure( Neo4jError.codeFromString( code ), msg ); + messageWriter.write( new FailureMessage( Neo4jError.codeFromString( code ), msg ) ); break; default: throw new BoltIOException( Status.Request.InvalidFormat, diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageRecorder.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageRecorder.java index 6400fbb0a1691..341ddddd9840a 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageRecorder.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageRecorder.java @@ -19,48 +19,25 @@ */ package org.neo4j.bolt.v1.messaging; +import java.io.IOException; import java.util.ArrayList; import java.util.List; -import org.neo4j.bolt.v1.messaging.message.FailureMessage; -import org.neo4j.bolt.v1.messaging.message.IgnoredMessage; -import org.neo4j.bolt.v1.messaging.message.RecordMessage; -import org.neo4j.bolt.v1.messaging.message.ResponseMessage; -import org.neo4j.bolt.v1.messaging.message.SuccessMessage; -import org.neo4j.cypher.result.QueryResult; -import org.neo4j.kernel.api.exceptions.Status; -import org.neo4j.values.virtual.MapValue; +import org.neo4j.bolt.messaging.ResponseMessage; +import org.neo4j.bolt.messaging.BoltResponseMessageWriter; -public class BoltResponseMessageRecorder implements BoltResponseMessageHandler +public class BoltResponseMessageRecorder implements BoltResponseMessageWriter { private final List messages = new ArrayList<>(); - @Override - public void onSuccess( MapValue metadata ) - { - messages.add( new SuccessMessage( metadata ) ); - } - - @Override - public void onRecord( QueryResult.Record item ) - { - messages.add( new RecordMessage( item ) ); - } - - @Override - public void onIgnored() + public List asList() { - messages.add( new IgnoredMessage() ); + return messages; } @Override - public void onFailure( Status status, String errorMessage ) - { - messages.add( new FailureMessage( status, errorMessage ) ); - } - - public List asList() + public void write( ResponseMessage message ) throws IOException { - return messages; + messages.add( message ); } } diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageTest.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageTest.java index f802fd4ff0846..c74c3f46b1612 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageTest.java @@ -28,11 +28,10 @@ import org.neo4j.bolt.logging.NullBoltMessageLogger; import org.neo4j.bolt.messaging.Neo4jPack; -import org.neo4j.bolt.v1.messaging.message.FailureMessage; -import org.neo4j.bolt.v1.messaging.message.IgnoredMessage; -import org.neo4j.bolt.v1.messaging.message.RecordMessage; -import org.neo4j.bolt.v1.messaging.message.ResponseMessage; -import org.neo4j.bolt.v1.messaging.message.SuccessMessage; +import org.neo4j.bolt.messaging.ResponseMessage; +import org.neo4j.bolt.v1.messaging.response.FailureMessage; +import org.neo4j.bolt.v1.messaging.response.RecordMessage; +import org.neo4j.bolt.v1.messaging.response.SuccessMessage; import org.neo4j.bolt.v1.packstream.BufferedChannelInput; import org.neo4j.bolt.v1.packstream.BufferedChannelOutput; import org.neo4j.kernel.api.exceptions.Status; @@ -56,6 +55,7 @@ import static org.neo4j.bolt.v1.messaging.example.Paths.PATH_WITH_NODES_VISITED_MULTIPLE_TIMES; import static org.neo4j.bolt.v1.messaging.example.Paths.PATH_WITH_RELATIONSHIP_TRAVERSED_AGAINST_ITS_DIRECTION; import static org.neo4j.bolt.v1.messaging.example.Paths.PATH_WITH_RELATIONSHIP_TRAVERSED_MULTIPLE_TIMES_IN_SAME_DIRECTION; +import static org.neo4j.bolt.v1.messaging.response.IgnoredMessage.IGNORED_MESSAGE; import static org.neo4j.bolt.v1.messaging.util.MessageMatchers.serialize; import static org.neo4j.bolt.v1.runtime.spi.Records.record; import static org.neo4j.helpers.collection.MapUtil.map; @@ -79,7 +79,7 @@ public void shouldHandleCommonMessages() throws Throwable assertSerializes( new RecordMessage( record( longValue( 1L ), stringValue( "b" ), longValue( 2L ) ) ) ); assertSerializes( new SuccessMessage( VirtualValues.EMPTY_MAP ) ); assertSerializes( new FailureMessage( Status.General.UnknownError, "Err" ) ); - assertSerializes( new IgnoredMessage() ); + assertSerializes( IGNORED_MESSAGE ); } @Test @@ -231,10 +231,10 @@ private T serializeAndDeserialize( T msg ) throws IO BoltResponseMessageReader reader = new BoltResponseMessageReader( neo4jPack.newUnpacker( new BufferedChannelInput( 16 ).reset( channel ) ) ); BufferedChannelOutput output = new BufferedChannelOutput( channel ); - BoltResponseMessageWriter writer = new BoltResponseMessageWriter( neo4jPack::newPacker, output, + BoltResponseMessageWriterV1 writer = new BoltResponseMessageWriterV1( neo4jPack::newPacker, output, NullLogService.getInstance(), NullBoltMessageLogger.getInstance() ); - msg.dispatch( writer ); + writer.write( msg ); writer.flush(); channel.eof(); diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageWriterTest.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageWriterV1Test.java similarity index 79% rename from community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageWriterTest.java rename to community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageWriterV1Test.java index 1680326a452ca..6d031a8283ad4 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageWriterTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageWriterV1Test.java @@ -26,6 +26,10 @@ import org.neo4j.bolt.logging.NullBoltMessageLogger; import org.neo4j.bolt.messaging.Neo4jPack; +import org.neo4j.bolt.v1.messaging.response.FailureMessage; +import org.neo4j.bolt.v1.messaging.response.IgnoredMessage; +import org.neo4j.bolt.v1.messaging.response.RecordMessage; +import org.neo4j.bolt.v1.messaging.response.SuccessMessage; import org.neo4j.bolt.v1.packstream.PackOutput; import org.neo4j.kernel.api.exceptions.Status; import org.neo4j.kernel.impl.logging.NullLogService; @@ -46,7 +50,7 @@ import static org.neo4j.values.storable.Values.stringValue; import static org.neo4j.values.virtual.VirtualValues.map; -public class BoltResponseMessageWriterTest +public class BoltResponseMessageWriterV1Test { @Test public void shouldWriteRecordMessage() throws Exception @@ -54,9 +58,9 @@ public void shouldWriteRecordMessage() throws Exception PackOutput output = mock( PackOutput.class ); Neo4jPack.Packer packer = mock( Neo4jPack.Packer.class ); - BoltResponseMessageWriter writer = newWriter( output, packer ); + BoltResponseMessageWriterV1 writer = newWriter( output, packer ); - writer.onRecord( () -> new AnyValue[]{longValue( 42 ), stringValue( "42" )} ); + writer.write( new RecordMessage( () -> new AnyValue[]{longValue( 42 ), stringValue( "42" )} ) ); InOrder inOrder = inOrder( output, packer ); inOrder.verify( output ).beginMessage(); @@ -71,10 +75,10 @@ public void shouldWriteSuccessMessage() throws Exception PackOutput output = mock( PackOutput.class ); Neo4jPack.Packer packer = mock( Neo4jPack.Packer.class ); - BoltResponseMessageWriter writer = newWriter( output, packer ); + BoltResponseMessageWriterV1 writer = newWriter( output, packer ); MapValue metadata = map( new String[]{"a", "b", "c"}, new AnyValue[]{intValue( 1 ), stringValue( "2" ), date( 2010, 02, 02 )} ); - writer.onSuccess( metadata ); + writer.write( new SuccessMessage( metadata ) ); InOrder inOrder = inOrder( output, packer ); inOrder.verify( output ).beginMessage(); @@ -88,11 +92,11 @@ public void shouldWriteFailureMessage() throws Exception PackOutput output = mock( PackOutput.class ); Neo4jPack.Packer packer = mock( Neo4jPack.Packer.class ); - BoltResponseMessageWriter writer = newWriter( output, packer ); + BoltResponseMessageWriterV1 writer = newWriter( output, packer ); Status.Transaction errorStatus = Status.Transaction.DeadlockDetected; String errorMessage = "Hi Deadlock!"; - writer.onFailure( errorStatus, errorMessage ); + writer.write( new FailureMessage( errorStatus, errorMessage ) ); InOrder inOrder = inOrder( output, packer ); inOrder.verify( output ).beginMessage(); @@ -107,9 +111,9 @@ public void shouldWriteIgnoredMessage() throws Exception PackOutput output = mock( PackOutput.class ); Neo4jPack.Packer packer = mock( Neo4jPack.Packer.class ); - BoltResponseMessageWriter writer = newWriter( output, packer ); + BoltResponseMessageWriterV1 writer = newWriter( output, packer ); - writer.onIgnored(); + writer.write( IgnoredMessage.IGNORED_MESSAGE ); InOrder inOrder = inOrder( output, packer ); inOrder.verify( output ).beginMessage(); @@ -123,7 +127,7 @@ public void shouldFlush() throws Exception PackOutput output = mock( PackOutput.class ); Neo4jPack.Packer packer = mock( Neo4jPack.Packer.class ); - BoltResponseMessageWriter writer = newWriter( output, packer ); + BoltResponseMessageWriterV1 writer = newWriter( output, packer ); writer.flush(); @@ -138,11 +142,11 @@ public void shouldNotifyOutputAboutFailedRecordMessage() throws Exception IOException error = new IOException( "Unable to pack 42" ); doThrow( error ).when( packer ).pack( longValue( 42 ) ); - BoltResponseMessageWriter writer = newWriter( output, packer ); + BoltResponseMessageWriterV1 writer = newWriter( output, packer ); try { - writer.onRecord( () -> new AnyValue[]{stringValue( "42" ), longValue( 42 )} ); + writer.write( new RecordMessage( () -> new AnyValue[]{stringValue( "42" ), longValue( 42 )} ) ); fail( "Exception expected" ); } catch ( IOException e ) @@ -165,11 +169,11 @@ public void shouldNotNotifyOutputWhenOutputItselfFails() throws Exception IOException error = new IOException( "Unable to flush" ); doThrow( error ).when( output ).messageSucceeded(); - BoltResponseMessageWriter writer = newWriter( output, packer ); + BoltResponseMessageWriterV1 writer = newWriter( output, packer ); try { - writer.onRecord( () -> new AnyValue[]{longValue( 1 ), longValue( 2 )} ); + writer.write( new RecordMessage( () -> new AnyValue[]{longValue( 1 ), longValue( 2 )} ) ); fail( "Exception expected" ); } catch ( IOException e ) @@ -186,8 +190,8 @@ public void shouldNotNotifyOutputWhenOutputItselfFails() throws Exception verify( output, never() ).messageFailed(); } - private static BoltResponseMessageWriter newWriter( PackOutput output, Neo4jPack.Packer packer ) + private static BoltResponseMessageWriterV1 newWriter( PackOutput output, Neo4jPack.Packer packer ) { - return new BoltResponseMessageWriter( out -> packer, output, NullLogService.getInstance(), NullBoltMessageLogger.getInstance() ); + return new BoltResponseMessageWriterV1( out -> packer, output, NullLogService.getInstance(), NullBoltMessageLogger.getInstance() ); } } diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/MessageProcessingHandlerTest.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/MessageProcessingHandlerTest.java index 0f62e062ba490..f7c6593a8f2a7 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/MessageProcessingHandlerTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/MessageProcessingHandlerTest.java @@ -23,18 +23,18 @@ import org.neo4j.bolt.runtime.BoltConnection; import org.neo4j.bolt.runtime.Neo4jError; +import org.neo4j.bolt.messaging.BoltResponseMessageWriter; +import org.neo4j.bolt.v1.messaging.response.SuccessMessage; import org.neo4j.bolt.v1.packstream.PackOutputClosedException; import org.neo4j.graphdb.TransactionTerminatedException; import org.neo4j.kernel.api.exceptions.Status; import org.neo4j.logging.AssertableLogProvider; import org.neo4j.logging.Log; -import org.neo4j.values.virtual.MapValue; import static org.hamcrest.Matchers.both; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.startsWith; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -47,13 +47,13 @@ public class MessageProcessingHandlerTest public void shouldCallHaltOnUnexpectedFailures() throws Exception { // Given - BoltResponseMessageHandler msgHandler = newResponseHandlerMock(); - doThrow( new RuntimeException( "Something went horribly wrong" ) ).when( msgHandler ).onSuccess( - any( MapValue.class ) ); + BoltResponseMessageWriter msgWriter = newResponseHandlerMock(); + doThrow( new RuntimeException( "Something went horribly wrong" ) ).when( msgWriter ).write( + any( SuccessMessage.class ) ); BoltConnection connection = mock( BoltConnection.class ); MessageProcessingHandler handler = - new MessageProcessingHandler( msgHandler, connection, mock( Log.class ) ); + new MessageProcessingHandler( msgWriter, connection, mock( Log.class ) ); // When handler.onFinish(); @@ -132,7 +132,7 @@ private static AssertableLogProvider emulateFailureWritingError( Neo4jError erro throws Exception { AssertableLogProvider logProvider = new AssertableLogProvider(); - BoltResponseMessageHandler responseHandler = newResponseHandlerMock( error.isFatal(), errorDuringWrite ); + BoltResponseMessageWriter responseHandler = newResponseHandlerMock( error.isFatal(), errorDuringWrite ); MessageProcessingHandler handler = new MessageProcessingHandler( responseHandler, mock( BoltConnection.class ), @@ -144,23 +144,17 @@ private static AssertableLogProvider emulateFailureWritingError( Neo4jError erro return logProvider; } - private static BoltResponseMessageHandler newResponseHandlerMock( boolean fatalError, Throwable error ) throws Exception + private static BoltResponseMessageWriter newResponseHandlerMock( boolean fatalError, Throwable error ) throws Exception { - BoltResponseMessageHandler handler = newResponseHandlerMock(); - if ( fatalError ) - { - doThrow( error ).when( handler ).onFatal( any( Status.class ), anyString() ); - } - else - { - doThrow( error ).when( handler ).onFailure( any( Status.class ), anyString() ); - } + BoltResponseMessageWriter handler = newResponseHandlerMock(); + + doThrow( error ).when( handler ).write( any( org.neo4j.bolt.v1.messaging.response.FailureMessage.class ) ); return handler; } @SuppressWarnings( "unchecked" ) - private static BoltResponseMessageHandler newResponseHandlerMock() + private static BoltResponseMessageWriter newResponseHandlerMock() { - return mock( BoltResponseMessageHandler.class ); + return mock( BoltResponseMessageWriter.class ); } } diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/ResultHandlerTest.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/ResultHandlerTest.java index e29a97e21d931..22b4cc3fbb6b3 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/ResultHandlerTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/ResultHandlerTest.java @@ -21,16 +21,21 @@ import org.junit.jupiter.api.Test; +import java.util.List; + +import org.neo4j.bolt.messaging.ResponseMessage; import org.neo4j.bolt.runtime.BoltConnection; import org.neo4j.bolt.runtime.BoltResult; +import org.neo4j.bolt.v1.messaging.response.RecordMessage; +import org.neo4j.bolt.v1.messaging.response.SuccessMessage; import org.neo4j.bolt.v1.runtime.spi.ImmutableRecord; import org.neo4j.cypher.result.QueryResult.Record; import org.neo4j.logging.NullLog; -import static org.mockito.ArgumentMatchers.any; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.instanceOf; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; import static org.neo4j.values.storable.Values.values; class ResultHandlerTest @@ -38,8 +43,8 @@ class ResultHandlerTest @Test void shouldPullTheResult() throws Exception { - BoltResponseMessageHandler responseMessageHandler = mock( BoltResponseMessageHandler.class ); - ResultHandler handler = new ResultHandler( responseMessageHandler, mock( BoltConnection.class ), NullLog.getInstance() ); + BoltResponseMessageRecorder messageWriter = new BoltResponseMessageRecorder(); + ResultHandler handler = new ResultHandler( messageWriter, mock( BoltConnection.class ), NullLog.getInstance() ); ImmutableRecord record1 = new ImmutableRecord( values( "a", "b", "c" ) ); ImmutableRecord record2 = new ImmutableRecord( values( "1", "2", "3" ) ); @@ -48,16 +53,18 @@ void shouldPullTheResult() throws Exception handler.onRecords( result, true ); handler.onFinish(); - verify( responseMessageHandler ).onRecord( record1 ); - verify( responseMessageHandler ).onRecord( record2 ); - verify( responseMessageHandler ).onSuccess( any() ); + List messages = messageWriter.asList(); + assertThat( messages.size(), equalTo( 3 ) ); + assertThat( messages.get( 0 ), equalTo( new RecordMessage( record1 ) ) ); + assertThat( messages.get( 1 ), equalTo( new RecordMessage( record2 ) ) ); + assertThat( messages.get( 2 ), instanceOf( SuccessMessage.class ) ); } @Test void shouldDiscardTheResult() throws Exception { - BoltResponseMessageHandler responseMessageHandler = mock( BoltResponseMessageHandler.class ); - ResultHandler handler = new ResultHandler( responseMessageHandler, mock( BoltConnection.class ), NullLog.getInstance() ); + BoltResponseMessageRecorder messageWriter = new BoltResponseMessageRecorder(); + ResultHandler handler = new ResultHandler( messageWriter, mock( BoltConnection.class ), NullLog.getInstance() ); ImmutableRecord record1 = new ImmutableRecord( values( "a", "b", "c" ) ); ImmutableRecord record2 = new ImmutableRecord( values( "1", "2", "3" ) ); @@ -66,8 +73,9 @@ void shouldDiscardTheResult() throws Exception handler.onRecords( result, false ); handler.onFinish(); - verify( responseMessageHandler, never() ).onRecord( any() ); - verify( responseMessageHandler ).onSuccess( any() ); + List messages = messageWriter.asList(); + assertThat( messages.size(), equalTo( 1 ) ); + assertThat( messages.get( 0 ), instanceOf( SuccessMessage.class ) ); } private static class TestBoltResult implements BoltResult diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/AckFailureDecoderTest.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/AckFailureMessageDecoderTest.java similarity index 84% rename from community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/AckFailureDecoderTest.java rename to community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/AckFailureMessageDecoderTest.java index e641bfc0aedba..974253af9d790 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/AckFailureDecoderTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/AckFailureMessageDecoderTest.java @@ -25,21 +25,21 @@ import org.neo4j.bolt.messaging.Neo4jPack.Unpacker; import org.neo4j.bolt.messaging.RequestMessageDecoder; import org.neo4j.bolt.runtime.BoltResponseHandler; -import org.neo4j.bolt.v1.messaging.message.AckFailure; +import org.neo4j.bolt.v1.messaging.request.AckFailureMessage; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; -class AckFailureDecoderTest +class AckFailureMessageDecoderTest { private final BoltResponseHandler responseHandler = mock( BoltResponseHandler.class ); private final BoltMessageLogger messageLogger = mock( BoltMessageLogger.class ); - private final RequestMessageDecoder decoder = new AckFailureDecoder( responseHandler, messageLogger ); + private final RequestMessageDecoder decoder = new AckFailureMessageDecoder( responseHandler, messageLogger ); @Test void shouldReturnCorrectSignature() { - assertEquals( AckFailure.SIGNATURE, decoder.signature() ); + assertEquals( AckFailureMessage.SIGNATURE, decoder.signature() ); } @Test @@ -51,6 +51,6 @@ void shouldReturnConnectResponseHandler() @Test void shouldDecodeAckFailure() throws Exception { - assertEquals( AckFailure.INSTANCE, decoder.decode( mock( Unpacker.class ) ) ); + assertEquals( AckFailureMessage.INSTANCE, decoder.decode( mock( Unpacker.class ) ) ); } } diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/DiscardAllDecoderTest.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/DiscardAllMessageDecoderTest.java similarity index 84% rename from community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/DiscardAllDecoderTest.java rename to community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/DiscardAllMessageDecoderTest.java index 2f686f437ec4f..001aa0353dc36 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/DiscardAllDecoderTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/DiscardAllMessageDecoderTest.java @@ -25,21 +25,21 @@ import org.neo4j.bolt.messaging.Neo4jPack.Unpacker; import org.neo4j.bolt.messaging.RequestMessageDecoder; import org.neo4j.bolt.runtime.BoltResponseHandler; -import org.neo4j.bolt.v1.messaging.message.DiscardAll; +import org.neo4j.bolt.v1.messaging.request.DiscardAllMessage; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; -class DiscardAllDecoderTest +class DiscardAllMessageDecoderTest { private final BoltResponseHandler responseHandler = mock( BoltResponseHandler.class ); private final BoltMessageLogger messageLogger = mock( BoltMessageLogger.class ); - private final RequestMessageDecoder decoder = new DiscardAllDecoder( responseHandler, messageLogger ); + private final RequestMessageDecoder decoder = new DiscardAllMessageDecoder( responseHandler, messageLogger ); @Test void shouldReturnCorrectSignature() { - assertEquals( DiscardAll.SIGNATURE, decoder.signature() ); + assertEquals( DiscardAllMessage.SIGNATURE, decoder.signature() ); } @Test @@ -51,6 +51,6 @@ void shouldReturnConnectResponseHandler() @Test void shouldDecodeAckFailure() throws Exception { - assertEquals( DiscardAll.INSTANCE, decoder.decode( mock( Unpacker.class ) ) ); + assertEquals( DiscardAllMessage.INSTANCE, decoder.decode( mock( Unpacker.class ) ) ); } } diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/InitDecoderTest.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/InitMessageDecoderTest.java similarity index 86% rename from community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/InitDecoderTest.java rename to community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/InitMessageDecoderTest.java index fdfe04e47074c..3d7a646549362 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/InitDecoderTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/InitMessageDecoderTest.java @@ -27,7 +27,7 @@ import org.neo4j.bolt.messaging.RequestMessageDecoder; import org.neo4j.bolt.runtime.BoltResponseHandler; import org.neo4j.bolt.v1.messaging.Neo4jPackV1; -import org.neo4j.bolt.v1.messaging.message.Init; +import org.neo4j.bolt.v1.messaging.request.InitMessage; import org.neo4j.bolt.v1.packstream.PackedInputArray; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -35,16 +35,16 @@ import static org.neo4j.bolt.v1.messaging.util.MessageMatchers.serialize; import static org.neo4j.helpers.collection.MapUtil.map; -class InitDecoderTest +class InitMessageDecoderTest { private final BoltResponseHandler responseHandler = mock( BoltResponseHandler.class ); private final BoltMessageLogger messageLogger = mock( BoltMessageLogger.class ); - private final RequestMessageDecoder decoder = new InitDecoder( responseHandler, messageLogger ); + private final RequestMessageDecoder decoder = new InitMessageDecoder( responseHandler, messageLogger ); @Test void shouldReturnCorrectSignature() { - assertEquals( Init.SIGNATURE, decoder.signature() ); + assertEquals( InitMessage.SIGNATURE, decoder.signature() ); } @Test @@ -57,7 +57,7 @@ void shouldReturnConnectResponseHandler() void shouldDecodeAckFailure() throws Exception { Neo4jPackV1 neo4jPack = new Neo4jPackV1(); - Init originalMessage = new Init( "My Driver", map( "user", "neo4j", "password", "secret" ) ); + InitMessage originalMessage = new InitMessage( "My Driver", map( "user", "neo4j", "password", "secret" ) ); PackedInputArray innput = new PackedInputArray( serialize( neo4jPack, originalMessage ) ); Unpacker unpacker = neo4jPack.newUnpacker( innput ); diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/PullAllDecoderTest.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/PullAllMessageDecoderTest.java similarity index 81% rename from community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/PullAllDecoderTest.java rename to community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/PullAllMessageDecoderTest.java index ee07edb232c56..d93965fd1ee0d 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/PullAllDecoderTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/PullAllMessageDecoderTest.java @@ -25,21 +25,21 @@ import org.neo4j.bolt.messaging.Neo4jPack.Unpacker; import org.neo4j.bolt.messaging.RequestMessageDecoder; import org.neo4j.bolt.runtime.BoltResponseHandler; -import org.neo4j.bolt.v1.messaging.message.PullAll; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; -class PullAllDecoderTest +class PullAllMessageDecoderTest { private final BoltResponseHandler responseHandler = mock( BoltResponseHandler.class ); private final BoltMessageLogger messageLogger = mock( BoltMessageLogger.class ); - private final RequestMessageDecoder decoder = new PullAllDecoder( responseHandler, messageLogger ); + private final RequestMessageDecoder decoder = new PullAllMessageDecoder( responseHandler, messageLogger ); @Test void shouldReturnCorrectSignature() { - assertEquals( PullAll.SIGNATURE, decoder.signature() ); + assertEquals( PullAllMessage.SIGNATURE, decoder.signature() ); } @Test @@ -51,6 +51,6 @@ void shouldReturnConnectResponseHandler() @Test void shouldDecodeAckFailure() throws Exception { - assertEquals( PullAll.INSTANCE, decoder.decode( mock( Unpacker.class ) ) ); + assertEquals( PullAllMessage.INSTANCE, decoder.decode( mock( Unpacker.class ) ) ); } } diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/ResetDecoderTest.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/ResetMessageDecoderTest.java similarity index 85% rename from community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/ResetDecoderTest.java rename to community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/ResetMessageDecoderTest.java index d59bf57ff4c2c..c5eceddaa9fa4 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/ResetDecoderTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/ResetMessageDecoderTest.java @@ -27,23 +27,23 @@ import org.neo4j.bolt.messaging.RequestMessageDecoder; import org.neo4j.bolt.runtime.BoltConnection; import org.neo4j.bolt.runtime.BoltResponseHandler; -import org.neo4j.bolt.v1.messaging.message.Reset; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -class ResetDecoderTest +class ResetMessageDecoderTest { private final BoltResponseHandler responseHandler = mock( BoltResponseHandler.class ); private final BoltMessageLogger messageLogger = mock( BoltMessageLogger.class ); private final BoltConnection connection = mock( BoltConnection.class ); - private final RequestMessageDecoder decoder = new ResetDecoder( connection, responseHandler, messageLogger ); + private final RequestMessageDecoder decoder = new ResetMessageDecoder( connection, responseHandler, messageLogger ); @Test void shouldReturnCorrectSignature() { - assertEquals( Reset.SIGNATURE, decoder.signature() ); + assertEquals( ResetMessage.SIGNATURE, decoder.signature() ); } @Test @@ -56,7 +56,7 @@ void shouldReturnConnectResponseHandler() void shouldDecodeAckFailure() throws Exception { RequestMessage message = decoder.decode( mock( Unpacker.class ) ); - assertEquals( Reset.INSTANCE, message ); + assertEquals( ResetMessage.INSTANCE, message ); verify( connection ).interrupt(); } } diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/RunDecoderTest.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/RunMessageDecoderTest.java similarity index 85% rename from community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/RunDecoderTest.java rename to community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/RunMessageDecoderTest.java index 141e3503d5983..86e1c478c46af 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/RunDecoderTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/decoder/RunMessageDecoderTest.java @@ -27,7 +27,7 @@ import org.neo4j.bolt.messaging.RequestMessageDecoder; import org.neo4j.bolt.runtime.BoltResponseHandler; import org.neo4j.bolt.v1.messaging.Neo4jPackV1; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.bolt.v1.packstream.PackedInputArray; import org.neo4j.values.AnyValue; @@ -37,16 +37,16 @@ import static org.neo4j.values.storable.Values.longValue; import static org.neo4j.values.virtual.VirtualValues.map; -class RunDecoderTest +class RunMessageDecoderTest { private final BoltResponseHandler responseHandler = mock( BoltResponseHandler.class ); private final BoltMessageLogger messageLogger = mock( BoltMessageLogger.class ); - private final RequestMessageDecoder decoder = new RunDecoder( responseHandler, messageLogger ); + private final RequestMessageDecoder decoder = new RunMessageDecoder( responseHandler, messageLogger ); @Test void shouldReturnCorrectSignature() { - assertEquals( Run.SIGNATURE, decoder.signature() ); + assertEquals( RunMessage.SIGNATURE, decoder.signature() ); } @Test @@ -59,7 +59,7 @@ void shouldReturnConnectResponseHandler() void shouldDecodeAckFailure() throws Exception { Neo4jPackV1 neo4jPack = new Neo4jPackV1(); - Run originalMessage = new Run( "UNWIND range(1, 10) AS x RETURN x, $y", map( new String[]{"y"}, new AnyValue[]{longValue( 42 )} ) ); + RunMessage originalMessage = new RunMessage( "UNWIND range(1, 10) AS x RETURN x, $y", map( new String[]{"y"}, new AnyValue[]{longValue( 42 )} ) ); PackedInputArray innput = new PackedInputArray( serialize( neo4jPack, originalMessage ) ); Unpacker unpacker = neo4jPack.newUnpacker( innput ); diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/util/MessageMatchers.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/util/MessageMatchers.java index 6a35955c20d20..89ee18ec83acc 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/util/MessageMatchers.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/util/MessageMatchers.java @@ -38,13 +38,13 @@ import org.neo4j.bolt.v1.messaging.BoltRequestMessageWriter; import org.neo4j.bolt.v1.messaging.BoltResponseMessageReader; import org.neo4j.bolt.v1.messaging.BoltResponseMessageRecorder; -import org.neo4j.bolt.v1.messaging.BoltResponseMessageWriter; +import org.neo4j.bolt.v1.messaging.BoltResponseMessageWriterV1; import org.neo4j.bolt.v1.messaging.RecordingByteChannel; -import org.neo4j.bolt.v1.messaging.message.FailureMessage; -import org.neo4j.bolt.v1.messaging.message.IgnoredMessage; -import org.neo4j.bolt.v1.messaging.message.RecordMessage; -import org.neo4j.bolt.v1.messaging.message.ResponseMessage; -import org.neo4j.bolt.v1.messaging.message.SuccessMessage; +import org.neo4j.bolt.v1.messaging.response.FailureMessage; +import org.neo4j.bolt.v1.messaging.response.IgnoredMessage; +import org.neo4j.bolt.v1.messaging.response.RecordMessage; +import org.neo4j.bolt.messaging.ResponseMessage; +import org.neo4j.bolt.v1.messaging.response.SuccessMessage; import org.neo4j.bolt.v1.packstream.BufferedChannelInput; import org.neo4j.bolt.v1.packstream.BufferedChannelOutput; import org.neo4j.bolt.v1.transport.integration.TestNotification; @@ -309,12 +309,12 @@ public static byte[] serialize( Neo4jPack neo4jPack, ResponseMessage... messages { RecordingByteChannel rawData = new RecordingByteChannel(); BufferedChannelOutput output = new BufferedChannelOutput( rawData ); - BoltResponseMessageWriter writer = new BoltResponseMessageWriter( neo4jPack::newPacker, output, + BoltResponseMessageWriterV1 writer = new BoltResponseMessageWriterV1( neo4jPack::newPacker, output, NullLogService.getInstance(), NullBoltMessageLogger.getInstance() ); for ( ResponseMessage message : messages ) { - message.dispatch( writer ); + writer.write( message ); } writer.flush(); diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/BoltStateMachineTest.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/BoltStateMachineTest.java index 0ab5d04b050c1..19ac3da12a208 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/BoltStateMachineTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/BoltStateMachineTest.java @@ -35,12 +35,12 @@ import org.neo4j.bolt.runtime.Neo4jError; import org.neo4j.bolt.runtime.TransactionStateMachineSPI; import org.neo4j.bolt.testing.BoltResponseRecorder; -import org.neo4j.bolt.v1.messaging.message.AckFailure; -import org.neo4j.bolt.v1.messaging.message.DiscardAll; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Reset; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.AckFailureMessage; +import org.neo4j.bolt.v1.messaging.request.DiscardAllMessage; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.function.ThrowingBiConsumer; import org.neo4j.graphdb.TransactionFailureException; import org.neo4j.graphdb.security.AuthorizationExpiredException; @@ -87,11 +87,11 @@ public class BoltStateMachineTest @Test public void allStateTransitionsShouldSendExactlyOneResponseToTheClient() throws Exception { - List messages = Arrays.asList( new Init( USER_AGENT, emptyMap() ), - AckFailure.INSTANCE, - Reset.INSTANCE, - new Run( "RETURN 1", EMPTY_PARAMS ), - DiscardAll.INSTANCE, PullAll.INSTANCE ); + List messages = Arrays.asList( new InitMessage( USER_AGENT, emptyMap() ), + AckFailureMessage.INSTANCE, + ResetMessage.INSTANCE, + new RunMessage( "RETURN 1", EMPTY_PARAMS ), + DiscardAllMessage.INSTANCE, PullAllMessage.INSTANCE ); for ( RequestMessage message: messages ) { @@ -113,7 +113,7 @@ public void shouldRollbackOpenTransactionOnReset() throws Throwable machine.markFailed( Neo4jError.from( new RuntimeException() ) ); // When RESET occurs - machine.process( Reset.INSTANCE, nullResponseHandler() ); + machine.process( ResetMessage.INSTANCE, nullResponseHandler() ); // Then the transaction should have been rolled back... assertThat( machine, hasNoTransaction() ); @@ -156,7 +156,7 @@ public void shouldResetWithOpenTransactionAndOpenResult() throws Throwable final BoltStateMachine machine = newMachineWithTransaction(); // ...and an open result - machine.process( new Run( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); // Then assertThat( machine, canReset() ); @@ -169,7 +169,7 @@ public void shouldResetWithOpenResult() throws Throwable final BoltStateMachine machine = init( newMachine() ); // ...and an open result - machine.process( new Run( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); // Then assertThat( machine, canReset() ); @@ -183,7 +183,7 @@ public void shouldFailWhenOutOfOrderRollback() throws Throwable machine.markFailed( Neo4jError.from( new RuntimeException() ) ); // When - machine.process( new Run( "ROLLBACK", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( new RunMessage( "ROLLBACK", EMPTY_PARAMS ), nullResponseHandler() ); // Then assertThat( machine, inState( FailedState.class ) ); @@ -197,7 +197,7 @@ public void shouldGoBackToReadyAfterAckFailure() throws Throwable machine.markFailed( Neo4jError.from( new RuntimeException() ) ); // When - machine.process( AckFailure.INSTANCE, nullResponseHandler() ); + machine.process( AckFailureMessage.INSTANCE, nullResponseHandler() ); // Then assertThat( machine, inState( ReadyState.class ) ); @@ -213,7 +213,7 @@ public void shouldNotRollbackOpenTransactionOnAckFailure() throws Throwable machine.markFailed( Neo4jError.from( new RuntimeException() ) ); // When the failure is acknowledged - machine.process( AckFailure.INSTANCE, nullResponseHandler() ); + machine.process( AckFailureMessage.INSTANCE, nullResponseHandler() ); // Then the transaction should still be open assertThat( machine, hasTransaction() ); @@ -231,7 +231,7 @@ public void shouldRemainStoppedAfterInterrupted() throws Throwable // When and interrupt and reset occurs machine.interrupt(); - machine.process( Reset.INSTANCE, nullResponseHandler() ); + machine.process( ResetMessage.INSTANCE, nullResponseHandler() ); // Then the machine should remain closed assertThat( machine, isClosed() ); @@ -248,9 +248,9 @@ public void shouldBeAbleToKillMessagesAheadInLineWithAnInterrupt() throws Throwa // ...and BoltResponseRecorder recorder = new BoltResponseRecorder(); - machine.process( new Run( "RETURN 1", EMPTY_PARAMS ), recorder ); - machine.process( Reset.INSTANCE, recorder ); - machine.process( new Run( "RETURN 1", EMPTY_PARAMS ), recorder ); + machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), recorder ); + machine.process( ResetMessage.INSTANCE, recorder ); + machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), recorder ); // Then assertThat( recorder.nextResponse(), wasIgnored() ); @@ -270,9 +270,9 @@ public void multipleInterruptsShouldBeMatchedWithMultipleResets() throws Throwab // ...and BoltResponseRecorder recorder = new BoltResponseRecorder(); - machine.process( new Run( "RETURN 1", EMPTY_PARAMS ), recorder ); - machine.process( Reset.INSTANCE, recorder ); - machine.process( new Run( "RETURN 1", EMPTY_PARAMS ), recorder ); + machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), recorder ); + machine.process( ResetMessage.INSTANCE, recorder ); + machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), recorder ); // Then assertThat( recorder.nextResponse(), wasIgnored() ); @@ -281,8 +281,8 @@ public void multipleInterruptsShouldBeMatchedWithMultipleResets() throws Throwab // But when recorder.reset(); - machine.process( Reset.INSTANCE, recorder ); - machine.process( new Run( "RETURN 1", EMPTY_PARAMS ), recorder ); + machine.process( ResetMessage.INSTANCE, recorder ); + machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), recorder ); // Then assertThat( recorder.nextResponse(), succeeded() ); @@ -296,7 +296,7 @@ public void testPublishingError() throws Throwable BoltStateMachine machine = init( newMachine() ); // ...and a result ready to be retrieved... - machine.process( new Run( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); // ...and a handler guaranteed to break BoltResponseRecorder recorder = new BoltResponseRecorder() @@ -309,7 +309,7 @@ public void onRecords( BoltResult result, boolean pull ) }; // When we pull using that handler - machine.process( PullAll.INSTANCE, recorder ); + machine.process( PullAllMessage.INSTANCE, recorder ); // Then the breakage should surface as a FAILURE assertThat( recorder.nextResponse(), failedWithStatus( Status.General.UnknownError ) ); @@ -325,8 +325,8 @@ public void testRollbackError() throws Throwable BoltStateMachine machine = init( newMachine() ); // Given there is a running transaction - machine.process( new Run( "BEGIN", EMPTY_PARAMS ), nullResponseHandler() ); - machine.process( DiscardAll.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "BEGIN", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); // And given that transaction will fail to roll back TransactionStateMachine txMachine = txStateMachine( machine ); @@ -335,8 +335,8 @@ public void testRollbackError() throws Throwable when( txMachine.ctx.currentTransaction ).close(); // When - machine.process( new Run( "ROLLBACK", EMPTY_PARAMS ), nullResponseHandler() ); - machine.process( DiscardAll.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "ROLLBACK", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); // Then assertThat( machine, inState( FailedState.class ) ); @@ -349,12 +349,12 @@ public void testFailOnNestedTransactions() throws Throwable BoltStateMachine machine = init( newMachine() ); // Given there is a running transaction - machine.process( new Run( "BEGIN", EMPTY_PARAMS ), nullResponseHandler() ); - machine.process( DiscardAll.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "BEGIN", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); // When - machine.process( new Run( "BEGIN", EMPTY_PARAMS ), nullResponseHandler() ); - machine.process( DiscardAll.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "BEGIN", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); // Then assertThat( machine, inState( FailedState.class ) ); @@ -368,13 +368,13 @@ public void testCantDoAnythingIfInFailedState() throws Throwable machine.markFailed( Neo4jError.from( new RuntimeException() ) ); // Then no RUN... - machine.process( new Run( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); assertThat( machine, inState( FailedState.class ) ); // ...DISCARD_ALL... - machine.process( DiscardAll.INSTANCE, nullResponseHandler() ); + machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); assertThat( machine, inState( FailedState.class ) ); // ...or PULL_ALL should be possible - machine.process( PullAll.INSTANCE, nullResponseHandler() ); + machine.process( PullAllMessage.INSTANCE, nullResponseHandler() ); assertThat( machine, inState( FailedState.class ) ); } @@ -389,13 +389,13 @@ public void testUsingResetToAcknowledgeError() throws Throwable machine.markFailed( Neo4jError.from( new RuntimeException() ) ); // When I RESET... - machine.process( Reset.INSTANCE, recorder ); + machine.process( ResetMessage.INSTANCE, recorder ); // ...successfully assertThat( recorder.nextResponse(), succeeded() ); // Then if I RUN a statement... - machine.process( new Run( "RETURN 1", EMPTY_PARAMS ), recorder ); + machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), recorder ); // ...everything should be fine again assertThat( recorder.nextResponse(), succeeded() ); @@ -410,7 +410,7 @@ public void actionsDisallowedBeforeInitialized() // When try { - machine.process( new Run( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); fail( "Failed to fail fatally" ); } @@ -434,7 +434,7 @@ public void shouldTerminateOnAuthExpiryDuringREADYRun() throws Throwable // When & Then try { - machine.process( new Run( "THIS WILL BE IGNORED", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( new RunMessage( "THIS WILL BE IGNORED", EMPTY_PARAMS ), nullResponseHandler() ); fail( "Exception expected" ); } catch ( BoltConnectionAuthFatality e ) @@ -452,14 +452,14 @@ public void shouldTerminateOnAuthExpiryDuringSTREAMINGPullAll() throws Throwable doThrow( new AuthorizationExpiredException( "Auth expired!" ) ).when( responseHandler ) .onRecords( any(), anyBoolean() ); BoltStateMachine machine = init( newMachine() ); - machine.process( new Run( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); // move to streaming state + machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); // move to streaming state // We assume the only implementation of statement processor is TransactionStateMachine txStateMachine( machine ).ctx.currentResult = BoltResult.EMPTY; // When & Then try { - machine.process( PullAll.INSTANCE, responseHandler ); + machine.process( PullAllMessage.INSTANCE, responseHandler ); fail( "Exception expected" ); } catch ( BoltConnectionAuthFatality e ) @@ -477,14 +477,14 @@ public void shouldTerminateOnAuthExpiryDuringSTREAMINGDiscardAll() throws Throwa doThrow( new AuthorizationExpiredException( "Auth expired!" ) ).when( responseHandler ) .onRecords( any(), anyBoolean() ); BoltStateMachine machine = init( newMachine() ); - machine.process( new Run( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); // move to streaming state + machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); // move to streaming state // We assume the only implementation of statement processor is TransactionStateMachine txStateMachine( machine ).ctx.currentResult = BoltResult.EMPTY; // When & Then try { - machine.process( DiscardAll.INSTANCE, responseHandler ); + machine.process( DiscardAllMessage.INSTANCE, responseHandler ); fail( "Exception expected" ); } catch ( BoltConnectionAuthFatality e ) @@ -558,25 +558,25 @@ public void shouldSetPendingErrorOnMarkFailedIfNoHandler() @Test public void shouldInvokeResponseHandlerOnNextInitMessageOnMarkFailedIfNoHandler() throws Exception { - testMarkFailedOnNextMessage( ( machine, handler ) -> machine.process( new Init( "Test/1.0", emptyMap() ), handler ) ); + testMarkFailedOnNextMessage( ( machine, handler ) -> machine.process( new InitMessage( "Test/1.0", emptyMap() ), handler ) ); } @Test public void shouldInvokeResponseHandlerOnNextRunMessageOnMarkFailedIfNoHandler() throws Exception { - testMarkFailedOnNextMessage( ( machine, handler ) -> machine.process( new Run( "RETURN 1", VirtualValues.EMPTY_MAP ), handler ) ); + testMarkFailedOnNextMessage( ( machine, handler ) -> machine.process( new RunMessage( "RETURN 1", VirtualValues.EMPTY_MAP ), handler ) ); } @Test public void shouldInvokeResponseHandlerOnNextPullAllMessageOnMarkFailedIfNoHandler() throws Exception { - testMarkFailedOnNextMessage( ( machine, handler ) -> machine.process( PullAll.INSTANCE, handler ) ); + testMarkFailedOnNextMessage( ( machine, handler ) -> machine.process( PullAllMessage.INSTANCE, handler ) ); } @Test public void shouldInvokeResponseHandlerOnNextDiscardAllMessageOnMarkFailedIfNoHandler() throws Exception { - testMarkFailedOnNextMessage( ( machine, handler ) -> machine.process( DiscardAll.INSTANCE, handler ) ); + testMarkFailedOnNextMessage( ( machine, handler ) -> machine.process( DiscardAllMessage.INSTANCE, handler ) ); } @Test @@ -590,7 +590,7 @@ public void shouldInvokeResponseHandlerOnNextResetMessageOnMarkFailedIfNoHandler machine.markFailed( error ); // When - machine.process( Reset.INSTANCE, responseHandler ); + machine.process( ResetMessage.INSTANCE, responseHandler ); // Expect assertNull( pendingError( machine ) ); @@ -611,7 +611,7 @@ public void shouldGotoReadyStateOnNextAckFailureMessageOnMarkFailedIfNoHandler() machine.markFailed( error ); // When - machine.process( AckFailure.INSTANCE, responseHandler ); + machine.process( AckFailureMessage.INSTANCE, responseHandler ); // Expect assertNull( pendingError( machine ) ); @@ -645,26 +645,26 @@ public void shouldSetPendingIgnoreOnMarkFailedIfAlreadyFailedAndNoHandler() thro @Test public void shouldInvokeResponseHandlerOnNextInitMessageOnMarkFailedIfAlreadyFailedAndNoHandler() throws Exception { - testMarkFailedShouldYieldIgnoredIfAlreadyFailed( ( machine, handler ) -> machine.process( new Init( "Test/1.0", emptyMap() ), handler ) ); + testMarkFailedShouldYieldIgnoredIfAlreadyFailed( ( machine, handler ) -> machine.process( new InitMessage( "Test/1.0", emptyMap() ), handler ) ); } @Test public void shouldInvokeResponseHandlerOnNextRunMessageOnMarkFailedIfAlreadyFailedAndNoHandler() throws Exception { testMarkFailedShouldYieldIgnoredIfAlreadyFailed( - ( machine, handler ) -> machine.process( new Run( "RETURN 1", VirtualValues.EMPTY_MAP ), handler ) ); + ( machine, handler ) -> machine.process( new RunMessage( "RETURN 1", VirtualValues.EMPTY_MAP ), handler ) ); } @Test public void shouldInvokeResponseHandlerOnNextPullAllMessageOnMarkFailedIfAlreadyFailedAndNoHandler() throws Exception { - testMarkFailedShouldYieldIgnoredIfAlreadyFailed( ( machine, handler ) -> machine.process( PullAll.INSTANCE, handler ) ); + testMarkFailedShouldYieldIgnoredIfAlreadyFailed( ( machine, handler ) -> machine.process( PullAllMessage.INSTANCE, handler ) ); } @Test public void shouldInvokeResponseHandlerOnNextDiscardAllMessageOnMarkFailedIfAlreadyFailedAndNoHandler() throws Exception { - testMarkFailedShouldYieldIgnoredIfAlreadyFailed( ( machine, handler ) -> machine.process( DiscardAll.INSTANCE, handler ) ); + testMarkFailedShouldYieldIgnoredIfAlreadyFailed( ( machine, handler ) -> machine.process( DiscardAllMessage.INSTANCE, handler ) ); } @Test @@ -679,7 +679,7 @@ public void shouldInvokeResponseHandlerOnNextResetMessageOnMarkFailedIfAlreadyFa machine.markFailed( error ); // When - machine.process( Reset.INSTANCE, responseHandler ); + machine.process( ResetMessage.INSTANCE, responseHandler ); // Expect assertNull( pendingError( machine ) ); @@ -701,7 +701,7 @@ public void shouldInvokeResponseHandlerOnNextAckFailureMessageOnMarkFailedIfAlre machine.markFailed( error ); // When - machine.process( AckFailure.INSTANCE, responseHandler ); + machine.process( AckFailureMessage.INSTANCE, responseHandler ); // Expect assertNull( pendingError( machine ) ); @@ -739,13 +739,13 @@ public void shouldNotFailWhenTerminatedAndPullAll() throws Exception { BoltStateMachineV1SPI spi = mock( BoltStateMachineV1SPI.class, RETURNS_MOCKS ); BoltStateMachine machine = init( newMachine( spi ) ); - machine.process( new Run( "RETURN 42", EMPTY_PARAMS ), nullResponseHandler() ); // move to streaming state + machine.process( new RunMessage( "RETURN 42", EMPTY_PARAMS ), nullResponseHandler() ); // move to streaming state txStateMachine( machine ).ctx.currentResult = BoltResult.EMPTY; BoltResponseHandler responseHandler = mock( BoltResponseHandler.class ); machine.terminate(); - machine.process( PullAll.INSTANCE, responseHandler ); + machine.process( PullAllMessage.INSTANCE, responseHandler ); verify( spi, never() ).reportError( any() ); assertThat( machine, not( inState( FailedState.class ) ) ); diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/ConnectedStateTest.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/ConnectedStateTest.java index 332af7fad2e3a..5c0b82b5a98ba 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/ConnectedStateTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/ConnectedStateTest.java @@ -31,13 +31,13 @@ import org.neo4j.bolt.runtime.MutableConnectionState; import org.neo4j.bolt.runtime.StateMachineContext; import org.neo4j.bolt.security.auth.AuthenticationResult; -import org.neo4j.bolt.v1.messaging.message.AckFailure; -import org.neo4j.bolt.v1.messaging.message.DiscardAll; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.Interrupt; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Reset; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.AckFailureMessage; +import org.neo4j.bolt.v1.messaging.request.DiscardAllMessage; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.InterruptSignal; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import static java.util.Arrays.asList; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -60,7 +60,7 @@ class ConnectedStateTest { private static final String USER_AGENT = "Driver 2.0"; private static final Map AUTH_TOKEN = map( PRINCIPAL, "neo4j", CREDENTIALS, "password" ); - private static final Init INIT_MESSAGE = new Init( USER_AGENT, AUTH_TOKEN ); + private static final InitMessage INIT_MESSAGE = new InitMessage( USER_AGENT, AUTH_TOKEN ); private final ConnectedState state = new ConnectedState(); @@ -181,8 +181,8 @@ void shouldHandleFailuresOnInitMessage() throws Exception @Test void shouldNotProcessUnsupportedMessage() throws Exception { - List unsupportedMessages = asList( AckFailure.INSTANCE, DiscardAll.INSTANCE, Interrupt.INSTANCE, - PullAll.INSTANCE, Reset.INSTANCE, new Run( "RETURN 1", EMPTY_MAP ) ); + List unsupportedMessages = asList( AckFailureMessage.INSTANCE, DiscardAllMessage.INSTANCE, InterruptSignal.INSTANCE, + PullAllMessage.INSTANCE, ResetMessage.INSTANCE, new RunMessage( "RETURN 1", EMPTY_MAP ) ); for ( RequestMessage message: unsupportedMessages ) { diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/FailedStateTest.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/FailedStateTest.java index cbfacd1ffadd8..e89f667e678ff 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/FailedStateTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/FailedStateTest.java @@ -27,12 +27,12 @@ import org.neo4j.bolt.runtime.MutableConnectionState; import org.neo4j.bolt.runtime.Neo4jError; import org.neo4j.bolt.runtime.StateMachineContext; -import org.neo4j.bolt.v1.messaging.message.AckFailure; -import org.neo4j.bolt.v1.messaging.message.DiscardAll; -import org.neo4j.bolt.v1.messaging.message.Interrupt; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Reset; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.AckFailureMessage; +import org.neo4j.bolt.v1.messaging.request.DiscardAllMessage; +import org.neo4j.bolt.v1.messaging.request.InterruptSignal; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -67,20 +67,20 @@ void shouldThrowWhenNotInitialized() throws Exception { FailedState state = new FailedState(); - assertThrows( IllegalStateException.class, () -> state.process( AckFailure.INSTANCE, context ) ); + assertThrows( IllegalStateException.class, () -> state.process( AckFailureMessage.INSTANCE, context ) ); state.setReadyState( readyState ); - assertThrows( IllegalStateException.class, () -> state.process( AckFailure.INSTANCE, context ) ); + assertThrows( IllegalStateException.class, () -> state.process( AckFailureMessage.INSTANCE, context ) ); state.setReadyState( null ); state.setInterruptedState( interruptedState ); - assertThrows( IllegalStateException.class, () -> state.process( AckFailure.INSTANCE, context ) ); + assertThrows( IllegalStateException.class, () -> state.process( AckFailureMessage.INSTANCE, context ) ); } @Test void shouldProcessRunMessage() throws Exception { - BoltStateMachineState newState = state.process( new Run( "RETURN 1", EMPTY_MAP ), context ); + BoltStateMachineState newState = state.process( new RunMessage( "RETURN 1", EMPTY_MAP ), context ); assertEquals( state, newState ); // remains in failed state assertTrue( connectionState.hasPendingIgnore() ); @@ -89,7 +89,7 @@ void shouldProcessRunMessage() throws Exception @Test void shouldProcessPullAllMessage() throws Exception { - BoltStateMachineState newState = state.process( PullAll.INSTANCE, context ); + BoltStateMachineState newState = state.process( PullAllMessage.INSTANCE, context ); assertEquals( state, newState ); // remains in failed state assertTrue( connectionState.hasPendingIgnore() ); @@ -98,7 +98,7 @@ void shouldProcessPullAllMessage() throws Exception @Test void shouldProcessDiscardAllMessage() throws Exception { - BoltStateMachineState newState = state.process( DiscardAll.INSTANCE, context ); + BoltStateMachineState newState = state.process( DiscardAllMessage.INSTANCE, context ); assertEquals( state, newState ); // remains in failed state assertTrue( connectionState.hasPendingIgnore() ); @@ -110,7 +110,7 @@ void shouldProcessAckFailureMessageWithPendingIgnore() throws Exception connectionState.markIgnored(); assertTrue( connectionState.hasPendingIgnore() ); - BoltStateMachineState newState = state.process( AckFailure.INSTANCE, context ); + BoltStateMachineState newState = state.process( AckFailureMessage.INSTANCE, context ); assertEquals( readyState, newState ); assertFalse( connectionState.hasPendingIgnore() ); @@ -123,7 +123,7 @@ void shouldProcessAckFailureMessageWithPendingError() throws Exception connectionState.markFailed( error ); assertEquals( error, connectionState.getPendingError() ); - BoltStateMachineState newState = state.process( AckFailure.INSTANCE, context ); + BoltStateMachineState newState = state.process( AckFailureMessage.INSTANCE, context ); assertEquals( readyState, newState ); assertNull( connectionState.getPendingError() ); @@ -136,7 +136,7 @@ void shouldProcessResetMessageWithPerndingIgnore() throws Exception connectionState.markIgnored(); assertTrue( connectionState.hasPendingIgnore() ); - BoltStateMachineState newState = state.process( Reset.INSTANCE, context ); + BoltStateMachineState newState = state.process( ResetMessage.INSTANCE, context ); assertEquals( readyState, newState ); assertFalse( connectionState.hasPendingIgnore() ); @@ -150,7 +150,7 @@ void shouldProcessResetMessageWithPerndingError() throws Exception connectionState.markFailed( error ); assertEquals( error, connectionState.getPendingError() ); - BoltStateMachineState newState = state.process( Reset.INSTANCE, context ); + BoltStateMachineState newState = state.process( ResetMessage.INSTANCE, context ); assertEquals( readyState, newState ); assertNull( connectionState.getPendingError() ); @@ -161,7 +161,7 @@ void shouldHandleResetMessageFailure() throws Exception { when( context.resetMachine() ).thenReturn( false ); // reset failed - BoltStateMachineState newState = state.process( Reset.INSTANCE, context ); + BoltStateMachineState newState = state.process( ResetMessage.INSTANCE, context ); assertEquals( state, newState ); // remains in failed state } @@ -169,7 +169,7 @@ void shouldHandleResetMessageFailure() throws Exception @Test void shouldProcessInterruptMessage() throws Exception { - BoltStateMachineState newState = state.process( Interrupt.INSTANCE, context ); + BoltStateMachineState newState = state.process( InterruptSignal.INSTANCE, context ); assertEquals( interruptedState, newState ); } diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/InterruptedStateTest.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/InterruptedStateTest.java index 7b13195e1def5..facc1ae3d5341 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/InterruptedStateTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/InterruptedStateTest.java @@ -28,13 +28,13 @@ import org.neo4j.bolt.runtime.BoltStateMachineState; import org.neo4j.bolt.runtime.MutableConnectionState; import org.neo4j.bolt.runtime.StateMachineContext; -import org.neo4j.bolt.v1.messaging.message.AckFailure; -import org.neo4j.bolt.v1.messaging.message.DiscardAll; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.Interrupt; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Reset; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.AckFailureMessage; +import org.neo4j.bolt.v1.messaging.request.DiscardAllMessage; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.InterruptSignal; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import static java.util.Arrays.asList; import static java.util.Collections.emptyMap; @@ -70,20 +70,20 @@ void shouldThrowWhenNotInitialized() throws Exception { InterruptedState state = new InterruptedState(); - assertThrows( IllegalStateException.class, () -> state.process( Reset.INSTANCE, context ) ); + assertThrows( IllegalStateException.class, () -> state.process( ResetMessage.INSTANCE, context ) ); state.setReadyState( readyState ); - assertThrows( IllegalStateException.class, () -> state.process( Reset.INSTANCE, context ) ); + assertThrows( IllegalStateException.class, () -> state.process( ResetMessage.INSTANCE, context ) ); state.setReadyState( null ); state.setFailedState( failedState ); - assertThrows( IllegalStateException.class, () -> state.process( Reset.INSTANCE, context ) ); + assertThrows( IllegalStateException.class, () -> state.process( ResetMessage.INSTANCE, context ) ); } @Test void shouldProcessInterruptMessage() throws Exception { - BoltStateMachineState newState = state.process( Interrupt.INSTANCE, context ); + BoltStateMachineState newState = state.process( InterruptSignal.INSTANCE, context ); assertEquals( state, newState ); // remains in interrupted state } @@ -96,7 +96,7 @@ void shouldProcessResetMessageWhenInterrupted() throws Exception assertTrue( connectionState.isInterrupted() ); assertFalse( connectionState.hasPendingIgnore() ); - BoltStateMachineState newState = state.process( Reset.INSTANCE, context ); + BoltStateMachineState newState = state.process( ResetMessage.INSTANCE, context ); assertEquals( state, newState ); // remains in interrupted state assertTrue( connectionState.hasPendingIgnore() ); @@ -106,7 +106,7 @@ void shouldProcessResetMessageWhenInterrupted() throws Exception void shouldProcessResetMessage() throws Exception { when( context.resetMachine() ).thenReturn( true ); // reset successful - BoltStateMachineState newState = state.process( Reset.INSTANCE, context ); + BoltStateMachineState newState = state.process( ResetMessage.INSTANCE, context ); assertEquals( readyState, newState ); } @@ -115,7 +115,7 @@ void shouldProcessResetMessage() throws Exception void shouldHandleFailureDuringResetMessageProcessing() throws Exception { when( context.resetMachine() ).thenReturn( false ); // reset failed - BoltStateMachineState newState = state.process( Reset.INSTANCE, context ); + BoltStateMachineState newState = state.process( ResetMessage.INSTANCE, context ); assertEquals( failedState, newState ); } @@ -123,8 +123,8 @@ void shouldHandleFailureDuringResetMessageProcessing() throws Exception @Test void shouldIgnoreMessagesOtherThanInterruptAndReset() throws Exception { - List messages = asList( AckFailure.INSTANCE, PullAll.INSTANCE, DiscardAll.INSTANCE, - new Run( "RETURN 1", EMPTY_MAP ), new Init( "Driver", emptyMap() ) ); + List messages = asList( AckFailureMessage.INSTANCE, PullAllMessage.INSTANCE, DiscardAllMessage.INSTANCE, + new RunMessage( "RETURN 1", EMPTY_MAP ), new InitMessage( "Driver", emptyMap() ) ); for ( RequestMessage message: messages ) { diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/MachineRoom.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/MachineRoom.java index 03923fdc758bb..4e690f2c252d1 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/MachineRoom.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/MachineRoom.java @@ -27,9 +27,9 @@ import org.neo4j.bolt.runtime.BoltStateMachineSPI; import org.neo4j.bolt.runtime.TransactionStateMachineSPI; import org.neo4j.bolt.security.auth.AuthenticationException; -import org.neo4j.bolt.v1.messaging.message.DiscardAll; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.DiscardAllMessage; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.kernel.api.security.AuthToken; import org.neo4j.values.virtual.MapValue; import org.neo4j.values.virtual.VirtualValues; @@ -93,14 +93,14 @@ public static BoltStateMachine init( BoltStateMachine machine ) throws Authentic private static BoltStateMachine init( BoltStateMachine machine, String owner ) throws AuthenticationException, BoltConnectionFatality { - machine.process( new Init( USER_AGENT, owner == null ? emptyMap() : singletonMap( AuthToken.PRINCIPAL, owner ) ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, owner == null ? emptyMap() : singletonMap( AuthToken.PRINCIPAL, owner ) ), nullResponseHandler() ); return machine; } private static void runBegin( BoltStateMachine machine ) throws BoltConnectionFatality { - machine.process( new Run( "BEGIN", EMPTY_PARAMS ), nullResponseHandler() ); - machine.process( DiscardAll.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "BEGIN", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); assertThat( machine, hasTransaction() ); } diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/ReadyStateTest.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/ReadyStateTest.java index 164b6d986acfb..a48e7dd0e0c99 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/ReadyStateTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/ReadyStateTest.java @@ -32,12 +32,12 @@ import org.neo4j.bolt.runtime.StateMachineContext; import org.neo4j.bolt.runtime.StatementMetadata; import org.neo4j.bolt.runtime.StatementProcessor; -import org.neo4j.bolt.v1.messaging.message.AckFailure; -import org.neo4j.bolt.v1.messaging.message.DiscardAll; -import org.neo4j.bolt.v1.messaging.message.Interrupt; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Reset; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.AckFailureMessage; +import org.neo4j.bolt.v1.messaging.request.DiscardAllMessage; +import org.neo4j.bolt.v1.messaging.request.InterruptSignal; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.graphdb.security.AuthorizationExpiredException; import static java.util.Arrays.asList; @@ -79,18 +79,18 @@ void shouldThrowWhenNotInitialized() throws Exception { ReadyState state = new ReadyState(); - assertThrows( IllegalStateException.class, () -> state.process( PullAll.INSTANCE, context ) ); + assertThrows( IllegalStateException.class, () -> state.process( PullAllMessage.INSTANCE, context ) ); state.setStreamingState( streamingState ); - assertThrows( IllegalStateException.class, () -> state.process( PullAll.INSTANCE, context ) ); + assertThrows( IllegalStateException.class, () -> state.process( PullAllMessage.INSTANCE, context ) ); state.setStreamingState( null ); state.setInterruptedState( interruptedState ); - assertThrows( IllegalStateException.class, () -> state.process( PullAll.INSTANCE, context ) ); + assertThrows( IllegalStateException.class, () -> state.process( PullAllMessage.INSTANCE, context ) ); state.setInterruptedState( null ); state.setFailedState( failedState ); - assertThrows( IllegalStateException.class, () -> state.process( PullAll.INSTANCE, context ) ); + assertThrows( IllegalStateException.class, () -> state.process( PullAllMessage.INSTANCE, context ) ); } @Test @@ -105,7 +105,7 @@ void shouldProcessRunMessage() throws Exception BoltResponseHandler responseHandler = mock( BoltResponseHandler.class ); connectionState.setResponseHandler( responseHandler ); - BoltStateMachineState nextState = state.process( new Run( "RETURN 1", EMPTY_MAP ), context ); + BoltStateMachineState nextState = state.process( new RunMessage( "RETURN 1", EMPTY_MAP ), context ); assertEquals( streamingState, nextState ); verify( statementProcessor ).run( "RETURN 1", EMPTY_MAP ); @@ -122,7 +122,7 @@ void shouldHandleAuthFailureDuringRunMessageProcessing() throws Exception when( statementProcessor.run( any(), any() ) ).thenThrow( error ); connectionState.setStatementProcessor( statementProcessor ); - BoltStateMachineState nextState = state.process( new Run( "RETURN 1", EMPTY_MAP ), context ); + BoltStateMachineState nextState = state.process( new RunMessage( "RETURN 1", EMPTY_MAP ), context ); assertEquals( failedState, nextState ); verify( context ).handleFailure( error, true ); @@ -137,7 +137,7 @@ void shouldHandleFailureDuringRunMessageProcessing() throws Exception when( statementProcessor.run( any(), any() ) ).thenThrow( error ); connectionState.setStatementProcessor( statementProcessor ); - BoltStateMachineState nextState = state.process( new Run( "RETURN 1", EMPTY_MAP ), context ); + BoltStateMachineState nextState = state.process( new RunMessage( "RETURN 1", EMPTY_MAP ), context ); assertEquals( failedState, nextState ); verify( context ).handleFailure( error, false ); @@ -148,7 +148,7 @@ void shouldProcessResetMessage() throws Exception { when( context.resetMachine() ).thenReturn( true ); // reset successful - BoltStateMachineState newState = state.process( Reset.INSTANCE, context ); + BoltStateMachineState newState = state.process( ResetMessage.INSTANCE, context ); assertEquals( state, newState ); } @@ -158,7 +158,7 @@ void shouldHandleFailureDuringResetMessageProcessing() throws Exception { when( context.resetMachine() ).thenReturn( false ); // reset failed - BoltStateMachineState newState = state.process( Reset.INSTANCE, context ); + BoltStateMachineState newState = state.process( ResetMessage.INSTANCE, context ); assertEquals( failedState, newState ); } @@ -166,7 +166,7 @@ void shouldHandleFailureDuringResetMessageProcessing() throws Exception @Test void shouldProcessInterruptMessage() throws Exception { - BoltStateMachineState newState = state.process( Interrupt.INSTANCE, context ); + BoltStateMachineState newState = state.process( InterruptSignal.INSTANCE, context ); assertEquals( interruptedState, newState ); } @@ -174,7 +174,7 @@ void shouldProcessInterruptMessage() throws Exception @Test void shouldNotProcessUnsupportedMessages() throws Exception { - List unsupportedMessages = asList( PullAll.INSTANCE, DiscardAll.INSTANCE, AckFailure.INSTANCE ); + List unsupportedMessages = asList( PullAllMessage.INSTANCE, DiscardAllMessage.INSTANCE, AckFailureMessage.INSTANCE ); for ( RequestMessage message: unsupportedMessages ) { diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/ResetFuzzTest.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/ResetFuzzTest.java index 63cda948fd190..22dd41aef05e9 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/ResetFuzzTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/ResetFuzzTest.java @@ -49,11 +49,11 @@ import org.neo4j.bolt.testing.BoltResponseRecorder; import org.neo4j.bolt.testing.RecordedBoltResponse; import org.neo4j.bolt.transport.TransportThrottleGroup; -import org.neo4j.bolt.v1.messaging.message.DiscardAll; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Reset; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.DiscardAllMessage; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.helpers.collection.Iterables; import org.neo4j.kernel.configuration.BoltConnector; import org.neo4j.kernel.configuration.Config; @@ -104,9 +104,9 @@ public class ResetFuzzTest private BoltChannel boltChannel; private final List> sequences = asList( - asList( new Run( "test", EMPTY_MAP ), DiscardAll.INSTANCE ), - asList( new Run( "test", EMPTY_MAP ), PullAll.INSTANCE ), - singletonList( new Run( "test", EMPTY_MAP ) ) + asList( new RunMessage( "test", EMPTY_MAP ), DiscardAllMessage.INSTANCE ), + asList( new RunMessage( "test", EMPTY_MAP ), PullAllMessage.INSTANCE ), + singletonList( new RunMessage( "test", EMPTY_MAP ) ) ); private final List sent = new LinkedList<>(); @@ -125,7 +125,7 @@ public void shouldAlwaysReturnToReadyAfterReset() throws Throwable // given life.start(); BoltConnection boltConnection = connectionFactory.newConnection( boltChannel, machine ); - boltConnection.enqueue( machine -> machine.process( new Init( "ResetFuzzTest/0.0", emptyMap() ), nullResponseHandler() ) ); + boltConnection.enqueue( machine -> machine.process( new InitMessage( "ResetFuzzTest/0.0", emptyMap() ), nullResponseHandler() ) ); // Test random combinations of messages within a small budget of testing time. long deadline = System.currentTimeMillis() + 2 * 1000; @@ -141,7 +141,7 @@ public void shouldAlwaysReturnToReadyAfterReset() throws Throwable private void assertSchedulerWorks( BoltConnection connection ) throws InterruptedException { BoltResponseRecorder recorder = new BoltResponseRecorder(); - connection.enqueue( machine -> machine.process( Reset.INSTANCE, recorder ) ); + connection.enqueue( machine -> machine.process( ResetMessage.INSTANCE, recorder ) ); try { diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/StreamingStateTest.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/StreamingStateTest.java index 8e8459b124217..5937be4c05362 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/StreamingStateTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/StreamingStateTest.java @@ -29,13 +29,13 @@ import org.neo4j.bolt.runtime.MutableConnectionState; import org.neo4j.bolt.runtime.StateMachineContext; import org.neo4j.bolt.runtime.StatementProcessor; -import org.neo4j.bolt.v1.messaging.message.AckFailure; -import org.neo4j.bolt.v1.messaging.message.DiscardAll; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.Interrupt; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Reset; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.AckFailureMessage; +import org.neo4j.bolt.v1.messaging.request.DiscardAllMessage; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.InterruptSignal; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.graphdb.security.AuthorizationExpiredException; import static java.util.Arrays.asList; @@ -76,18 +76,18 @@ void shouldThrowWhenNotInitialized() throws Exception { StreamingState state = new StreamingState(); - assertThrows( IllegalStateException.class, () -> state.process( PullAll.INSTANCE, context ) ); + assertThrows( IllegalStateException.class, () -> state.process( PullAllMessage.INSTANCE, context ) ); state.setReadyState( readyState ); - assertThrows( IllegalStateException.class, () -> state.process( PullAll.INSTANCE, context ) ); + assertThrows( IllegalStateException.class, () -> state.process( PullAllMessage.INSTANCE, context ) ); state.setReadyState( null ); state.setInterruptedState( interruptedState ); - assertThrows( IllegalStateException.class, () -> state.process( PullAll.INSTANCE, context ) ); + assertThrows( IllegalStateException.class, () -> state.process( PullAllMessage.INSTANCE, context ) ); state.setInterruptedState( null ); state.setFailedState( failedState ); - assertThrows( IllegalStateException.class, () -> state.process( PullAll.INSTANCE, context ) ); + assertThrows( IllegalStateException.class, () -> state.process( PullAllMessage.INSTANCE, context ) ); } @Test @@ -96,7 +96,7 @@ void shouldProcessPullAllMessage() throws Exception StatementProcessor statementProcessor = mock( StatementProcessor.class ); connectionState.setStatementProcessor( statementProcessor ); - BoltStateMachineState nextState = state.process( PullAll.INSTANCE, context ); + BoltStateMachineState nextState = state.process( PullAllMessage.INSTANCE, context ); assertEquals( readyState, nextState ); verify( statementProcessor ).streamResult( any() ); @@ -111,7 +111,7 @@ void shouldHandleAuthErrorWhenProcessingPullAllMessage() throws Exception doThrow( error ).when( statementProcessor ).streamResult( any() ); connectionState.setStatementProcessor( statementProcessor ); - BoltStateMachineState nextState = state.process( PullAll.INSTANCE, context ); + BoltStateMachineState nextState = state.process( PullAllMessage.INSTANCE, context ); assertEquals( failedState, nextState ); verify( context ).handleFailure( error, true ); @@ -126,7 +126,7 @@ void shouldHandleErrorWhenProcessingPullAllMessage() throws Exception doThrow( error ).when( statementProcessor ).streamResult( any() ); connectionState.setStatementProcessor( statementProcessor ); - BoltStateMachineState nextState = state.process( PullAll.INSTANCE, context ); + BoltStateMachineState nextState = state.process( PullAllMessage.INSTANCE, context ); assertEquals( failedState, nextState ); verify( context ).handleFailure( error, false ); @@ -138,7 +138,7 @@ void shouldProcessDiscardAllMessage() throws Exception StatementProcessor statementProcessor = mock( StatementProcessor.class ); connectionState.setStatementProcessor( statementProcessor ); - BoltStateMachineState nextState = state.process( DiscardAll.INSTANCE, context ); + BoltStateMachineState nextState = state.process( DiscardAllMessage.INSTANCE, context ); assertEquals( readyState, nextState ); verify( statementProcessor ).streamResult( any() ); @@ -153,7 +153,7 @@ void shouldHandleAuthErrorWhenProcessingDiscardAllMessage() throws Exception doThrow( error ).when( statementProcessor ).streamResult( any() ); connectionState.setStatementProcessor( statementProcessor ); - BoltStateMachineState nextState = state.process( DiscardAll.INSTANCE, context ); + BoltStateMachineState nextState = state.process( DiscardAllMessage.INSTANCE, context ); assertEquals( failedState, nextState ); verify( context ).handleFailure( error, true ); @@ -168,7 +168,7 @@ void shouldHandleErrorWhenProcessingDiscardAllMessage() throws Exception doThrow( error ).when( statementProcessor ).streamResult( any() ); connectionState.setStatementProcessor( statementProcessor ); - BoltStateMachineState nextState = state.process( DiscardAll.INSTANCE, context ); + BoltStateMachineState nextState = state.process( DiscardAllMessage.INSTANCE, context ); assertEquals( failedState, nextState ); verify( context ).handleFailure( error, false ); @@ -179,7 +179,7 @@ void shouldProcessResetMessage() throws Exception { when( context.resetMachine() ).thenReturn( true ); // reset successful - BoltStateMachineState newState = state.process( Reset.INSTANCE, context ); + BoltStateMachineState newState = state.process( ResetMessage.INSTANCE, context ); assertEquals( readyState, newState ); } @@ -189,7 +189,7 @@ void shouldHandleResetMessageFailure() throws Exception { when( context.resetMachine() ).thenReturn( false ); // reset failed - BoltStateMachineState newState = state.process( Reset.INSTANCE, context ); + BoltStateMachineState newState = state.process( ResetMessage.INSTANCE, context ); assertEquals( failedState, newState ); } @@ -197,7 +197,7 @@ void shouldHandleResetMessageFailure() throws Exception @Test void shouldProcessInterruptMessage() throws Exception { - BoltStateMachineState newState = state.process( Interrupt.INSTANCE, context ); + BoltStateMachineState newState = state.process( InterruptSignal.INSTANCE, context ); assertEquals( interruptedState, newState ); } @@ -205,9 +205,10 @@ void shouldProcessInterruptMessage() throws Exception @Test void shouldNotProcessUnsupportedMessages() throws Exception { - List unsupportedMessages = asList( AckFailure.INSTANCE, new Run( "RETURN 1", EMPTY_MAP ), new Init( "Driver 2.5", emptyMap() ) ); + List unsupportedMessages = + asList( AckFailureMessage.INSTANCE, new RunMessage( "RETURN 1", EMPTY_MAP ), new InitMessage( "Driver 2.5", emptyMap() ) ); - for ( RequestMessage message: unsupportedMessages ) + for ( RequestMessage message : unsupportedMessages ) { assertNull( state.process( message, context ) ); } diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/TransportTestUtil.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/TransportTestUtil.java index 4fb29ce89def8..1d1bfda2c843d 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/TransportTestUtil.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/TransportTestUtil.java @@ -32,7 +32,7 @@ import org.neo4j.bolt.messaging.Neo4jPack; import org.neo4j.bolt.messaging.RequestMessage; -import org.neo4j.bolt.v1.messaging.message.ResponseMessage; +import org.neo4j.bolt.messaging.ResponseMessage; import org.neo4j.bolt.v1.transport.socket.client.TransportConnection; import org.neo4j.function.Predicates; diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/socket/FragmentedMessageDeliveryTest.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/socket/FragmentedMessageDeliveryTest.java index ae9c03c0ceb1a..73185d81c500a 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/socket/FragmentedMessageDeliveryTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/socket/FragmentedMessageDeliveryTest.java @@ -42,7 +42,7 @@ import org.neo4j.bolt.v1.messaging.BoltRequestMessageWriter; import org.neo4j.bolt.v1.messaging.Neo4jPackV1; import org.neo4j.bolt.v1.messaging.RecordingByteChannel; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.bolt.v1.packstream.BufferedChannelOutput; import org.neo4j.bolt.v2.messaging.Neo4jPackV2; import org.neo4j.kernel.impl.logging.NullLogService; @@ -81,7 +81,7 @@ public class FragmentedMessageDeliveryTest private int chunkSize = 16; // Only test one message for now. This can be parameterized later to test lots of different ones - private RequestMessage[] messages = new RequestMessage[]{new Run( "Mjölnir" )}; + private RequestMessage[] messages = new RequestMessage[]{new RunMessage( "Mjölnir" )}; @Parameter public Neo4jPack neo4jPack; @@ -151,7 +151,7 @@ private void testPermutation( byte[] unfragmented, ByteBuf[] fragments ) throws // Then the session should've received the specified messages, and the protocol should be in a nice clean state try { - RequestMessage run = new Run( "Mjölnir", EMPTY_MAP ); + RequestMessage run = new RunMessage( "Mjölnir", EMPTY_MAP ); verify( machine ).process( eq( run ), any( BoltResponseHandler.class ) ); } catch ( AssertionError e ) diff --git a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/runtime/integration/BoltSchedulerShouldReportFailureWhenBusyIT.java b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/runtime/integration/BoltSchedulerShouldReportFailureWhenBusyIT.java index beaf879940088..3f7ed6c01215d 100644 --- a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/runtime/integration/BoltSchedulerShouldReportFailureWhenBusyIT.java +++ b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/runtime/integration/BoltSchedulerShouldReportFailureWhenBusyIT.java @@ -34,9 +34,9 @@ import org.neo4j.bolt.AbstractBoltTransportsTest; import org.neo4j.bolt.runtime.BoltConnection; -import org.neo4j.bolt.v1.messaging.message.DiscardAll; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.DiscardAllMessage; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.bolt.v1.transport.integration.Neo4jWithSocket; import org.neo4j.bolt.v1.transport.socket.client.TransportConnection; import org.neo4j.graphdb.factory.GraphDatabaseSettings; @@ -119,7 +119,7 @@ public void shouldReportFailureWhenAllThreadsInThreadPoolAreBusy() throws Throwa { connection3 = connectAndPerformBoltHandshake( newConnection() ); - connection3.send( util.chunk( new Init( "TestClient/1.1", emptyMap() ) ) ); + connection3.send( util.chunk( new InitMessage( "TestClient/1.1", emptyMap() ) ) ); assertThat( connection3, util.eventuallyReceives( msgFailure( Status.Request.NoThreadsAvailable, "There are no available threads to serve this request at the moment" ) ) ); @@ -182,12 +182,12 @@ private void enterStreaming( TransportConnection connection, int sleepSeconds ) { connectAndPerformBoltHandshake( connection ); - connection.send( util.chunk( new Init( "TestClient/1.1", emptyMap() ) ) ); + connection.send( util.chunk( new InitMessage( "TestClient/1.1", emptyMap() ) ) ); assertThat( connection, util.eventuallyReceives( msgSuccess() ) ); SECONDS.sleep( sleepSeconds ); // sleep a bit to allow worker thread return back to the pool - connection.send( util.chunk( new Run( "UNWIND RANGE (1, 100) AS x RETURN x" ) ) ); + connection.send( util.chunk( new RunMessage( "UNWIND RANGE (1, 100) AS x RETURN x" ) ) ); assertThat( connection, util.eventuallyReceives( msgSuccess() ) ); } @@ -200,7 +200,7 @@ private TransportConnection connectAndPerformBoltHandshake( TransportConnection private void exitStreaming( TransportConnection connection ) throws Exception { - connection.send( util.chunk( DiscardAll.INSTANCE ) ); + connection.send( util.chunk( DiscardAllMessage.INSTANCE ) ); assertThat( connection, util.eventuallyReceives( msgSuccess() ) ); } diff --git a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/runtime/integration/BoltConfigIT.java b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/runtime/integration/BoltConfigIT.java index 91885db34a5fe..5f2cc72b429c7 100644 --- a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/runtime/integration/BoltConfigIT.java +++ b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/runtime/integration/BoltConfigIT.java @@ -23,7 +23,7 @@ import org.junit.Test; import org.neo4j.bolt.AbstractBoltTransportsTest; -import org.neo4j.bolt.v1.messaging.message.Init; +import org.neo4j.bolt.v1.messaging.request.InitMessage; import org.neo4j.bolt.v1.transport.integration.Neo4jWithSocket; import org.neo4j.bolt.v1.transport.socket.client.TransportConnection; import org.neo4j.helpers.HostnamePort; @@ -77,7 +77,7 @@ private void assertConnectionAccepted( HostnamePort address, TransportConnection { client.connect( address ) .send( util.defaultAcceptedVersions() ) - .send( util.chunk( new Init( "TestClient/1.1", emptyMap() ) ) ); + .send( util.chunk( new InitMessage( "TestClient/1.1", emptyMap() ) ) ); assertThat( client, util.eventuallyReceivesSelectedProtocolVersion() ); } } diff --git a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/runtime/integration/BoltConnectionAuthIT.java b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/runtime/integration/BoltConnectionAuthIT.java index 0e433308fccd8..fbbadd76bbdab 100644 --- a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/runtime/integration/BoltConnectionAuthIT.java +++ b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/runtime/integration/BoltConnectionAuthIT.java @@ -25,8 +25,8 @@ import org.neo4j.bolt.BoltChannel; import org.neo4j.bolt.runtime.BoltStateMachine; import org.neo4j.bolt.testing.BoltResponseRecorder; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.kernel.api.exceptions.Status; import org.neo4j.kernel.internal.Version; @@ -58,13 +58,13 @@ public void shouldGiveCredentialsExpiredStatusOnExpiredCredentials() throws Thro BoltResponseRecorder recorder = new BoltResponseRecorder(); // When - Init init = new Init( USER_AGENT, map( + InitMessage init = new InitMessage( USER_AGENT, map( "scheme", "basic", "principal", "neo4j", "credentials", "neo4j" ) ); machine.process( init, recorder ); - machine.process( new Run( "CREATE ()", EMPTY_MAP ), recorder ); + machine.process( new RunMessage( "CREATE ()", EMPTY_MAP ), recorder ); // Then assertThat( recorder.nextResponse(), succeededWithMetadata( "credentials_expired", TRUE ) ); @@ -81,13 +81,13 @@ public void shouldGiveKernelVersionOnInit() throws Throwable String version = "Neo4j/" + Version.getNeo4jVersion(); // When - Init init = new Init( USER_AGENT, map( + InitMessage init = new InitMessage( USER_AGENT, map( "scheme", "basic", "principal", "neo4j", "credentials", "neo4j" ) ); machine.process( init, recorder ); - machine.process( new Run( "CREATE ()", EMPTY_MAP ), recorder ); + machine.process( new RunMessage( "CREATE ()", EMPTY_MAP ), recorder ); // Then assertThat( recorder.nextResponse(), succeededWithMetadata( "server", stringValue( version ) ) ); @@ -100,7 +100,7 @@ public void shouldCloseConnectionAfterAuthenticationFailure() throws Throwable BoltStateMachine machine = env.newMachine( boltChannel ); // When... then - Init init = new Init( USER_AGENT, map( + InitMessage init = new InitMessage( USER_AGENT, map( "scheme", "basic", "principal", "neo4j", "credentials", "j4oen" ) ); @@ -118,13 +118,13 @@ public void shouldBeAbleToActOnSessionWhenUpdatingCredentials() throws Throwable BoltResponseRecorder recorder = new BoltResponseRecorder(); // when - Init message = new Init( USER_AGENT, map( + InitMessage message = new InitMessage( USER_AGENT, map( "scheme", "basic", "principal", "neo4j", "credentials", "neo4j", "new_credentials", "secret" ) ); machine.process( message, recorder ); - machine.process( new Run( "CREATE ()", EMPTY_MAP ), recorder ); + machine.process( new RunMessage( "CREATE ()", EMPTY_MAP ), recorder ); // then assertThat( recorder.nextResponse(), succeeded() ); diff --git a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/runtime/integration/BoltConnectionIT.java b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/runtime/integration/BoltConnectionIT.java index 129be3923be32..8c7b26697a068 100644 --- a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/runtime/integration/BoltConnectionIT.java +++ b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/runtime/integration/BoltConnectionIT.java @@ -35,12 +35,12 @@ import org.neo4j.bolt.testing.BoltResponseRecorder; import org.neo4j.bolt.testing.RecordedBoltResponse; import org.neo4j.bolt.v1.messaging.BoltResponseMessage; -import org.neo4j.bolt.v1.messaging.message.AckFailure; -import org.neo4j.bolt.v1.messaging.message.DiscardAll; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Reset; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.AckFailureMessage; +import org.neo4j.bolt.v1.messaging.request.DiscardAllMessage; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.bolt.v1.runtime.BoltStateMachineV1; import org.neo4j.cypher.result.QueryResult.Record; import org.neo4j.helpers.collection.MapUtil; @@ -84,7 +84,7 @@ public void shouldCloseConnectionAckFailureBeforeInit() throws Throwable // when BoltResponseRecorder recorder = new BoltResponseRecorder(); - verifyKillsConnection( () -> machine.process( AckFailure.INSTANCE, recorder ) ); + verifyKillsConnection( () -> machine.process( AckFailureMessage.INSTANCE, recorder ) ); // then assertThat( recorder.nextResponse(), failedWithStatus( Status.Request.Invalid ) ); @@ -98,7 +98,7 @@ public void shouldCloseConnectionResetBeforeInit() throws Throwable // when BoltResponseRecorder recorder = new BoltResponseRecorder(); - verifyKillsConnection( () -> machine.process( Reset.INSTANCE, recorder ) ); + verifyKillsConnection( () -> machine.process( ResetMessage.INSTANCE, recorder ) ); // then assertThat( recorder.nextResponse(), failedWithStatus( Status.Request.Invalid ) ); @@ -112,7 +112,7 @@ public void shouldCloseConnectionOnRunBeforeInit() throws Throwable // when BoltResponseRecorder recorder = new BoltResponseRecorder(); - verifyKillsConnection( () -> machine.process( new Run( "RETURN 1", map() ), recorder ) ); + verifyKillsConnection( () -> machine.process( new RunMessage( "RETURN 1", map() ), recorder ) ); // then assertThat( recorder.nextResponse(), failedWithStatus( Status.Request.Invalid ) ); @@ -126,7 +126,7 @@ public void shouldCloseConnectionOnDiscardAllBeforeInit() throws Throwable // when BoltResponseRecorder recorder = new BoltResponseRecorder(); - verifyKillsConnection( () -> machine.process( DiscardAll.INSTANCE, recorder ) ); + verifyKillsConnection( () -> machine.process( DiscardAllMessage.INSTANCE, recorder ) ); // then assertThat( recorder.nextResponse(), failedWithStatus( Status.Request.Invalid ) ); @@ -140,7 +140,7 @@ public void shouldCloseConnectionOnPullAllBeforeInit() throws Throwable // when BoltResponseRecorder recorder = new BoltResponseRecorder(); - verifyKillsConnection( () -> machine.process( PullAll.INSTANCE, recorder ) ); + verifyKillsConnection( () -> machine.process( PullAllMessage.INSTANCE, recorder ) ); // then assertThat( recorder.nextResponse(), failedWithStatus( Status.Request.Invalid ) ); @@ -151,18 +151,18 @@ public void shouldExecuteStatement() throws Throwable { // Given BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); // When BoltResponseRecorder recorder = new BoltResponseRecorder(); - machine.process( new Run( "CREATE (n {k:'k'}) RETURN n.k", EMPTY_PARAMS ), recorder ); + machine.process( new RunMessage( "CREATE (n {k:'k'}) RETURN n.k", EMPTY_PARAMS ), recorder ); // Then assertThat( recorder.nextResponse(), succeeded() ); // When recorder.reset(); - machine.process( PullAll.INSTANCE, recorder ); + machine.process( PullAllMessage.INSTANCE, recorder ); // Then recorder.nextResponse().assertRecord( 0, stringValue( "k" ) ); @@ -174,15 +174,15 @@ public void shouldSucceedOn__run__pullAll__run() throws Throwable { // Given BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); // And Given that I've ran and pulled one stream - machine.process( new Run( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); - machine.process( PullAll.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( PullAllMessage.INSTANCE, nullResponseHandler() ); // When I run a new statement BoltResponseRecorder recorder = new BoltResponseRecorder(); - machine.process( new Run( "RETURN 2", EMPTY_PARAMS ), recorder ); + machine.process( new RunMessage( "RETURN 2", EMPTY_PARAMS ), recorder ); // Then assertThat( recorder.nextResponse(), succeeded() ); @@ -193,15 +193,15 @@ public void shouldSucceedOn__run__discardAll__run() throws Throwable { // Given BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); // And Given that I've ran and pulled one stream - machine.process( new Run( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); - machine.process( DiscardAll.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); // When I run a new statement BoltResponseRecorder recorder = new BoltResponseRecorder(); - machine.process( new Run( "RETURN 2", EMPTY_PARAMS ), recorder ); + machine.process( new RunMessage( "RETURN 2", EMPTY_PARAMS ), recorder ); // Then assertThat( recorder.nextResponse(), succeeded() ); @@ -212,14 +212,14 @@ public void shouldSucceedOn__run_BEGIN__pullAll__run_COMMIT__pullALL__run_COMMIT { // Given BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); // And Given that I've ran and pulled one stream BoltResponseRecorder recorder = new BoltResponseRecorder(); - machine.process( new Run( "BEGIN", EMPTY_PARAMS ), recorder ); - machine.process( PullAll.INSTANCE, recorder ); - machine.process( new Run( "COMMIT", EMPTY_PARAMS ), recorder ); - machine.process( PullAll.INSTANCE, recorder ); + machine.process( new RunMessage( "BEGIN", EMPTY_PARAMS ), recorder ); + machine.process( PullAllMessage.INSTANCE, recorder ); + machine.process( new RunMessage( "COMMIT", EMPTY_PARAMS ), recorder ); + machine.process( PullAllMessage.INSTANCE, recorder ); assertThat( recorder.nextResponse(), succeeded() ); assertThat( recorder.nextResponse(), succeeded() ); assertThat( recorder.nextResponse(), succeeded() ); @@ -227,7 +227,7 @@ public void shouldSucceedOn__run_BEGIN__pullAll__run_COMMIT__pullALL__run_COMMIT // When I run a new statement recorder.reset(); - machine.process( new Run( "BEGIN", EMPTY_PARAMS ), recorder ); + machine.process( new RunMessage( "BEGIN", EMPTY_PARAMS ), recorder ); // Then assertThat( recorder.nextResponse(), succeeded() ); @@ -238,14 +238,14 @@ public void shouldFailOn__run__run() throws Throwable { // Given BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); // And Given that I've ran one statement - machine.process( new Run( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); // When I run a new statement, before consuming the stream BoltResponseRecorder recorder = new BoltResponseRecorder(); - verifyKillsConnection( () -> machine.process( new Run( "RETURN 1", EMPTY_PARAMS ), recorder ) ); + verifyKillsConnection( () -> machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), recorder ) ); // Then assertThat( recorder.nextResponse(), failedWithStatus( Status.Request.Invalid ) ); @@ -256,15 +256,15 @@ public void shouldFailOn__pullAll__pullAll() throws Throwable { // Given BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); // And Given that I've ran and pulled one stream - machine.process( new Run( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); - machine.process( PullAll.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( PullAllMessage.INSTANCE, nullResponseHandler() ); // Then further attempts to PULL should be treated as protocol violations BoltResponseRecorder recorder = new BoltResponseRecorder(); - verifyKillsConnection( () -> machine.process( PullAll.INSTANCE, recorder ) ); + verifyKillsConnection( () -> machine.process( PullAllMessage.INSTANCE, recorder ) ); // Then assertThat( recorder.nextResponse(), failedWithStatus( Status.Request.Invalid ) ); @@ -275,15 +275,15 @@ public void shouldFailOn__pullAll__discardAll() throws Throwable { // Given BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); // And Given that I've ran and pulled one stream - machine.process( new Run( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); - machine.process( PullAll.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( PullAllMessage.INSTANCE, nullResponseHandler() ); // When I attempt to pull more items from the stream BoltResponseRecorder recorder = new BoltResponseRecorder(); - verifyKillsConnection( () -> machine.process( DiscardAll.INSTANCE, recorder ) ); + verifyKillsConnection( () -> machine.process( DiscardAllMessage.INSTANCE, recorder ) ); // Then assertThat( recorder.nextResponse(), failedWithStatus( Status.Request.Invalid ) ); @@ -294,15 +294,15 @@ public void shouldFailOn__discardAll__discardAll() throws Throwable { // Given BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); // And Given that I've ran and pulled one stream - machine.process( new Run( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); - machine.process( DiscardAll.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); // When I attempt to pull more items from the stream BoltResponseRecorder recorder = new BoltResponseRecorder(); - verifyKillsConnection( () -> machine.process( DiscardAll.INSTANCE, recorder ) ); + verifyKillsConnection( () -> machine.process( DiscardAllMessage.INSTANCE, recorder ) ); // Then assertThat( recorder.nextResponse(), failedWithStatus( Status.Request.Invalid ) ); @@ -313,15 +313,15 @@ public void shouldFailOn__discardAll__pullAll() throws Throwable { // Given BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); // And Given that I've ran and pulled one stream - machine.process( new Run( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); - machine.process( DiscardAll.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); // When I attempt to pull more items from the stream BoltResponseRecorder recorder = new BoltResponseRecorder(); - verifyKillsConnection( () -> machine.process( PullAll.INSTANCE, recorder ) ); + verifyKillsConnection( () -> machine.process( PullAllMessage.INSTANCE, recorder ) ); // Then assertThat( recorder.nextResponse(), failedWithStatus( Status.Request.Invalid ) ); @@ -332,18 +332,18 @@ public void shouldHandleImplicitCommitFailure() throws Throwable { // Given BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); - machine.process( new Run( "CREATE (n:Victim)-[:REL]->()", EMPTY_PARAMS ), nullResponseHandler() ); - machine.process( DiscardAll.INSTANCE, nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new RunMessage( "CREATE (n:Victim)-[:REL]->()", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); // When I perform an action that will fail on commit BoltResponseRecorder recorder = new BoltResponseRecorder(); - machine.process( new Run( "MATCH (n:Victim) DELETE n", EMPTY_PARAMS ), recorder ); + machine.process( new RunMessage( "MATCH (n:Victim) DELETE n", EMPTY_PARAMS ), recorder ); // Then the statement running should have succeeded assertThat( recorder.nextResponse(), succeeded() ); recorder.reset(); - machine.process( DiscardAll.INSTANCE, recorder ); + machine.process( DiscardAllMessage.INSTANCE, recorder ); // But the stop should have failed, since it implicitly triggers commit and thus triggers a failure assertThat( recorder.nextResponse(), failedWithStatus( Status.Schema.ConstraintValidationFailed ) ); @@ -359,24 +359,24 @@ public void shouldAllowUserControlledRollbackOnExplicitTxFailure() throws Throwa // transaction, be they client-local or inside neo, can be handled the // same way by a driver. BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); - machine.process( new Run( "BEGIN", EMPTY_PARAMS ), nullResponseHandler() ); - machine.process( DiscardAll.INSTANCE, nullResponseHandler() ); - machine.process( new Run( "CREATE (n:Victim)-[:REL]->()", EMPTY_PARAMS ), nullResponseHandler() ); - machine.process( DiscardAll.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "BEGIN", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "CREATE (n:Victim)-[:REL]->()", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); // When I perform an action that will fail BoltResponseRecorder recorder = new BoltResponseRecorder(); - machine.process( new Run( "this is not valid syntax", EMPTY_PARAMS ), recorder ); + machine.process( new RunMessage( "this is not valid syntax", EMPTY_PARAMS ), recorder ); // Then I should see a failure assertThat( recorder.nextResponse(), failedWithStatus( Status.Statement.SyntaxError ) ); // And when I acknowledge that failure, and roll back the transaction recorder.reset(); - machine.process( AckFailure.INSTANCE, recorder ); - machine.process( new Run( "ROLLBACK", EMPTY_PARAMS ), recorder ); + machine.process( AckFailureMessage.INSTANCE, recorder ); + machine.process( new RunMessage( "ROLLBACK", EMPTY_PARAMS ), recorder ); // Then both operations should succeed assertThat( recorder.nextResponse(), succeeded() ); @@ -388,14 +388,14 @@ public void shouldHandleFailureDuringResultPublishing() throws Throwable { // Given BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); final CountDownLatch pullAllCallbackCalled = new CountDownLatch( 1 ); final AtomicReference error = new AtomicReference<>(); // When something fails while publishing the result stream - machine.process( new Run( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); - machine.process( PullAll.INSTANCE, new BoltResponseHandler() + machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( PullAllMessage.INSTANCE, new BoltResponseHandler() { @Override public void onRecords( BoltResult result, boolean pull ) @@ -438,9 +438,9 @@ public void shouldBeAbleToCleanlyRunMultipleSessionsInSingleThread() throws Thro { // Given BoltStateMachine firstMachine = env.newMachine( boltChannel ); - firstMachine.process( new Init( USER_AGENT, emptyMap() ), null ); + firstMachine.process( new InitMessage( USER_AGENT, emptyMap() ), null ); BoltStateMachine secondMachine = env.newMachine( boltChannel ); - secondMachine.process( new Init( USER_AGENT, emptyMap() ), null ); + secondMachine.process( new InitMessage( USER_AGENT, emptyMap() ), null ); // And given I've started a transaction in one session runAndPull( firstMachine, "BEGIN" ); @@ -462,7 +462,7 @@ public void shouldSupportUsingPeriodicCommitInSession() throws Exception { // Given BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); MapValue params = map( "csvFileUrl", createLocalIrisData( machine ) ); long txIdBeforeQuery = env.lastClosedTxId(); long batch = 40; @@ -508,13 +508,13 @@ public void shouldNotSupportUsingPeriodicCommitInTransaction() throws Exception { // Given BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); MapValue params = map( "csvFileUrl", createLocalIrisData( machine ) ); runAndPull( machine, "BEGIN" ); // When BoltResponseRecorder recorder = new BoltResponseRecorder(); - machine.process( new Run( + machine.process( new RunMessage( "USING PERIODIC COMMIT 40\n" + "LOAD CSV WITH HEADERS FROM {csvFileUrl} AS l\n" + "MATCH (c:Class {name: l.class_name})\n" + @@ -536,7 +536,7 @@ public void shouldCloseTransactionOnCommit() throws Exception { // Given BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); runAndPull( machine, "BEGIN" ); runAndPull( machine, "RETURN 1" ); @@ -550,13 +550,13 @@ public void shouldCloseTransactionEvenIfCommitFails() throws Exception { // Given BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); runAndPull( machine, "BEGIN" ); runAndPull( machine, "X", map(), IGNORED ); - machine.process( AckFailure.INSTANCE, nullResponseHandler() ); + machine.process( AckFailureMessage.INSTANCE, nullResponseHandler() ); runAndPull( machine, "COMMIT", map(), IGNORED ); - machine.process( AckFailure.INSTANCE, nullResponseHandler() ); + machine.process( AckFailureMessage.INSTANCE, nullResponseHandler() ); assertFalse( hasTransaction( machine ) ); } @@ -566,7 +566,7 @@ public void shouldCloseTransactionOnRollback() throws Exception { // Given BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); runAndPull( machine, "BEGIN" ); runAndPull( machine, "RETURN 1" ); @@ -580,11 +580,11 @@ public void shouldCloseTransactionOnRollbackAfterFailure() throws Exception { // Given BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); runAndPull( machine, "BEGIN" ); runAndPull( machine, "X", map(), IGNORED ); - machine.process( AckFailure.INSTANCE, nullResponseHandler() ); + machine.process( AckFailureMessage.INSTANCE, nullResponseHandler() ); runAndPull( machine, "ROLLBACK" ); assertFalse( hasTransaction( machine ) ); @@ -595,12 +595,12 @@ public void shouldAllowNewTransactionAfterFailure() throws Throwable { // Given BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); // And given I've started a transaction that failed runAndPull( machine, "BEGIN" ); - machine.process( new Run( "invalid", EMPTY_PARAMS ), nullResponseHandler() ); - machine.process( Reset.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "invalid", EMPTY_PARAMS ), nullResponseHandler() ); + machine.process( ResetMessage.INSTANCE, nullResponseHandler() ); // When runAndPull( machine, "BEGIN" ); @@ -640,8 +640,8 @@ private Record[] runAndPull( BoltStateMachine machine, String statement, MapValu BoltResponseMessage expectedResponse ) throws Exception { BoltResponseRecorder recorder = new BoltResponseRecorder(); - machine.process( new Run( statement, params ), nullResponseHandler() ); - machine.process( PullAll.INSTANCE, recorder ); + machine.process( new RunMessage( statement, params ), nullResponseHandler() ); + machine.process( PullAllMessage.INSTANCE, recorder ); RecordedBoltResponse response = recorder.nextResponse(); assertEquals( expectedResponse, response.message() ); return response.records(); diff --git a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/runtime/integration/TransactionIT.java b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/runtime/integration/TransactionIT.java index 7ec74addd031c..8ad8ca27207e3 100644 --- a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/runtime/integration/TransactionIT.java +++ b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/runtime/integration/TransactionIT.java @@ -36,12 +36,12 @@ import org.neo4j.bolt.runtime.BoltConnectionFatality; import org.neo4j.bolt.runtime.BoltStateMachine; import org.neo4j.bolt.testing.BoltResponseRecorder; -import org.neo4j.bolt.v1.messaging.message.AckFailure; -import org.neo4j.bolt.v1.messaging.message.DiscardAll; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Reset; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.AckFailureMessage; +import org.neo4j.bolt.v1.messaging.request.DiscardAllMessage; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.graphdb.Label; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Transaction; @@ -86,17 +86,17 @@ public void shouldHandleBeginCommit() throws Throwable // Given BoltResponseRecorder recorder = new BoltResponseRecorder(); BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); // When - machine.process( new Run( "BEGIN", EMPTY_MAP ), recorder ); - machine.process( DiscardAll.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "BEGIN", EMPTY_MAP ), recorder ); + machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); - machine.process( new Run( "CREATE (n:InTx)", EMPTY_MAP ), recorder ); - machine.process( DiscardAll.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "CREATE (n:InTx)", EMPTY_MAP ), recorder ); + machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); - machine.process( new Run( "COMMIT", EMPTY_MAP ), recorder ); - machine.process( DiscardAll.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "COMMIT", EMPTY_MAP ), recorder ); + machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); // Then assertThat( recorder.nextResponse(), succeeded() ); @@ -110,17 +110,17 @@ public void shouldHandleBeginRollback() throws Throwable // Given BoltResponseRecorder recorder = new BoltResponseRecorder(); BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); // When - machine.process( new Run( "BEGIN", EMPTY_MAP ), recorder ); - machine.process( DiscardAll.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "BEGIN", EMPTY_MAP ), recorder ); + machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); - machine.process( new Run( "CREATE (n:InTx)", EMPTY_MAP ), recorder ); - machine.process( DiscardAll.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "CREATE (n:InTx)", EMPTY_MAP ), recorder ); + machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); - machine.process( new Run( "ROLLBACK", EMPTY_MAP ), recorder ); - machine.process( DiscardAll.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "ROLLBACK", EMPTY_MAP ), recorder ); + machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); // Then assertThat( recorder.nextResponse(), succeeded() ); @@ -135,11 +135,11 @@ public void shouldNotFailWhenOutOfOrderRollbackInAutoCommitMode() throws Throwab BoltResponseRecorder runRecorder = new BoltResponseRecorder(); BoltResponseRecorder pullAllRecorder = new BoltResponseRecorder(); BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); // When - machine.process( new Run( "ROLLBACK", EMPTY_MAP ), runRecorder ); - machine.process( PullAll.INSTANCE, pullAllRecorder ); + machine.process( new RunMessage( "ROLLBACK", EMPTY_MAP ), runRecorder ); + machine.process( PullAllMessage.INSTANCE, pullAllRecorder ); // Then assertThat( runRecorder.nextResponse(), succeeded() ); @@ -152,17 +152,17 @@ public void shouldReceiveBookmarkOnCommitAndDiscardAll() throws Throwable // Given BoltResponseRecorder recorder = new BoltResponseRecorder(); BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); // When - machine.process( new Run( "BEGIN", EMPTY_MAP ), recorder ); - machine.process( DiscardAll.INSTANCE, recorder ); + machine.process( new RunMessage( "BEGIN", EMPTY_MAP ), recorder ); + machine.process( DiscardAllMessage.INSTANCE, recorder ); - machine.process( new Run( "CREATE (a:Person)", EMPTY_MAP ), recorder ); - machine.process( DiscardAll.INSTANCE, recorder ); + machine.process( new RunMessage( "CREATE (a:Person)", EMPTY_MAP ), recorder ); + machine.process( DiscardAllMessage.INSTANCE, recorder ); - machine.process( new Run( "COMMIT", EMPTY_MAP ), recorder ); - machine.process( DiscardAll.INSTANCE, recorder ); + machine.process( new RunMessage( "COMMIT", EMPTY_MAP ), recorder ); + machine.process( DiscardAllMessage.INSTANCE, recorder ); // Then assertThat( recorder.nextResponse(), succeeded() ); @@ -179,17 +179,17 @@ public void shouldReceiveBookmarkOnCommitAndPullAll() throws Throwable // Given BoltResponseRecorder recorder = new BoltResponseRecorder(); BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); // When - machine.process( new Run( "BEGIN", EMPTY_MAP ), recorder ); - machine.process( DiscardAll.INSTANCE, recorder ); + machine.process( new RunMessage( "BEGIN", EMPTY_MAP ), recorder ); + machine.process( DiscardAllMessage.INSTANCE, recorder ); - machine.process( new Run( "CREATE (a:Person)", EMPTY_MAP ), recorder ); - machine.process( DiscardAll.INSTANCE, recorder ); + machine.process( new RunMessage( "CREATE (a:Person)", EMPTY_MAP ), recorder ); + machine.process( DiscardAllMessage.INSTANCE, recorder ); - machine.process( new Run( "COMMIT", EMPTY_MAP ), recorder ); - machine.process( PullAll.INSTANCE, recorder ); + machine.process( new RunMessage( "COMMIT", EMPTY_MAP ), recorder ); + machine.process( PullAllMessage.INSTANCE, recorder ); // Then assertThat( recorder.nextResponse(), succeeded() ); @@ -216,10 +216,10 @@ public void shouldReadYourOwnWrites() throws Exception Thread thread = new Thread( () -> { try ( BoltStateMachine machine = env.newMachine( boltChannel ) ) { - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); latch.await(); - machine.process( new Run( "MATCH (n:A) SET n.prop = 'two'", EMPTY_MAP ), nullResponseHandler() ); - machine.process( PullAll.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "MATCH (n:A) SET n.prop = 'two'", EMPTY_MAP ), nullResponseHandler() ); + machine.process( PullAllMessage.INSTANCE, nullResponseHandler() ); } catch ( BoltConnectionFatality connectionFatality ) { @@ -232,15 +232,15 @@ public void shouldReadYourOwnWrites() throws Exception try ( BoltStateMachine machine = env.newMachine( boltChannel ) ) { BoltResponseRecorder recorder = new BoltResponseRecorder(); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); latch.release(); final String bookmark = "neo4j:bookmark:v1:tx" + dbVersionAfterWrite; - machine.process( new Run( "BEGIN", ValueUtils.asMapValue( singletonMap( "bookmark", bookmark ) ) ), nullResponseHandler() ); - machine.process( PullAll.INSTANCE, recorder ); - machine.process( new Run( "MATCH (n:A) RETURN n.prop", EMPTY_MAP ), nullResponseHandler() ); - machine.process( PullAll.INSTANCE, recorder ); - machine.process( new Run( "COMMIT", EMPTY_MAP ), nullResponseHandler() ); - machine.process( PullAll.INSTANCE, recorder ); + machine.process( new RunMessage( "BEGIN", ValueUtils.asMapValue( singletonMap( "bookmark", bookmark ) ) ), nullResponseHandler() ); + machine.process( PullAllMessage.INSTANCE, recorder ); + machine.process( new RunMessage( "MATCH (n:A) RETURN n.prop", EMPTY_MAP ), nullResponseHandler() ); + machine.process( PullAllMessage.INSTANCE, recorder ); + machine.process( new RunMessage( "COMMIT", EMPTY_MAP ), nullResponseHandler() ); + machine.process( PullAllMessage.INSTANCE, recorder ); assertThat( recorder.nextResponse(), succeededWithMetadata( "bookmark", BOOKMARK_PATTERN ) ); assertThat( recorder.nextResponse(), succeededWithRecord( "two" ) ); @@ -276,7 +276,7 @@ public void shouldTerminateQueriesEvenIfUsingPeriodicCommit() throws Exception try ( BoltStateMachine stateMachine = env.newMachine( mock( BoltChannel.class ) ) ) { machine[0] = stateMachine; - stateMachine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + stateMachine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); String query = format( "USING PERIODIC COMMIT 10 LOAD CSV FROM 'http://localhost:%d' AS line " + "CREATE (n:A {id: line[0], square: line[1]}) " + "WITH count(*) as number " + @@ -285,8 +285,8 @@ public void shouldTerminateQueriesEvenIfUsingPeriodicCommit() throws Exception try { latch.start(); - stateMachine.process( new Run( query, EMPTY_MAP ), nullResponseHandler() ); - stateMachine.process( PullAll.INSTANCE, nullResponseHandler() ); + stateMachine.process( new RunMessage( query, EMPTY_MAP ), nullResponseHandler() ); + stateMachine.process( PullAllMessage.INSTANCE, nullResponseHandler() ); } finally { @@ -306,7 +306,7 @@ public void shouldTerminateQueriesEvenIfUsingPeriodicCommit() throws Exception Thread.sleep( 1000 ); // This is the call that RESETs the Bolt connection and will terminate the running query - machine[0].process( Reset.INSTANCE, nullResponseHandler() ); + machine[0].process( ResetMessage.INSTANCE, nullResponseHandler() ); barrier.release(); @@ -327,14 +327,14 @@ public void shouldInterpretEmptyStatementAsReuseLastStatementInAutocommitTransac { // Given final BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); BoltResponseRecorder recorder = new BoltResponseRecorder(); // When - machine.process( new Run( "RETURN 1", EMPTY_MAP ), nullResponseHandler() ); - machine.process( PullAll.INSTANCE, recorder ); - machine.process( new Run( "", EMPTY_MAP ), nullResponseHandler() ); - machine.process( PullAll.INSTANCE, recorder ); + machine.process( new RunMessage( "RETURN 1", EMPTY_MAP ), nullResponseHandler() ); + machine.process( PullAllMessage.INSTANCE, recorder ); + machine.process( new RunMessage( "", EMPTY_MAP ), nullResponseHandler() ); + machine.process( PullAllMessage.INSTANCE, recorder ); // Then assertThat( recorder.nextResponse(), succeededWithRecord( 1L ) ); @@ -346,18 +346,18 @@ public void shouldInterpretEmptyStatementAsReuseLastStatementInExplicitTransacti { // Given final BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); BoltResponseRecorder recorder = new BoltResponseRecorder(); // When - machine.process( new Run( "BEGIN", EMPTY_MAP ), nullResponseHandler() ); - machine.process( DiscardAll.INSTANCE, nullResponseHandler() ); - machine.process( new Run( "RETURN 1", EMPTY_MAP ), nullResponseHandler() ); - machine.process( PullAll.INSTANCE, recorder ); - machine.process( new Run( "", EMPTY_MAP ), nullResponseHandler() ); - machine.process( PullAll.INSTANCE, recorder ); - machine.process( new Run( "COMMIT", EMPTY_MAP ), nullResponseHandler() ); - machine.process( DiscardAll.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "BEGIN", EMPTY_MAP ), nullResponseHandler() ); + machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "RETURN 1", EMPTY_MAP ), nullResponseHandler() ); + machine.process( PullAllMessage.INSTANCE, recorder ); + machine.process( new RunMessage( "", EMPTY_MAP ), nullResponseHandler() ); + machine.process( PullAllMessage.INSTANCE, recorder ); + machine.process( new RunMessage( "COMMIT", EMPTY_MAP ), nullResponseHandler() ); + machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); // Then assertThat( recorder.nextResponse(), succeededWithRecord( 1L ) ); @@ -369,18 +369,18 @@ public void beginShouldNotOverwriteLastStatement() throws Throwable { // Given final BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); BoltResponseRecorder recorder = new BoltResponseRecorder(); // When - machine.process( new Run( "RETURN 1", EMPTY_MAP ), nullResponseHandler() ); - machine.process( PullAll.INSTANCE, recorder ); - machine.process( new Run( "BEGIN", EMPTY_MAP ), nullResponseHandler() ); - machine.process( DiscardAll.INSTANCE, nullResponseHandler() ); - machine.process( new Run( "", EMPTY_MAP ), nullResponseHandler() ); - machine.process( PullAll.INSTANCE, recorder ); - machine.process( new Run( "COMMIT", EMPTY_MAP ), nullResponseHandler() ); - machine.process( DiscardAll.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "RETURN 1", EMPTY_MAP ), nullResponseHandler() ); + machine.process( PullAllMessage.INSTANCE, recorder ); + machine.process( new RunMessage( "BEGIN", EMPTY_MAP ), nullResponseHandler() ); + machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); + machine.process( new RunMessage( "", EMPTY_MAP ), nullResponseHandler() ); + machine.process( PullAllMessage.INSTANCE, recorder ); + machine.process( new RunMessage( "COMMIT", EMPTY_MAP ), nullResponseHandler() ); + machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); // Then assertThat( recorder.nextResponse(), succeededWithRecord( 1L ) ); @@ -392,15 +392,15 @@ public void shouldCloseAutoCommitTransactionAndRespondToNextStatementWhenRunFail { // Given final BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); BoltResponseRecorder recorder = new BoltResponseRecorder(); // When - machine.process( new Run( "INVALID QUERY", EMPTY_MAP ), recorder ); - machine.process( PullAll.INSTANCE, recorder ); - machine.process( AckFailure.INSTANCE, recorder ); - machine.process( new Run( "RETURN 2", EMPTY_MAP ), recorder ); - machine.process( PullAll.INSTANCE, recorder ); + machine.process( new RunMessage( "INVALID QUERY", EMPTY_MAP ), recorder ); + machine.process( PullAllMessage.INSTANCE, recorder ); + machine.process( AckFailureMessage.INSTANCE, recorder ); + machine.process( new RunMessage( "RETURN 2", EMPTY_MAP ), recorder ); + machine.process( PullAllMessage.INSTANCE, recorder ); // Then assertThat( recorder.nextResponse(), failedWithStatus( Status.Statement.SyntaxError ) ); @@ -416,15 +416,15 @@ public void shouldCloseAutoCommitTransactionAndRespondToNextStatementWhenStreami { // Given final BoltStateMachine machine = env.newMachine( boltChannel ); - machine.process( new Init( USER_AGENT, emptyMap() ), nullResponseHandler() ); + machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() ); BoltResponseRecorder recorder = new BoltResponseRecorder(); // When - machine.process( new Run( "UNWIND [1, 0] AS x RETURN 1 / x", EMPTY_MAP ), recorder ); - machine.process( PullAll.INSTANCE, recorder ); - machine.process( AckFailure.INSTANCE, recorder ); - machine.process( new Run( "RETURN 2", EMPTY_MAP ), recorder ); - machine.process( PullAll.INSTANCE, recorder ); + machine.process( new RunMessage( "UNWIND [1, 0] AS x RETURN 1 / x", EMPTY_MAP ), recorder ); + machine.process( PullAllMessage.INSTANCE, recorder ); + machine.process( AckFailureMessage.INSTANCE, recorder ); + machine.process( new RunMessage( "RETURN 2", EMPTY_MAP ), recorder ); + machine.process( PullAllMessage.INSTANCE, recorder ); // Then assertThat( recorder.nextResponse(), succeeded() ); diff --git a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/AuthenticationIT.java b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/AuthenticationIT.java index 90107b4f1c567..0bafe7342c91a 100644 --- a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/AuthenticationIT.java +++ b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/AuthenticationIT.java @@ -37,13 +37,13 @@ import java.util.function.Consumer; import org.neo4j.bolt.AbstractBoltTransportsTest; -import org.neo4j.bolt.v1.messaging.message.AckFailure; -import org.neo4j.bolt.v1.messaging.message.FailureMessage; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Reset; -import org.neo4j.bolt.v1.messaging.message.ResponseMessage; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.messaging.ResponseMessage; +import org.neo4j.bolt.v1.messaging.request.AckFailureMessage; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; +import org.neo4j.bolt.v1.messaging.response.FailureMessage; import org.neo4j.bolt.v1.transport.socket.client.TransportConnection; import org.neo4j.graphdb.factory.GraphDatabaseSettings; import org.neo4j.helpers.HostnamePort; @@ -105,7 +105,7 @@ public void shouldRespondWithCredentialsExpiredOnFirstUse() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", + new InitMessage( "TestClient/1.1", map( "principal", "neo4j", "credentials", "neo4j", "scheme", "basic" ) ) ) ); // Then @@ -117,7 +117,7 @@ public void shouldRespondWithCredentialsExpiredOnFirstUse() throws Throwable private void verifyConnectionOpen() throws IOException { - connection.send( util.chunk( Reset.INSTANCE ) ); + connection.send( util.chunk( ResetMessage.INSTANCE ) ); assertThat( connection, util.eventuallyReceives( msgSuccess() ) ); } @@ -128,7 +128,7 @@ public void shouldFailIfWrongCredentials() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", + new InitMessage( "TestClient/1.1", map( "principal", "neo4j", "credentials", "wrong", "scheme", "basic" ) ) ) ); // Then @@ -146,7 +146,7 @@ public void shouldFailIfWrongCredentialsFollowingSuccessfulLogin() throws Throwa connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", map( "principal", "neo4j", + new InitMessage( "TestClient/1.1", map( "principal", "neo4j", "credentials", "neo4j", "new_credentials", "secret", "scheme", "basic" ) ) ) ); // Then assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); @@ -157,7 +157,7 @@ public void shouldFailIfWrongCredentialsFollowingSuccessfulLogin() throws Throwa connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", + new InitMessage( "TestClient/1.1", map( "principal", "neo4j", "credentials", "secret", "scheme", "basic" ) ) ) ); // Then @@ -169,7 +169,7 @@ public void shouldFailIfWrongCredentialsFollowingSuccessfulLogin() throws Throwa connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", + new InitMessage( "TestClient/1.1", map( "principal", "neo4j", "credentials", "wrong", "scheme", "basic" ) ) ) ); // Then @@ -187,7 +187,7 @@ public void shouldFailIfMalformedAuthTokenWrongType() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", + new InitMessage( "TestClient/1.1", map( "principal", singletonList( "neo4j" ), "credentials", "neo4j", "scheme", "basic" ) ) ) ); @@ -207,7 +207,7 @@ public void shouldFailIfMalformedAuthTokenMissingKey() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", + new InitMessage( "TestClient/1.1", map( "principal", "neo4j", "this-should-have-been-credentials", "neo4j", "scheme", "basic" ) ) ) ); @@ -226,7 +226,7 @@ public void shouldFailIfMalformedAuthTokenMissingScheme() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", + new InitMessage( "TestClient/1.1", map( "principal", "neo4j", "credentials", "neo4j" ) ) ) ); // Then @@ -244,7 +244,7 @@ public void shouldFailIfMalformedAuthTokenUnknownScheme() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", + new InitMessage( "TestClient/1.1", map( "principal", "neo4j", "credentials", "neo4j", "scheme", "unknown" ) ) ) ); @@ -321,7 +321,7 @@ public void shouldBeAbleToUpdateCredentials() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", map( "principal", "neo4j", + new InitMessage( "TestClient/1.1", map( "principal", "neo4j", "credentials", "neo4j", "new_credentials", "secret", "scheme", "basic" ) ) ) ); // Then @@ -333,7 +333,7 @@ public void shouldBeAbleToUpdateCredentials() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", + new InitMessage( "TestClient/1.1", map( "principal", "neo4j", "credentials", "neo4j", "scheme", "basic" ) ) ) ); assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); assertThat( connection, util.eventuallyReceives( msgFailure( Status.Security.Unauthorized, @@ -344,7 +344,7 @@ public void shouldBeAbleToUpdateCredentials() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", + new InitMessage( "TestClient/1.1", map( "principal", "neo4j", "credentials", "secret", "scheme", "basic" ) ) ) ); assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); assertThat( connection, util.eventuallyReceives( msgSuccess() ) ); @@ -357,7 +357,7 @@ public void shouldBeAuthenticatedAfterUpdatingCredentials() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", map( "principal", "neo4j", + new InitMessage( "TestClient/1.1", map( "principal", "neo4j", "credentials", "neo4j", "new_credentials", "secret", "scheme", "basic" ) ) ) ); // Then @@ -366,8 +366,8 @@ public void shouldBeAuthenticatedAfterUpdatingCredentials() throws Throwable // When connection.send( util.chunk( - new Run( "MATCH (n) RETURN n", EMPTY_MAP ), - PullAll.INSTANCE ) ); + new RunMessage( "MATCH (n) RETURN n", EMPTY_MAP ), + PullAllMessage.INSTANCE ) ); // Then assertThat( connection, util.eventuallyReceives( msgSuccess(), msgSuccess() ) ); @@ -380,7 +380,7 @@ public void shouldBeAbleToChangePasswordUsingBuiltInProcedure() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", + new InitMessage( "TestClient/1.1", map( "principal", "neo4j", "credentials", "neo4j", "scheme", "basic" ) ) ) ); // Then @@ -389,8 +389,8 @@ public void shouldBeAbleToChangePasswordUsingBuiltInProcedure() throws Throwable // When connection.send( util.chunk( - new Run( "CALL dbms.security.changePassword", singletonMap( "password", "secret" ) ), - PullAll.INSTANCE ) ); + new RunMessage( "CALL dbms.security.changePassword", singletonMap( "password", "secret" ) ), + PullAllMessage.INSTANCE ) ); // Then assertThat( connection, util.eventuallyReceives( msgSuccess() ) ); @@ -400,7 +400,7 @@ public void shouldBeAbleToChangePasswordUsingBuiltInProcedure() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", + new InitMessage( "TestClient/1.1", map( "principal", "neo4j", "credentials", "neo4j", "scheme", "basic" ) ) ) ); assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); assertThat( connection, util.eventuallyReceives( msgFailure( Status.Security.Unauthorized, @@ -411,7 +411,7 @@ public void shouldBeAbleToChangePasswordUsingBuiltInProcedure() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", + new InitMessage( "TestClient/1.1", map( "principal", "neo4j", "credentials", "secret", "scheme", "basic" ) ) ) ); assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); assertThat( connection, util.eventuallyReceives( msgSuccess() ) ); @@ -424,7 +424,7 @@ public void shouldBeAuthenticatedAfterChangePasswordUsingBuiltInProcedure() thro connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", + new InitMessage( "TestClient/1.1", map( "principal", "neo4j", "credentials", "neo4j", "scheme", "basic" ) ) ) ); // Then @@ -433,16 +433,16 @@ public void shouldBeAuthenticatedAfterChangePasswordUsingBuiltInProcedure() thro // When connection.send( util.chunk( - new Run( "CALL dbms.security.changePassword", singletonMap( "password", "secret" ) ), - PullAll.INSTANCE ) ); + new RunMessage( "CALL dbms.security.changePassword", singletonMap( "password", "secret" ) ), + PullAllMessage.INSTANCE ) ); // Then assertThat( connection, util.eventuallyReceives( msgSuccess(), msgSuccess() ) ); // When connection.send( util.chunk( - new Run( "MATCH (n) RETURN n", EMPTY_MAP ), - PullAll.INSTANCE ) ); + new RunMessage( "MATCH (n) RETURN n", EMPTY_MAP ), + PullAllMessage.INSTANCE ) ); // Then assertThat( connection, util.eventuallyReceives( msgSuccess(), msgSuccess() ) ); @@ -455,7 +455,7 @@ public void shouldFailWhenReusingTheSamePassword() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", + new InitMessage( "TestClient/1.1", map( "principal", "neo4j", "credentials", "neo4j", "scheme", "basic" ) ) ) ); // Then @@ -464,8 +464,8 @@ public void shouldFailWhenReusingTheSamePassword() throws Throwable // When connection.send( util.chunk( - new Run( "CALL dbms.security.changePassword", singletonMap( "password", "neo4j" ) ), - PullAll.INSTANCE ) ); + new RunMessage( "CALL dbms.security.changePassword", singletonMap( "password", "neo4j" ) ), + PullAllMessage.INSTANCE ) ); // Then assertThat( connection, util.eventuallyReceives( msgFailure( Status.General.InvalidArguments, @@ -473,9 +473,9 @@ public void shouldFailWhenReusingTheSamePassword() throws Throwable // However you should also be able to recover connection.send( util.chunk( - AckFailure.INSTANCE, - new Run( "CALL dbms.security.changePassword", singletonMap( "password", "abc" ) ), - PullAll.INSTANCE ) ); + AckFailureMessage.INSTANCE, + new RunMessage( "CALL dbms.security.changePassword", singletonMap( "password", "abc" ) ), + PullAllMessage.INSTANCE ) ); assertThat( connection, util.eventuallyReceives( msgIgnored(), msgSuccess(), msgSuccess(), msgSuccess() ) ); } @@ -486,7 +486,7 @@ public void shouldFailWhenSubmittingEmptyPassword() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", + new InitMessage( "TestClient/1.1", map( "principal", "neo4j", "credentials", "neo4j", "scheme", "basic" ) ) ) ); // Then @@ -495,8 +495,8 @@ public void shouldFailWhenSubmittingEmptyPassword() throws Throwable // When connection.send( util.chunk( - new Run( "CALL dbms.security.changePassword", singletonMap( "password", "" ) ), - PullAll.INSTANCE ) ); + new RunMessage( "CALL dbms.security.changePassword", singletonMap( "password", "" ) ), + PullAllMessage.INSTANCE ) ); // Then assertThat( connection, util.eventuallyReceives( msgFailure( Status.General.InvalidArguments, @@ -504,9 +504,9 @@ public void shouldFailWhenSubmittingEmptyPassword() throws Throwable // However you should also be able to recover connection.send( util.chunk( - AckFailure.INSTANCE, - new Run( "CALL dbms.security.changePassword", singletonMap( "password", "abc" ) ), - PullAll.INSTANCE ) ); + AckFailureMessage.INSTANCE, + new RunMessage( "CALL dbms.security.changePassword", singletonMap( "password", "abc" ) ), + PullAllMessage.INSTANCE ) ); assertThat( connection, util.eventuallyReceives( msgIgnored(), msgSuccess(), msgSuccess(), msgSuccess() ) ); } @@ -517,7 +517,7 @@ public void shouldNotBeAbleToReadWhenPasswordChangeRequired() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", + new InitMessage( "TestClient/1.1", map( "principal", "neo4j", "credentials", "neo4j", "scheme", "basic" ) ) ) ); // Then @@ -526,8 +526,8 @@ public void shouldNotBeAbleToReadWhenPasswordChangeRequired() throws Throwable // When connection.send( util.chunk( - new Run( "MATCH (n) RETURN n", EMPTY_MAP ), - PullAll.INSTANCE ) ); + new RunMessage( "MATCH (n) RETURN n", EMPTY_MAP ), + PullAllMessage.INSTANCE ) ); // Then assertThat( connection, util.eventuallyReceives( msgFailure( Status.Security.CredentialsExpired, @@ -580,7 +580,7 @@ private FailureMessage collectAuthFailureOnFailedAuth() connection = newConnection(); connection.connect( address ).send( util.defaultAcceptedVersions() ).send( util.chunk( - new Init( "TestClient/1.1", + new InitMessage( "TestClient/1.1", map( "principal", "neo4j", "credentials", "WHAT_WAS_THE_PASSWORD_AGAIN", "scheme", "basic" ) ) ) ); assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); diff --git a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/BoltChannelAutoReadLimiterIT.java b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/BoltChannelAutoReadLimiterIT.java index a7c02864aa475..03c293a46ee1e 100644 --- a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/BoltChannelAutoReadLimiterIT.java +++ b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/BoltChannelAutoReadLimiterIT.java @@ -30,9 +30,9 @@ import org.neo4j.bolt.runtime.BoltConnectionReadLimiter; import org.neo4j.bolt.v1.messaging.Neo4jPackV1; -import org.neo4j.bolt.v1.messaging.message.DiscardAll; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.DiscardAllMessage; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.bolt.v1.transport.socket.client.SocketConnection; import org.neo4j.bolt.v1.transport.socket.client.TransportConnection; import org.neo4j.collection.RawIterator; @@ -110,7 +110,7 @@ public void largeNumberOfSlowRunningJobsShouldChangeAutoReadState() throws Excep connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", emptyMap() ) ) ); + new InitMessage( "TestClient/1.1", emptyMap() ) ) ); assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); assertThat( connection, util.eventuallyReceives( msgSuccess() ) ); @@ -119,8 +119,8 @@ public void largeNumberOfSlowRunningJobsShouldChangeAutoReadState() throws Excep for ( int i = 0; i < numberOfRunDiscardPairs; i++ ) { connection.send( util.chunk( - new Run( "CALL boltissue.sleep( $data )", ValueUtils.asMapValue( singletonMap( "data", largeString ) ) ), - DiscardAll.INSTANCE ) ); + new RunMessage( "CALL boltissue.sleep( $data )", ValueUtils.asMapValue( singletonMap( "data", largeString ) ) ), + DiscardAllMessage.INSTANCE ) ); } // expect diff --git a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/BoltThrottleMaxDurationIT.java b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/BoltThrottleMaxDurationIT.java index b4c3fce3e175d..257f119add08e 100644 --- a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/BoltThrottleMaxDurationIT.java +++ b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/BoltThrottleMaxDurationIT.java @@ -39,9 +39,9 @@ import org.neo4j.bolt.runtime.BoltConnection; import org.neo4j.bolt.v1.messaging.Neo4jPackV1; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.bolt.v1.transport.socket.client.SecureSocketConnection; import org.neo4j.bolt.v1.transport.socket.client.SocketConnection; import org.neo4j.bolt.v1.transport.socket.client.TransportConnection; @@ -140,7 +140,7 @@ public void sendingButNotReceivingClientShouldBeKilledWhenWriteThrottleMaxDurati client.connect( address ) .send( util.acceptedVersions( 1, 0, 0, 0 ) ) .send( util.chunk( - new Init( "TestClient/1.1", emptyMap() ) ) ); + new InitMessage( "TestClient/1.1", emptyMap() ) ) ); assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) ); assertThat( client, util.eventuallyReceives( msgSuccess() ) ); @@ -150,8 +150,8 @@ public void sendingButNotReceivingClientShouldBeKilledWhenWriteThrottleMaxDurati for ( int i = 0; i < numberOfRunDiscardPairs; i++ ) { client.send( util.chunk( - new Run( "RETURN $data as data", ValueUtils.asMapValue( singletonMap( "data", largeString ) ) ), - PullAll.INSTANCE + new RunMessage( "RETURN $data as data", ValueUtils.asMapValue( singletonMap( "data", largeString ) ) ), + PullAllMessage.INSTANCE ) ); } diff --git a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/ConcurrentAccessIT.java b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/ConcurrentAccessIT.java index c287b1bab4170..e296d392e94e4 100644 --- a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/ConcurrentAccessIT.java +++ b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/ConcurrentAccessIT.java @@ -34,9 +34,9 @@ import java.util.concurrent.TimeUnit; import org.neo4j.bolt.AbstractBoltTransportsTest; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.bolt.v1.transport.socket.client.TransportConnection; import org.neo4j.graphdb.factory.GraphDatabaseSettings; @@ -99,14 +99,14 @@ private Callable newWorker( final int iterationsToRun ) throws Exception { return new Callable() { - private final byte[] init = util.chunk( new Init( "TestClient", emptyMap() ) ); + private final byte[] init = util.chunk( new InitMessage( "TestClient", emptyMap() ) ); private final byte[] createAndRollback = util.chunk( - new Run( "BEGIN" ), PullAll.INSTANCE, - new Run( "CREATE (n)" ), PullAll.INSTANCE, - new Run( "ROLLBACK" ), PullAll.INSTANCE ); + new RunMessage( "BEGIN" ), PullAllMessage.INSTANCE, + new RunMessage( "CREATE (n)" ), PullAllMessage.INSTANCE, + new RunMessage( "ROLLBACK" ), PullAllMessage.INSTANCE ); private final byte[] matchAll = util.chunk( - new Run( "MATCH (n) RETURN n" ), PullAll.INSTANCE ); + new RunMessage( "MATCH (n) RETURN n" ), PullAllMessage.INSTANCE ); @Override public Void call() throws Exception diff --git a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/TransportErrorIT.java b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/TransportErrorIT.java index c9bc83b9fefd6..2e294390c4c6e 100644 --- a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/TransportErrorIT.java +++ b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/TransportErrorIT.java @@ -27,7 +27,7 @@ import org.neo4j.bolt.AbstractBoltTransportsTest; import org.neo4j.bolt.v1.messaging.RecordingByteChannel; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.bolt.v1.packstream.BufferedChannelOutput; import org.neo4j.bolt.v1.packstream.PackStream; @@ -50,7 +50,7 @@ public void setup() public void shouldHandleIncorrectFraming() throws Throwable { // Given I have a message that gets truncated in the chunking, so part of it is missing - byte[] truncated = serialize( util.getNeo4jPack(), new Run( "UNWIND [1,2,3] AS a RETURN a, a * a AS a_squared" ) ); + byte[] truncated = serialize( util.getNeo4jPack(), new RunMessage( "UNWIND [1,2,3] AS a RETURN a, a * a AS a_squared" ) ); truncated = Arrays.copyOf(truncated, truncated.length - 12); // When @@ -70,7 +70,7 @@ public void shouldHandleMessagesWithIncorrectFields() throws Throwable final RecordingByteChannel rawData = new RecordingByteChannel(); final PackStream.Packer packer = new PackStream.Packer( new BufferedChannelOutput( rawData ) ); - packer.packStructHeader( 2, Run.SIGNATURE ); + packer.packStructHeader( 2, RunMessage.SIGNATURE ); packer.pack( "RETURN 1" ); packer.pack( 1234 ); // Should've been a map packer.flush(); @@ -118,7 +118,7 @@ public void shouldHandleUnknownMarkerBytes() throws Throwable final BufferedChannelOutput out = new BufferedChannelOutput( rawData ); final PackStream.Packer packer = new PackStream.Packer( out ); - packer.packStructHeader( 2, Run.SIGNATURE ); + packer.packStructHeader( 2, RunMessage.SIGNATURE ); out.writeByte( PackStream.RESERVED_C7 ); // Invalid marker byte out.flush(); diff --git a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/TransportSessionIT.java b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/TransportSessionIT.java index 98dac311518db..93606ac5c250e 100644 --- a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/TransportSessionIT.java +++ b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/TransportSessionIT.java @@ -31,11 +31,11 @@ import org.neo4j.bolt.AbstractBoltTransportsTest; import org.neo4j.bolt.v1.messaging.Neo4jPackV1; -import org.neo4j.bolt.v1.messaging.message.AckFailure; -import org.neo4j.bolt.v1.messaging.message.DiscardAll; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.AckFailureMessage; +import org.neo4j.bolt.v1.messaging.request.DiscardAllMessage; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.graphdb.InputPosition; import org.neo4j.graphdb.SeverityLevel; import org.neo4j.graphdb.factory.GraphDatabaseSettings; @@ -105,9 +105,9 @@ public void shouldRunSimpleStatement() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", emptyMap() ), - new Run( "UNWIND [1,2,3] AS a RETURN a, a * a AS a_squared" ), - PullAll.INSTANCE ) ); + new InitMessage( "TestClient/1.1", emptyMap() ), + new RunMessage( "UNWIND [1,2,3] AS a RETURN a, a * a AS a_squared" ), + PullAllMessage.INSTANCE ) ); // Then assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); @@ -130,9 +130,9 @@ public void shouldRespondWithMetadataToDiscardAll() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", emptyMap() ), - new Run( "UNWIND [1,2,3] AS a RETURN a, a * a AS a_squared" ), - DiscardAll.INSTANCE ) ); + new InitMessage( "TestClient/1.1", emptyMap() ), + new RunMessage( "UNWIND [1,2,3] AS a RETURN a, a * a AS a_squared" ), + DiscardAllMessage.INSTANCE ) ); // Then assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); @@ -151,9 +151,9 @@ public void shouldBeAbleToRunQueryAfterAckFailure() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", emptyMap() ), - new Run( "QINVALID" ), - PullAll.INSTANCE ) ); + new InitMessage( "TestClient/1.1", emptyMap() ), + new RunMessage( "QINVALID" ), + PullAllMessage.INSTANCE ) ); assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); assertThat( connection, util.eventuallyReceives( @@ -164,7 +164,7 @@ public void shouldBeAbleToRunQueryAfterAckFailure() throws Throwable " ^" ) ), msgIgnored() ) ); // When - connection.send( util.chunk( AckFailure.INSTANCE, new Run( "RETURN 1" ), PullAll.INSTANCE ) ); + connection.send( util.chunk( AckFailureMessage.INSTANCE, new RunMessage( "RETURN 1" ), PullAllMessage.INSTANCE ) ); // Then assertThat( connection, util.eventuallyReceives( @@ -181,9 +181,9 @@ public void shouldRunProcedure() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", emptyMap() ), - new Run( "CREATE (n:Test {age: 2}) RETURN n.age AS age" ), - PullAll.INSTANCE ) ); + new InitMessage( "TestClient/1.1", emptyMap() ), + new RunMessage( "CREATE (n:Test {age: 2}) RETURN n.age AS age" ), + PullAllMessage.INSTANCE ) ); assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); Matcher> ageMatcher = hasEntry( is( "fields" ), equalTo( singletonList( "age" ) ) ); @@ -195,8 +195,8 @@ public void shouldRunProcedure() throws Throwable // When connection.send( util.chunk( - new Run( "CALL db.labels() YIELD label" ), - PullAll.INSTANCE ) ); + new RunMessage( "CALL db.labels() YIELD label" ), + PullAllMessage.INSTANCE ) ); // Then Matcher> entryFieldsMatcher = hasEntry( is( "fields" ), equalTo( singletonList( "label" ) ) ); @@ -215,9 +215,9 @@ public void shouldHandleDeletedNodes() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", emptyMap() ), - new Run( "CREATE (n:Test) DELETE n RETURN n" ), - PullAll.INSTANCE ) ); + new InitMessage( "TestClient/1.1", emptyMap() ), + new RunMessage( "CREATE (n:Test) DELETE n RETURN n" ), + PullAllMessage.INSTANCE ) ); // Then assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); @@ -247,9 +247,9 @@ public void shouldHandleDeletedRelationships() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", emptyMap() ), - new Run( "CREATE ()-[r:T {prop: 42}]->() DELETE r RETURN r" ), - PullAll.INSTANCE ) ); + new InitMessage( "TestClient/1.1", emptyMap() ), + new RunMessage( "CREATE ()-[r:T {prop: 42}]->() DELETE r RETURN r" ), + PullAllMessage.INSTANCE ) ); // Then assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); @@ -281,9 +281,9 @@ public void shouldNotLeakStatsToNextStatement() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", emptyMap() ), - new Run( "CREATE (n)" ), - PullAll.INSTANCE ) ); + new InitMessage( "TestClient/1.1", emptyMap() ), + new RunMessage( "CREATE (n)" ), + PullAllMessage.INSTANCE ) ); assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); assertThat( connection, util.eventuallyReceives( msgSuccess(), @@ -293,8 +293,8 @@ public void shouldNotLeakStatsToNextStatement() throws Throwable // When connection.send( util.chunk( - new Run( "RETURN 1" ), - PullAll.INSTANCE ) ); + new RunMessage( "RETURN 1" ), + PullAllMessage.INSTANCE ) ); // Then Matcher> typeMatcher = hasEntry( is( "type" ), equalTo( "r" ) ); @@ -311,9 +311,9 @@ public void shouldSendNotifications() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", emptyMap() ), - new Run( "EXPLAIN MATCH (a:THIS_IS_NOT_A_LABEL) RETURN count(*)" ), - PullAll.INSTANCE ) ); + new InitMessage( "TestClient/1.1", emptyMap() ), + new RunMessage( "EXPLAIN MATCH (a:THIS_IS_NOT_A_LABEL) RETURN count(*)" ), + PullAllMessage.INSTANCE ) ); // Then assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); @@ -341,9 +341,9 @@ public void shouldFailNicelyOnPointsWhenProtocolDoesNotSupportThem() throws Thro connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", emptyMap() ), - new Run( "RETURN point({x:13, y:37, crs:'cartesian'}) as p" ), - PullAll.INSTANCE ) ); + new InitMessage( "TestClient/1.1", emptyMap() ), + new RunMessage( "RETURN point({x:13, y:37, crs:'cartesian'}) as p" ), + PullAllMessage.INSTANCE ) ); // Then assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); @@ -378,9 +378,9 @@ public void shouldFailNicelyOnNullKeysInMap() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", emptyMap() ), - new Run( "RETURN {p}", ValueUtils.asMapValue( params ) ), - PullAll.INSTANCE ) ); + new InitMessage( "TestClient/1.1", emptyMap() ), + new RunMessage( "RETURN {p}", ValueUtils.asMapValue( params ) ), + PullAllMessage.INSTANCE ) ); // Then assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); @@ -390,7 +390,7 @@ public void shouldFailNicelyOnNullKeysInMap() throws Throwable "Value `null` is not supported as key in maps, must be a non-nullable string." ), msgIgnored() ) ); - connection.send( util.chunk( AckFailure.INSTANCE, new Run( "RETURN 1" ), PullAll.INSTANCE ) ); + connection.send( util.chunk( AckFailureMessage.INSTANCE, new RunMessage( "RETURN 1" ), PullAllMessage.INSTANCE ) ); // Then assertThat( connection, util.eventuallyReceives( @@ -407,9 +407,9 @@ public void shouldFailNicelyWhenDroppingUnknownIndex() throws Throwable connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( - new Init( "TestClient/1.1", emptyMap() ), - new Run( "DROP INDEX on :Movie12345(id)" ), - PullAll.INSTANCE ) ); + new InitMessage( "TestClient/1.1", emptyMap() ), + new RunMessage( "DROP INDEX on :Movie12345(id)" ), + PullAllMessage.INSTANCE ) ); // Then assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); diff --git a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/UnsupportedStructTypesV1IT.java b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/UnsupportedStructTypesV1IT.java index a99aa08ee01d9..f393a9f6b0329 100644 --- a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/UnsupportedStructTypesV1IT.java +++ b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/UnsupportedStructTypesV1IT.java @@ -39,8 +39,8 @@ import org.neo4j.bolt.messaging.Neo4jPack; import org.neo4j.bolt.v1.messaging.Neo4jPackV1; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.bolt.v1.packstream.PackedOutputArray; import org.neo4j.bolt.v1.transport.socket.client.SecureSocketConnection; import org.neo4j.bolt.v1.transport.socket.client.SecureWebSocketConnection; @@ -158,7 +158,7 @@ private void testFailureWithV2Value( AnyValue value, String description ) throws { connection.connect( address ).send( util.defaultAcceptedVersions() ); assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); - connection.send( util.chunk( new Init( USER_AGENT, Collections.emptyMap() ) ) ); + connection.send( util.chunk( new InitMessage( USER_AGENT, Collections.emptyMap() ) ) ); assertThat( connection, util.eventuallyReceives( msgSuccess() ) ); connection.send( util.chunk( 64, createRunWithV2Value( value ) ) ); @@ -173,7 +173,7 @@ private byte[] createRunWithV2Value( AnyValue value ) throws IOException PackedOutputArray out = new PackedOutputArray(); Neo4jPack.Packer packer = new Neo4jPackV2().newPacker( out ); - packer.packStructHeader( 2, Run.SIGNATURE ); + packer.packStructHeader( 2, RunMessage.SIGNATURE ); packer.pack( "RETURN $x" ); packer.packMapHeader( 1 ); packer.pack( "x" ); diff --git a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/UnsupportedStructTypesV1V2IT.java b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/UnsupportedStructTypesV1V2IT.java index 114eaafa04d6b..ab3771844e759 100644 --- a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/UnsupportedStructTypesV1V2IT.java +++ b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v1/transport/integration/UnsupportedStructTypesV1V2IT.java @@ -28,8 +28,8 @@ import org.neo4j.bolt.AbstractBoltTransportsTest; import org.neo4j.bolt.messaging.Neo4jPack; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.bolt.v1.packstream.PackedOutputArray; import org.neo4j.kernel.api.exceptions.Status; import org.neo4j.kernel.impl.util.ValueUtils; @@ -64,7 +64,7 @@ public void shouldFailWhenNullKeyIsSentWithInit() throws Exception connection.connect( address ).send( util.defaultAcceptedVersions() ); assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); - connection.send( util.chunk( 64, createMsgWithNullKey( Init.SIGNATURE ) ) ); + connection.send( util.chunk( 64, createMsgWithNullKey( InitMessage.SIGNATURE ) ) ); assertThat( connection, util.eventuallyReceives( msgFailure( Status.Request.Invalid, "Value `null` is not supported as key in maps, must be a non-nullable string." ) ) ); @@ -77,7 +77,7 @@ public void shouldFailWhenDuplicateKeyIsSentWithInit() throws Exception connection.connect( address ).send( util.defaultAcceptedVersions() ); assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); - connection.send( util.chunk( 64, createMsgWithDuplicateKey( Init.SIGNATURE ) ) ); + connection.send( util.chunk( 64, createMsgWithDuplicateKey( InitMessage.SIGNATURE ) ) ); assertThat( connection, util.eventuallyReceives( msgFailure( Status.Request.Invalid, "Duplicate map key `key1`." ) ) ); assertThat( connection, eventuallyDisconnects() ); @@ -88,10 +88,10 @@ public void shouldFailWhenNullKeyIsSentWithRun() throws Exception { connection.connect( address ).send( util.defaultAcceptedVersions() ); assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); - connection.send( util.chunk( new Init( USER_AGENT, Collections.emptyMap() ) ) ); + connection.send( util.chunk( new InitMessage( USER_AGENT, Collections.emptyMap() ) ) ); assertThat( connection, util.eventuallyReceives( msgSuccess() ) ); - connection.send( util.chunk( 64, createMsgWithNullKey( Run.SIGNATURE ) ) ); + connection.send( util.chunk( 64, createMsgWithNullKey( RunMessage.SIGNATURE ) ) ); assertThat( connection, util.eventuallyReceives( msgFailure( Status.Request.Invalid, "Value `null` is not supported as key in maps, must be a non-nullable string." ) ) ); @@ -103,10 +103,10 @@ public void shouldFailWhenDuplicateKeyIsSentWithRun() throws Exception { connection.connect( address ).send( util.defaultAcceptedVersions() ); assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); - connection.send( util.chunk( new Init( USER_AGENT, Collections.emptyMap() ) ) ); + connection.send( util.chunk( new InitMessage( USER_AGENT, Collections.emptyMap() ) ) ); assertThat( connection, util.eventuallyReceives( msgSuccess() ) ); - connection.send( util.chunk( 64, createMsgWithDuplicateKey( Run.SIGNATURE ) ) ); + connection.send( util.chunk( 64, createMsgWithDuplicateKey( RunMessage.SIGNATURE ) ) ); assertThat( connection, util.eventuallyReceives( msgFailure( Status.Request.Invalid, "Duplicate map key `key1`." ) ) ); assertThat( connection, eventuallyDisconnects() ); @@ -145,7 +145,7 @@ public void shouldTerminateConnectionWhenUnknownMessageIsSent() throws Exception { connection.connect( address ).send( util.defaultAcceptedVersions() ); assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); - connection.send( util.chunk( new Init( USER_AGENT, Collections.emptyMap() ) ) ); + connection.send( util.chunk( new InitMessage( USER_AGENT, Collections.emptyMap() ) ) ); assertThat( connection, util.eventuallyReceives( msgSuccess() ) ); connection.send( util.chunk( 64, createMsg( (byte)'A' ) ) ); @@ -158,10 +158,10 @@ public void shouldTerminateConnectionWhenUnknownTypeIsSent() throws Exception { connection.connect( address ).send( util.defaultAcceptedVersions() ); assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); - connection.send( util.chunk( new Init( USER_AGENT, Collections.emptyMap() ) ) ); + connection.send( util.chunk( new InitMessage( USER_AGENT, Collections.emptyMap() ) ) ); assertThat( connection, util.eventuallyReceives( msgSuccess() ) ); - connection.send( util.chunk( 64, createMsgWithUnknownValue( Run.SIGNATURE ) ) ); + connection.send( util.chunk( 64, createMsgWithUnknownValue( RunMessage.SIGNATURE ) ) ); assertThat( connection, eventuallyDisconnects() ); } @@ -170,7 +170,7 @@ private void testFailureWithV1Value( AnyValue value, String description ) throws { connection.connect( address ).send( util.defaultAcceptedVersions() ); assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); - connection.send( util.chunk( new Init( USER_AGENT, Collections.emptyMap() ) ) ); + connection.send( util.chunk( new InitMessage( USER_AGENT, Collections.emptyMap() ) ) ); assertThat( connection, util.eventuallyReceives( msgSuccess() ) ); connection.send( util.chunk( 64, createRunWithV1Value( value ) ) ); @@ -185,7 +185,7 @@ private byte[] createRunWithV1Value( AnyValue value ) throws IOException PackedOutputArray out = new PackedOutputArray(); Neo4jPack.Packer packer = neo4jPack.newPacker( out ); - packer.packStructHeader( 2, Run.SIGNATURE ); + packer.packStructHeader( 2, RunMessage.SIGNATURE ); packer.pack( "RETURN $x" ); packer.packMapHeader( 1 ); packer.pack( "x" ); diff --git a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v2/transport/integration/BoltV2TransportIT.java b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v2/transport/integration/BoltV2TransportIT.java index fce06a549d0ea..57e1d8755dde6 100644 --- a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v2/transport/integration/BoltV2TransportIT.java +++ b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v2/transport/integration/BoltV2TransportIT.java @@ -30,9 +30,9 @@ import java.time.ZoneOffset; import java.util.List; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.bolt.v1.transport.integration.Neo4jWithSocket; import org.neo4j.bolt.v1.transport.integration.TransportTestUtil; import org.neo4j.bolt.v1.transport.socket.client.SecureSocketConnection; @@ -109,7 +109,7 @@ public void shouldNegotiateProtocolV2() throws Exception { connection.connect( address ) .send( util.acceptedVersions( 2, 0, 0, 0 ) ) - .send( util.chunk( new Init( USER_AGENT, emptyMap() ) ) ); + .send( util.chunk( new InitMessage( USER_AGENT, emptyMap() ) ) ); assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 2} ) ); } @@ -119,7 +119,7 @@ public void shouldNegotiateProtocolV2WhenClientSupportsBothV1AndV2() throws Exce { connection.connect( address ) .send( util.acceptedVersions( 2, 1, 0, 0 ) ) - .send( util.chunk( new Init( USER_AGENT, emptyMap() ) ) ); + .send( util.chunk( new InitMessage( USER_AGENT, emptyMap() ) ) ); assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 2} ) ); } @@ -275,8 +275,8 @@ private void testSendingOfBoltV2Value( T value ) throws Exc negotiateBoltV2(); connection.send( util.chunk( - new Run( "CREATE (n:Node {value: $value}) RETURN 42", map( new String[]{"value"}, new AnyValue[]{value} ) ), - PullAll.INSTANCE ) ); + new RunMessage( "CREATE (n:Node {value: $value}) RETURN 42", map( new String[]{"value"}, new AnyValue[]{value} ) ), + PullAllMessage.INSTANCE ) ); assertThat( connection, util.eventuallyReceives( msgSuccess(), @@ -290,8 +290,8 @@ private void testReceivingOfBoltV2Value( String query, T ex negotiateBoltV2(); connection.send( util.chunk( - new Run( query ), - PullAll.INSTANCE ) ); + new RunMessage( query ), + PullAllMessage.INSTANCE ) ); assertThat( connection, util.eventuallyReceives( msgSuccess(), @@ -305,8 +305,8 @@ private void testSendingAndReceivingOfBoltV2Value( T value negotiateBoltV2(); connection.send( util.chunk( - new Run( "RETURN $value", map( new String[]{"value"}, new AnyValue[]{value} ) ), - PullAll.INSTANCE ) ); + new RunMessage( "RETURN $value", map( new String[]{"value"}, new AnyValue[]{value} ) ), + PullAllMessage.INSTANCE ) ); assertThat( connection, util.eventuallyReceives( msgSuccess(), @@ -319,7 +319,7 @@ private void negotiateBoltV2() throws Exception { connection.connect( address ) .send( util.acceptedVersions( 2, 0, 0, 0 ) ) - .send( util.chunk( new Init( USER_AGENT, emptyMap() ) ) ); + .send( util.chunk( new InitMessage( USER_AGENT, emptyMap() ) ) ); assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 2} ) ); } diff --git a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v2/transport/integration/UnsupportedStructTypesV2IT.java b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v2/transport/integration/UnsupportedStructTypesV2IT.java index 221b865b7c78f..b5bae330bac67 100644 --- a/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v2/transport/integration/UnsupportedStructTypesV2IT.java +++ b/community/community-it/bolt-it/src/test/java/org/neo4j/bolt/v2/transport/integration/UnsupportedStructTypesV2IT.java @@ -32,8 +32,8 @@ import org.neo4j.bolt.messaging.Neo4jPack; import org.neo4j.bolt.messaging.StructType; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.bolt.v1.packstream.PackedOutputArray; import org.neo4j.bolt.v1.transport.integration.Neo4jWithSocket; import org.neo4j.bolt.v1.transport.integration.TransportTestUtil; @@ -160,7 +160,7 @@ private void testFailureWithUnpackableValue( ThrowingConsumer va PackedOutputArray out = new PackedOutputArray(); Neo4jPack.Packer packer = new Neo4jPackV2().newPacker( out ); - packer.packStructHeader( 2, Run.SIGNATURE ); + packer.packStructHeader( 2, RunMessage.SIGNATURE ); packer.pack( "RETURN $x" ); packer.packMapHeader( 1 ); packer.pack( "x" ); diff --git a/enterprise/metrics/src/test/java/org/neo4j/metrics/BoltMetricsIT.java b/enterprise/metrics/src/test/java/org/neo4j/metrics/BoltMetricsIT.java index 46564e2145ab1..42cf4942f50e6 100644 --- a/enterprise/metrics/src/test/java/org/neo4j/metrics/BoltMetricsIT.java +++ b/enterprise/metrics/src/test/java/org/neo4j/metrics/BoltMetricsIT.java @@ -29,7 +29,7 @@ import java.io.File; import org.neo4j.bolt.v1.messaging.Neo4jPackV1; -import org.neo4j.bolt.v1.messaging.message.Init; +import org.neo4j.bolt.v1.messaging.request.InitMessage; import org.neo4j.bolt.v1.transport.integration.TransportTestUtil; import org.neo4j.bolt.v1.transport.socket.client.SocketConnection; import org.neo4j.bolt.v1.transport.socket.client.TransportConnection; @@ -92,7 +92,7 @@ public void shouldMonitorBolt() throws Throwable conn = new SocketConnection() .connect( new HostnamePort( "localhost", port ) ) .send( util.acceptedVersions( 1, 0, 0, 0 ) ) - .send( util.chunk( new Init( "TestClient", + .send( util.chunk( new InitMessage( "TestClient", map("scheme", "basic", "principal", "neo4j", "credentials", "neo4j") ) ) ); // Then diff --git a/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/BoltInteraction.java b/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/BoltInteraction.java index 3ceb2b1f06d68..e7b5fba88a9e3 100644 --- a/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/BoltInteraction.java +++ b/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/BoltInteraction.java @@ -30,16 +30,16 @@ import java.util.function.Consumer; import java.util.function.Supplier; +import org.neo4j.bolt.messaging.ResponseMessage; import org.neo4j.bolt.security.auth.AuthenticationException; import org.neo4j.bolt.v1.messaging.Neo4jPackV1; -import org.neo4j.bolt.v1.messaging.message.FailureMessage; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.RecordMessage; -import org.neo4j.bolt.v1.messaging.message.Reset; -import org.neo4j.bolt.v1.messaging.message.ResponseMessage; -import org.neo4j.bolt.v1.messaging.message.Run; -import org.neo4j.bolt.v1.messaging.message.SuccessMessage; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; +import org.neo4j.bolt.v1.messaging.response.FailureMessage; +import org.neo4j.bolt.v1.messaging.response.RecordMessage; +import org.neo4j.bolt.v1.messaging.response.SuccessMessage; import org.neo4j.bolt.v1.transport.integration.Neo4jWithSocket; import org.neo4j.bolt.v1.transport.integration.TransportTestUtil; import org.neo4j.bolt.v1.transport.socket.client.SocketConnection; @@ -151,7 +151,7 @@ public String executeQuery( BoltSubject subject, String call, Map } try { - subject.client.send( util.chunk( new Run( call, ValueUtils.asMapValue( params ) ), PullAll.INSTANCE ) ); + subject.client.send( util.chunk( new RunMessage( call, ValueUtils.asMapValue( params ) ), PullAllMessage.INSTANCE ) ); resultConsumer.accept( collectResults( subject.client ) ); return ""; } @@ -177,7 +177,7 @@ public BoltSubject login( String username, String password ) throws Exception } subject.client.connect( server.lookupDefaultConnector() ) .send( util.acceptedVersions( 1, 0, 0, 0 ) ) - .send( util.chunk( new Init( "TestClient/1.1", + .send( util.chunk( new InitMessage( "TestClient/1.1", map( REALM_KEY, NATIVE_REALM, PRINCIPAL, username, CREDENTIALS, password, SCHEME_KEY, BASIC_SCHEME ) ) ) ); assertThat( subject.client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) ); @@ -272,7 +272,7 @@ else if ( message instanceof FailureMessage ) FailureMessage failMessage = (FailureMessage) message; // drain ignoredMessage, ack failure, get successMessage util.receiveOneResponseMessage( client ); - client.send( util.chunk( Reset.INSTANCE ) ); + client.send( util.chunk( ResetMessage.INSTANCE ) ); util.receiveOneResponseMessage( client ); throw new AuthenticationException( failMessage.status(), failMessage.message() ); } @@ -297,7 +297,7 @@ else if ( message instanceof FailureMessage ) { FailureMessage failMessage = (FailureMessage) message; // ack failure, get successMessage - client.send( util.chunk( Reset.INSTANCE ) ); + client.send( util.chunk( ResetMessage.INSTANCE ) ); util.receiveOneResponseMessage( client ); throw new AuthenticationException( failMessage.status(), failMessage.message() ); } diff --git a/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/ProcedureInteractionTestBase.java b/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/ProcedureInteractionTestBase.java index fdcc5d211ac03..2c9a90ed5484c 100644 --- a/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/ProcedureInteractionTestBase.java +++ b/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/ProcedureInteractionTestBase.java @@ -43,7 +43,7 @@ import java.util.stream.Stream; import org.neo4j.bolt.v1.messaging.Neo4jPackV1; -import org.neo4j.bolt.v1.messaging.message.Init; +import org.neo4j.bolt.v1.messaging.request.InitMessage; import org.neo4j.bolt.v1.transport.integration.TransportTestUtil; import org.neo4j.bolt.v1.transport.socket.client.SocketConnection; import org.neo4j.bolt.v1.transport.socket.client.TransportConnection; @@ -621,7 +621,7 @@ TransportConnection startBoltSession( String username, String password ) throws Map authToken = map( "principal", username, "credentials", password, "scheme", "basic" ); connection.connect( address ).send( util.acceptedVersions( 1, 0, 0, 0 ) ) - .send( util.chunk( new Init( "TestClient/1.1", authToken ) ) ); + .send( util.chunk( new InitMessage( "TestClient/1.1", authToken ) ) ); assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) ); assertThat( connection, util.eventuallyReceives( msgSuccess() ) ); diff --git a/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/integration/bolt/ActiveDirectoryAuthenticationIT.java b/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/integration/bolt/ActiveDirectoryAuthenticationIT.java index 1b7eb1c1d22c7..d884c133227e5 100644 --- a/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/integration/bolt/ActiveDirectoryAuthenticationIT.java +++ b/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/integration/bolt/ActiveDirectoryAuthenticationIT.java @@ -33,9 +33,9 @@ import java.util.function.Consumer; import org.neo4j.bolt.v1.messaging.Neo4jPackV1; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.bolt.v1.transport.integration.Neo4jWithSocket; import org.neo4j.bolt.v1.transport.integration.TransportTestUtil; import org.neo4j.bolt.v1.transport.socket.client.SecureSocketConnection; @@ -283,7 +283,7 @@ private void assertAuth( String username, String password, String realm ) throws { client.connect( address ) .send( util.acceptedVersions( 1, 0, 0, 0 ) ) - .send( util.chunk( new Init( "TestClient/1.1", authToken( username, password, realm ) ) ) ); + .send( util.chunk( new InitMessage( "TestClient/1.1", authToken( username, password, realm ) ) ) ); assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) ); assertThat( client, util.eventuallyReceives( msgSuccess() ) ); @@ -306,7 +306,7 @@ private void assertAuthFail( String username, String password ) throws Exception client.connect( address ) .send( util.acceptedVersions( 1, 0, 0, 0 ) ) .send( util.chunk( - new Init( "TestClient/1.1", map( "principal", username, + new InitMessage( "TestClient/1.1", map( "principal", username, "credentials", password, "scheme", "basic" ) ) ) ); assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) ); @@ -318,8 +318,8 @@ protected void assertReadSucceeds() throws Exception { // When client.send( util.chunk( - new Run( "MATCH (n) RETURN n" ), - PullAll.INSTANCE ) ); + new RunMessage( "MATCH (n) RETURN n" ), + PullAllMessage.INSTANCE ) ); // Then assertThat( client, util.eventuallyReceives( msgSuccess(), msgSuccess() ) ); @@ -329,8 +329,8 @@ protected void assertReadFails( String username ) throws Exception { // When client.send( util.chunk( - new Run( "MATCH (n) RETURN n" ), - PullAll.INSTANCE ) ); + new RunMessage( "MATCH (n) RETURN n" ), + PullAllMessage.INSTANCE ) ); // Then assertThat( client, util.eventuallyReceives( @@ -342,8 +342,8 @@ protected void assertWriteSucceeds() throws Exception { // When client.send( util.chunk( - new Run( "CREATE ()" ), - PullAll.INSTANCE ) ); + new RunMessage( "CREATE ()" ), + PullAllMessage.INSTANCE ) ); // Then assertThat( client, util.eventuallyReceives( msgSuccess(), msgSuccess() ) ); @@ -353,8 +353,8 @@ protected void assertWriteFails( String username ) throws Exception { // When client.send( util.chunk( - new Run( "CREATE ()" ), - PullAll.INSTANCE ) ); + new RunMessage( "CREATE ()" ), + PullAllMessage.INSTANCE ) ); // Then assertThat( client, util.eventuallyReceives( diff --git a/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/integration/bolt/BoltConnectionManagementIT.java b/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/integration/bolt/BoltConnectionManagementIT.java index cb5e6c256167d..9403fb95a8a28 100644 --- a/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/integration/bolt/BoltConnectionManagementIT.java +++ b/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/integration/bolt/BoltConnectionManagementIT.java @@ -37,10 +37,10 @@ import java.util.function.Consumer; import org.neo4j.bolt.v1.messaging.Neo4jPackV1; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Reset; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.ResetMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.bolt.v1.runtime.spi.ImmutableRecord; import org.neo4j.bolt.v1.transport.integration.Neo4jWithSocket; import org.neo4j.bolt.v1.transport.integration.TransportTestUtil; @@ -146,8 +146,8 @@ public void shouldListOwnConnection() throws Throwable { // When admin.send( util.chunk( - new Run( "CALL dbms.listConnections() YIELD username, connectionCount" ), - PullAll.INSTANCE ) ); + new RunMessage( "CALL dbms.listConnections() YIELD username, connectionCount" ), + PullAllMessage.INSTANCE ) ); // Then Map result = collectConnectionResult( admin, 1 ); @@ -162,8 +162,8 @@ public void shouldListAllConnections() throws Throwable // When authenticate( user, "Igor", "123", null ); admin.send( util.chunk( - new Run( "CALL dbms.listConnections() YIELD username, connectionCount" ), - PullAll.INSTANCE ) ); + new RunMessage( "CALL dbms.listConnections() YIELD username, connectionCount" ), + PullAllMessage.INSTANCE ) ); // Then Map result = collectConnectionResult( admin, 2 ); @@ -180,8 +180,8 @@ public void shouldNotListConnectionsIfNotAdmin() throws Throwable // When authenticate( user, "Igor", "123", null ); user.send( util.chunk( - new Run( "CALL dbms.listConnections() YIELD username, connectionCount" ), - PullAll.INSTANCE ) ); + new RunMessage( "CALL dbms.listConnections() YIELD username, connectionCount" ), + PullAllMessage.INSTANCE ) ); // Then assertThat( user, util.eventuallyReceives( @@ -196,8 +196,8 @@ public void shouldTerminateConnectionForUser() throws Throwable // When authenticate( user, "Igor", "123", null ); admin.send( util.chunk( - new Run( "CALL dbms.terminateConnectionsForUser( 'Igor' ) YIELD username, connectionCount" ), - PullAll.INSTANCE ) ); + new RunMessage( "CALL dbms.terminateConnectionsForUser( 'Igor' ) YIELD username, connectionCount" ), + PullAllMessage.INSTANCE ) ); // Then Map terminationResult = collectConnectionResult( admin, 1 ); @@ -205,8 +205,8 @@ public void shouldTerminateConnectionForUser() throws Throwable assertTrue( terminationResult.get( "Igor" ) == 1L ); admin.send( util.chunk( - new Run( "CALL dbms.listConnections() YIELD username, connectionCount" ), - PullAll.INSTANCE ) ); + new RunMessage( "CALL dbms.listConnections() YIELD username, connectionCount" ), + PullAllMessage.INSTANCE ) ); Map listResult = collectConnectionResult( admin, 1 ); assertTrue( listResult.containsKey( "neo4j" ) ); assertTrue( listResult.get( "neo4j" ) == 1L ); @@ -219,8 +219,8 @@ public void shouldNotFailWhenTerminatingConnectionsForUserWithNoConnections() th { // When admin.send( util.chunk( - new Run( "CALL dbms.terminateConnectionsForUser( 'Igor' ) YIELD username, connectionCount" ), - PullAll.INSTANCE ) ); + new RunMessage( "CALL dbms.terminateConnectionsForUser( 'Igor' ) YIELD username, connectionCount" ), + PullAllMessage.INSTANCE ) ); // Then Map terminationResult = collectConnectionResult( admin, 1 ); @@ -233,8 +233,8 @@ public void shouldFailWhenTerminatingConnectionsForNonExistentUser() throws Thro { // When admin.send( util.chunk( - new Run( "CALL dbms.terminateConnectionsForUser( 'NonExistentUser' ) YIELD username, connectionCount" ), - PullAll.INSTANCE ) ); + new RunMessage( "CALL dbms.terminateConnectionsForUser( 'NonExistentUser' ) YIELD username, connectionCount" ), + PullAllMessage.INSTANCE ) ); // Then assertThat( admin, util.eventuallyReceives( msgFailure( Status.General.InvalidArguments, @@ -302,8 +302,8 @@ private void assertTerminateOwnConnection( TransportConnection conn, String user { // Given conn.send( util.chunk( - new Run( "CALL dbms.terminateConnectionsForUser( '" + username + "' ) YIELD username, connectionCount" ), - PullAll.INSTANCE ) ); + new RunMessage( "CALL dbms.terminateConnectionsForUser( '" + username + "' ) YIELD username, connectionCount" ), + PullAllMessage.INSTANCE ) ); // Then verifyConnectionHasTerminated( conn ); @@ -312,8 +312,8 @@ private void assertTerminateOwnConnection( TransportConnection conn, String user private void assertTerminateOwnConnections( TransportConnection conn1, TransportConnection conn2, String username ) throws Exception { conn1.send( util.chunk( - new Run( "CALL dbms.terminateConnectionsForUser( '" + username + "' ) YIELD username, connectionCount" ), - PullAll.INSTANCE ) ); + new RunMessage( "CALL dbms.terminateConnectionsForUser( '" + username + "' ) YIELD username, connectionCount" ), + PullAllMessage.INSTANCE ) ); // Then verifyConnectionHasTerminated( conn1 ); @@ -323,8 +323,8 @@ private void assertTerminateOwnConnections( TransportConnection conn1, Transport private void assertFailTerminateConnectionForUser( TransportConnection client, String username ) throws Exception { client.send( util.chunk( - new Run( "CALL dbms.terminateConnectionsForUser( '" + username + "' ) YIELD username, connectionCount" ), - PullAll.INSTANCE ) ); + new RunMessage( "CALL dbms.terminateConnectionsForUser( '" + username + "' ) YIELD username, connectionCount" ), + PullAllMessage.INSTANCE ) ); // Then assertThat( client, util.eventuallyReceives( @@ -332,7 +332,7 @@ private void assertFailTerminateConnectionForUser( TransportConnection client, S msgIgnored() ) ); - client.send( util.chunk( Reset.INSTANCE ) ); + client.send( util.chunk( ResetMessage.INSTANCE ) ); assertThat( client, util.eventuallyReceives( msgSuccess() ) ); } @@ -350,7 +350,7 @@ private void authenticate( TransportConnection client, String username, String p client.connect( address ) .send( util.acceptedVersions( 1, 0, 0, 0 ) ) .send( util.chunk( - new Init( "TestClient/1.1", authToken ) ) ); + new InitMessage( "TestClient/1.1", authToken ) ) ); assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) ); assertThat( client, util.eventuallyReceives( msgSuccess() ) ); @@ -359,8 +359,8 @@ private void authenticate( TransportConnection client, String username, String p private void createNewUser( TransportConnection client, String username, String password ) throws Exception { client.send( util.chunk( - new Run( "CALL dbms.security.createUser( '" + username + "', '" + password + "', false )" ), - PullAll.INSTANCE ) ); + new RunMessage( "CALL dbms.security.createUser( '" + username + "', '" + password + "', false )" ), + PullAllMessage.INSTANCE ) ); assertThat( client, util.eventuallyReceives( msgSuccess(), msgSuccess() ) ); } diff --git a/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/integration/bolt/EnterpriseAuthenticationTestBase.java b/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/integration/bolt/EnterpriseAuthenticationTestBase.java index 25318f9aa2c90..f23e4799e66e6 100644 --- a/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/integration/bolt/EnterpriseAuthenticationTestBase.java +++ b/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/integration/bolt/EnterpriseAuthenticationTestBase.java @@ -34,9 +34,9 @@ import java.util.function.Consumer; import org.neo4j.bolt.v1.messaging.Neo4jPackV1; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.bolt.v1.transport.integration.Neo4jWithSocket; import org.neo4j.bolt.v1.transport.integration.TransportTestUtil; import org.neo4j.bolt.v1.transport.socket.client.SecureSocketConnection; @@ -163,9 +163,9 @@ protected void testCreateReaderUser( String username ) throws Exception assertAuthAndChangePassword( "neo4j", "abc123", "123" ); client.send( util.chunk( - new Run( "CALL dbms.security.createUser( '" + username + "', '" + createdUserPassword + "', false ) " + + new RunMessage( "CALL dbms.security.createUser( '" + username + "', '" + createdUserPassword + "', false ) " + "CALL dbms.security.addRoleToUser( 'reader', '" + username + "' ) RETURN 0" ), - PullAll.INSTANCE ) ); + PullAllMessage.INSTANCE ) ); assertThat( client, util.eventuallyReceives( msgSuccess(), msgRecord( eqRecord( equalTo( longValue( 0L ) ) ) ) ) ); } @@ -198,7 +198,7 @@ protected void assertAuthAndChangePassword( String username, String password, St { assertAuth( username, password ); String query = format( "CALL dbms.security.changePassword('%s')", newPassword ); - client.send( util.chunk( new Run( query ), PullAll.INSTANCE ) ); + client.send( util.chunk( new RunMessage( query ), PullAllMessage.INSTANCE ) ); assertThat( client, util.eventuallyReceives( msgSuccess(), msgSuccess() ) ); } @@ -214,7 +214,7 @@ protected void assertAuthFail( String username, String password ) throws Excepti protected void assertRoles( String... roles ) throws Exception { - client.send( util.chunk( new Run( "CALL dbms.showCurrentUser" ), PullAll.INSTANCE ) ); + client.send( util.chunk( new RunMessage( "CALL dbms.showCurrentUser" ), PullAllMessage.INSTANCE ) ); // Then assertThat( client, util.eventuallyReceives( @@ -230,7 +230,7 @@ protected void assertConnectionSucceeds( Map authToken ) throws E client.connect( address ) .send( util.acceptedVersions( 1, 0, 0, 0 ) ) .send( util.chunk( - new Init( "TestClient/1.1", authToken ) ) ); + new InitMessage( "TestClient/1.1", authToken ) ) ); // Then assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) ); @@ -248,7 +248,7 @@ protected void assertConnectionFails( Map authToken ) throws Exce client.connect( address ) .send( util.acceptedVersions( 1, 0, 0, 0 ) ) .send( util.chunk( - new Init( "TestClient/1.1", authToken ) ) ); + new InitMessage( "TestClient/1.1", authToken ) ) ); assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) ); assertThat( client, util.eventuallyReceives( msgFailure( Status.Security.Unauthorized, @@ -273,8 +273,8 @@ protected void assertConnectionFails( Map authToken ) throws Exce protected void assertReadSucceeds() throws Exception { // When - client.send( util.chunk( new Run( "MATCH (n) RETURN count(n)" ), - PullAll.INSTANCE ) ); + client.send( util.chunk( new RunMessage( "MATCH (n) RETURN count(n)" ), + PullAllMessage.INSTANCE ) ); // Then assertThat( client, util.eventuallyReceives( @@ -287,8 +287,8 @@ protected void assertReadFails( String username, String roles ) throws Exception { // When client.send( util.chunk( - new Run( "MATCH (n) RETURN n" ), - PullAll.INSTANCE ) ); + new RunMessage( "MATCH (n) RETURN n" ), + PullAllMessage.INSTANCE ) ); String roleString = StringUtils.isEmpty( roles ) ? "no roles" : "roles [" + roles + "]"; @@ -302,8 +302,8 @@ protected void assertWriteSucceeds() throws Exception { // When client.send( util.chunk( - new Run( "CREATE ()" ), - PullAll.INSTANCE ) ); + new RunMessage( "CREATE ()" ), + PullAllMessage.INSTANCE ) ); // Then assertThat( client, util.eventuallyReceives( msgSuccess(), msgSuccess() ) ); @@ -313,8 +313,8 @@ protected void assertWriteFails( String username, String roles ) throws Exceptio { // When client.send( util.chunk( - new Run( "CREATE ()" ), - PullAll.INSTANCE ) ); + new RunMessage( "CREATE ()" ), + PullAllMessage.INSTANCE ) ); String roleString = StringUtils.isEmpty( roles ) ? "no roles" : "roles [" + roles + "]"; @@ -327,8 +327,8 @@ protected void assertWriteFails( String username, String roles ) throws Exceptio protected void assertBeginTransactionSucceeds() throws Exception { // When - client.send( util.chunk( new Run( "BEGIN" ), - PullAll.INSTANCE ) ); + client.send( util.chunk( new RunMessage( "BEGIN" ), + PullAllMessage.INSTANCE ) ); // Then assertThat( client, util.eventuallyReceives( msgSuccess(), msgSuccess() ) ); @@ -338,8 +338,8 @@ protected void assertCommitTransaction() throws Exception { // When client.send( util.chunk( - new Run( "COMMIT" ), - PullAll.INSTANCE ) ); + new RunMessage( "COMMIT" ), + PullAllMessage.INSTANCE ) ); // Then assertThat( client, util.eventuallyReceives( msgSuccess(), msgSuccess() ) ); @@ -349,8 +349,8 @@ protected void assertQuerySucceeds( String query ) throws Exception { // When client.send( util.chunk( - new Run( query ), - PullAll.INSTANCE ) ); + new RunMessage( query ), + PullAllMessage.INSTANCE ) ); // Then assertThat( client, util.eventuallyReceives( msgSuccess(), msgSuccess() ) ); diff --git a/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/integration/bolt/LdapAuthIT.java b/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/integration/bolt/LdapAuthIT.java index 79c8850aeea4d..a37fdb9ad6a7d 100644 --- a/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/integration/bolt/LdapAuthIT.java +++ b/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/integration/bolt/LdapAuthIT.java @@ -57,9 +57,9 @@ import javax.naming.directory.ModificationItem; import javax.naming.ldap.LdapContext; -import org.neo4j.bolt.v1.messaging.message.Init; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.InitMessage; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.bolt.v1.transport.socket.client.TransportConnection; import org.neo4j.graphdb.config.Setting; import org.neo4j.internal.kernel.api.security.AuthSubject; @@ -286,8 +286,8 @@ public void shouldShowCurrentUser() throws Throwable // When assertAuth( "smith", "abc123" ); client.send( util.chunk( - new Run( "CALL dbms.showCurrentUser()" ), - PullAll.INSTANCE ) ); + new RunMessage( "CALL dbms.showCurrentUser()" ), + PullAllMessage.INSTANCE ) ); // Then // Assuming showCurrentUser has fields username, roles, flags @@ -357,12 +357,12 @@ public void shouldFailIfAuthorizationExpiredWithUserLdapContext() throws Throwab // When client.send( util.chunk( - new Run( "CALL dbms.security.clearAuthCache()" ), PullAll.INSTANCE ) ); + new RunMessage( "CALL dbms.security.clearAuthCache()" ), PullAllMessage.INSTANCE ) ); assertThat( client, util.eventuallyReceives( msgSuccess(), msgSuccess() ) ); // Then client.send( util.chunk( - new Run( "MATCH (n) RETURN n" ), PullAll.INSTANCE ) ); + new RunMessage( "MATCH (n) RETURN n" ), PullAllMessage.INSTANCE ) ); assertThat( client, util.eventuallyReceives( msgFailure( Status.Security.AuthorizationExpired, "LDAP authorization info expired." ) ) ); @@ -378,7 +378,7 @@ public void shouldSucceedIfAuthorizationExpiredWithinTransactionWithUserLdapCont assertAuth( "neo4j", "abc123" ); client.send( util.chunk( - new Run( "CALL dbms.security.clearAuthCache() MATCH (n) RETURN n" ), PullAll.INSTANCE ) ); + new RunMessage( "CALL dbms.security.clearAuthCache() MATCH (n) RETURN n" ), PullAllMessage.INSTANCE ) ); // Then assertThat( client, util.eventuallyReceives( msgSuccess(), msgSuccess() ) ); @@ -654,7 +654,7 @@ public void shouldTimeoutIfLdapServerDoesNotRespondWithLdapUserContext() throws private void assertAllowedReadProcedure() throws IOException { - client.send( util.chunk( new Run( "CALL test.allowedReadProcedure()" ), PullAll.INSTANCE ) ); + client.send( util.chunk( new RunMessage( "CALL test.allowedReadProcedure()" ), PullAllMessage.INSTANCE ) ); // Then assertThat( client, util.eventuallyReceives( @@ -1201,19 +1201,19 @@ private void clearAuthCacheFromDifferentConnection() throws Exception adminClient.connect( address ) .send( util.acceptedVersions( 1, 0, 0, 0 ) ) .send( util.chunk( - new Init( "TestClient/1.1", authToken ) ) ); + new InitMessage( "TestClient/1.1", authToken ) ) ); assertThat( adminClient, eventuallyReceives( new byte[]{0, 0, 0, 1} ) ); assertThat( adminClient, util.eventuallyReceives( msgSuccess() ) ); // Clear auth cache - adminClient.send( util.chunk( new Run( "CALL dbms.security.clearAuthCache()" ), PullAll.INSTANCE ) ); + adminClient.send( util.chunk( new RunMessage( "CALL dbms.security.clearAuthCache()" ), PullAllMessage.INSTANCE ) ); assertThat( adminClient, util.eventuallyReceives( msgSuccess(), msgSuccess() ) ); } private void assertLdapAuthorizationTimeout() throws IOException { // When - client.send( util.chunk( new Run( "MATCH (n) RETURN n" ), PullAll.INSTANCE ) ); + client.send( util.chunk( new RunMessage( "MATCH (n) RETURN n" ), PullAllMessage.INSTANCE ) ); // Then assertThat( client, util.eventuallyReceives( @@ -1225,7 +1225,7 @@ private void assertLdapAuthorizationTimeout() throws IOException private void assertLdapAuthorizationFailed() throws IOException { // When - client.send( util.chunk( new Run( "MATCH (n) RETURN n" ), PullAll.INSTANCE ) ); + client.send( util.chunk( new RunMessage( "MATCH (n) RETURN n" ), PullAllMessage.INSTANCE ) ); // Then assertThat( client, util.eventuallyReceives( @@ -1239,7 +1239,7 @@ private void assertConnectionTimeout( Map authToken, String messa client.connect( address ) .send( util.acceptedVersions( 1, 0, 0, 0 ) ) .send( util.chunk( - new Init( "TestClient/1.1", authToken ) ) ); + new InitMessage( "TestClient/1.1", authToken ) ) ); assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) ); assertThat( client, util.eventuallyReceives( msgFailure( Status.Security.AuthProviderTimeout, message ) ) ); @@ -1252,7 +1252,7 @@ private void assertConnectionRefused( Map authToken, String messa client.connect( address ) .send( util.acceptedVersions( 1, 0, 0, 0 ) ) .send( util.chunk( - new Init( "TestClient/1.1", authToken ) ) ); + new InitMessage( "TestClient/1.1", authToken ) ) ); assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) ); assertThat( client, util.eventuallyReceives( msgFailure( Status.Security.AuthProviderFailed, message ) ) ); @@ -1264,7 +1264,7 @@ private void testClearAuthCache() throws Exception { assertAuth( "neo4j", "abc123" ); - client.send( util.chunk( new Run( "CALL dbms.security.clearAuthCache()" ), PullAll.INSTANCE ) ); + client.send( util.chunk( new RunMessage( "CALL dbms.security.clearAuthCache()" ), PullAllMessage.INSTANCE ) ); assertThat( client, util.eventuallyReceives( msgSuccess(), msgSuccess() ) ); } diff --git a/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/integration/bolt/PluginAuthenticationIT.java b/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/integration/bolt/PluginAuthenticationIT.java index 33f04442a75e9..1d6a8f6117f7e 100644 --- a/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/integration/bolt/PluginAuthenticationIT.java +++ b/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/integration/bolt/PluginAuthenticationIT.java @@ -31,8 +31,8 @@ import java.util.function.Consumer; import java.util.stream.Collectors; -import org.neo4j.bolt.v1.messaging.message.PullAll; -import org.neo4j.bolt.v1.messaging.message.Run; +import org.neo4j.bolt.v1.messaging.request.PullAllMessage; +import org.neo4j.bolt.v1.messaging.request.RunMessage; import org.neo4j.graphdb.config.Setting; import org.neo4j.kernel.api.exceptions.Status; import org.neo4j.server.security.enterprise.auth.plugin.TestCacheableAuthPlugin; @@ -211,12 +211,12 @@ public void shouldFailIfAuthorizationExpiredWithAuthPlugin() throws Throwable // When client.send( util.chunk( - new Run( "CALL dbms.security.clearAuthCache()" ), PullAll.INSTANCE ) ); + new RunMessage( "CALL dbms.security.clearAuthCache()" ), PullAllMessage.INSTANCE ) ); assertThat( client, util.eventuallyReceives( msgSuccess(), msgSuccess() ) ); // Then client.send( util.chunk( - new Run( "MATCH (n) RETURN n" ), PullAll.INSTANCE ) ); + new RunMessage( "MATCH (n) RETURN n" ), PullAllMessage.INSTANCE ) ); assertThat( client, util.eventuallyReceives( msgFailure( Status.Security.AuthorizationExpired, "Plugin 'plugin-TestCacheableAdminAuthPlugin' authorization info expired." ) ) ); @@ -232,7 +232,7 @@ public void shouldSucceedIfAuthorizationExpiredWithinTransactionWithAuthPlugin() assertConnectionSucceeds( authToken( "neo4j", "neo4j", "plugin-TestCacheableAdminAuthPlugin" ) ); client.send( util.chunk( - new Run( "CALL dbms.security.clearAuthCache() MATCH (n) RETURN n" ), PullAll.INSTANCE ) ); + new RunMessage( "CALL dbms.security.clearAuthCache() MATCH (n) RETURN n" ), PullAllMessage.INSTANCE ) ); // Then assertThat( client, util.eventuallyReceives( msgSuccess(), msgSuccess() ) ); @@ -258,7 +258,7 @@ public void shouldPassOnAuthorizationExpiredException() throws Throwable // Then client.send( util.chunk( - new Run( "MATCH (n) RETURN n" ), PullAll.INSTANCE ) ); + new RunMessage( "MATCH (n) RETURN n" ), PullAllMessage.INSTANCE ) ); assertThat( client, util.eventuallyReceives( msgFailure( Status.Security.AuthorizationExpired, "Plugin 'plugin-TestCombinedAuthPlugin' authorization info expired: " +