diff --git a/driver/clirr-ignored-differences.xml b/driver/clirr-ignored-differences.xml
index 9b77f32b46..9f143e3ff2 100644
--- a/driver/clirr-ignored-differences.xml
+++ b/driver/clirr-ignored-differences.xml
@@ -43,4 +43,10 @@
org.reactivestreams.Publisher close()
+
+ org/neo4j/driver/summary/ServerInfo
+ 7002
+ java.lang.String version()
+
+
diff --git a/driver/src/main/java/org/neo4j/driver/internal/ImpersonationUtil.java b/driver/src/main/java/org/neo4j/driver/internal/ImpersonationUtil.java
index 0a944c7001..a41ee61d68 100644
--- a/driver/src/main/java/org/neo4j/driver/internal/ImpersonationUtil.java
+++ b/driver/src/main/java/org/neo4j/driver/internal/ImpersonationUtil.java
@@ -21,7 +21,6 @@
import org.neo4j.driver.exceptions.ClientException;
import org.neo4j.driver.internal.messaging.v44.BoltProtocolV44;
import org.neo4j.driver.internal.spi.Connection;
-import org.neo4j.driver.internal.util.ServerVersion;
public class ImpersonationUtil
{
@@ -40,7 +39,6 @@ public static Connection ensureImpersonationSupport( Connection connection, Stri
private static boolean supportsImpersonation( Connection connection )
{
- return connection.serverVersion().greaterThanOrEqual( ServerVersion.v4_4_0 ) &&
- connection.protocol().version().compareTo( BoltProtocolV44.VERSION ) >= 0;
+ return connection.protocol().version().compareTo( BoltProtocolV44.VERSION ) >= 0;
}
}
diff --git a/driver/src/main/java/org/neo4j/driver/internal/async/NetworkConnection.java b/driver/src/main/java/org/neo4j/driver/internal/async/NetworkConnection.java
index c9e607f85b..c8916aaf32 100644
--- a/driver/src/main/java/org/neo4j/driver/internal/async/NetworkConnection.java
+++ b/driver/src/main/java/org/neo4j/driver/internal/async/NetworkConnection.java
@@ -43,7 +43,6 @@
import org.neo4j.driver.internal.spi.Connection;
import org.neo4j.driver.internal.spi.ResponseHandler;
import org.neo4j.driver.internal.util.Clock;
-import org.neo4j.driver.internal.util.ServerVersion;
import static java.util.Collections.emptyMap;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.poolId;
@@ -61,7 +60,6 @@ public class NetworkConnection implements Connection
private final InboundMessageDispatcher messageDispatcher;
private final String serverAgent;
private final BoltServerAddress serverAddress;
- private final ServerVersion serverVersion;
private final BoltProtocol protocol;
private final ExtendedChannelPool channelPool;
private final CompletableFuture releaseFuture;
@@ -81,7 +79,6 @@ public NetworkConnection( Channel channel, ExtendedChannelPool channelPool, Cloc
this.messageDispatcher = ChannelAttributes.messageDispatcher( channel );
this.serverAgent = ChannelAttributes.serverAgent( channel );
this.serverAddress = ChannelAttributes.serverAddress( channel );
- this.serverVersion = ChannelAttributes.serverVersion( channel );
this.protocol = BoltProtocol.forChannel( channel );
this.channelPool = channelPool;
this.releaseFuture = new CompletableFuture<>();
@@ -213,12 +210,6 @@ public BoltServerAddress serverAddress()
return serverAddress;
}
- @Override
- public ServerVersion serverVersion()
- {
- return serverVersion;
- }
-
@Override
public BoltProtocol protocol()
{
diff --git a/driver/src/main/java/org/neo4j/driver/internal/async/connection/ChannelAttributes.java b/driver/src/main/java/org/neo4j/driver/internal/async/connection/ChannelAttributes.java
index f3a8eefc95..f3baef0471 100644
--- a/driver/src/main/java/org/neo4j/driver/internal/async/connection/ChannelAttributes.java
+++ b/driver/src/main/java/org/neo4j/driver/internal/async/connection/ChannelAttributes.java
@@ -26,7 +26,6 @@
import org.neo4j.driver.internal.BoltServerAddress;
import org.neo4j.driver.internal.async.inbound.InboundMessageDispatcher;
import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
-import org.neo4j.driver.internal.util.ServerVersion;
import static io.netty.util.AttributeKey.newInstance;
@@ -37,7 +36,6 @@ public final class ChannelAttributes
private static final AttributeKey PROTOCOL_VERSION = newInstance( "protocolVersion" );
private static final AttributeKey SERVER_AGENT = newInstance( "serverAgent" );
private static final AttributeKey ADDRESS = newInstance( "serverAddress" );
- private static final AttributeKey SERVER_VERSION = newInstance( "serverVersion" );
private static final AttributeKey CREATION_TIMESTAMP = newInstance( "creationTimestamp" );
private static final AttributeKey LAST_USED_TIMESTAMP = newInstance( "lastUsedTimestamp" );
private static final AttributeKey MESSAGE_DISPATCHER = newInstance( "messageDispatcher" );
@@ -101,16 +99,6 @@ public static void setServerAddress( Channel channel, BoltServerAddress address
setOnce( channel, ADDRESS, address );
}
- public static ServerVersion serverVersion( Channel channel )
- {
- return get( channel, SERVER_VERSION );
- }
-
- public static void setServerVersion( Channel channel, ServerVersion version )
- {
- setOnce( channel, SERVER_VERSION, version );
- }
-
public static long creationTimestamp( Channel channel )
{
return get( channel, CREATION_TIMESTAMP );
diff --git a/driver/src/main/java/org/neo4j/driver/internal/async/connection/DirectConnection.java b/driver/src/main/java/org/neo4j/driver/internal/async/connection/DirectConnection.java
index ff0f663e55..3ed523488d 100644
--- a/driver/src/main/java/org/neo4j/driver/internal/async/connection/DirectConnection.java
+++ b/driver/src/main/java/org/neo4j/driver/internal/async/connection/DirectConnection.java
@@ -28,7 +28,6 @@
import org.neo4j.driver.internal.messaging.Message;
import org.neo4j.driver.internal.spi.Connection;
import org.neo4j.driver.internal.spi.ResponseHandler;
-import org.neo4j.driver.internal.util.ServerVersion;
/**
* This is a connection used by {@link DirectConnectionProvider} to connect to a remote database.
@@ -125,12 +124,6 @@ public BoltServerAddress serverAddress()
return delegate.serverAddress();
}
- @Override
- public ServerVersion serverVersion()
- {
- return delegate.serverVersion();
- }
-
@Override
public BoltProtocol protocol()
{
diff --git a/driver/src/main/java/org/neo4j/driver/internal/async/connection/RoutingConnection.java b/driver/src/main/java/org/neo4j/driver/internal/async/connection/RoutingConnection.java
index 9735a6382e..582975a192 100644
--- a/driver/src/main/java/org/neo4j/driver/internal/async/connection/RoutingConnection.java
+++ b/driver/src/main/java/org/neo4j/driver/internal/async/connection/RoutingConnection.java
@@ -29,7 +29,6 @@
import org.neo4j.driver.internal.messaging.Message;
import org.neo4j.driver.internal.spi.Connection;
import org.neo4j.driver.internal.spi.ResponseHandler;
-import org.neo4j.driver.internal.util.ServerVersion;
/**
* A connection used by the routing driver.
@@ -123,12 +122,6 @@ public BoltServerAddress serverAddress()
return delegate.serverAddress();
}
- @Override
- public ServerVersion serverVersion()
- {
- return delegate.serverVersion();
- }
-
@Override
public BoltProtocol protocol()
{
diff --git a/driver/src/main/java/org/neo4j/driver/internal/cluster/MultiDatabasesRoutingProcedureRunner.java b/driver/src/main/java/org/neo4j/driver/internal/cluster/MultiDatabasesRoutingProcedureRunner.java
index 43a054a227..71f09cfc08 100644
--- a/driver/src/main/java/org/neo4j/driver/internal/cluster/MultiDatabasesRoutingProcedureRunner.java
+++ b/driver/src/main/java/org/neo4j/driver/internal/cluster/MultiDatabasesRoutingProcedureRunner.java
@@ -28,8 +28,8 @@
import org.neo4j.driver.internal.DatabaseName;
import org.neo4j.driver.internal.ReadOnlyBookmarkHolder;
import org.neo4j.driver.internal.async.connection.DirectConnection;
+import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
import org.neo4j.driver.internal.spi.Connection;
-import org.neo4j.driver.internal.util.ServerVersion;
import static org.neo4j.driver.Values.value;
import static org.neo4j.driver.internal.DatabaseNameUtil.systemDatabase;
@@ -56,7 +56,7 @@ BookmarkHolder bookmarkHolder( Bookmark bookmark )
}
@Override
- Query procedureQuery(ServerVersion serverVersion, DatabaseName databaseName )
+ Query procedureQuery( BoltProtocolVersion protocolVersion, DatabaseName databaseName )
{
HashMap map = new HashMap<>();
map.put( ROUTING_CONTEXT, value( context.toMap() ) );
diff --git a/driver/src/main/java/org/neo4j/driver/internal/cluster/SingleDatabaseRoutingProcedureRunner.java b/driver/src/main/java/org/neo4j/driver/internal/cluster/SingleDatabaseRoutingProcedureRunner.java
index 3be6f7fc3b..585f19f1c5 100644
--- a/driver/src/main/java/org/neo4j/driver/internal/cluster/SingleDatabaseRoutingProcedureRunner.java
+++ b/driver/src/main/java/org/neo4j/driver/internal/cluster/SingleDatabaseRoutingProcedureRunner.java
@@ -33,9 +33,9 @@
import org.neo4j.driver.internal.BookmarkHolder;
import org.neo4j.driver.internal.DatabaseName;
import org.neo4j.driver.internal.async.connection.DirectConnection;
+import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
import org.neo4j.driver.internal.spi.Connection;
import org.neo4j.driver.internal.util.Futures;
-import org.neo4j.driver.internal.util.ServerVersion;
import static org.neo4j.driver.Values.parameters;
import static org.neo4j.driver.internal.DatabaseNameUtil.defaultDatabase;
@@ -61,7 +61,7 @@ public SingleDatabaseRoutingProcedureRunner( RoutingContext context )
public CompletionStage run( Connection connection, DatabaseName databaseName, Bookmark bookmark, String impersonatedUser )
{
DirectConnection delegate = connection( connection );
- Query procedure = procedureQuery( connection.serverVersion(), databaseName );
+ Query procedure = procedureQuery( connection.protocol().version(), databaseName );
BookmarkHolder bookmarkHolder = bookmarkHolder( bookmark );
return runProcedure( delegate, procedure, bookmarkHolder )
.thenCompose( records -> releaseConnection( delegate, records ) )
@@ -73,13 +73,13 @@ DirectConnection connection( Connection connection )
return new DirectConnection( connection, defaultDatabase(), AccessMode.WRITE, null );
}
- Query procedureQuery(ServerVersion serverVersion, DatabaseName databaseName )
+ Query procedureQuery( BoltProtocolVersion protocolVersion, DatabaseName databaseName )
{
if ( databaseName.databaseName().isPresent() )
{
throw new FatalDiscoveryException( String.format(
- "Refreshing routing table for multi-databases is not supported in server version lower than 4.0. " +
- "Current server version: %s. Database name: '%s'", serverVersion, databaseName.description() ) );
+ "Refreshing routing table for multi-databases is not supported over Bolt protocol lower than 4.0. " +
+ "Current protocol version: %s. Database name: '%s'", protocolVersion, databaseName.description() ) );
}
return new Query( GET_ROUTING_TABLE, parameters( ROUTING_CONTEXT, context.toMap() ) );
}
diff --git a/driver/src/main/java/org/neo4j/driver/internal/handlers/HelloResponseHandler.java b/driver/src/main/java/org/neo4j/driver/internal/handlers/HelloResponseHandler.java
index af028cef16..1de5eea024 100644
--- a/driver/src/main/java/org/neo4j/driver/internal/handlers/HelloResponseHandler.java
+++ b/driver/src/main/java/org/neo4j/driver/internal/handlers/HelloResponseHandler.java
@@ -26,17 +26,12 @@
import java.util.function.Supplier;
import org.neo4j.driver.Value;
-import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
-import org.neo4j.driver.internal.messaging.v3.BoltProtocolV3;
import org.neo4j.driver.internal.spi.ResponseHandler;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setConnectionId;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setConnectionReadTimeout;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setServerAgent;
-import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setServerVersion;
-import static org.neo4j.driver.internal.util.MetadataExtractor.extractNeo4jServerVersion;
import static org.neo4j.driver.internal.util.MetadataExtractor.extractServer;
-import static org.neo4j.driver.internal.util.ServerVersion.fromBoltProtocolVersion;
public class HelloResponseHandler implements ResponseHandler
{
@@ -46,13 +41,11 @@ public class HelloResponseHandler implements ResponseHandler
private final ChannelPromise connectionInitializedPromise;
private final Channel channel;
- private final BoltProtocolVersion protocolVersion;
- public HelloResponseHandler( ChannelPromise connectionInitializedPromise, BoltProtocolVersion protocolVersion )
+ public HelloResponseHandler( ChannelPromise connectionInitializedPromise )
{
this.connectionInitializedPromise = connectionInitializedPromise;
this.channel = connectionInitializedPromise.channel();
- this.protocolVersion = protocolVersion;
}
@Override
@@ -60,19 +53,8 @@ public void onSuccess( Map metadata )
{
try
{
- Value serverValue = extractServer( metadata );
- setServerAgent( channel, serverValue.asString() );
-
- // From Server V4 extracting server from metadata in the success message is unreliable
- // so we fix the Server version against the Bolt Protocol version for Server V4 and above.
- if ( BoltProtocolV3.VERSION.equals( protocolVersion ) )
- {
- setServerVersion( channel, extractNeo4jServerVersion( metadata ) );
- }
- else
- {
- setServerVersion( channel, fromBoltProtocolVersion( protocolVersion ) );
- }
+ String serverAgent = extractServer( metadata ).asString();
+ setServerAgent( channel, serverAgent );
String connectionId = extractConnectionId( metadata );
setConnectionId( channel, connectionId );
diff --git a/driver/src/main/java/org/neo4j/driver/internal/handlers/InitResponseHandler.java b/driver/src/main/java/org/neo4j/driver/internal/handlers/InitResponseHandler.java
index 0fc39e42b0..9f196cedeb 100644
--- a/driver/src/main/java/org/neo4j/driver/internal/handlers/InitResponseHandler.java
+++ b/driver/src/main/java/org/neo4j/driver/internal/handlers/InitResponseHandler.java
@@ -19,18 +19,15 @@
package org.neo4j.driver.internal.handlers;
import io.netty.channel.Channel;
-import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelPromise;
import java.util.Map;
-import org.neo4j.driver.internal.async.outbound.OutboundMessageHandler;
-import org.neo4j.driver.internal.spi.ResponseHandler;
-import org.neo4j.driver.internal.util.ServerVersion;
import org.neo4j.driver.Value;
+import org.neo4j.driver.exceptions.UntrustedServerException;
+import org.neo4j.driver.internal.spi.ResponseHandler;
-import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setServerVersion;
-import static org.neo4j.driver.internal.util.MetadataExtractor.extractNeo4jServerVersion;
+import static org.neo4j.driver.internal.util.MetadataExtractor.extractServer;
public class InitResponseHandler implements ResponseHandler
{
@@ -48,8 +45,13 @@ public void onSuccess( Map metadata )
{
try
{
- ServerVersion serverVersion = extractNeo4jServerVersion( metadata );
- setServerVersion( channel, serverVersion );
+ String serverAgent = extractServer( metadata ).asString();
+
+ if ( !serverAgent.startsWith( "Neo4j/" ) )
+ {
+ throw new UntrustedServerException( "Server does not identify as a genuine Neo4j instance: '" + serverAgent + "'" );
+ }
+
connectionInitializedPromise.setSuccess();
}
catch ( Throwable error )
diff --git a/driver/src/main/java/org/neo4j/driver/internal/messaging/request/MultiDatabaseUtil.java b/driver/src/main/java/org/neo4j/driver/internal/messaging/request/MultiDatabaseUtil.java
index 8907fe7b43..a5ac286f08 100644
--- a/driver/src/main/java/org/neo4j/driver/internal/messaging/request/MultiDatabaseUtil.java
+++ b/driver/src/main/java/org/neo4j/driver/internal/messaging/request/MultiDatabaseUtil.java
@@ -24,7 +24,6 @@
import org.neo4j.driver.internal.messaging.v4.BoltProtocolV4;
import org.neo4j.driver.internal.messaging.v43.BoltProtocolV43;
import org.neo4j.driver.internal.spi.Connection;
-import org.neo4j.driver.internal.util.ServerVersion;
public final class MultiDatabaseUtil
{
@@ -39,8 +38,7 @@ public static void assertEmptyDatabaseName( DatabaseName databaseName, BoltProto
public static boolean supportsMultiDatabase( Connection connection )
{
- return connection.serverVersion().greaterThanOrEqual( ServerVersion.v4_0_0 ) &&
- connection.protocol().version().compareTo( BoltProtocolV4.VERSION ) >= 0;
+ return connection.protocol().version().compareTo( BoltProtocolV4.VERSION ) >= 0;
}
public static boolean supportsRouteMessage( Connection connection )
diff --git a/driver/src/main/java/org/neo4j/driver/internal/messaging/v3/BoltProtocolV3.java b/driver/src/main/java/org/neo4j/driver/internal/messaging/v3/BoltProtocolV3.java
index 1f86459c7a..9ab9bdaa31 100644
--- a/driver/src/main/java/org/neo4j/driver/internal/messaging/v3/BoltProtocolV3.java
+++ b/driver/src/main/java/org/neo4j/driver/internal/messaging/v3/BoltProtocolV3.java
@@ -91,7 +91,7 @@ public void initializeChannel( String userAgent, AuthToken authToken, RoutingCon
message = new HelloMessage( userAgent, ( ( InternalAuthToken ) authToken ).toMap(), null );
}
- HelloResponseHandler handler = new HelloResponseHandler( channelInitializedPromise, version() );
+ HelloResponseHandler handler = new HelloResponseHandler( channelInitializedPromise );
messageDispatcher( channel ).enqueue( handler );
channel.writeAndFlush( message, channel.voidPromise() );
diff --git a/driver/src/main/java/org/neo4j/driver/internal/spi/Connection.java b/driver/src/main/java/org/neo4j/driver/internal/spi/Connection.java
index f6d676c0e7..89ed89ab21 100644
--- a/driver/src/main/java/org/neo4j/driver/internal/spi/Connection.java
+++ b/driver/src/main/java/org/neo4j/driver/internal/spi/Connection.java
@@ -25,7 +25,6 @@
import org.neo4j.driver.internal.DatabaseName;
import org.neo4j.driver.internal.messaging.BoltProtocol;
import org.neo4j.driver.internal.messaging.Message;
-import org.neo4j.driver.internal.util.ServerVersion;
import static java.lang.String.format;
@@ -55,8 +54,6 @@ public interface Connection
BoltServerAddress serverAddress();
- ServerVersion serverVersion();
-
BoltProtocol protocol();
default AccessMode mode()
diff --git a/driver/src/main/java/org/neo4j/driver/internal/summary/InternalServerInfo.java b/driver/src/main/java/org/neo4j/driver/internal/summary/InternalServerInfo.java
index 71ab8983b0..60c389f5ba 100644
--- a/driver/src/main/java/org/neo4j/driver/internal/summary/InternalServerInfo.java
+++ b/driver/src/main/java/org/neo4j/driver/internal/summary/InternalServerInfo.java
@@ -22,21 +22,20 @@
import org.neo4j.driver.internal.BoltServerAddress;
import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
-import org.neo4j.driver.internal.util.ServerVersion;
import org.neo4j.driver.summary.ServerInfo;
public class InternalServerInfo implements ServerInfo
{
+ private static final String TO_STRING_FMT = "%s{address='%s'}";
+
private final String agent;
private final String address;
- private final String version;
private final String protocolVersion;
- public InternalServerInfo( String agent, BoltServerAddress address, ServerVersion version, BoltProtocolVersion protocolVersion )
+ public InternalServerInfo( String agent, BoltServerAddress address, BoltProtocolVersion protocolVersion )
{
this.agent = agent;
this.address = address.toString();
- this.version = version.toString();
this.protocolVersion = protocolVersion.toString();
}
@@ -52,12 +51,6 @@ public String address()
return address;
}
- @Override
- public String version()
- {
- return version;
- }
-
@Override
public String protocolVersion()
{
@@ -76,18 +69,18 @@ public boolean equals( Object o )
return false;
}
InternalServerInfo that = (InternalServerInfo) o;
- return Objects.equals( address, that.address ) && Objects.equals( version, that.version );
+ return Objects.equals( address, that.address );
}
@Override
public int hashCode()
{
- return Objects.hash( address, version );
+ return Objects.hash( address );
}
@Override
public String toString()
{
- return "InternalServerInfo{" + "address='" + address + '\'' + ", version='" + version + '\'' + '}';
+ return String.format( TO_STRING_FMT, this.getClass().getSimpleName(), address );
}
}
diff --git a/driver/src/main/java/org/neo4j/driver/internal/util/MetadataExtractor.java b/driver/src/main/java/org/neo4j/driver/internal/util/MetadataExtractor.java
index c4968ffc4a..f726478c4f 100644
--- a/driver/src/main/java/org/neo4j/driver/internal/util/MetadataExtractor.java
+++ b/driver/src/main/java/org/neo4j/driver/internal/util/MetadataExtractor.java
@@ -101,7 +101,7 @@ public long extractResultAvailableAfter( Map metadata )
public ResultSummary extractSummary(Query query, Connection connection, long resultAvailableAfter, Map metadata )
{
ServerInfo serverInfo =
- new InternalServerInfo( connection.serverAgent(), connection.serverAddress(), connection.serverVersion(), connection.protocol().version() );
+ new InternalServerInfo( connection.serverAgent(), connection.serverAddress(), connection.protocol().version() );
DatabaseInfo dbInfo = extractDatabaseInfo( metadata );
return new InternalResultSummary(query, serverInfo, dbInfo, extractQueryType( metadata ), extractCounters( metadata ), extractPlan( metadata ),
extractProfiledPlan( metadata ), extractNotifications( metadata ), resultAvailableAfter,
@@ -131,20 +131,6 @@ public static Bookmark extractBookmarks( Map metadata )
return InternalBookmark.empty();
}
- public static ServerVersion extractNeo4jServerVersion( Map metadata )
- {
- Value serverValue = extractServer( metadata );
- ServerVersion server = ServerVersion.version( serverValue.asString() );
- if ( ServerVersion.NEO4J_PRODUCT.equalsIgnoreCase( server.product() ) )
- {
- return server;
- }
- else
- {
- throw new UntrustedServerException( "Server does not identify as a genuine Neo4j instance: '" + server.product() + "'" );
- }
- }
-
public static Value extractServer( Map metadata )
{
Value versionValue = metadata.get( "server" );
@@ -152,6 +138,11 @@ public static Value extractServer( Map metadata )
{
throw new UntrustedServerException( "Server provides no product identifier" );
}
+ String serverAgent = versionValue.asString();
+ if ( !serverAgent.startsWith( "Neo4j/" ) )
+ {
+ throw new UntrustedServerException( "Server does not identify as a genuine Neo4j instance: '" + serverAgent + "'" );
+ }
return versionValue;
}
diff --git a/driver/src/main/java/org/neo4j/driver/internal/util/ServerVersion.java b/driver/src/main/java/org/neo4j/driver/internal/util/ServerVersion.java
deleted file mode 100644
index 5232d4e76f..0000000000
--- a/driver/src/main/java/org/neo4j/driver/internal/util/ServerVersion.java
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * Copyright (c) "Neo4j"
- * Neo4j Sweden AB [http://neo4j.com]
- *
- * This file is part of Neo4j.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.neo4j.driver.internal.util;
-
-import java.util.Objects;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.neo4j.driver.Driver;
-import org.neo4j.driver.Session;
-import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
-import org.neo4j.driver.internal.messaging.v4.BoltProtocolV4;
-import org.neo4j.driver.internal.messaging.v41.BoltProtocolV41;
-import org.neo4j.driver.internal.messaging.v42.BoltProtocolV42;
-import org.neo4j.driver.internal.messaging.v43.BoltProtocolV43;
-import org.neo4j.driver.internal.messaging.v44.BoltProtocolV44;
-
-import static java.lang.Integer.compare;
-
-public class ServerVersion
-{
- public static final String NEO4J_PRODUCT = "Neo4j";
-
- public static final ServerVersion v4_4_0 = new ServerVersion( NEO4J_PRODUCT, 4, 4, 0 );
- public static final ServerVersion v4_3_0 = new ServerVersion( NEO4J_PRODUCT, 4, 3, 0 );
- public static final ServerVersion v4_2_0 = new ServerVersion( NEO4J_PRODUCT, 4, 2, 0 );
- public static final ServerVersion v4_1_0 = new ServerVersion( NEO4J_PRODUCT, 4, 1, 0 );
- public static final ServerVersion v4_0_0 = new ServerVersion( NEO4J_PRODUCT, 4, 0, 0 );
- public static final ServerVersion v3_5_0 = new ServerVersion( NEO4J_PRODUCT, 3, 5, 0 );
- public static final ServerVersion v3_4_0 = new ServerVersion( NEO4J_PRODUCT, 3, 4, 0 );
- public static final ServerVersion vInDev = new ServerVersion( NEO4J_PRODUCT, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE );
-
- private static final String NEO4J_IN_DEV_VERSION_STRING = NEO4J_PRODUCT + "/dev";
- private static final Pattern PATTERN =
- Pattern.compile( "([^/]+)/(\\d+)\\.(\\d+)(?:\\.)?(\\d*)(\\.|-|\\+)?([0-9A-Za-z-.]*)?" );
-
- private final String product;
- private final int major;
- private final int minor;
- private final int patch;
- private final String stringValue;
-
- private ServerVersion( String product, int major, int minor, int patch )
- {
- this.product = product;
- this.major = major;
- this.minor = minor;
- this.patch = patch;
- this.stringValue = stringValue( product, major, minor, patch );
- }
-
- public String product()
- {
- return product;
- }
-
- public static ServerVersion version( Driver driver )
- {
- try ( Session session = driver.session() )
- {
- String versionString = session.readTransaction( tx -> tx.run( "RETURN 1" ).consume().server().version() );
- return version( versionString );
- }
- }
-
- public static ServerVersion version( String server )
- {
- Matcher matcher = PATTERN.matcher( server );
- if ( matcher.matches() )
- {
- String product = matcher.group( 1 );
- int major = Integer.valueOf( matcher.group( 2 ) );
- int minor = Integer.valueOf( matcher.group( 3 ) );
- String patchString = matcher.group( 4 );
- int patch = 0;
- if ( patchString != null && !patchString.isEmpty() )
- {
- patch = Integer.valueOf( patchString );
- }
- return new ServerVersion( product, major, minor, patch );
- }
- else if ( server.equalsIgnoreCase( NEO4J_IN_DEV_VERSION_STRING ) )
- {
- return vInDev;
- }
- else
- {
- throw new IllegalArgumentException( "Cannot parse " + server );
- }
- }
-
- @Override
- public boolean equals( Object o )
- {
- if ( this == o )
- { return true; }
- if ( o == null || getClass() != o.getClass() )
- { return false; }
-
- ServerVersion that = (ServerVersion) o;
-
- if ( !product.equals( that.product ) )
- { return false; }
- if ( major != that.major )
- { return false; }
- if ( minor != that.minor )
- { return false; }
- return patch == that.patch;
- }
-
- @Override
- public int hashCode()
- {
- return Objects.hash(product, major, minor, patch);
- }
-
- public boolean greaterThan(ServerVersion other)
- {
- return compareTo( other ) > 0;
- }
-
- public boolean greaterThanOrEqual(ServerVersion other)
- {
- return compareTo( other ) >= 0;
- }
-
- public boolean lessThan(ServerVersion other)
- {
- return compareTo( other ) < 0;
- }
-
- public boolean lessThanOrEqual(ServerVersion other)
- {
- return compareTo( other ) <= 0;
- }
-
- private int compareTo( ServerVersion o )
- {
- if ( !product.equals( o.product ) )
- {
- throw new IllegalArgumentException( "Comparing different products '" + product + "' with '" + o.product + "'" );
- }
- int c = compare( major, o.major );
- if (c == 0)
- {
- c = compare( minor, o.minor );
- if (c == 0)
- {
- c = compare( patch, o.patch );
- }
- }
-
- return c;
- }
-
- @Override
- public String toString()
- {
- return stringValue;
- }
-
- private static String stringValue( String product, int major, int minor, int patch )
- {
- if ( major == Integer.MAX_VALUE && minor == Integer.MAX_VALUE && patch == Integer.MAX_VALUE )
- {
- return NEO4J_IN_DEV_VERSION_STRING;
- }
- return String.format( "%s/%s.%s.%s", product, major, minor, patch );
- }
-
- public static ServerVersion fromBoltProtocolVersion( BoltProtocolVersion protocolVersion )
- {
-
- if ( BoltProtocolV4.VERSION.equals( protocolVersion ) )
- {
- return ServerVersion.v4_0_0;
- }
- else if ( BoltProtocolV41.VERSION.equals( protocolVersion ) )
- {
- return ServerVersion.v4_1_0;
- } else if ( BoltProtocolV42.VERSION.equals( protocolVersion ) )
- {
- return ServerVersion.v4_2_0;
- }
- else if ( BoltProtocolV43.VERSION.equals( protocolVersion ) )
- {
- return ServerVersion.v4_3_0;
- }
- else if ( BoltProtocolV44.VERSION.equals( protocolVersion ) )
- {
- return ServerVersion.v4_4_0;
- }
-
- return ServerVersion.vInDev;
- }
-}
diff --git a/driver/src/main/java/org/neo4j/driver/summary/ServerInfo.java b/driver/src/main/java/org/neo4j/driver/summary/ServerInfo.java
index 5178ebc985..ec5b41998f 100644
--- a/driver/src/main/java/org/neo4j/driver/summary/ServerInfo.java
+++ b/driver/src/main/java/org/neo4j/driver/summary/ServerInfo.java
@@ -30,16 +30,6 @@ public interface ServerInfo
*/
String address();
- /**
- * Returns a string telling which version of the server the query was executed. Supported since neo4j 3.1.
- *
- * @return The server version.
- * @deprecated in 4.3, please use {@link ServerInfo#agent()}, {@link ServerInfo#protocolVersion()}, or call the dbms.components procedure instead.
- * Method might be removed in the next major release.
- */
- @Deprecated
- String version();
-
/**
* Returns Bolt protocol version with which the remote server communicates. This is returned as a string in format X.Y where X is the major version and Y is
* the minor version.
diff --git a/driver/src/test/java/org/neo4j/driver/integration/reactive/RxResultIT.java b/driver/src/test/java/org/neo4j/driver/integration/reactive/RxResultIT.java
index d66f1c0194..f55f0180aa 100644
--- a/driver/src/test/java/org/neo4j/driver/integration/reactive/RxResultIT.java
+++ b/driver/src/test/java/org/neo4j/driver/integration/reactive/RxResultIT.java
@@ -29,10 +29,10 @@
import org.neo4j.driver.Record;
import org.neo4j.driver.exceptions.ClientException;
import org.neo4j.driver.internal.util.EnabledOnNeo4jWith;
-import org.neo4j.driver.reactive.RxSession;
import org.neo4j.driver.reactive.RxResult;
-import org.neo4j.driver.summary.ResultSummary;
+import org.neo4j.driver.reactive.RxSession;
import org.neo4j.driver.summary.QueryType;
+import org.neo4j.driver.summary.ResultSummary;
import org.neo4j.driver.util.DatabaseExtension;
import org.neo4j.driver.util.ParallelizableIT;
@@ -230,7 +230,6 @@ void shouldOnlyErrorRecordAfterFailure()
.assertNext( summary -> {
assertThat( summary.query().text(), equalTo( "INVALID" ) );
assertNotNull( summary.server().address() );
- assertNotNull( summary.server().version() );
} ).verifyComplete();
}
diff --git a/driver/src/test/java/org/neo4j/driver/internal/InternalResultTest.java b/driver/src/test/java/org/neo4j/driver/internal/InternalResultTest.java
index 658a24f2fd..7779cef1b3 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/InternalResultTest.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/InternalResultTest.java
@@ -60,7 +60,6 @@
import static org.neo4j.driver.Values.ofString;
import static org.neo4j.driver.Values.value;
import static org.neo4j.driver.internal.BoltServerAddress.LOCAL_DEFAULT;
-import static org.neo4j.driver.util.TestUtil.anyServerVersion;
class InternalResultTest
{
@@ -360,7 +359,6 @@ private Result createResult(int numberOfRecords )
Query query = new Query( "" );
Connection connection = mock( Connection.class );
when( connection.serverAddress() ).thenReturn( LOCAL_DEFAULT );
- when( connection.serverVersion() ).thenReturn( anyServerVersion() );
when( connection.protocol() ).thenReturn( BoltProtocolV43.INSTANCE );
when( connection.serverAgent() ).thenReturn( "Neo4j/4.2.5" );
PullAllResponseHandler pullAllHandler =
diff --git a/driver/src/test/java/org/neo4j/driver/internal/async/AsyncResultCursorImplTest.java b/driver/src/test/java/org/neo4j/driver/internal/async/AsyncResultCursorImplTest.java
index b58de0d4ef..12593a87b9 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/async/AsyncResultCursorImplTest.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/async/AsyncResultCursorImplTest.java
@@ -64,7 +64,6 @@
import static org.neo4j.driver.internal.summary.InternalDatabaseInfo.DEFAULT_DATABASE_INFO;
import static org.neo4j.driver.internal.util.Futures.completedWithNull;
import static org.neo4j.driver.internal.util.Futures.failedFuture;
-import static org.neo4j.driver.util.TestUtil.anyServerVersion;
import static org.neo4j.driver.util.TestUtil.await;
class AsyncResultCursorImplTest
@@ -90,7 +89,7 @@ void shouldReturnSummary()
ResultSummary summary = new InternalResultSummary(
new Query( "RETURN 42" ),
- new InternalServerInfo( "Neo4j/4.2.5", BoltServerAddress.LOCAL_DEFAULT, anyServerVersion(), BoltProtocolV43.VERSION ),
+ new InternalServerInfo( "Neo4j/4.2.5", BoltServerAddress.LOCAL_DEFAULT, BoltProtocolV43.VERSION ),
DEFAULT_DATABASE_INFO, QueryType.SCHEMA_WRITE,
new InternalSummaryCounters( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0 ),
null, null, emptyList(), 42, 42
diff --git a/driver/src/test/java/org/neo4j/driver/internal/async/NetworkConnectionTest.java b/driver/src/test/java/org/neo4j/driver/internal/async/NetworkConnectionTest.java
index bcbcf33c16..3b7b10b026 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/async/NetworkConnectionTest.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/async/NetworkConnectionTest.java
@@ -43,7 +43,6 @@
import org.neo4j.driver.internal.messaging.request.RunMessage;
import org.neo4j.driver.internal.spi.ResponseHandler;
import org.neo4j.driver.internal.util.FakeClock;
-import org.neo4j.driver.internal.util.ServerVersion;
import static java.util.Collections.emptyMap;
import static org.hamcrest.Matchers.startsWith;
@@ -66,7 +65,6 @@
import static org.neo4j.driver.internal.util.Iterables.single;
import static org.neo4j.driver.util.DaemonThreadFactory.daemon;
import static org.neo4j.driver.util.TestUtil.DEFAULT_TEST_PROTOCOL_VERSION;
-import static org.neo4j.driver.util.TestUtil.anyServerVersion;
class NetworkConnectionTest
{
@@ -386,19 +384,6 @@ void shouldReturnServerAddressWhenReleased()
assertEquals( address, connection.serverAddress() );
}
- @Test
- void shouldReturnServerVersionWhenReleased()
- {
- EmbeddedChannel channel = newChannel();
- ServerVersion version = anyServerVersion();
- ChannelAttributes.setServerVersion( channel, version );
-
- NetworkConnection connection = newConnection( channel );
- connection.release();
-
- assertEquals( version, connection.serverVersion() );
- }
-
@Test
void shouldReturnSameCompletionStageFromRelease()
{
diff --git a/driver/src/test/java/org/neo4j/driver/internal/async/connection/ChannelAttributesTest.java b/driver/src/test/java/org/neo4j/driver/internal/async/connection/ChannelAttributesTest.java
index fef5808d8a..a302cc50ce 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/async/connection/ChannelAttributesTest.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/async/connection/ChannelAttributesTest.java
@@ -24,7 +24,6 @@
import org.neo4j.driver.internal.BoltServerAddress;
import org.neo4j.driver.internal.async.inbound.InboundMessageDispatcher;
import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
-import org.neo4j.driver.internal.util.ServerVersion;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -39,7 +38,6 @@
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.protocolVersion;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.serverAddress;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.serverAgent;
-import static org.neo4j.driver.internal.async.connection.ChannelAttributes.serverVersion;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setAuthorizationStateListener;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setConnectionId;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setConnectionReadTimeout;
@@ -49,10 +47,8 @@
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setProtocolVersion;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setServerAddress;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setServerAgent;
-import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setServerVersion;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setTerminationReason;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.terminationReason;
-import static org.neo4j.driver.internal.util.ServerVersion.version;
class ChannelAttributesTest
{
@@ -170,22 +166,6 @@ void shouldFailToSetMessageDispatcherTwice()
assertThrows( IllegalStateException.class, () -> setMessageDispatcher( channel, mock( InboundMessageDispatcher.class ) ) );
}
- @Test
- void shouldSetAndGetServerVersion()
- {
- ServerVersion version = version( "Neo4j/3.2.1" );
- setServerVersion( channel, version );
- assertEquals( version, serverVersion( channel ) );
- }
-
- @Test
- void shouldFailToSetServerVersionTwice()
- {
- setServerVersion( channel, version( "Neo4j/3.2.2" ) );
-
- assertThrows( IllegalStateException.class, () -> setServerVersion( channel, version( "Neo4j/3.2.3" ) ) );
- }
-
@Test
void shouldSetAndGetTerminationReason()
{
diff --git a/driver/src/test/java/org/neo4j/driver/internal/async/connection/DecoratedConnectionTest.java b/driver/src/test/java/org/neo4j/driver/internal/async/connection/DecoratedConnectionTest.java
index 3892160fa8..27954b9c33 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/async/connection/DecoratedConnectionTest.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/async/connection/DecoratedConnectionTest.java
@@ -29,7 +29,6 @@
import org.neo4j.driver.internal.messaging.Message;
import org.neo4j.driver.internal.spi.Connection;
import org.neo4j.driver.internal.spi.ResponseHandler;
-import org.neo4j.driver.internal.util.ServerVersion;
import org.neo4j.driver.net.ServerAddress;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -182,18 +181,6 @@ void shouldDelegateServerAddress()
verify( mockConnection ).serverAddress();
}
- @Test
- void shouldDelegateServerVersion()
- {
- ServerVersion version = ServerVersion.version( "Neo4j/3.5.3" );
- Connection mockConnection = mock( Connection.class );
- when( mockConnection.serverVersion() ).thenReturn( version );
- DirectConnection connection = newConnection( mockConnection );
-
- assertSame( version, connection.serverVersion() );
- verify( mockConnection ).serverVersion();
- }
-
@Test
void shouldDelegateProtocol()
{
diff --git a/driver/src/test/java/org/neo4j/driver/internal/cluster/AbstractRoutingProcedureRunnerTest.java b/driver/src/test/java/org/neo4j/driver/internal/cluster/AbstractRoutingProcedureRunnerTest.java
index 0fe12d5165..a24f33e25a 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/cluster/AbstractRoutingProcedureRunnerTest.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/cluster/AbstractRoutingProcedureRunnerTest.java
@@ -25,6 +25,8 @@
import org.neo4j.driver.Record;
import org.neo4j.driver.exceptions.ClientException;
+import org.neo4j.driver.internal.messaging.BoltProtocol;
+import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
import org.neo4j.driver.internal.spi.Connection;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -101,6 +103,10 @@ static Connection connection()
static Connection connection( CompletionStage releaseStage )
{
Connection connection = mock( Connection.class );
+ BoltProtocol boltProtocol = mock( BoltProtocol.class );
+ BoltProtocolVersion protocolVersion = new BoltProtocolVersion( 4, 4 );
+ when( boltProtocol.version() ).thenReturn( protocolVersion );
+ when( connection.protocol() ).thenReturn( boltProtocol );
when( connection.release() ).thenReturn( releaseStage );
return connection;
}
diff --git a/driver/src/test/java/org/neo4j/driver/internal/cluster/RoutingProcedureClusterCompositionProviderTest.java b/driver/src/test/java/org/neo4j/driver/internal/cluster/RoutingProcedureClusterCompositionProviderTest.java
index d2cc5b3750..5b6b175b37 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/cluster/RoutingProcedureClusterCompositionProviderTest.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/cluster/RoutingProcedureClusterCompositionProviderTest.java
@@ -39,7 +39,6 @@
import org.neo4j.driver.internal.messaging.v43.BoltProtocolV43;
import org.neo4j.driver.internal.spi.Connection;
import org.neo4j.driver.internal.util.Clock;
-import org.neo4j.driver.internal.util.ServerVersion;
import org.neo4j.driver.internal.value.StringValue;
import static java.util.Arrays.asList;
@@ -414,7 +413,6 @@ private static RoutingProcedureResponse newRoutingResponse( Throwable error )
private static RoutingProcedureClusterCompositionProvider newClusterCompositionProvider( SingleDatabaseRoutingProcedureRunner runner,
Connection connection )
{
- when( connection.serverVersion() ).thenReturn( ServerVersion.v3_5_0 );
when( connection.protocol() ).thenReturn( BoltProtocolV3.INSTANCE );
return new RoutingProcedureClusterCompositionProvider( mock( Clock.class ), runner, newMultiDBProcedureRunnerMock(),
newRouteMessageRoutingProcedureRunnerMock() );
@@ -423,7 +421,6 @@ private static RoutingProcedureClusterCompositionProvider newClusterCompositionP
private static RoutingProcedureClusterCompositionProvider newClusterCompositionProvider( MultiDatabasesRoutingProcedureRunner runner,
Connection connection )
{
- when( connection.serverVersion() ).thenReturn( ServerVersion.v4_0_0 );
when( connection.protocol() ).thenReturn( BoltProtocolV4.INSTANCE );
return new RoutingProcedureClusterCompositionProvider( mock( Clock.class ), newProcedureRunnerMock(), runner,
newRouteMessageRoutingProcedureRunnerMock() );
@@ -432,7 +429,6 @@ private static RoutingProcedureClusterCompositionProvider newClusterCompositionP
private static RoutingProcedureClusterCompositionProvider newClusterCompositionProvider( MultiDatabasesRoutingProcedureRunner runner, Connection connection,
Clock clock )
{
- when( connection.serverVersion() ).thenReturn( ServerVersion.v4_0_0 );
when( connection.protocol() ).thenReturn( BoltProtocolV4.INSTANCE );
return new RoutingProcedureClusterCompositionProvider( clock, newProcedureRunnerMock(), runner, newRouteMessageRoutingProcedureRunnerMock() );
}
diff --git a/driver/src/test/java/org/neo4j/driver/internal/cluster/loadbalancing/LoadBalancerTest.java b/driver/src/test/java/org/neo4j/driver/internal/cluster/loadbalancing/LoadBalancerTest.java
index 8b174ad2c4..ab9d7e8281 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/cluster/loadbalancing/LoadBalancerTest.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/cluster/loadbalancing/LoadBalancerTest.java
@@ -57,7 +57,6 @@
import org.neo4j.driver.internal.spi.ConnectionPool;
import org.neo4j.driver.internal.util.FakeClock;
import org.neo4j.driver.internal.util.Futures;
-import org.neo4j.driver.internal.util.ServerVersion;
import static java.util.Arrays.asList;
import static java.util.Collections.emptySet;
@@ -442,7 +441,6 @@ private static Connection newBoltV4Connection( BoltServerAddress address )
Connection connection = mock( Connection.class );
when( connection.serverAddress() ).thenReturn( address );
when( connection.protocol() ).thenReturn( BoltProtocol.forVersion( BoltProtocolV42.VERSION ) );
- when( connection.serverVersion() ).thenReturn( ServerVersion.v4_1_0 );
when( connection.release() ).thenReturn( completedWithNull() );
return connection;
}
diff --git a/driver/src/test/java/org/neo4j/driver/internal/handlers/HelloResponseHandlerTest.java b/driver/src/test/java/org/neo4j/driver/internal/handlers/HelloResponseHandlerTest.java
index bfe0f4c502..f2b353d254 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/handlers/HelloResponseHandlerTest.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/handlers/HelloResponseHandlerTest.java
@@ -36,11 +36,7 @@
import org.neo4j.driver.internal.async.inbound.ChannelErrorHandler;
import org.neo4j.driver.internal.async.inbound.InboundMessageDispatcher;
import org.neo4j.driver.internal.async.outbound.OutboundMessageHandler;
-import org.neo4j.driver.internal.messaging.v3.BoltProtocolV3;
import org.neo4j.driver.internal.messaging.v3.MessageFormatV3;
-import org.neo4j.driver.internal.messaging.v4.BoltProtocolV4;
-import org.neo4j.driver.internal.messaging.v41.BoltProtocolV41;
-import org.neo4j.driver.internal.util.ServerVersion;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -50,14 +46,14 @@
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.connectionId;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.connectionReadTimeout;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.serverAgent;
-import static org.neo4j.driver.internal.async.connection.ChannelAttributes.serverVersion;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setMessageDispatcher;
import static org.neo4j.driver.internal.async.outbound.OutboundMessageHandler.NAME;
import static org.neo4j.driver.internal.logging.DevNullLogging.DEV_NULL_LOGGING;
-import static org.neo4j.driver.util.TestUtil.anyServerVersion;
class HelloResponseHandlerTest
{
+ private static final String SERVER_AGENT = "Neo4j/4.4.0";
+
private final EmbeddedChannel channel = new EmbeddedChannel();
@BeforeEach
@@ -75,38 +71,24 @@ void tearDown()
channel.finishAndReleaseAll();
}
- @Test
- void shouldSetServerVersionOnChannel()
- {
- ChannelPromise channelPromise = channel.newPromise();
- HelloResponseHandler handler = new HelloResponseHandler( channelPromise, BoltProtocolV3.VERSION );
-
- Map metadata = metadata( anyServerVersion(), "bolt-1" );
- handler.onSuccess( metadata );
-
- assertTrue( channelPromise.isSuccess() );
- assertEquals( anyServerVersion(), serverVersion( channel ) );
- }
-
@Test
void shouldSetServerAgentOnChannel()
{
ChannelPromise channelPromise = channel.newPromise();
- HelloResponseHandler handler = new HelloResponseHandler( channelPromise, BoltProtocolV3.VERSION );
+ HelloResponseHandler handler = new HelloResponseHandler( channelPromise );
- String agent = "Neo4j/4.2.5";
- Map metadata = metadata( agent, "bolt-1" );
+ Map metadata = metadata( SERVER_AGENT, "bolt-1" );
handler.onSuccess( metadata );
assertTrue( channelPromise.isSuccess() );
- assertEquals( agent, serverAgent( channel ) );
+ assertEquals( SERVER_AGENT, serverAgent( channel ) );
}
@Test
void shouldThrowWhenServerVersionNotReturned()
{
ChannelPromise channelPromise = channel.newPromise();
- HelloResponseHandler handler = new HelloResponseHandler( channelPromise, BoltProtocolV3.VERSION );
+ HelloResponseHandler handler = new HelloResponseHandler( channelPromise );
Map metadata = metadata( null, "bolt-1" );
assertThrows( UntrustedServerException.class, () -> handler.onSuccess( metadata ) );
@@ -119,7 +101,7 @@ void shouldThrowWhenServerVersionNotReturned()
void shouldThrowWhenServerVersionIsNull()
{
ChannelPromise channelPromise = channel.newPromise();
- HelloResponseHandler handler = new HelloResponseHandler( channelPromise, BoltProtocolV3.VERSION );
+ HelloResponseHandler handler = new HelloResponseHandler( channelPromise );
Map metadata = metadata( Values.NULL, "bolt-x" );
assertThrows( UntrustedServerException.class, () -> handler.onSuccess( metadata ) );
@@ -129,53 +111,25 @@ void shouldThrowWhenServerVersionIsNull()
}
@Test
- void shouldThrowWhenServerVersionCantBeParsed()
+ void shouldThrowWhenServerAgentIsUnrecognised()
{
ChannelPromise channelPromise = channel.newPromise();
- HelloResponseHandler handler = new HelloResponseHandler( channelPromise, BoltProtocolV3.VERSION );
+ HelloResponseHandler handler = new HelloResponseHandler( channelPromise );
Map metadata = metadata( "WrongServerVersion", "bolt-x" );
- assertThrows( IllegalArgumentException.class, () -> handler.onSuccess( metadata ) );
+ assertThrows( UntrustedServerException.class, () -> handler.onSuccess( metadata ) );
assertFalse( channelPromise.isSuccess() ); // initialization failed
assertTrue( channel.closeFuture().isDone() ); // channel was closed
}
- @Test
- void shouldUseProtocolVersionForServerVersionWhenConnectedWithBoltV4()
- {
- ChannelPromise channelPromise = channel.newPromise();
- HelloResponseHandler handler = new HelloResponseHandler( channelPromise, BoltProtocolV4.VERSION );
-
- // server used in metadata should be ignored
- Map metadata = metadata( ServerVersion.vInDev, "bolt-1" );
- handler.onSuccess( metadata );
-
- assertTrue( channelPromise.isSuccess() );
- assertEquals( ServerVersion.v4_0_0, serverVersion( channel ) );
- }
-
- @Test
- void shouldUseProtocolVersionForServerVersionWhenConnectedWithBoltV41()
- {
- ChannelPromise channelPromise = channel.newPromise();
- HelloResponseHandler handler = new HelloResponseHandler( channelPromise, BoltProtocolV41.VERSION );
-
- // server used in metadata should be ignored
- Map metadata = metadata( ServerVersion.vInDev, "bolt-1" );
- handler.onSuccess( metadata );
-
- assertTrue( channelPromise.isSuccess() );
- assertEquals( ServerVersion.v4_1_0, serverVersion( channel ) );
- }
-
@Test
void shouldSetConnectionIdOnChannel()
{
ChannelPromise channelPromise = channel.newPromise();
- HelloResponseHandler handler = new HelloResponseHandler( channelPromise, BoltProtocolV3.VERSION );
+ HelloResponseHandler handler = new HelloResponseHandler( channelPromise );
- Map metadata = metadata( anyServerVersion(), "bolt-42" );
+ Map metadata = metadata( SERVER_AGENT, "bolt-42" );
handler.onSuccess( metadata );
assertTrue( channelPromise.isSuccess() );
@@ -186,9 +140,9 @@ void shouldSetConnectionIdOnChannel()
void shouldThrowWhenConnectionIdNotReturned()
{
ChannelPromise channelPromise = channel.newPromise();
- HelloResponseHandler handler = new HelloResponseHandler( channelPromise, BoltProtocolV3.VERSION );
+ HelloResponseHandler handler = new HelloResponseHandler( channelPromise );
- Map metadata = metadata( anyServerVersion(), null );
+ Map metadata = metadata( SERVER_AGENT, null );
assertThrows( IllegalStateException.class, () -> handler.onSuccess( metadata ) );
assertFalse( channelPromise.isSuccess() ); // initialization failed
@@ -199,9 +153,9 @@ void shouldThrowWhenConnectionIdNotReturned()
void shouldThrowWhenConnectionIdIsNull()
{
ChannelPromise channelPromise = channel.newPromise();
- HelloResponseHandler handler = new HelloResponseHandler( channelPromise, BoltProtocolV3.VERSION );
+ HelloResponseHandler handler = new HelloResponseHandler( channelPromise );
- Map metadata = metadata( anyServerVersion(), Values.NULL );
+ Map metadata = metadata( SERVER_AGENT, Values.NULL );
assertThrows( IllegalStateException.class, () -> handler.onSuccess( metadata ) );
assertFalse( channelPromise.isSuccess() ); // initialization failed
@@ -212,7 +166,7 @@ void shouldThrowWhenConnectionIdIsNull()
void shouldCloseChannelOnFailure() throws Exception
{
ChannelPromise channelPromise = channel.newPromise();
- HelloResponseHandler handler = new HelloResponseHandler( channelPromise, BoltProtocolV3.VERSION );
+ HelloResponseHandler handler = new HelloResponseHandler( channelPromise );
RuntimeException error = new RuntimeException( "Hi!" );
handler.onFailure( error );
@@ -229,9 +183,9 @@ void shouldCloseChannelOnFailure() throws Exception
void shouldNotThrowWhenConfigurationHintsAreAbsent()
{
ChannelPromise channelPromise = channel.newPromise();
- HelloResponseHandler handler = new HelloResponseHandler( channelPromise, BoltProtocolV41.VERSION );
+ HelloResponseHandler handler = new HelloResponseHandler( channelPromise );
- Map metadata = metadata( anyServerVersion(), "bolt-x" );
+ Map metadata = metadata( SERVER_AGENT, "bolt-x" );
handler.onSuccess( metadata );
assertTrue( channelPromise.isSuccess() );
@@ -242,9 +196,9 @@ void shouldNotThrowWhenConfigurationHintsAreAbsent()
void shouldNotThrowWhenConfigurationHintsAreEmpty()
{
ChannelPromise channelPromise = channel.newPromise();
- HelloResponseHandler handler = new HelloResponseHandler( channelPromise, BoltProtocolV41.VERSION );
+ HelloResponseHandler handler = new HelloResponseHandler( channelPromise );
- Map metadata = metadata( anyServerVersion(), "bolt-x", value( new HashMap<>() ) );
+ Map metadata = metadata( SERVER_AGENT, "bolt-x", value( new HashMap<>() ) );
handler.onSuccess( metadata );
assertTrue( channelPromise.isSuccess() );
@@ -255,9 +209,9 @@ void shouldNotThrowWhenConfigurationHintsAreEmpty()
void shouldNotThrowWhenConfigurationHintsAreNull()
{
ChannelPromise channelPromise = channel.newPromise();
- HelloResponseHandler handler = new HelloResponseHandler( channelPromise, BoltProtocolV41.VERSION );
+ HelloResponseHandler handler = new HelloResponseHandler( channelPromise );
- Map metadata = metadata( anyServerVersion(), "bolt-x", Values.NULL );
+ Map metadata = metadata( SERVER_AGENT, "bolt-x", Values.NULL );
handler.onSuccess( metadata );
assertTrue( channelPromise.isSuccess() );
@@ -268,12 +222,12 @@ void shouldNotThrowWhenConfigurationHintsAreNull()
void shouldSetConnectionTimeoutHint()
{
ChannelPromise channelPromise = channel.newPromise();
- HelloResponseHandler handler = new HelloResponseHandler( channelPromise, BoltProtocolV41.VERSION );
+ HelloResponseHandler handler = new HelloResponseHandler( channelPromise );
long timeout = 15L;
Map hints = new HashMap<>();
hints.put( HelloResponseHandler.CONNECTION_RECEIVE_TIMEOUT_SECONDS_KEY, value( timeout ) );
- Map metadata = metadata( anyServerVersion(), "bolt-x", value( hints ) );
+ Map metadata = metadata( SERVER_AGENT, "bolt-x", value( hints ) );
handler.onSuccess( metadata );
assertEquals( timeout, connectionReadTimeout( channel ).orElse( null ) );
diff --git a/driver/src/test/java/org/neo4j/driver/internal/handlers/InitResponseHandlerTest.java b/driver/src/test/java/org/neo4j/driver/internal/handlers/InitResponseHandlerTest.java
index d2839af892..2a894e5a2e 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/handlers/InitResponseHandlerTest.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/handlers/InitResponseHandlerTest.java
@@ -43,11 +43,9 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.neo4j.driver.Values.value;
-import static org.neo4j.driver.internal.async.connection.ChannelAttributes.serverVersion;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setMessageDispatcher;
import static org.neo4j.driver.internal.async.outbound.OutboundMessageHandler.NAME;
import static org.neo4j.driver.internal.logging.DevNullLogging.DEV_NULL_LOGGING;
-import static org.neo4j.driver.util.TestUtil.anyServerVersion;
class InitResponseHandlerTest
{
@@ -68,19 +66,6 @@ void tearDown()
channel.finishAndReleaseAll();
}
- @Test
- void shouldSetServerVersionOnChannel()
- {
- ChannelPromise channelPromise = channel.newPromise();
- InitResponseHandler handler = new InitResponseHandler( channelPromise );
-
- Map metadata = singletonMap( "server", value( anyServerVersion().toString() ) );
- handler.onSuccess( metadata );
-
- assertTrue( channelPromise.isSuccess() );
- assertEquals( anyServerVersion(), serverVersion( channel ) );
- }
-
@Test
void shouldFailToConnectWhenNoServerIdentifierIsProvided()
{
@@ -96,7 +81,7 @@ void shouldAllowByteArrays()
{
InitResponseHandler handler = new InitResponseHandler( channel.newPromise() );
- Map metadata = singletonMap( "server", value( anyServerVersion().toString() ) );
+ Map metadata = singletonMap( "server", value( "Neo4j/4.4.0" ) );
handler.onSuccess( metadata );
Map params = singletonMap( "array", value( new byte[]{1, 2, 3} ) );
diff --git a/driver/src/test/java/org/neo4j/driver/internal/handlers/PullAllResponseHandlerTestBase.java b/driver/src/test/java/org/neo4j/driver/internal/handlers/PullAllResponseHandlerTestBase.java
index 78763751d0..c65020fc6e 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/handlers/PullAllResponseHandlerTestBase.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/handlers/PullAllResponseHandlerTestBase.java
@@ -54,7 +54,6 @@
import static org.mockito.Mockito.when;
import static org.neo4j.driver.Values.value;
import static org.neo4j.driver.Values.values;
-import static org.neo4j.driver.util.TestUtil.anyServerVersion;
import static org.neo4j.driver.util.TestUtil.await;
public abstract class PullAllResponseHandlerTestBase
@@ -711,7 +710,6 @@ protected Connection connectionMock()
{
Connection connection = mock( Connection.class );
when( connection.serverAddress() ).thenReturn( BoltServerAddress.LOCAL_DEFAULT );
- when( connection.serverVersion() ).thenReturn( anyServerVersion() );
when( connection.protocol() ).thenReturn( BoltProtocolV43.INSTANCE );
when( connection.serverAgent() ).thenReturn( "Neo4j/4.2.5" );
return connection;
diff --git a/driver/src/test/java/org/neo4j/driver/internal/handlers/SessionPullResponseCompletionListenerTest.java b/driver/src/test/java/org/neo4j/driver/internal/handlers/SessionPullResponseCompletionListenerTest.java
index 4b2cc67f4c..daaeb1c26f 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/handlers/SessionPullResponseCompletionListenerTest.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/handlers/SessionPullResponseCompletionListenerTest.java
@@ -41,7 +41,6 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.neo4j.driver.Values.value;
-import static org.neo4j.driver.util.TestUtil.anyServerVersion;
class SessionPullResponseCompletionListenerTest
{
@@ -128,7 +127,6 @@ private static Connection newConnectionMock()
{
Connection connection = mock( Connection.class );
when( connection.serverAddress() ).thenReturn( BoltServerAddress.LOCAL_DEFAULT );
- when( connection.serverVersion() ).thenReturn( anyServerVersion() );
when( connection.protocol() ).thenReturn( BoltProtocolV43.INSTANCE );
when( connection.serverAgent() ).thenReturn( "Neo4j/4.2.5" );
return connection;
diff --git a/driver/src/test/java/org/neo4j/driver/internal/handlers/TransactionPullResponseCompletionListenerTest.java b/driver/src/test/java/org/neo4j/driver/internal/handlers/TransactionPullResponseCompletionListenerTest.java
index 287c9d2794..f7d3e78d3c 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/handlers/TransactionPullResponseCompletionListenerTest.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/handlers/TransactionPullResponseCompletionListenerTest.java
@@ -39,7 +39,6 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.neo4j.driver.internal.messaging.v3.BoltProtocolV3.METADATA_EXTRACTOR;
-import static org.neo4j.driver.util.TestUtil.anyServerVersion;
class TransactionPullResponseCompletionListenerTest
{
@@ -63,7 +62,6 @@ private static void testErrorHandling( Throwable error )
{
Connection connection = mock( Connection.class );
when( connection.serverAddress() ).thenReturn( BoltServerAddress.LOCAL_DEFAULT );
- when( connection.serverVersion() ).thenReturn( anyServerVersion() );
when( connection.protocol() ).thenReturn( BoltProtocolV43.INSTANCE );
when( connection.serverAgent() ).thenReturn( "Neo4j/4.2.5" );
UnmanagedTransaction tx = mock( UnmanagedTransaction.class );
diff --git a/driver/src/test/java/org/neo4j/driver/internal/handlers/pulln/BasicPullResponseHandlerTestBase.java b/driver/src/test/java/org/neo4j/driver/internal/handlers/pulln/BasicPullResponseHandlerTestBase.java
index eb8f68e699..7db9d635ba 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/handlers/pulln/BasicPullResponseHandlerTestBase.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/handlers/pulln/BasicPullResponseHandlerTestBase.java
@@ -33,7 +33,6 @@
import org.neo4j.driver.internal.messaging.request.PullMessage;
import org.neo4j.driver.internal.messaging.v43.BoltProtocolV43;
import org.neo4j.driver.internal.spi.Connection;
-import org.neo4j.driver.internal.util.ServerVersion;
import org.neo4j.driver.internal.value.BooleanValue;
import org.neo4j.driver.summary.ResultSummary;
@@ -241,7 +240,6 @@ static Connection mockConnection()
{
Connection conn = mock( Connection.class );
when( conn.serverAddress() ).thenReturn( mock( BoltServerAddress.class ) );
- when( conn.serverVersion() ).thenReturn( mock( ServerVersion.class ) );
when( conn.protocol() ).thenReturn( BoltProtocolV43.INSTANCE );
when( conn.serverAgent() ).thenReturn( "Neo4j/4.2.5" );
return conn;
diff --git a/driver/src/test/java/org/neo4j/driver/internal/messaging/v3/BoltProtocolV3Test.java b/driver/src/test/java/org/neo4j/driver/internal/messaging/v3/BoltProtocolV3Test.java
index 14f6d3bcb2..60f34a4f3f 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/messaging/v3/BoltProtocolV3Test.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/messaging/v3/BoltProtocolV3Test.java
@@ -90,7 +90,6 @@
import static org.neo4j.driver.Values.value;
import static org.neo4j.driver.internal.DatabaseNameUtil.defaultDatabase;
import static org.neo4j.driver.internal.handlers.pulln.FetchSizeUtil.UNLIMITED_FETCH_SIZE;
-import static org.neo4j.driver.util.TestUtil.anyServerVersion;
import static org.neo4j.driver.util.TestUtil.await;
import static org.neo4j.driver.util.TestUtil.connectionMock;
@@ -150,7 +149,7 @@ void shouldInitializeChannel()
assertFalse( promise.isDone() );
Map metadata = new HashMap<>();
- metadata.put( "server", value( anyServerVersion().toString() ) );
+ metadata.put( "server", value( "Neo4j/3.5.0" ) );
metadata.put( "connection_id", value( "bolt-42" ) );
messageDispatcher.handleSuccessMessage( metadata );
diff --git a/driver/src/test/java/org/neo4j/driver/internal/messaging/v4/BoltProtocolV4Test.java b/driver/src/test/java/org/neo4j/driver/internal/messaging/v4/BoltProtocolV4Test.java
index ac26d0a2f0..4c7eac908b 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/messaging/v4/BoltProtocolV4Test.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/messaging/v4/BoltProtocolV4Test.java
@@ -92,7 +92,6 @@
import static org.neo4j.driver.internal.DatabaseNameUtil.database;
import static org.neo4j.driver.internal.DatabaseNameUtil.defaultDatabase;
import static org.neo4j.driver.internal.handlers.pulln.FetchSizeUtil.UNLIMITED_FETCH_SIZE;
-import static org.neo4j.driver.util.TestUtil.anyServerVersion;
import static org.neo4j.driver.util.TestUtil.await;
import static org.neo4j.driver.util.TestUtil.connectionMock;
@@ -143,7 +142,7 @@ void shouldInitializeChannel()
assertFalse( promise.isDone() );
Map metadata = new HashMap<>();
- metadata.put( "server", value( anyServerVersion().toString() ) );
+ metadata.put( "server", value( "Neo4j/4.0.0" ) );
metadata.put( "connection_id", value( "bolt-42" ) );
messageDispatcher.handleSuccessMessage( metadata );
diff --git a/driver/src/test/java/org/neo4j/driver/internal/messaging/v41/BoltProtocolV41Test.java b/driver/src/test/java/org/neo4j/driver/internal/messaging/v41/BoltProtocolV41Test.java
index f722df6b78..5ec5d4dd34 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/messaging/v41/BoltProtocolV41Test.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/messaging/v41/BoltProtocolV41Test.java
@@ -93,7 +93,6 @@
import static org.neo4j.driver.internal.DatabaseNameUtil.database;
import static org.neo4j.driver.internal.DatabaseNameUtil.defaultDatabase;
import static org.neo4j.driver.internal.handlers.pulln.FetchSizeUtil.UNLIMITED_FETCH_SIZE;
-import static org.neo4j.driver.util.TestUtil.anyServerVersion;
import static org.neo4j.driver.util.TestUtil.await;
import static org.neo4j.driver.util.TestUtil.connectionMock;
@@ -148,7 +147,7 @@ void shouldInitializeChannel()
assertFalse( promise.isDone() );
Map metadata = new HashMap<>();
- metadata.put( "server", value( anyServerVersion().toString() ) );
+ metadata.put( "server", value( "Neo4j/4.1.0" ) );
metadata.put( "connection_id", value( "bolt-42" ) );
messageDispatcher.handleSuccessMessage( metadata );
diff --git a/driver/src/test/java/org/neo4j/driver/internal/messaging/v42/BoltProtocolV42Test.java b/driver/src/test/java/org/neo4j/driver/internal/messaging/v42/BoltProtocolV42Test.java
index b163030c50..7bd3d211ae 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/messaging/v42/BoltProtocolV42Test.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/messaging/v42/BoltProtocolV42Test.java
@@ -93,7 +93,6 @@
import static org.neo4j.driver.internal.DatabaseNameUtil.database;
import static org.neo4j.driver.internal.DatabaseNameUtil.defaultDatabase;
import static org.neo4j.driver.internal.handlers.pulln.FetchSizeUtil.UNLIMITED_FETCH_SIZE;
-import static org.neo4j.driver.util.TestUtil.anyServerVersion;
import static org.neo4j.driver.util.TestUtil.await;
import static org.neo4j.driver.util.TestUtil.connectionMock;
@@ -148,7 +147,7 @@ void shouldInitializeChannel()
assertFalse( promise.isDone() );
Map metadata = new HashMap<>();
- metadata.put( "server", value( anyServerVersion().toString() ) );
+ metadata.put( "server", value( "Neo4j/4.2.0" ) );
metadata.put( "connection_id", value( "bolt-42" ) );
messageDispatcher.handleSuccessMessage( metadata );
diff --git a/driver/src/test/java/org/neo4j/driver/internal/messaging/v43/BoltProtocolV43Test.java b/driver/src/test/java/org/neo4j/driver/internal/messaging/v43/BoltProtocolV43Test.java
index d8b2ee13c8..f2ab8545cf 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/messaging/v43/BoltProtocolV43Test.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/messaging/v43/BoltProtocolV43Test.java
@@ -92,7 +92,6 @@
import static org.neo4j.driver.internal.DatabaseNameUtil.database;
import static org.neo4j.driver.internal.DatabaseNameUtil.defaultDatabase;
import static org.neo4j.driver.internal.handlers.pulln.FetchSizeUtil.UNLIMITED_FETCH_SIZE;
-import static org.neo4j.driver.util.TestUtil.anyServerVersion;
import static org.neo4j.driver.util.TestUtil.await;
import static org.neo4j.driver.util.TestUtil.connectionMock;
@@ -147,7 +146,7 @@ void shouldInitializeChannel()
assertFalse( promise.isDone() );
Map metadata = new HashMap<>();
- metadata.put( "server", value( anyServerVersion().toString() ) );
+ metadata.put( "server", value( "Neo4j/4.3.0" ) );
metadata.put( "connection_id", value( "bolt-42" ) );
messageDispatcher.handleSuccessMessage( metadata );
diff --git a/driver/src/test/java/org/neo4j/driver/internal/messaging/v44/BoltProtocolV44Test.java b/driver/src/test/java/org/neo4j/driver/internal/messaging/v44/BoltProtocolV44Test.java
index 09cd33c40e..adffe6d22a 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/messaging/v44/BoltProtocolV44Test.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/messaging/v44/BoltProtocolV44Test.java
@@ -92,7 +92,6 @@
import static org.neo4j.driver.internal.DatabaseNameUtil.database;
import static org.neo4j.driver.internal.DatabaseNameUtil.defaultDatabase;
import static org.neo4j.driver.internal.handlers.pulln.FetchSizeUtil.UNLIMITED_FETCH_SIZE;
-import static org.neo4j.driver.util.TestUtil.anyServerVersion;
import static org.neo4j.driver.util.TestUtil.await;
import static org.neo4j.driver.util.TestUtil.connectionMock;
@@ -147,7 +146,7 @@ void shouldInitializeChannel()
assertFalse( promise.isDone() );
Map metadata = new HashMap<>();
- metadata.put( "server", value( anyServerVersion().toString() ) );
+ metadata.put( "server", value( "Neo4j/4.4.0" ) );
metadata.put( "connection_id", value( "bolt-42" ) );
messageDispatcher.handleSuccessMessage( metadata );
diff --git a/driver/src/test/java/org/neo4j/driver/internal/util/FailingConnectionDriverFactory.java b/driver/src/test/java/org/neo4j/driver/internal/util/FailingConnectionDriverFactory.java
index 57bb9b3c5b..2aaa4c9bf5 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/util/FailingConnectionDriverFactory.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/util/FailingConnectionDriverFactory.java
@@ -206,12 +206,6 @@ public BoltServerAddress serverAddress()
return delegate.serverAddress();
}
- @Override
- public ServerVersion serverVersion()
- {
- return delegate.serverVersion();
- }
-
@Override
public BoltProtocol protocol()
{
diff --git a/driver/src/test/java/org/neo4j/driver/internal/util/MetadataExtractorTest.java b/driver/src/test/java/org/neo4j/driver/internal/util/MetadataExtractorTest.java
index afbc7c5dd2..6c26c27dbc 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/util/MetadataExtractorTest.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/util/MetadataExtractorTest.java
@@ -60,14 +60,11 @@
import static org.neo4j.driver.Values.values;
import static org.neo4j.driver.internal.summary.InternalSummaryCounters.EMPTY_STATS;
import static org.neo4j.driver.internal.util.MetadataExtractor.extractDatabaseInfo;
-import static org.neo4j.driver.internal.util.MetadataExtractor.extractNeo4jServerVersion;
import static org.neo4j.driver.internal.util.MetadataExtractor.extractServer;
-import static org.neo4j.driver.internal.util.ServerVersion.v4_0_0;
import static org.neo4j.driver.summary.QueryType.READ_ONLY;
import static org.neo4j.driver.summary.QueryType.READ_WRITE;
import static org.neo4j.driver.summary.QueryType.SCHEMA_WRITE;
import static org.neo4j.driver.summary.QueryType.WRITE_ONLY;
-import static org.neo4j.driver.util.TestUtil.anyServerVersion;
class MetadataExtractorTest
{
@@ -126,14 +123,13 @@ void shouldBuildResultSummaryWithQuery()
}
@Test
- void shouldBuildResultSummaryWithServerInfo()
+ void shouldBuildResultSummaryWithServerAddress()
{
- Connection connection = connectionMock( new BoltServerAddress( "server:42" ), v4_0_0 );
+ Connection connection = connectionMock( new BoltServerAddress( "server:42" ) );
ResultSummary summary = extractor.extractSummary( query(), connection, 42, emptyMap() );
assertEquals( "server:42", summary.server().address() );
- assertEquals( "Neo4j/4.0.0", summary.server().version() );
}
@Test
@@ -405,16 +401,6 @@ void shouldExtractNoBookmarkWhenMetadataContainsValueOfIncorrectType()
assertEquals( InternalBookmark.empty(), bookmark );
}
- @Test
- void shouldExtractServerVersion()
- {
- Map metadata = singletonMap( "server", value( "Neo4j/3.5.0" ) );
-
- ServerVersion version = extractNeo4jServerVersion( metadata );
-
- assertEquals( ServerVersion.v3_5_0, version );
- }
-
@Test
void shouldExtractServer()
{
@@ -468,14 +454,14 @@ void shouldErrorWhenTypeIsWrong()
@Test
void shouldFailToExtractServerVersionWhenMetadataDoesNotContainIt()
{
- assertThrows( UntrustedServerException.class, () -> extractNeo4jServerVersion( singletonMap( "server", Values.NULL ) ) );
- assertThrows( UntrustedServerException.class, () -> extractNeo4jServerVersion( singletonMap( "server", null ) ) );
+ assertThrows( UntrustedServerException.class, () -> extractServer( singletonMap( "server", Values.NULL ) ) );
+ assertThrows( UntrustedServerException.class, () -> extractServer( singletonMap( "server", null ) ) );
}
@Test
void shouldFailToExtractServerVersionFromNonNeo4jProduct()
{
- assertThrows( UntrustedServerException.class, () -> extractNeo4jServerVersion( singletonMap( "server", value( "NotNeo4j/1.2.3" ) ) ) );
+ assertThrows( UntrustedServerException.class, () -> extractServer( singletonMap( "server", value( "NotNeo4j/1.2.3" ) ) ) );
}
private ResultSummary createWithQueryType( Value typeValue )
@@ -491,14 +477,13 @@ private static Query query()
private static Connection connectionMock()
{
- return connectionMock( BoltServerAddress.LOCAL_DEFAULT, anyServerVersion() );
+ return connectionMock( BoltServerAddress.LOCAL_DEFAULT );
}
- private static Connection connectionMock( BoltServerAddress address, ServerVersion version )
+ private static Connection connectionMock( BoltServerAddress address )
{
Connection connection = mock( Connection.class );
when( connection.serverAddress() ).thenReturn( address );
- when( connection.serverVersion() ).thenReturn( version );
when( connection.protocol() ).thenReturn( BoltProtocolV43.INSTANCE );
when( connection.serverAgent() ).thenReturn( "Neo4j/4.2.5" );
return connection;
diff --git a/driver/src/test/java/org/neo4j/driver/internal/util/Neo4jFeature.java b/driver/src/test/java/org/neo4j/driver/internal/util/Neo4jFeature.java
index 8cb197d449..acb70c1e66 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/util/Neo4jFeature.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/util/Neo4jFeature.java
@@ -18,27 +18,59 @@
*/
package org.neo4j.driver.internal.util;
+import static java.lang.Integer.compare;
import static java.util.Objects.requireNonNull;
-import static org.neo4j.driver.internal.util.ServerVersion.v3_4_0;
-import static org.neo4j.driver.internal.util.ServerVersion.v3_5_0;
-import static org.neo4j.driver.internal.util.ServerVersion.v4_0_0;
public enum Neo4jFeature
{
- SPATIAL_TYPES( v3_4_0 ),
- TEMPORAL_TYPES( v3_4_0 ),
- BOLT_V3( v3_5_0 ),
- BOLT_V4( v4_0_0 );
+ SPATIAL_TYPES( new Version( 3, 4, 0 ) ),
+ TEMPORAL_TYPES( new Version( 3, 4, 0 ) ),
+ BOLT_V3( new Version( 3, 5, 0 ) ),
+ BOLT_V4( new Version( 4, 0, 0 ) );
- private final ServerVersion availableFromVersion;
+ private final Version availableFromVersion;
- Neo4jFeature( ServerVersion availableFromVersion )
+ Neo4jFeature( Version availableFromVersion )
{
this.availableFromVersion = requireNonNull( availableFromVersion );
}
- public boolean availableIn( ServerVersion version )
+ public boolean availableIn( Version version )
{
return version.greaterThanOrEqual( availableFromVersion );
}
+
+ public static class Version
+ {
+
+ private final int major;
+ private final int minor;
+ private final int patch;
+
+ public Version( int major, int minor, int patch )
+ {
+ this.major = major;
+ this.minor = minor;
+ this.patch = patch;
+ }
+
+ public boolean greaterThanOrEqual( Version other )
+ {
+ return compareTo( other ) >= 0;
+ }
+
+ private int compareTo( Version o )
+ {
+ int c = compare( major, o.major );
+ if ( c == 0 )
+ {
+ c = compare( minor, o.minor );
+ if ( c == 0 )
+ {
+ c = compare( patch, o.patch );
+ }
+ }
+ return c;
+ }
+ }
}
diff --git a/driver/src/test/java/org/neo4j/driver/internal/util/Neo4jWithFeatureCondition.java b/driver/src/test/java/org/neo4j/driver/internal/util/Neo4jWithFeatureCondition.java
index 6d85c4e006..3998c52aeb 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/util/Neo4jWithFeatureCondition.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/util/Neo4jWithFeatureCondition.java
@@ -24,6 +24,8 @@
import java.lang.reflect.AnnotatedElement;
import java.util.Optional;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.neo4j.driver.Driver;
import org.neo4j.driver.Session;
@@ -70,8 +72,19 @@ private static ConditionEvaluationResult checkFeatureAvailability( Neo4jFeature
Driver driver = getSharedNeo4jDriver();
if ( driver != null )
{
- ServerVersion version = ServerVersion.version( driver );
- return createResult( version, feature, negated );
+ try ( Session session = driver.session() )
+ {
+ String agent = session.readTransaction( tx -> tx.run( "RETURN 1" ).consume().server().agent() );
+ Pattern pattern = Pattern.compile( "^Neo4j/(\\d+)\\.(\\d+)\\.(\\d+)$" );
+ Matcher matcher = pattern.matcher( agent );
+ if ( !matcher.matches() )
+ {
+ throw new IllegalStateException( String.format( "Unexpected server agent value %s", agent ) );
+ }
+ Neo4jFeature.Version version = new Neo4jFeature.Version( Integer.parseInt( matcher.group( 1 ) ), Integer.parseInt( matcher.group( 2 ) ),
+ Integer.parseInt( matcher.group( 3 ) ) );
+ return createResult( version, feature, negated );
+ }
}
return ENABLED_UNKNOWN_DB_VERSION;
}
@@ -96,7 +109,7 @@ private static ConditionEvaluationResult checkEditionAvailability( ConditionEval
return ENABLED_UNKNOWN_DB_VERSION;
}
- private static ConditionEvaluationResult createResult( ServerVersion version, Neo4jFeature feature, boolean negated )
+ private static ConditionEvaluationResult createResult( Neo4jFeature.Version version, Neo4jFeature feature, boolean negated )
{
if ( feature.availableIn( version ) )
{
diff --git a/driver/src/test/java/org/neo4j/driver/internal/util/ServerVersionTest.java b/driver/src/test/java/org/neo4j/driver/internal/util/ServerVersionTest.java
deleted file mode 100644
index d0e880d5d0..0000000000
--- a/driver/src/test/java/org/neo4j/driver/internal/util/ServerVersionTest.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (c) "Neo4j"
- * Neo4j Sweden AB [http://neo4j.com]
- *
- * This file is part of Neo4j.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.neo4j.driver.internal.util;
-
-import org.junit.jupiter.api.Test;
-
-import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
-import org.neo4j.driver.internal.messaging.v4.BoltProtocolV4;
-import org.neo4j.driver.internal.messaging.v41.BoltProtocolV41;
-import org.neo4j.driver.internal.messaging.v42.BoltProtocolV42;
-import org.neo4j.driver.internal.messaging.v43.BoltProtocolV43;
-import org.neo4j.driver.internal.messaging.v44.BoltProtocolV44;
-
-import static java.lang.Integer.MAX_VALUE;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
-class ServerVersionTest
-{
- @Test
- void version()
- {
- assertThat( ServerVersion.version( "Neo4j/dev" ), is( ServerVersion.vInDev ) );
- assertThat( ServerVersion.version( "Neo4j/4.0.0" ), is( ServerVersion.v4_0_0 ) );
- }
-
- @Test
- void shouldHaveCorrectToString()
- {
- assertEquals( "Neo4j/dev", ServerVersion.vInDev.toString() );
- assertEquals( "Neo4j/4.0.0", ServerVersion.v4_0_0.toString() );
- assertEquals( "Neo4j/3.5.0", ServerVersion.v3_5_0.toString() );
- assertEquals( "Neo4j/3.5.7", ServerVersion.version( "Neo4j/3.5.7" ).toString() );
- }
-
- @Test
- void shouldFailToParseIllegalVersions()
- {
- assertThrows( IllegalArgumentException.class, () -> ServerVersion.version( "" ) );
- assertThrows( IllegalArgumentException.class, () -> ServerVersion.version( "/1.2.3" ) );
- assertThrows( IllegalArgumentException.class, () -> ServerVersion.version( "Neo4j1.2.3" ) );
- assertThrows( IllegalArgumentException.class, () -> ServerVersion.version( "Neo4j" ) );
- }
-
- @Test
- void shouldFailToCompareDifferentProducts()
- {
- ServerVersion version1 = ServerVersion.version( "MyNeo4j/1.2.3" );
- ServerVersion version2 = ServerVersion.version( "OtherNeo4j/1.2.4" );
-
- assertThrows( IllegalArgumentException.class, () -> version1.greaterThanOrEqual( version2 ) );
- }
-
- @Test
- void shouldReturnCorrectServerVersionFromBoltProtocolVersion()
- {
- assertEquals( ServerVersion.v4_0_0, ServerVersion.fromBoltProtocolVersion( BoltProtocolV4.VERSION ) );
- assertEquals( ServerVersion.v4_1_0, ServerVersion.fromBoltProtocolVersion( BoltProtocolV41.VERSION ) );
- assertEquals( ServerVersion.v4_2_0, ServerVersion.fromBoltProtocolVersion( BoltProtocolV42.VERSION ) );
- assertEquals( ServerVersion.v4_3_0, ServerVersion.fromBoltProtocolVersion( BoltProtocolV43.VERSION ) );
- assertEquals( ServerVersion.v4_4_0, ServerVersion.fromBoltProtocolVersion( BoltProtocolV44.VERSION ) );
- assertEquals( ServerVersion.vInDev, ServerVersion.fromBoltProtocolVersion( new BoltProtocolVersion( MAX_VALUE, MAX_VALUE ) ) );
- }
-}
diff --git a/driver/src/test/java/org/neo4j/driver/util/DatabaseExtension.java b/driver/src/test/java/org/neo4j/driver/util/DatabaseExtension.java
index 49c6cd5e4b..8a1803d4b8 100644
--- a/driver/src/test/java/org/neo4j/driver/util/DatabaseExtension.java
+++ b/driver/src/test/java/org/neo4j/driver/util/DatabaseExtension.java
@@ -30,11 +30,11 @@
import org.neo4j.driver.AuthToken;
import org.neo4j.driver.Driver;
+import org.neo4j.driver.Session;
import org.neo4j.driver.internal.BoltServerAddress;
-import org.neo4j.driver.internal.util.ServerVersion;
import org.neo4j.driver.types.TypeSystem;
-import static org.junit.jupiter.api.Assumptions.assumeTrue;
+import static org.junit.Assume.assumeTrue;
import static org.neo4j.driver.util.Neo4jRunner.DEFAULT_AUTH_TOKEN;
import static org.neo4j.driver.util.Neo4jRunner.HOME_DIR;
import static org.neo4j.driver.util.Neo4jRunner.debug;
@@ -152,15 +152,15 @@ public File tlsKeyFile()
public void ensureProcedures( String jarName ) throws IOException
{
- // These procedures was written against 3.x API.
+ // These procedures were written against 3.x API.
// As graph database service API is totally changed since 4.0. These procedures are no long valid.
- assumeTrue( version().lessThan( ServerVersion.v4_0_0 ) );
+ assumeTrue( getMajorVersion() < 4 );
File procedureJar = new File( HOME_DIR, "plugins/" + jarName );
if ( !procedureJar.exists() )
{
FileTools.copyFile( new File( TEST_RESOURCE_FOLDER_PATH, jarName ), procedureJar );
debug( "Added a new procedure `%s`", jarName );
- runner.forceToRestart(); // needs to force to restart as no configuration changed
+ runner.forceToRestart(); // needs to force restart as no configuration changed
}
}
@@ -174,9 +174,14 @@ public void stopDb()
runner.stopNeo4j();
}
- public ServerVersion version()
+ public int getMajorVersion()
{
- return ServerVersion.version( driver() );
+ try ( Session session = driver().session() )
+ {
+ String protocolVersion = session.readTransaction( tx -> tx.run( "RETURN 1" ).consume().server().protocolVersion() );
+ String[] versions = protocolVersion.split( "\\." );
+ return Integer.parseInt( versions[0] );
+ }
}
public void dumpLogs()
diff --git a/driver/src/test/java/org/neo4j/driver/util/TestUtil.java b/driver/src/test/java/org/neo4j/driver/util/TestUtil.java
index 7daf34448f..05e9fd501c 100644
--- a/driver/src/test/java/org/neo4j/driver/util/TestUtil.java
+++ b/driver/src/test/java/org/neo4j/driver/util/TestUtil.java
@@ -84,7 +84,6 @@
import org.neo4j.driver.internal.spi.ConnectionProvider;
import org.neo4j.driver.internal.spi.ResponseHandler;
import org.neo4j.driver.internal.util.FixedRetryLogic;
-import org.neo4j.driver.internal.util.ServerVersion;
import static java.util.Collections.emptyMap;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
@@ -519,7 +518,6 @@ public static Connection connectionMock( String databaseName, AccessMode mode, B
{
Connection connection = mock( Connection.class );
when( connection.serverAddress() ).thenReturn( BoltServerAddress.LOCAL_DEFAULT );
- when( connection.serverVersion() ).thenReturn( ServerVersion.vInDev );
when( connection.protocol() ).thenReturn( protocol );
when( connection.mode() ).thenReturn( mode );
when( connection.databaseName() ).thenReturn( database( databaseName ) );
@@ -644,14 +642,6 @@ public static ArgumentMatcher beginMessageWithPredicate( Predicate message instanceof BeginMessage && predicate.test( (BeginMessage) message );
}
- /**
- * Used in tests that expect a server version but the tests do not depend on server version to behave differently.
- */
- public static ServerVersion anyServerVersion()
- {
- return ServerVersion.v4_0_0;
- }
-
public static void assertNoCircularReferences(Throwable ex)
{
assertNoCircularReferences( ex, new ArrayList<>() );
diff --git a/driver/src/test/java/org/neo4j/driver/util/cc/ClusterDrivers.java b/driver/src/test/java/org/neo4j/driver/util/cc/ClusterDrivers.java
index c1a058348b..1d68da6c5c 100644
--- a/driver/src/test/java/org/neo4j/driver/util/cc/ClusterDrivers.java
+++ b/driver/src/test/java/org/neo4j/driver/util/cc/ClusterDrivers.java
@@ -18,18 +18,22 @@
*/
package org.neo4j.driver.util.cc;
+import java.util.Arrays;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
import org.neo4j.driver.AuthTokens;
import org.neo4j.driver.Config;
import org.neo4j.driver.Driver;
import org.neo4j.driver.GraphDatabase;
+import org.neo4j.driver.Session;
+import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
import org.neo4j.driver.util.cc.ClusterMemberRoleDiscoveryFactory.ClusterMemberRoleDiscovery;
import static org.neo4j.driver.internal.logging.DevNullLogging.DEV_NULL_LOGGING;
-import static org.neo4j.driver.internal.util.ServerVersion.version;
public class ClusterDrivers implements AutoCloseable
{
@@ -50,7 +54,13 @@ public Driver getDriver( ClusterMember member )
final Driver driver = membersWithDrivers.computeIfAbsent( member, this::createDriver );
if ( discovery == null )
{
- discovery = ClusterMemberRoleDiscoveryFactory.newInstance( version( driver ) );
+ try ( Session session = driver.session() )
+ {
+ String version = session.readTransaction( tx -> tx.run( "RETURN 1" ).consume().server().protocolVersion() );
+ List versionParts = Arrays.stream( version.split( "\\." ) ).map( Integer::parseInt ).collect( Collectors.toList() );
+ BoltProtocolVersion protocolVersion = new BoltProtocolVersion( versionParts.get( 0 ), versionParts.get( 1 ) );
+ discovery = ClusterMemberRoleDiscoveryFactory.newInstance( protocolVersion );
+ }
}
return driver;
}
diff --git a/driver/src/test/java/org/neo4j/driver/util/cc/ClusterMemberRoleDiscoveryFactory.java b/driver/src/test/java/org/neo4j/driver/util/cc/ClusterMemberRoleDiscoveryFactory.java
index 0b48f2a299..ece7025c8c 100644
--- a/driver/src/test/java/org/neo4j/driver/util/cc/ClusterMemberRoleDiscoveryFactory.java
+++ b/driver/src/test/java/org/neo4j/driver/util/cc/ClusterMemberRoleDiscoveryFactory.java
@@ -32,7 +32,7 @@
import org.neo4j.driver.Session;
import org.neo4j.driver.Values;
import org.neo4j.driver.internal.BoltServerAddress;
-import org.neo4j.driver.internal.util.ServerVersion;
+import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
import static org.neo4j.driver.SessionConfig.builder;
import static org.neo4j.driver.Values.parameters;
@@ -40,9 +40,9 @@
public class ClusterMemberRoleDiscoveryFactory
{
- public static ClusterMemberRoleDiscovery newInstance( ServerVersion version )
+ public static ClusterMemberRoleDiscovery newInstance( BoltProtocolVersion version )
{
- if ( version.greaterThanOrEqual( ServerVersion.v4_0_0 ) )
+ if ( version.getMajorVersion() >= 4 )
{
return new SimpleClusterMemberRoleDiscovery();
}