diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/core/EnterpriseCoreEditionModule.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/core/EnterpriseCoreEditionModule.java index 069ecb3a239d..f66ac3f7c1b2 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/core/EnterpriseCoreEditionModule.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/core/EnterpriseCoreEditionModule.java @@ -68,15 +68,14 @@ import org.neo4j.causalclustering.protocol.ModifierProtocolInstaller; import org.neo4j.causalclustering.protocol.NettyPipelineBuilderFactory; import org.neo4j.causalclustering.protocol.Protocol; -import org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocol; -import org.neo4j.causalclustering.protocol.Protocol.ModifierProtocol; import org.neo4j.causalclustering.protocol.ProtocolInstaller; import org.neo4j.causalclustering.protocol.ProtocolInstallerRepository; import org.neo4j.causalclustering.protocol.handshake.ApplicationProtocolRepository; +import org.neo4j.causalclustering.protocol.handshake.ApplicationSupportedProtocols; import org.neo4j.causalclustering.protocol.handshake.HandshakeClientInitializer; import org.neo4j.causalclustering.protocol.handshake.ModifierProtocolRepository; +import org.neo4j.causalclustering.protocol.handshake.ModifierSupportedProtocols; import org.neo4j.causalclustering.protocol.handshake.ProtocolStack; -import org.neo4j.causalclustering.protocol.handshake.SupportedProtocols; import org.neo4j.com.storecopy.StoreUtil; import org.neo4j.function.Predicates; import org.neo4j.graphdb.DependencyResolver; @@ -241,8 +240,8 @@ public EnterpriseCoreEditionModule( final PlatformModule platformModule, long logThresholdMillis = config.get( CausalClusteringSettings.unknown_address_logging_throttle ).toMillis(); SupportedProtocolCreator supportedProtocolCreator = new SupportedProtocolCreator( config ); - SupportedProtocols supportedApplicationProtocol = supportedProtocolCreator.createSupportedRaftProtocol(); - Collection> supportedModifierProtocols = supportedProtocolCreator.createSupportedModifierProtocols(); + ApplicationSupportedProtocols supportedApplicationProtocol = supportedProtocolCreator.createSupportedRaftProtocol(); + Collection supportedModifierProtocols = supportedProtocolCreator.createSupportedModifierProtocols(); ApplicationProtocolRepository applicationProtocolRepository = new ApplicationProtocolRepository( Protocol.ApplicationProtocols.values(), supportedApplicationProtocol ); diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/core/RaftServerModule.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/core/RaftServerModule.java index 59ea47177e68..41988583fc39 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/core/RaftServerModule.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/core/RaftServerModule.java @@ -43,14 +43,13 @@ import org.neo4j.causalclustering.protocol.ModifierProtocolInstaller; import org.neo4j.causalclustering.protocol.NettyPipelineBuilderFactory; import org.neo4j.causalclustering.protocol.Protocol; -import org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocol; -import org.neo4j.causalclustering.protocol.Protocol.ModifierProtocol; import org.neo4j.causalclustering.protocol.ProtocolInstaller; import org.neo4j.causalclustering.protocol.ProtocolInstallerRepository; import org.neo4j.causalclustering.protocol.handshake.ApplicationProtocolRepository; +import org.neo4j.causalclustering.protocol.handshake.ApplicationSupportedProtocols; import org.neo4j.causalclustering.protocol.handshake.HandshakeServerInitializer; import org.neo4j.causalclustering.protocol.handshake.ModifierProtocolRepository; -import org.neo4j.causalclustering.protocol.handshake.SupportedProtocols; +import org.neo4j.causalclustering.protocol.handshake.ModifierSupportedProtocols; import org.neo4j.kernel.impl.factory.PlatformModule; import org.neo4j.logging.LogProvider; import org.neo4j.scheduler.JobScheduler; @@ -62,19 +61,19 @@ class RaftServerModule private final PlatformModule platformModule; private final ConsensusModule consensusModule; private final IdentityModule identityModule; - private final SupportedProtocols supportedApplicationProtocol; + private final ApplicationSupportedProtocols supportedApplicationProtocol; private final LocalDatabase localDatabase; private final MessageLogger messageLogger; private final LogProvider logProvider; private final NettyPipelineBuilderFactory pipelineBuilderFactory; private final TopologyService topologyService; - private final Collection> supportedModifierProtocols; + private final Collection supportedModifierProtocols; private final RaftServer raftServer; private RaftServerModule( PlatformModule platformModule, ConsensusModule consensusModule, IdentityModule identityModule, CoreServerModule coreServerModule, LocalDatabase localDatabase, NettyPipelineBuilderFactory pipelineBuilderFactory, MessageLogger messageLogger, - CoreTopologyService topologyService, SupportedProtocols supportedApplicationProtocol, - Collection> supportedModifierProtocols ) + CoreTopologyService topologyService, ApplicationSupportedProtocols supportedApplicationProtocol, + Collection supportedModifierProtocols ) { this.platformModule = platformModule; this.consensusModule = consensusModule; @@ -94,8 +93,8 @@ private RaftServerModule( PlatformModule platformModule, ConsensusModule consens static RaftServerModule createAndStart( PlatformModule platformModule, ConsensusModule consensusModule, IdentityModule identityModule, CoreServerModule coreServerModule, LocalDatabase localDatabase, NettyPipelineBuilderFactory pipelineBuilderFactory, - MessageLogger messageLogger, CoreTopologyService topologyService, SupportedProtocols supportedApplicationProtocol, - Collection> supportedModifierProtocols ) + MessageLogger messageLogger, CoreTopologyService topologyService, ApplicationSupportedProtocols supportedApplicationProtocol, + Collection supportedModifierProtocols ) { return new RaftServerModule( platformModule, consensusModule, identityModule, coreServerModule, localDatabase, pipelineBuilderFactory, messageLogger, topologyService, supportedApplicationProtocol, supportedModifierProtocols ); diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/core/SupportedProtocolCreator.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/core/SupportedProtocolCreator.java index 1bd6a5d4f8d5..12f2e5e7892f 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/core/SupportedProtocolCreator.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/core/SupportedProtocolCreator.java @@ -25,7 +25,8 @@ import java.util.stream.Stream; import org.neo4j.causalclustering.protocol.Protocol; -import org.neo4j.causalclustering.protocol.handshake.SupportedProtocols; +import org.neo4j.causalclustering.protocol.handshake.ApplicationSupportedProtocols; +import org.neo4j.causalclustering.protocol.handshake.ModifierSupportedProtocols; import org.neo4j.graphdb.config.Setting; import org.neo4j.kernel.configuration.Config; import org.neo4j.stream.Streams; @@ -39,37 +40,37 @@ public SupportedProtocolCreator( Config config ) this.config = config; } - public SupportedProtocols createSupportedRaftProtocol() + public ApplicationSupportedProtocols createSupportedRaftProtocol() { List raftVersions = config.get( CausalClusteringSettings.raft_versions ); - return new SupportedProtocols<>( Protocol.ApplicationProtocolIdentifier.RAFT, raftVersions ); + return new ApplicationSupportedProtocols( Protocol.ApplicationProtocolCategory.RAFT, raftVersions ); } - public List> createSupportedModifierProtocols() + public List createSupportedModifierProtocols() { - SupportedProtocols supportedCompression = compressionProtocolVersions(); + ModifierSupportedProtocols supportedCompression = compressionProtocolVersions(); return Stream.of( supportedCompression ) .filter( supportedProtocols -> !supportedProtocols.versions().isEmpty() ) .collect( Collectors.toList() ); } - private SupportedProtocols compressionProtocolVersions() + private ModifierSupportedProtocols compressionProtocolVersions() { - return modifierProtocolVersions( CausalClusteringSettings.compression_versions, Protocol.ModifierProtocolIdentifier.COMPRESSION ); + return modifierProtocolVersions( CausalClusteringSettings.compression_versions, Protocol.ModifierProtocolCategory.COMPRESSION ); } - private SupportedProtocols modifierProtocolVersions( - Setting> compressionVersions, Protocol.ModifierProtocolIdentifier identifier ) + private ModifierSupportedProtocols modifierProtocolVersions( + Setting> compressionVersions, Protocol.ModifierProtocolCategory identifier ) { List compressionAlgorithms = config.get( compressionVersions ); - List versions = compressionAlgorithms.stream() + List versions = compressionAlgorithms.stream() .map( Protocol.ModifierProtocols::fromFriendlyName ) .flatMap( Streams::ofOptional ) - .filter( protocol -> Objects.equals( protocol.identifier(), identifier.canonicalName() ) ) - .map( Protocol.ModifierProtocols::version ) + .filter( protocol -> Objects.equals( protocol.category(), identifier.canonicalName() ) ) + .map( Protocol.ModifierProtocols::implementation ) .collect( Collectors.toList() ); - return new SupportedProtocols<>( identifier, versions ); + return new ModifierSupportedProtocols( identifier, versions ); } } diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/discovery/procedures/InstalledProtocolsProcedure.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/discovery/procedures/InstalledProtocolsProcedure.java index affb51e9750e..63e6defb6df4 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/discovery/procedures/InstalledProtocolsProcedure.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/discovery/procedures/InstalledProtocolsProcedure.java @@ -93,8 +93,8 @@ private Object[] buildRow( Pair conne { orientation, socketAddress.toString(), - protocolStack.applicationProtocol().identifier(), - (long) protocolStack.applicationProtocol().version(), + protocolStack.applicationProtocol().category(), + (long) protocolStack.applicationProtocol().implementation(), modifierString( protocolStack ) }; } @@ -104,7 +104,7 @@ private String modifierString( ProtocolStack protocolStack ) return protocolStack .modifierProtocols() .stream() - .map( Protocol.ModifierProtocol::friendlyName ) + .map( Protocol.ModifierProtocol::implementation ) .collect( Collectors.joining( ",", "[", "]") ); } } diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/Protocol.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/Protocol.java index ef0688e88fe6..bf89fe05dbbc 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/Protocol.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/Protocol.java @@ -23,22 +23,22 @@ import java.util.Optional; import java.util.stream.Stream; -public interface Protocol +public interface Protocol> { - String identifier(); + String category(); - int version(); + IMPL implementation(); - interface Identifier + interface Category { String canonicalName(); } - interface ApplicationProtocol extends Protocol + interface ApplicationProtocol extends Protocol { } - enum ApplicationProtocolIdentifier implements Identifier + enum ApplicationProtocolCategory implements Category { RAFT, CATCHUP; @@ -52,43 +52,39 @@ public String canonicalName() enum ApplicationProtocols implements ApplicationProtocol { - RAFT_1( ApplicationProtocolIdentifier.RAFT, 1 ), - CATCHUP_1( ApplicationProtocolIdentifier.CATCHUP, 1 ); + RAFT_1( ApplicationProtocolCategory.RAFT, 1 ), + CATCHUP_1( ApplicationProtocolCategory.CATCHUP, 1 ); - private final int version; - private final ApplicationProtocolIdentifier identifier; + private final Integer version; + private final ApplicationProtocolCategory identifier; - ApplicationProtocols( ApplicationProtocolIdentifier identifier, int version ) + ApplicationProtocols( ApplicationProtocolCategory identifier, int version ) { this.identifier = identifier; this.version = version; } @Override - public String identifier() + public String category() { return identifier.canonicalName(); } @Override - public int version() + public Integer implementation() { return version; } } - interface ModifierProtocol extends Protocol + interface ModifierProtocol extends Protocol { - /** - * Should be human readable when in a comma separated list - */ - String friendlyName(); } - enum ModifierProtocolIdentifier implements Identifier + enum ModifierProtocolCategory implements Category { COMPRESSION, - // Need a second Identifier for testing purposes. + // Need a second Category for testing purposes. GRATUITOUS_OBFUSCATION; @Override @@ -100,43 +96,36 @@ public String canonicalName() enum ModifierProtocols implements ModifierProtocol { - COMPRESSION_GZIP( ModifierProtocolIdentifier.COMPRESSION, 1, "Gzip" ), - COMPRESSION_SNAPPY( ModifierProtocolIdentifier.COMPRESSION, 2, "Snappy" ), - COMPRESSION_SNAPPY_VALIDATING( ModifierProtocolIdentifier.COMPRESSION, 3, "Snappy_validating" ), - COMPRESSION_LZ4( ModifierProtocolIdentifier.COMPRESSION, 4, "LZ4" ), - COMPRESSION_LZ4_HIGH_COMPRESSION( ModifierProtocolIdentifier.COMPRESSION, 5, "LZ4_high_compression" ), - COMPRESSION_LZ4_VALIDATING( ModifierProtocolIdentifier.COMPRESSION, 6, "LZ_validating" ), - COMPRESSION_LZ4_HIGH_COMPRESSION_VALIDATING( ModifierProtocolIdentifier.COMPRESSION, 7, "LZ4_high_compression_validating" ); - - private final int version; - private final ModifierProtocolIdentifier identifier; + COMPRESSION_GZIP( ModifierProtocolCategory.COMPRESSION, "Gzip" ), + COMPRESSION_SNAPPY( ModifierProtocolCategory.COMPRESSION, "Snappy" ), + COMPRESSION_SNAPPY_VALIDATING( ModifierProtocolCategory.COMPRESSION, "Snappy_validating" ), + COMPRESSION_LZ4( ModifierProtocolCategory.COMPRESSION, "LZ4" ), + COMPRESSION_LZ4_HIGH_COMPRESSION( ModifierProtocolCategory.COMPRESSION, "LZ4_high_compression" ), + COMPRESSION_LZ4_VALIDATING( ModifierProtocolCategory.COMPRESSION, "LZ_validating" ), + COMPRESSION_LZ4_HIGH_COMPRESSION_VALIDATING( ModifierProtocolCategory.COMPRESSION, "LZ4_high_compression_validating" ); + + // Should be human writable into a comma separated list private final String friendlyName; + private final ModifierProtocolCategory identifier; - ModifierProtocols( ModifierProtocolIdentifier identifier, int version, String friendlyName ) + ModifierProtocols( ModifierProtocolCategory identifier, String friendlyName ) { - this.version = version; this.identifier = identifier; this.friendlyName = friendlyName; } @Override - public int version() + public String implementation() { - return version; + return friendlyName; } @Override - public String identifier() + public String category() { return identifier.canonicalName(); } - @Override - public String friendlyName() - { - return friendlyName; - } - public static Optional fromFriendlyName( String friendlyName ) { return Stream.of( ModifierProtocols.values() ) diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/ProtocolInstallerRepository.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/ProtocolInstallerRepository.java index c6646e5661dc..1c6d86d51b7e 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/ProtocolInstallerRepository.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/ProtocolInstallerRepository.java @@ -89,10 +89,10 @@ private void ensureNotDuplicate( List> modifierProt boolean duplicateIdentifier = modifierProtocolInstallers .stream() .flatMap( modifier -> modifier.protocols().stream() ) - .anyMatch( protocol -> protocol.identifier().equals( modifierProtocol.identifier() ) ); + .anyMatch( protocol -> protocol.category().equals( modifierProtocol.category() ) ); if ( duplicateIdentifier ) { - throw new IllegalArgumentException( "Attempted to install multiple versions of " + modifierProtocol.identifier() ); + throw new IllegalArgumentException( "Attempted to install multiple versions of " + modifierProtocol.category() ); } } diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ApplicationProtocolRepository.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ApplicationProtocolRepository.java index a69fd877d15d..1dc44102e1b6 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ApplicationProtocolRepository.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ApplicationProtocolRepository.java @@ -21,17 +21,17 @@ import org.neo4j.causalclustering.protocol.Protocol; -public class ApplicationProtocolRepository extends ProtocolRepository +public class ApplicationProtocolRepository extends ProtocolRepository { - private final SupportedProtocols supportedProtocol; + private final ApplicationSupportedProtocols supportedProtocol; - public ApplicationProtocolRepository( Protocol.ApplicationProtocol[] protocols, SupportedProtocols supportedProtocol ) + public ApplicationProtocolRepository( Protocol.ApplicationProtocol[] protocols, ApplicationSupportedProtocols supportedProtocol ) { - super( protocols, ignored -> versionNumberComparator() ); + super( protocols, ignored -> versionNumberComparator(), ApplicationProtocolSelection::new ); this.supportedProtocol = supportedProtocol; } - public SupportedProtocols supportedProtocol() + public ApplicationSupportedProtocols supportedProtocol() { return supportedProtocol; } diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ApplicationProtocolRequest.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ApplicationProtocolRequest.java index ab3f401e2bfe..c0d6d4d1c2a2 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ApplicationProtocolRequest.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ApplicationProtocolRequest.java @@ -21,7 +21,7 @@ import java.util.Set; -public class ApplicationProtocolRequest extends BaseProtocolRequest implements ServerMessage +public class ApplicationProtocolRequest extends BaseProtocolRequest { ApplicationProtocolRequest( String protocolName, Set versions ) { diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ApplicationProtocolResponse.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ApplicationProtocolResponse.java index 10a0eae65b47..8f7289bde968 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ApplicationProtocolResponse.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ApplicationProtocolResponse.java @@ -21,7 +21,7 @@ import static org.neo4j.causalclustering.protocol.handshake.StatusCode.FAILURE; -public class ApplicationProtocolResponse extends BaseProtocolResponse implements ClientMessage +public class ApplicationProtocolResponse extends BaseProtocolResponse { public static final ApplicationProtocolResponse NO_PROTOCOL = new ApplicationProtocolResponse( FAILURE, "", 0 ); diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ApplicationProtocolSelection.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ApplicationProtocolSelection.java new file mode 100644 index 000000000000..6185628d5a40 --- /dev/null +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ApplicationProtocolSelection.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2002-2018 "Neo Technology," + * Network Engine for Objects in Lund AB [http://neotechnology.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 Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.neo4j.causalclustering.protocol.handshake; + +import java.util.Set; + +import org.neo4j.causalclustering.protocol.Protocol; + +public class ApplicationProtocolSelection extends ProtocolSelection +{ + public ApplicationProtocolSelection( String identifier, Set versions ) + { + super( identifier, versions ); + } +} diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ApplicationSupportedProtocols.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ApplicationSupportedProtocols.java new file mode 100644 index 000000000000..84aece8fc831 --- /dev/null +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ApplicationSupportedProtocols.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2002-2018 "Neo Technology," + * Network Engine for Objects in Lund AB [http://neotechnology.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 Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.neo4j.causalclustering.protocol.handshake; + +import java.util.List; + +import org.neo4j.causalclustering.protocol.Protocol; + +public class ApplicationSupportedProtocols extends SupportedProtocols +{ + public ApplicationSupportedProtocols( Protocol.Category category, List versions ) + { + super( category, versions ); + } +} diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/BaseProtocolRequest.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/BaseProtocolRequest.java index 3a90681f717e..cde88e7ac9a0 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/BaseProtocolRequest.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/BaseProtocolRequest.java @@ -22,12 +22,12 @@ import java.util.Objects; import java.util.Set; -public abstract class BaseProtocolRequest +public abstract class BaseProtocolRequest> implements ServerMessage { private final String protocolName; - private final Set versions; + private final Set versions; - BaseProtocolRequest( String protocolName, Set versions ) + BaseProtocolRequest( String protocolName, Set versions ) { this.protocolName = protocolName; this.versions = versions; @@ -38,7 +38,7 @@ public String protocolName() return protocolName; } - public Set versions() + public Set versions() { return versions; } @@ -63,4 +63,10 @@ public int hashCode() { return Objects.hash( protocolName, versions ); } + + @Override + public String toString() + { + return "BaseProtocolRequest{" + "protocolName='" + protocolName + '\'' + ", versions=" + versions + '}'; + } } diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/BaseProtocolResponse.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/BaseProtocolResponse.java index 2ce2572c15a2..fa02af65e48d 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/BaseProtocolResponse.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/BaseProtocolResponse.java @@ -21,13 +21,13 @@ import java.util.Objects; -public abstract class BaseProtocolResponse +public abstract class BaseProtocolResponse> implements ClientMessage { private final StatusCode statusCode; private final String protocolName; - private final int version; + private final IMPL version; - BaseProtocolResponse( StatusCode statusCode, String protocolName, int version ) + BaseProtocolResponse( StatusCode statusCode, String protocolName, IMPL version ) { this.statusCode = statusCode; this.protocolName = protocolName; @@ -46,7 +46,7 @@ public boolean equals( Object o ) return false; } BaseProtocolResponse that = (BaseProtocolResponse) o; - return version == that.version && Objects.equals( protocolName, that.protocolName ); + return Objects.equals( version, that.version ) && Objects.equals( protocolName, that.protocolName ); } @Override @@ -65,8 +65,14 @@ public String protocolName() return protocolName; } - public int version() + public IMPL version() { return version; } + + @Override + public String toString() + { + return "BaseProtocolResponse{" + "statusCode=" + statusCode + ", protocolName='" + protocolName + '\'' + ", version=" + version + '}'; + } } diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ClientMessageDecoder.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ClientMessageDecoder.java index 08413623e277..0884781c0587 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ClientMessageDecoder.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ClientMessageDecoder.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Optional; +import java.util.function.Function; import org.neo4j.causalclustering.messaging.marshalling.StringMarshal; @@ -48,14 +49,14 @@ protected void decode( ChannelHandlerContext ctx, ByteBuf in, List out ) } case 0: { - ApplicationProtocolResponse applicationProtocolResponse = decodeProtocolResponse( ApplicationProtocolResponse::new, in ); + ApplicationProtocolResponse applicationProtocolResponse = decodeProtocolResponse( ApplicationProtocolResponse::new, ByteBuf::readInt, in ); out.add( applicationProtocolResponse ); return; } case 1: { - ModifierProtocolResponse modifierProtocolResponse = decodeProtocolResponse( ModifierProtocolResponse::new, in ); + ModifierProtocolResponse modifierProtocolResponse = decodeProtocolResponse( ModifierProtocolResponse::new, StringMarshal::unmarshal, in ); out.add( modifierProtocolResponse ); return; @@ -80,12 +81,13 @@ protected void decode( ChannelHandlerContext ctx, ByteBuf in, List out ) } } - private T decodeProtocolResponse( TriFunction constructor, ByteBuf in ) + private ,T extends BaseProtocolResponse> T decodeProtocolResponse( TriFunction constructor, + Function reader, ByteBuf in ) throws ClientHandshakeException { int statusCodeValue = in.readInt(); String identifier = StringMarshal.unmarshal( in ); - int version = in.readInt(); + U version = reader.apply( in ); Optional statusCode = StatusCode.fromCodeValue( statusCodeValue ); diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ClientMessageEncoder.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ClientMessageEncoder.java index 033b11fec63c..88ba8a45356d 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ClientMessageEncoder.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ClientMessageEncoder.java @@ -23,6 +23,8 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; +import java.util.function.BiConsumer; + import org.neo4j.causalclustering.messaging.marshalling.StringMarshal; /** @@ -56,14 +58,14 @@ public void handle( InitialMagicMessage magicMessage ) public void handle( ApplicationProtocolRequest applicationProtocolRequest ) { out.writeInt( 1 ); - encodeProtocolRequest( applicationProtocolRequest ); + encodeProtocolRequest( applicationProtocolRequest, ByteBuf::writeInt ); } @Override public void handle( ModifierProtocolRequest modifierProtocolRequest ) { out.writeInt( 2 ); - encodeProtocolRequest( modifierProtocolRequest ); + encodeProtocolRequest( modifierProtocolRequest, StringMarshal::marshal ); } @Override @@ -76,16 +78,16 @@ public void handle( SwitchOverRequest switchOverRequest ) switchOverRequest.modifierProtocols().forEach( pair -> { StringMarshal.marshal( out, pair.first() ); - out.writeInt( pair.other() ); + StringMarshal.marshal( out, pair.other() ); } ); } - private void encodeProtocolRequest( BaseProtocolRequest applicationProtocolRequest ) + private > void encodeProtocolRequest( BaseProtocolRequest protocolRequest, BiConsumer writer ) { - StringMarshal.marshal( out, applicationProtocolRequest.protocolName() ); - out.writeInt( applicationProtocolRequest.versions().size() ); - applicationProtocolRequest.versions().forEach( out::writeInt ); + StringMarshal.marshal( out, protocolRequest.protocolName() ); + out.writeInt( protocolRequest.versions().size() ); + protocolRequest.versions().forEach( version -> writer.accept( out, version) ); } } } diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/HandshakeClient.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/HandshakeClient.java index e21ea438f648..2c3388c3b207 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/HandshakeClient.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/HandshakeClient.java @@ -38,9 +38,9 @@ public class HandshakeClient implements ClientMessageHandler { private Channel channel; private ApplicationProtocolRepository applicationProtocolRepository; - private SupportedProtocols supportedApplicationProtocol; - private ProtocolRepository modifierProtocolRepository; - private Collection> supportedModifierProtocols; + private ApplicationSupportedProtocols supportedApplicationProtocol; + private ModifierProtocolRepository modifierProtocolRepository; + private Collection supportedModifierProtocols; private ApplicationProtocol applicationProtocol; private List>> negotiatedModifierProtocols; private ProtocolStack protocolStack; @@ -67,17 +67,17 @@ public CompletableFuture initiate( Channel channel, ApplicationPr return future; } - private void sendProtocolRequests( Channel channel, SupportedProtocols applicationProtocols, - Collection> supportedModifierProtocols ) + private void sendProtocolRequests( Channel channel, ApplicationSupportedProtocols applicationProtocols, + Collection supportedModifierProtocols ) { supportedModifierProtocols.forEach( modifierProtocol -> { - ProtocolSelection protocolSelection = + ProtocolSelection protocolSelection = modifierProtocolRepository.getAll( modifierProtocol.identifier(), modifierProtocol.versions() ); channel.write( new ModifierProtocolRequest( protocolSelection.identifier(), protocolSelection.versions() ) ); } ); - ProtocolSelection applicationProtocolSelection = + ProtocolSelection applicationProtocolSelection = applicationProtocolRepository.getAll( applicationProtocols.identifier(), applicationProtocols.versions() ); channel.writeAndFlush( new ApplicationProtocolRequest( applicationProtocolSelection.identifier(), applicationProtocolSelection.versions() ) ); } @@ -118,7 +118,7 @@ public void handle( ApplicationProtocolResponse applicationProtocolResponse ) if ( !protocol.isPresent() ) { - ProtocolSelection knownApplicationProtocolVersions = + ProtocolSelection knownApplicationProtocolVersions = applicationProtocolRepository.getAll( supportedApplicationProtocol.identifier(), supportedApplicationProtocol.versions() ); decline( String.format( "Mismatch of application protocols between client and server: Server protocol %s version %d: Client protocol %s versions %s", @@ -162,13 +162,13 @@ private void sendSwitchOverRequestIfReady() .collect( Collectors.toList() ); protocolStack = new ProtocolStack( applicationProtocol, agreedModifierProtocols ); - List> switchOverModifierProtocols = + List> switchOverModifierProtocols = agreedModifierProtocols .stream() - .map( protocol -> Pair.of( protocol.identifier(), protocol.version() ) ) + .map( protocol -> Pair.of( protocol.category(), protocol.implementation() ) ) .collect( Collectors.toList() ); - channel.writeAndFlush( new SwitchOverRequest( applicationProtocol.identifier(), applicationProtocol.version(), switchOverModifierProtocols ) ); + channel.writeAndFlush( new SwitchOverRequest( applicationProtocol.category(), applicationProtocol.implementation(), switchOverModifierProtocols ) ); } } diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/HandshakeServer.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/HandshakeServer.java index c3d8d6ed90af..57e2ea7e86a0 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/HandshakeServer.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/HandshakeServer.java @@ -38,7 +38,7 @@ public class HandshakeServer implements ServerMessageHandler private final Channel channel; private final ApplicationProtocolRepository applicationProtocolRepository; private final ModifierProtocolRepository modifierProtocolRepository; - private final SupportedProtocols supportedApplicationProtocol; + private final SupportedProtocols supportedApplicationProtocol; private final ProtocolStack.Builder protocolStackBuilder = ProtocolStack.builder(); private final CompletableFuture protocolStackFuture = new CompletableFuture<>(); private boolean magicReceived; @@ -103,7 +103,7 @@ public void handle( ApplicationProtocolRequest request ) { ApplicationProtocol selectedProtocol = selected.get(); protocolStackBuilder.application( selectedProtocol ); - response = new ApplicationProtocolResponse( SUCCESS, selectedProtocol.identifier(), selectedProtocol.version() ); + response = new ApplicationProtocolResponse( SUCCESS, selectedProtocol.category(), selectedProtocol.implementation() ); channel.writeAndFlush( response ); } else @@ -128,7 +128,7 @@ public void handle( ModifierProtocolRequest modifierProtocolRequest ) { ModifierProtocol modifierProtocol = selected.get(); protocolStackBuilder.modifier( modifierProtocol ); - response = new ModifierProtocolResponse( SUCCESS, modifierProtocol.identifier(), modifierProtocol.version() ); + response = new ModifierProtocolResponse( SUCCESS, modifierProtocol.category(), modifierProtocol.implementation() ); } else { @@ -167,7 +167,7 @@ else if ( !switchOverProtocol.get().equals( protocolStack.applicationProtocol() channel.writeAndFlush( SwitchOverResponse.FAILURE ); decline( String.format( "Switch over mismatch: requested %s version %s but negotiated %s version %s", switchOverRequest.protocolName(), switchOverRequest.version(), - protocolStack.applicationProtocol().identifier(), protocolStack.applicationProtocol().version() ) ); + protocolStack.applicationProtocol().category(), protocolStack.applicationProtocol().implementation() ) ); } else if ( !switchOverModifiers.equals( protocolStack.modifierProtocols() ) ) { @@ -184,7 +184,7 @@ else if ( !switchOverModifiers.equals( protocolStack.modifierProtocols() ) ) } } - private Set supportedVersionsFor( ModifierProtocolRequest request ) + private Set supportedVersionsFor( ModifierProtocolRequest request ) { return modifierProtocolRepository.supportedProtocolFor( request.protocolName() ) .map( supported -> supported.mutuallySupportedVersionsFor( request.versions() ) ) diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/InitialMagicMessage.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/InitialMagicMessage.java index 4aca8f181e74..62bcabfbabd7 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/InitialMagicMessage.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/InitialMagicMessage.java @@ -84,4 +84,10 @@ public String magic() { return magic; } + + @Override + public String toString() + { + return "InitialMagicMessage{" + "magic='" + magic + '\'' + '}'; + } } diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ModifierProtocolRepository.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ModifierProtocolRepository.java index e90520f1ed64..23968660b09d 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ModifierProtocolRepository.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ModifierProtocolRepository.java @@ -30,32 +30,32 @@ import org.neo4j.causalclustering.protocol.Protocol; -public class ModifierProtocolRepository extends ProtocolRepository +public class ModifierProtocolRepository extends ProtocolRepository { - private final Collection> supportedProtocols; - private final Map> supportedProtocolsLookup; + private final Collection supportedProtocols; + private final Map supportedProtocolsLookup; - public ModifierProtocolRepository( Protocol.ModifierProtocol[] protocols, Collection> supportedProtocols ) + public ModifierProtocolRepository( Protocol.ModifierProtocol[] protocols, Collection supportedProtocols ) { - super( protocols, getModifierProtocolComparator( supportedProtocols ) ); + super( protocols, getModifierProtocolComparator( supportedProtocols ), ModifierProtocolSelection::new ); this.supportedProtocols = Collections.unmodifiableCollection( supportedProtocols ); this.supportedProtocolsLookup = supportedProtocols.stream() .collect( Collectors.toMap( supp -> supp.identifier().canonicalName(), Function.identity() ) ); } static Function> getModifierProtocolComparator( - Collection> supportedProtocols ) + Collection supportedProtocols ) { return getModifierProtocolComparator( versionMap( supportedProtocols ) ); } - private static Map> versionMap( Collection> supportedProtocols ) + private static Map> versionMap( Collection supportedProtocols ) { return supportedProtocols.stream() .collect( Collectors.toMap( supportedProtocol -> supportedProtocol.identifier().canonicalName(), SupportedProtocols::versions ) ); } - private static Function> getModifierProtocolComparator( Map> versionMap ) + private static Function> getModifierProtocolComparator( Map> versionMap ) { return protocolName -> { Comparator positionalComparator = Comparator.comparing( modifierProtocol -> @@ -76,18 +76,18 @@ private static Comparator fallBackToVersionNumbers( C /** * @return Greatest is head of versions, least is not included in versions */ - private static Integer byPosition( Protocol.ModifierProtocol modifierProtocol, List versions ) + private static Integer byPosition( Protocol.ModifierProtocol modifierProtocol, List versions ) { - int index = versions.indexOf( modifierProtocol.version() ); + int index = versions.indexOf( modifierProtocol.implementation() ); return index == -1 ? Integer.MIN_VALUE : -index; } - public Optional> supportedProtocolFor( String protocolName ) + public Optional> supportedProtocolFor( String protocolName ) { return Optional.ofNullable( supportedProtocolsLookup.get( protocolName ) ); } - public Collection> supportedProtocols() + public Collection supportedProtocols() { return supportedProtocols; } diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ModifierProtocolRequest.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ModifierProtocolRequest.java index 2382087ffefd..df8272c2b5a4 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ModifierProtocolRequest.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ModifierProtocolRequest.java @@ -21,9 +21,9 @@ import java.util.Set; -public class ModifierProtocolRequest extends BaseProtocolRequest implements ServerMessage +public class ModifierProtocolRequest extends BaseProtocolRequest { - ModifierProtocolRequest( String protocolName, Set versions ) + ModifierProtocolRequest( String protocolName, Set versions ) { super( protocolName, versions ); } diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ModifierProtocolResponse.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ModifierProtocolResponse.java index 3ece11b846a4..fbded5a7363c 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ModifierProtocolResponse.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ModifierProtocolResponse.java @@ -19,16 +19,16 @@ */ package org.neo4j.causalclustering.protocol.handshake; -public class ModifierProtocolResponse extends BaseProtocolResponse implements ClientMessage +public class ModifierProtocolResponse extends BaseProtocolResponse { - ModifierProtocolResponse( StatusCode statusCode, String protocolName, int version ) + ModifierProtocolResponse( StatusCode statusCode, String protocolName, String implementation ) { - super( statusCode, protocolName, version ); + super( statusCode, protocolName, implementation ); } static ModifierProtocolResponse failure( String protocolName ) { - return new ModifierProtocolResponse( StatusCode.FAILURE, protocolName, 0 ); + return new ModifierProtocolResponse( StatusCode.FAILURE, protocolName, "" ); } @Override diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ModifierProtocolSelection.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ModifierProtocolSelection.java new file mode 100644 index 000000000000..99981dd8a391 --- /dev/null +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ModifierProtocolSelection.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2002-2018 "Neo Technology," + * Network Engine for Objects in Lund AB [http://neotechnology.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 Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.neo4j.causalclustering.protocol.handshake; + +import java.util.Set; + +import org.neo4j.causalclustering.protocol.Protocol; + +public class ModifierProtocolSelection extends ProtocolSelection +{ + public ModifierProtocolSelection( String identifier, Set versions ) + { + super( identifier, versions ); + } +} diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ModifierSupportedProtocols.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ModifierSupportedProtocols.java new file mode 100644 index 000000000000..16ac14405688 --- /dev/null +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ModifierSupportedProtocols.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2002-2018 "Neo Technology," + * Network Engine for Objects in Lund AB [http://neotechnology.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 Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.neo4j.causalclustering.protocol.handshake; + +import java.util.List; + +import org.neo4j.causalclustering.protocol.Protocol; + +public class ModifierSupportedProtocols extends SupportedProtocols +{ + public ModifierSupportedProtocols( Protocol.Category category, List versions ) + { + super( category, versions ); + } +} diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ProtocolRepository.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ProtocolRepository.java index 399cbe5a5bc8..e8f22b96ed74 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ProtocolRepository.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ProtocolRepository.java @@ -26,6 +26,7 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.function.BiFunction; import java.util.function.Function; import java.util.stream.Collectors; @@ -33,17 +34,20 @@ import org.neo4j.helpers.collection.Pair; import org.neo4j.stream.Streams; -public abstract class ProtocolRepository +public abstract class ProtocolRepository,T extends Protocol> { - private final Map,T> protocolMap; + private final Map,T> protocolMap; + private final BiFunction,ProtocolSelection> protocolSelectionFactory; private Function> comparator; - public ProtocolRepository( T[] protocols, Function> comparators ) + public ProtocolRepository( T[] protocols, Function> comparators, + BiFunction,ProtocolSelection> protocolSelectionFactory ) { - Map,T> map = new HashMap<>(); + this.protocolSelectionFactory = protocolSelectionFactory; + Map,T> map = new HashMap<>(); for ( T protocol : protocols ) { - Protocol previous = map.put( Pair.of( protocol.identifier(), protocol.version() ), protocol ); + Protocol previous = map.put( Pair.of( protocol.category(), protocol.implementation() ), protocol ); if ( previous != null ) { throw new IllegalArgumentException( @@ -54,12 +58,12 @@ public ProtocolRepository( T[] protocols, Function> compara this.comparator = comparators; } - Optional select( String protocolName, Integer version ) + Optional select( String protocolName, U version ) { return Optional.ofNullable( protocolMap.get( Pair.of( protocolName, version ) ) ); } - Optional select( String protocolName, Set versions ) + Optional select( String protocolName, Set versions ) { return versions .stream() @@ -68,13 +72,13 @@ Optional select( String protocolName, Set versions ) .max( comparator.apply( protocolName ) ); } - public ProtocolSelection getAll( Protocol.Identifier identifier, Collection versions ) + public ProtocolSelection getAll( Protocol.Category category, Collection versions ) { - Set selectedVersions = protocolMap + Set selectedVersions = protocolMap .entrySet() .stream() .map( Map.Entry::getKey ) - .filter( pair -> pair.first().equals( identifier.canonicalName() ) ) + .filter( pair -> pair.first().equals( category.canonicalName() ) ) .map( Pair::other ) .filter( version -> versions.isEmpty() || versions.contains( version ) ) .collect( Collectors.toSet() ); @@ -82,18 +86,17 @@ public ProtocolSelection getAll( Protocol.Identifier identifier, Collectio if ( selectedVersions.isEmpty() ) { throw new IllegalArgumentException( String.format( - "Attempted to select protocols for %s versions %s but no match in known protocols %s", - identifier, versions, protocolMap + "Attempted to select protocols for %s versions %s but no match in known protocols %s", category, versions, protocolMap ) ); } else { - return new ProtocolSelection<>( identifier.canonicalName(), selectedVersions ); + return protocolSelectionFactory.apply( category.canonicalName(), selectedVersions ); } } - static Comparator versionNumberComparator() + static , T extends Protocol> Comparator versionNumberComparator() { - return Comparator.comparingInt( Protocol::version ); + return Comparator.comparing( Protocol::implementation ); } } diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ProtocolSelection.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ProtocolSelection.java index cedbbed48dc4..6c8b2d813a50 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ProtocolSelection.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ProtocolSelection.java @@ -24,12 +24,12 @@ import org.neo4j.causalclustering.protocol.Protocol; -public class ProtocolSelection +public abstract class ProtocolSelection, T extends Protocol> { private final String identifier; - private final Set versions; + private final Set versions; - public ProtocolSelection( String identifier, Set versions ) + public ProtocolSelection( String identifier, Set versions ) { this.identifier = identifier; this.versions = Collections.unmodifiableSet( versions ); @@ -40,7 +40,7 @@ public String identifier() return identifier; } - public Set versions() + public Set versions() { return versions; } diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ServerMessageDecoder.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ServerMessageDecoder.java index 3871d5036721..b4535bdafe4c 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ServerMessageDecoder.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ServerMessageDecoder.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Set; import java.util.function.BiFunction; +import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -52,12 +53,12 @@ protected void decode( ChannelHandlerContext ctx, ByteBuf in, List out ) } case 1: { - ApplicationProtocolRequest applicationProtocolRequest = decodeProtocolRequest( ApplicationProtocolRequest::new, in ); + ApplicationProtocolRequest applicationProtocolRequest = decodeProtocolRequest( ApplicationProtocolRequest::new, in, ByteBuf::readInt ); out.add( applicationProtocolRequest ); return; } case 2: - ModifierProtocolRequest modifierProtocolRequest = decodeProtocolRequest( ModifierProtocolRequest::new, in ); + ModifierProtocolRequest modifierProtocolRequest = decodeProtocolRequest( ModifierProtocolRequest::new, in, StringMarshal::unmarshal ); out.add( modifierProtocolRequest ); return; case 3: @@ -65,7 +66,7 @@ protected void decode( ChannelHandlerContext ctx, ByteBuf in, List out ) String protocolName = StringMarshal.unmarshal( in ); int version = in.readInt(); int numberOfModifierProtocols = in.readInt(); - List> modifierProtocols = Stream.generate( () -> Pair.of( StringMarshal.unmarshal( in ), in.readInt() ) ) + List> modifierProtocols = Stream.generate( () -> Pair.of( StringMarshal.unmarshal( in ), StringMarshal.unmarshal( in ) ) ) .limit( numberOfModifierProtocols ) .collect( Collectors.toList() ); out.add( new SwitchOverRequest( protocolName, version, modifierProtocols ) ); @@ -77,12 +78,13 @@ protected void decode( ChannelHandlerContext ctx, ByteBuf in, List out ) } } - private T decodeProtocolRequest( BiFunction, T> constructor, ByteBuf in ) + private , T extends BaseProtocolRequest> T decodeProtocolRequest( BiFunction,T> constructor, ByteBuf in, + Function versionDecoder ) { String protocolName = StringMarshal.unmarshal( in ); int versionArrayLength = in.readInt(); - Set versions = Stream.generate( in::readInt ).limit( versionArrayLength ).collect( Collectors.toSet() ); + Set versions = Stream.generate( () -> versionDecoder.apply( in ) ).limit( versionArrayLength ).collect( Collectors.toSet() ); return constructor.apply( protocolName, versions ); } diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ServerMessageEncoder.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ServerMessageEncoder.java index 5b023dc83079..22a71fd17d75 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ServerMessageEncoder.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/ServerMessageEncoder.java @@ -23,6 +23,8 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; +import java.util.function.BiConsumer; + import org.neo4j.causalclustering.messaging.marshalling.StringMarshal; /** @@ -56,14 +58,14 @@ public void handle( InitialMagicMessage magicMessage ) public void handle( ApplicationProtocolResponse applicationProtocolResponse ) { out.writeInt( 0 ); - encodeProtocolResponse( applicationProtocolResponse ); + encodeProtocolResponse( applicationProtocolResponse, ByteBuf::writeInt ); } @Override public void handle( ModifierProtocolResponse modifierProtocolResponse ) { out.writeInt( 1 ); - encodeProtocolResponse( modifierProtocolResponse ); + encodeProtocolResponse( modifierProtocolResponse, StringMarshal::marshal ); } @Override @@ -73,11 +75,11 @@ public void handle( SwitchOverResponse switchOverResponse ) out.writeInt( switchOverResponse.status().codeValue() ); } - private void encodeProtocolResponse( BaseProtocolResponse protocolResponse ) + private > void encodeProtocolResponse( BaseProtocolResponse protocolResponse, BiConsumer writer ) { out.writeInt( protocolResponse.statusCode().codeValue() ); StringMarshal.marshal( out, protocolResponse.protocolName() ); - out.writeInt( protocolResponse.version() ); + writer.accept( out, protocolResponse.version() ); } } } diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/SupportedProtocols.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/SupportedProtocols.java index 01412a9459ae..64883bb38f60 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/SupportedProtocols.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/SupportedProtocols.java @@ -26,21 +26,21 @@ import org.neo4j.causalclustering.protocol.Protocol; -public class SupportedProtocols +public abstract class SupportedProtocols,T extends Protocol> { - private final Protocol.Identifier identifier; - private final List versions; + private final Protocol.Category category; + private final List versions; /** * @param versions Empty means support everything */ - public SupportedProtocols( Protocol.Identifier identifier, List versions ) + public SupportedProtocols( Protocol.Category category, List versions ) { - this.identifier = identifier; + this.category = category; this.versions = Collections.unmodifiableList( versions ); } - public Set mutuallySupportedVersionsFor( Set requestedVersions ) + public Set mutuallySupportedVersionsFor( Set requestedVersions ) { if ( versions().isEmpty() ) { @@ -52,15 +52,15 @@ public Set mutuallySupportedVersionsFor( Set requestedVersions } } - public Protocol.Identifier identifier() + public Protocol.Category identifier() { - return identifier; + return category; } /** * @return If an empty list then all versions of a matching protocol will be supported */ - public List versions() + public List versions() { return versions; } diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/SwitchOverRequest.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/SwitchOverRequest.java index b8d10c0fd74e..b7957b4b65ec 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/SwitchOverRequest.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/SwitchOverRequest.java @@ -27,10 +27,10 @@ public class SwitchOverRequest implements ServerMessage { private final String protocolName; - private final int version; - private final List> modifierProtocols; + private final Integer version; + private final List> modifierProtocols; - public SwitchOverRequest( String applicationProtocolName, int applicationProtocolVersion, List> modifierProtocols ) + public SwitchOverRequest( String applicationProtocolName, int applicationProtocolVersion, List> modifierProtocols ) { this.protocolName = applicationProtocolName; this.version = applicationProtocolVersion; @@ -48,7 +48,7 @@ public String protocolName() return protocolName; } - public List> modifierProtocols() + public List> modifierProtocols() { return modifierProtocols; } @@ -70,7 +70,9 @@ public boolean equals( Object o ) return false; } SwitchOverRequest that = (SwitchOverRequest) o; - return version == that.version && Objects.equals( protocolName, that.protocolName ) && Objects.equals( modifierProtocols, that.modifierProtocols ); + return Objects.equals( version, that.version ) && + Objects.equals( protocolName, that.protocolName ) && + Objects.equals( modifierProtocols, that.modifierProtocols ); } @Override diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/SwitchOverResponse.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/SwitchOverResponse.java index b942ebcea1dd..13a85d64aa58 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/SwitchOverResponse.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/protocol/handshake/SwitchOverResponse.java @@ -62,4 +62,10 @@ public int hashCode() { return Objects.hash( status ); } + + @Override + public String toString() + { + return "SwitchOverResponse{" + "status=" + status + '}'; + } } diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/core/SupportedProtocolCreatorTest.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/core/SupportedProtocolCreatorTest.java index 0104d8b3a05d..0642d5542b07 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/core/SupportedProtocolCreatorTest.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/core/SupportedProtocolCreatorTest.java @@ -26,6 +26,8 @@ import java.util.stream.Stream; import org.neo4j.causalclustering.protocol.Protocol; +import org.neo4j.causalclustering.protocol.handshake.ApplicationSupportedProtocols; +import org.neo4j.causalclustering.protocol.handshake.ModifierSupportedProtocols; import org.neo4j.causalclustering.protocol.handshake.SupportedProtocols; import org.neo4j.kernel.configuration.Config; @@ -43,10 +45,10 @@ public void shouldReturnRAftProtocol() throws Throwable Config config = Config.defaults(); // when - SupportedProtocols supportedRaftProtocol = new SupportedProtocolCreator( config ).createSupportedRaftProtocol(); + ApplicationSupportedProtocols supportedRaftProtocol = new SupportedProtocolCreator( config ).createSupportedRaftProtocol(); // then - assertThat( supportedRaftProtocol.identifier(), equalTo( Protocol.ApplicationProtocolIdentifier.RAFT ) ); + assertThat( supportedRaftProtocol.identifier(), equalTo( Protocol.ApplicationProtocolCategory.RAFT ) ); } @Test @@ -56,7 +58,7 @@ public void shouldReturnEmptyVersionSupportedRaftProtocolIfNoVersionsConfigured( Config config = Config.defaults(); // when - SupportedProtocols supportedRaftProtocol = new SupportedProtocolCreator( config ).createSupportedRaftProtocol(); + ApplicationSupportedProtocols supportedRaftProtocol = new SupportedProtocolCreator( config ).createSupportedRaftProtocol(); // then assertThat( supportedRaftProtocol.versions(), empty() ); @@ -69,7 +71,7 @@ public void shouldReturnConfiguredRaftProtocolVersions() throws Throwable Config config = Config.defaults( CausalClusteringSettings.raft_versions, "2,3,1" ); // when - SupportedProtocols supportedRaftProtocol = new SupportedProtocolCreator( config ).createSupportedRaftProtocol(); + ApplicationSupportedProtocols supportedRaftProtocol = new SupportedProtocolCreator( config ).createSupportedRaftProtocol(); // then assertThat( supportedRaftProtocol.versions(), contains( 2,3,1 ) ); @@ -82,7 +84,7 @@ public void shouldNotReturnModifiersIfNoVersionsSpecified() throws Throwable Config config = Config.defaults(); // when - List> supportedModifierProtocols = + List supportedModifierProtocols = new SupportedProtocolCreator( config ).createSupportedModifierProtocols(); // then @@ -96,12 +98,12 @@ public void shouldReturnCompressionIfVersionsSpecified() throws Throwable Config config = Config.defaults( CausalClusteringSettings.compression_versions, "snappy" ); // when - List> supportedModifierProtocols = + List supportedModifierProtocols = new SupportedProtocolCreator( config ).createSupportedModifierProtocols(); // then - Stream> identifiers = supportedModifierProtocols.stream().map( SupportedProtocols::identifier ); - assertThat( identifiers, StreamMatchers.contains( Protocol.ModifierProtocolIdentifier.COMPRESSION ) ); + Stream> identifiers = supportedModifierProtocols.stream().map( SupportedProtocols::identifier ); + assertThat( identifiers, StreamMatchers.contains( Protocol.ModifierProtocolCategory.COMPRESSION ) ); } @Test @@ -111,11 +113,11 @@ public void shouldReturnCompressionVersionsSpecified() throws Throwable Config config = Config.defaults( CausalClusteringSettings.compression_versions, "snappy" ); // when - List> supportedModifierProtocols = + List supportedModifierProtocols = new SupportedProtocolCreator( config ).createSupportedModifierProtocols(); // then - List versions = supportedModifierProtocols.get( 0 ).versions(); - assertThat( versions, contains( Protocol.ModifierProtocols.COMPRESSION_SNAPPY.version() ) ); + List versions = supportedModifierProtocols.get( 0 ).versions(); + assertThat( versions, contains( Protocol.ModifierProtocols.COMPRESSION_SNAPPY.implementation() ) ); } } diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/messaging/SenderServiceIT.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/messaging/SenderServiceIT.java index fbf6dcdf5952..1a12686d92ea 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/messaging/SenderServiceIT.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/messaging/SenderServiceIT.java @@ -45,10 +45,11 @@ import org.neo4j.causalclustering.protocol.ProtocolInstaller; import org.neo4j.causalclustering.protocol.ProtocolInstallerRepository; import org.neo4j.causalclustering.protocol.handshake.ApplicationProtocolRepository; +import org.neo4j.causalclustering.protocol.handshake.ApplicationSupportedProtocols; import org.neo4j.causalclustering.protocol.handshake.HandshakeClientInitializer; import org.neo4j.causalclustering.protocol.handshake.HandshakeServerInitializer; import org.neo4j.causalclustering.protocol.handshake.ModifierProtocolRepository; -import org.neo4j.causalclustering.protocol.handshake.SupportedProtocols; +import org.neo4j.causalclustering.protocol.handshake.ModifierSupportedProtocols; import org.neo4j.helpers.AdvertisedSocketAddress; import org.neo4j.helpers.HostnamePort; import org.neo4j.kernel.configuration.Config; @@ -69,9 +70,9 @@ public class SenderServiceIT { private final LogProvider logProvider = NullLogProvider.getInstance(); - private final SupportedProtocols supportedApplicationProtocol = - new SupportedProtocols<>( Protocol.ApplicationProtocolIdentifier.RAFT, emptyList() ); - private final Collection> supportedModifierProtocols = emptyList(); + private final ApplicationSupportedProtocols supportedApplicationProtocol = + new ApplicationSupportedProtocols( Protocol.ApplicationProtocolCategory.RAFT, emptyList() ); + private final Collection supportedModifierProtocols = emptyList(); private final ApplicationProtocolRepository applicationProtocolRepository = new ApplicationProtocolRepository( ApplicationProtocols.values(), supportedApplicationProtocol ); diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ApplicationProtocolRepositoryTest.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ApplicationProtocolRepositoryTest.java index 41032e4ce617..98c319233356 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ApplicationProtocolRepositoryTest.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ApplicationProtocolRepositoryTest.java @@ -36,13 +36,13 @@ import static java.util.Collections.emptyList; import static java.util.Collections.emptySet; import static org.junit.Assert.assertThat; -import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolIdentifier.RAFT; +import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolCategory.RAFT; import static org.neo4j.helpers.collection.Iterators.asSet; public class ApplicationProtocolRepositoryTest { private ApplicationProtocolRepository applicationProtocolRepository = new ApplicationProtocolRepository( - TestApplicationProtocols.values(), new SupportedProtocols<>( RAFT, TestApplicationProtocols.listVersionsOf( RAFT ) ) ); + TestApplicationProtocols.values(), new ApplicationSupportedProtocols( RAFT, TestApplicationProtocols.listVersionsOf( RAFT ) ) ); @Test public void shouldReturnEmptyIfUnknownVersion() @@ -113,7 +113,7 @@ public void shouldReturnApplicationProtocolOfHighestVersionNumberRequestedAndSup public void shouldIncludeAllProtocolsInSelectionIfEmptyVersionsProvided() throws Throwable { // when - ProtocolSelection protocolSelection = + ProtocolSelection protocolSelection = applicationProtocolRepository.getAll( RAFT, emptyList() ); // then @@ -128,7 +128,7 @@ public void shouldIncludeProtocolsInSelectionWithVersionsLimitedByThoseConfigure Integer[] expectedRaftVersions = { 1 }; // when - ProtocolSelection protocolSelection = + ProtocolSelection protocolSelection = applicationProtocolRepository.getAll( RAFT, asList( expectedRaftVersions ) ); // then @@ -144,7 +144,7 @@ public void shouldIncludeProtocolsInSelectionWithVersionsLimitedByThoseExisting( Stream.concat( Stream.of( expectedRaftVersions ), Stream.of( Integer.MAX_VALUE ) ).collect( Collectors.toList() ); // when - ProtocolSelection protocolSelection = + ProtocolSelection protocolSelection = applicationProtocolRepository.getAll( RAFT, configuredRaftVersions ); // then @@ -170,13 +170,13 @@ public void shouldNotInstantiateIfDuplicateProtocolsSupplied() Protocol.ApplicationProtocol protocol = new Protocol.ApplicationProtocol() { @Override - public String identifier() + public String category() { return "foo"; } @Override - public int version() + public Integer implementation() { return 1; } @@ -184,7 +184,7 @@ public int version() Protocol.ApplicationProtocol[] protocols = {protocol, protocol}; // when - new ApplicationProtocolRepository( protocols, new SupportedProtocols<>( RAFT, TestApplicationProtocols.listVersionsOf( RAFT ) ) ); + new ApplicationProtocolRepository( protocols, new ApplicationSupportedProtocols( RAFT, TestApplicationProtocols.listVersionsOf( RAFT ) ) ); // then throw } diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ClientMessageEncodingTest.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ClientMessageEncodingTest.java index c3750274ee1a..3c64087420e7 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ClientMessageEncodingTest.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ClientMessageEncodingTest.java @@ -57,7 +57,7 @@ public static Collection data() { return Arrays.asList( new ApplicationProtocolResponse( StatusCode.FAILURE, "protocol", 13 ), - new ModifierProtocolResponse( StatusCode.SUCCESS, "modifier", 7 ), + new ModifierProtocolResponse( StatusCode.SUCCESS, "modifier", "7" ), new SwitchOverResponse( StatusCode.FAILURE ) ); } diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/HandshakeClientEnsureMagicTest.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/HandshakeClientEnsureMagicTest.java index 0ab2b7ebf2f1..65c950b9764b 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/HandshakeClientEnsureMagicTest.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/HandshakeClientEnsureMagicTest.java @@ -29,7 +29,6 @@ import java.util.concurrent.CompletionException; import org.neo4j.causalclustering.messaging.Channel; -import org.neo4j.causalclustering.protocol.Protocol; import org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestApplicationProtocols; import org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestModifierProtocols; @@ -39,7 +38,9 @@ import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.mock; -import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolIdentifier.RAFT; +import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolCategory.RAFT; +import static org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestApplicationProtocols.RAFT_1; +import static org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestModifierProtocols.LZ4; @RunWith( Parameterized.class ) public class HandshakeClientEnsureMagicTest @@ -50,8 +51,8 @@ public class HandshakeClientEnsureMagicTest public static Collection data() { return asList( - new ApplicationProtocolResponse( StatusCode.SUCCESS, "protocol", 2 ), - new ModifierProtocolResponse( StatusCode.SUCCESS, "modifier", 4 ), + new ApplicationProtocolResponse( StatusCode.SUCCESS, "protocol", RAFT_1.implementation() ), + new ModifierProtocolResponse( StatusCode.SUCCESS, "modifier", LZ4.implementation() ), new SwitchOverResponse( StatusCode.SUCCESS ) ); } @@ -61,8 +62,8 @@ public static Collection data() private Channel channel = mock( Channel.class ); - private SupportedProtocols supportedApplicationProtocol = - new SupportedProtocols<>( RAFT, TestApplicationProtocols.listVersionsOf( RAFT ) ); + private ApplicationSupportedProtocols supportedApplicationProtocol = + new ApplicationSupportedProtocols( RAFT, TestApplicationProtocols.listVersionsOf( RAFT ) ); private ApplicationProtocolRepository applicationProtocolRepository = new ApplicationProtocolRepository( TestApplicationProtocols.values(), supportedApplicationProtocol ); private ModifierProtocolRepository modifierProtocolRepository = diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/HandshakeClientTest.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/HandshakeClientTest.java index 359d11a10e21..d1c6261dceaf 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/HandshakeClientTest.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/HandshakeClientTest.java @@ -30,6 +30,7 @@ import java.util.stream.Stream; import org.neo4j.causalclustering.messaging.Channel; +import org.neo4j.causalclustering.protocol.Protocol; import org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestApplicationProtocols; import org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestModifierProtocols; import org.neo4j.helpers.collection.Pair; @@ -47,9 +48,10 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocol; -import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolIdentifier; -import static org.neo4j.causalclustering.protocol.Protocol.ModifierProtocol; -import static org.neo4j.causalclustering.protocol.Protocol.ModifierProtocolIdentifier; +import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolCategory; +import static org.neo4j.causalclustering.protocol.Protocol.ModifierProtocolCategory; +import static org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestModifierProtocols.ROT13; +import static org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestModifierProtocols.SNAPPY; /** * @see HandshakeClientEnsureMagicTest @@ -58,17 +60,17 @@ public class HandshakeClientTest { private HandshakeClient client = new HandshakeClient(); private Channel channel = mock( Channel.class ); - private ApplicationProtocolIdentifier applicationProtocolIdentifier = ApplicationProtocolIdentifier.RAFT; - private SupportedProtocols supportedApplicationProtocol = - new SupportedProtocols<>( applicationProtocolIdentifier, emptyList() ); - private Collection> supportedModifierProtocols = Stream.of( ModifierProtocolIdentifier.values() ) - .map( id -> new SupportedProtocols<>( id, emptyList() ) ) + private ApplicationProtocolCategory applicationProtocolIdentifier = ApplicationProtocolCategory.RAFT; + private ApplicationSupportedProtocols supportedApplicationProtocol = + new ApplicationSupportedProtocols( applicationProtocolIdentifier, emptyList() ); + private Collection supportedModifierProtocols = Stream.of( Protocol.ModifierProtocolCategory.values() ) + .map( id -> new ModifierSupportedProtocols( id, emptyList() ) ) .collect( Collectors.toList() ); private ApplicationProtocolRepository applicationProtocolRepository = new ApplicationProtocolRepository( TestApplicationProtocols.values(), supportedApplicationProtocol ); private ModifierProtocolRepository modifierProtocolRepository = new ModifierProtocolRepository( TestModifierProtocols.values(), supportedModifierProtocols ); - private int raftVersion = TestApplicationProtocols.latest( ApplicationProtocolIdentifier.RAFT ).version(); + private int raftVersion = TestApplicationProtocols.latest( ApplicationProtocolCategory.RAFT ).implementation(); private ApplicationProtocol expectedApplicationProtocol = applicationProtocolRepository.select( applicationProtocolIdentifier.canonicalName(), raftVersion ).get(); @@ -100,9 +102,9 @@ public void shouldSendModifierProtocolRequestsOnInitiation() client.initiate( channel, applicationProtocolRepository, modifierProtocolRepository ); // then - Stream.of( ModifierProtocolIdentifier.values() ).forEach( modifierProtocolIdentifier -> + Stream.of( Protocol.ModifierProtocolCategory.values() ).forEach( modifierProtocolIdentifier -> { - Set versions = modifierProtocolRepository.getAll( modifierProtocolIdentifier, emptyList() ).versions(); + Set versions = modifierProtocolRepository.getAll( modifierProtocolIdentifier, emptyList() ).versions(); verify( channel ).write( new ModifierProtocolRequest( modifierProtocolIdentifier.canonicalName(), versions ) ); } ); } @@ -207,7 +209,7 @@ public void shouldNotSendSwitchOverRequestOnModifierProtocolResponseIfNotAllModi client.handle( new ApplicationProtocolResponse( StatusCode.SUCCESS, applicationProtocolIdentifier.canonicalName(), raftVersion ) ); // when - client.handle( new ModifierProtocolResponse( StatusCode.SUCCESS, ModifierProtocolIdentifier.COMPRESSION.canonicalName(), 1 ) ); + client.handle( new ModifierProtocolResponse( StatusCode.SUCCESS, Protocol.ModifierProtocolCategory.COMPRESSION.canonicalName(), "woot" ) ); // then verify( channel, never() ).writeAndFlush( any( SwitchOverRequest.class ) ); @@ -223,7 +225,7 @@ public void shouldNotSendSwitchOverRequestIfApplicationProtocolResponseNotReceiv client.handle( InitialMagicMessage.instance() ); // when - client.handle( new ModifierProtocolResponse( StatusCode.SUCCESS, ModifierProtocolIdentifier.COMPRESSION.canonicalName(), 1 ) ); + client.handle( new ModifierProtocolResponse( StatusCode.SUCCESS, ModifierProtocolCategory.COMPRESSION.canonicalName(), SNAPPY.implementation() ) ); // then verify( channel, never() ).writeAndFlush( any( SwitchOverRequest.class ) ); @@ -240,13 +242,15 @@ public void shouldSendSwitchOverRequestOnModifierProtocolResponseIfAllModifierPr client.handle( new ApplicationProtocolResponse( StatusCode.SUCCESS, applicationProtocolIdentifier.canonicalName(), raftVersion ) ); // when - client.handle( new ModifierProtocolResponse( StatusCode.SUCCESS, ModifierProtocolIdentifier.COMPRESSION.canonicalName(), 1 ) ); - client.handle( new ModifierProtocolResponse( StatusCode.SUCCESS, ModifierProtocolIdentifier.GRATUITOUS_OBFUSCATION.canonicalName(), 1 ) ); + client.handle( new ModifierProtocolResponse( + StatusCode.SUCCESS, ModifierProtocolCategory.COMPRESSION.canonicalName(), SNAPPY.implementation() ) ); + client.handle( new ModifierProtocolResponse( + StatusCode.SUCCESS, Protocol.ModifierProtocolCategory.GRATUITOUS_OBFUSCATION.canonicalName(), ROT13.implementation() ) ); // then - List> switchOverModifierProtocols = asList( - Pair.of( ModifierProtocolIdentifier.COMPRESSION.canonicalName(), 1 ), - Pair.of( ModifierProtocolIdentifier.GRATUITOUS_OBFUSCATION.canonicalName(), 1 ) + List> switchOverModifierProtocols = asList( + Pair.of( ModifierProtocolCategory.COMPRESSION.canonicalName(), SNAPPY.implementation() ), + Pair.of( ModifierProtocolCategory.GRATUITOUS_OBFUSCATION.canonicalName(), ROT13.implementation() ) ); verify( channel ).writeAndFlush( new SwitchOverRequest( applicationProtocolIdentifier.canonicalName(), raftVersion, switchOverModifierProtocols ) ); assertFalse( protocolStackCompletableFuture.isDone() ); @@ -262,11 +266,14 @@ public void shouldNotIncludeModifierProtocolInSwitchOverRequestIfNotSuccessful() client.handle( new ApplicationProtocolResponse( StatusCode.SUCCESS, applicationProtocolIdentifier.canonicalName(), raftVersion ) ); // when - client.handle( new ModifierProtocolResponse( StatusCode.SUCCESS, ModifierProtocolIdentifier.COMPRESSION.canonicalName(), 1 ) ); - client.handle( new ModifierProtocolResponse( StatusCode.FAILURE, ModifierProtocolIdentifier.GRATUITOUS_OBFUSCATION.canonicalName(), 1 ) ); + client.handle( new ModifierProtocolResponse( + StatusCode.SUCCESS, Protocol.ModifierProtocolCategory.COMPRESSION.canonicalName(), SNAPPY.implementation() ) ); + client.handle( new ModifierProtocolResponse( + StatusCode.FAILURE, ModifierProtocolCategory.GRATUITOUS_OBFUSCATION.canonicalName(), ROT13.implementation() ) ); // then - List> switchOverModifierProtocols = asList( Pair.of( ModifierProtocolIdentifier.COMPRESSION.canonicalName(), 1 ) ); + List> switchOverModifierProtocols = + asList( Pair.of( ModifierProtocolCategory.COMPRESSION.canonicalName(), SNAPPY.implementation() ) ); verify( channel ).writeAndFlush( new SwitchOverRequest( applicationProtocolIdentifier.canonicalName(), raftVersion, switchOverModifierProtocols ) ); assertFalse( protocolStackCompletableFuture.isDone() ); } @@ -281,11 +288,12 @@ public void shouldNotIncludeModifierProtocolInSwitchOverRequestIfUnsupportedProt client.handle( new ApplicationProtocolResponse( StatusCode.SUCCESS, applicationProtocolIdentifier.canonicalName(), raftVersion ) ); // when - client.handle( new ModifierProtocolResponse( StatusCode.SUCCESS, ModifierProtocolIdentifier.COMPRESSION.canonicalName(), 1 ) ); - client.handle( new ModifierProtocolResponse( StatusCode.SUCCESS, "not a protocol", 1 ) ); + client.handle( new ModifierProtocolResponse( StatusCode.SUCCESS, ModifierProtocolCategory.COMPRESSION.canonicalName(), SNAPPY.implementation() ) ); + client.handle( new ModifierProtocolResponse( StatusCode.SUCCESS, "not a protocol", "not an implementation" ) ); // then - List> switchOverModifierProtocols = asList( Pair.of( ModifierProtocolIdentifier.COMPRESSION.canonicalName(), 1 ) ); + List> switchOverModifierProtocols = + asList( Pair.of( Protocol.ModifierProtocolCategory.COMPRESSION.canonicalName(), SNAPPY.implementation() ) ); verify( channel ).writeAndFlush( new SwitchOverRequest( applicationProtocolIdentifier.canonicalName(), raftVersion, switchOverModifierProtocols ) ); assertFalse( protocolStackCompletableFuture.isDone() ); } @@ -300,13 +308,14 @@ public void shouldNotIncludeModifierProtocolInSwitchOverRequestIfUnsupportedVers client.handle( new ApplicationProtocolResponse( StatusCode.SUCCESS, applicationProtocolIdentifier.canonicalName(), raftVersion ) ); // when - client.handle( - new ModifierProtocolResponse( StatusCode.SUCCESS, ModifierProtocolIdentifier.COMPRESSION.canonicalName(), 1 ) ); - client.handle( - new ModifierProtocolResponse( StatusCode.SUCCESS, ModifierProtocolIdentifier.GRATUITOUS_OBFUSCATION.canonicalName(), Integer.MAX_VALUE ) ); + client.handle( new ModifierProtocolResponse( + StatusCode.SUCCESS, Protocol.ModifierProtocolCategory.COMPRESSION.canonicalName(), SNAPPY.implementation() ) ); + client.handle( new ModifierProtocolResponse( + StatusCode.SUCCESS, Protocol.ModifierProtocolCategory.GRATUITOUS_OBFUSCATION.canonicalName(), "Rearrange the bytes at random" ) ); // then - List> switchOverModifierProtocols = asList( Pair.of( ModifierProtocolIdentifier.COMPRESSION.canonicalName(), 1 ) ); + List> switchOverModifierProtocols = + asList( Pair.of( Protocol.ModifierProtocolCategory.COMPRESSION.canonicalName(), SNAPPY.implementation() ) ); verify( channel ).writeAndFlush( new SwitchOverRequest( applicationProtocolIdentifier.canonicalName(), raftVersion, switchOverModifierProtocols ) ); assertFalse( protocolStackCompletableFuture.isDone() ); } @@ -348,21 +357,21 @@ public void shouldCompleteProtocolStackOnSwitchoverResponse() // given ModifierProtocolRepository repo = new ModifierProtocolRepository( TestModifierProtocols.values(), - asList( new SupportedProtocols<>( ModifierProtocolIdentifier.COMPRESSION, emptyList() ) ) ); + asList( new ModifierSupportedProtocols( Protocol.ModifierProtocolCategory.COMPRESSION, emptyList() ) ) ); CompletableFuture protocolStackCompletableFuture = client.initiate( channel, applicationProtocolRepository, repo ); client.handle( InitialMagicMessage.instance() ); client.handle( new ApplicationProtocolResponse( StatusCode.SUCCESS, applicationProtocolIdentifier.canonicalName(), raftVersion ) ); client.handle( - new ModifierProtocolResponse( StatusCode.SUCCESS, TestModifierProtocols.SNAPPY.identifier(), TestModifierProtocols.SNAPPY.version() ) ); + new ModifierProtocolResponse( StatusCode.SUCCESS, SNAPPY.category(), SNAPPY.implementation() ) ); // when client.handle( new SwitchOverResponse( StatusCode.SUCCESS ) ); // then ProtocolStack protocolStack = protocolStackCompletableFuture.getNow( null ); - assertThat( protocolStack, equalTo( new ProtocolStack( expectedApplicationProtocol, singletonList( TestModifierProtocols.SNAPPY ) ) ) ); + assertThat( protocolStack, equalTo( new ProtocolStack( expectedApplicationProtocol, singletonList( SNAPPY ) ) ) ); } private void assertCompletedExceptionally( CompletableFuture protocolStackCompletableFuture ) diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/HandshakeServerEnsureMagicTest.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/HandshakeServerEnsureMagicTest.java index d46ed386ef1d..81500facef5a 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/HandshakeServerEnsureMagicTest.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/HandshakeServerEnsureMagicTest.java @@ -37,7 +37,7 @@ import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static org.mockito.Mockito.mock; -import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolIdentifier.RAFT; +import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolCategory.RAFT; @RunWith( Parameterized.class ) public class HandshakeServerEnsureMagicTest @@ -47,7 +47,7 @@ public static Collection data() { return asList( new ApplicationProtocolRequest( RAFT.canonicalName(), Iterators.asSet( 1, 2 ) ), - new ModifierProtocolRequest( Protocol.ModifierProtocolIdentifier.COMPRESSION.canonicalName(), Iterators.asSet( 3, 4 ) ), + new ModifierProtocolRequest( Protocol.ModifierProtocolCategory.COMPRESSION.canonicalName(), Iterators.asSet( "3", "4" ) ), new SwitchOverRequest( RAFT.canonicalName(), 2, emptyList() ) ); } @@ -55,8 +55,8 @@ public static Collection data() @Parameterized.Parameter public ServerMessage message; - private final SupportedProtocols supportedApplicationProtocol = - new SupportedProtocols<>( RAFT, TestApplicationProtocols.listVersionsOf( RAFT ) ); + private final ApplicationSupportedProtocols supportedApplicationProtocol = + new ApplicationSupportedProtocols( RAFT, TestApplicationProtocols.listVersionsOf( RAFT ) ); private Channel channel = mock( Channel.class ); private ApplicationProtocolRepository applicationProtocolRepository = diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/HandshakeServerTest.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/HandshakeServerTest.java index 5195cf9dfbfc..c50736e354e7 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/HandshakeServerTest.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/HandshakeServerTest.java @@ -44,15 +44,15 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; -import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocol; -import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolIdentifier.RAFT; +import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolCategory.RAFT; import static org.neo4j.causalclustering.protocol.Protocol.ModifierProtocol; -import static org.neo4j.causalclustering.protocol.Protocol.ModifierProtocolIdentifier; -import static org.neo4j.causalclustering.protocol.Protocol.ModifierProtocolIdentifier.COMPRESSION; -import static org.neo4j.causalclustering.protocol.Protocol.ModifierProtocolIdentifier.GRATUITOUS_OBFUSCATION; +import static org.neo4j.causalclustering.protocol.Protocol.ModifierProtocolCategory.COMPRESSION; +import static org.neo4j.causalclustering.protocol.Protocol.ModifierProtocolCategory.GRATUITOUS_OBFUSCATION; import static org.neo4j.causalclustering.protocol.handshake.StatusCode.FAILURE; import static org.neo4j.causalclustering.protocol.handshake.StatusCode.SUCCESS; import static org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestApplicationProtocols.RAFT_1; +import static org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestModifierProtocols.LZ4; +import static org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestModifierProtocols.LZO; import static org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestModifierProtocols.ROT13; import static org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestModifierProtocols.SNAPPY; import static org.neo4j.helpers.collection.Iterators.asSet; @@ -63,11 +63,11 @@ public class HandshakeServerTest { private Channel channel = mock( Channel.class ); - private SupportedProtocols supportedApplicationProtocol = - new SupportedProtocols<>( RAFT, emptyList() ); - private Collection> supportedModifierProtocols = asList( - new SupportedProtocols<>( COMPRESSION, TestModifierProtocols.listVersionsOf( COMPRESSION ) ), - new SupportedProtocols<>( GRATUITOUS_OBFUSCATION, TestModifierProtocols.listVersionsOf( GRATUITOUS_OBFUSCATION ) ) + private ApplicationSupportedProtocols supportedApplicationProtocol = + new ApplicationSupportedProtocols( RAFT, emptyList() ); + private Collection supportedModifierProtocols = asList( + new ModifierSupportedProtocols( COMPRESSION, TestModifierProtocols.listVersionsOf( COMPRESSION ) ), + new ModifierSupportedProtocols( GRATUITOUS_OBFUSCATION, TestModifierProtocols.listVersionsOf( GRATUITOUS_OBFUSCATION ) ) ); private ApplicationProtocolRepository applicationProtocolRepository = new ApplicationProtocolRepository( TestApplicationProtocols.values(), supportedApplicationProtocol ); @@ -85,7 +85,7 @@ public void shouldDeclineUnallowedApplicationProtocol() // when server.handle( - new ApplicationProtocolRequest( TestApplicationProtocols.CATCHUP_1.identifier(), asSet( TestApplicationProtocols.CATCHUP_1.version() ) ) ); + new ApplicationProtocolRequest( TestApplicationProtocols.CATCHUP_1.category(), asSet( TestApplicationProtocols.CATCHUP_1.implementation() ) ) ); // then verify( channel ).dispose(); @@ -99,7 +99,7 @@ public void shouldExceptionallyCompleteProtocolStackOnUnallowedApplicationProtoc // when server.handle( - new ApplicationProtocolRequest( TestApplicationProtocols.CATCHUP_1.identifier(), asSet( TestApplicationProtocols.CATCHUP_1.version() ) ) ); + new ApplicationProtocolRequest( TestApplicationProtocols.CATCHUP_1.category(), asSet( TestApplicationProtocols.CATCHUP_1.implementation() ) ) ); // then assertExceptionallyCompletedProtocolStackFuture(); @@ -147,7 +147,7 @@ public void shouldSendApplicationProtocolResponseForKnownProtocol() // then verify( channel ).writeAndFlush( - new ApplicationProtocolResponse( SUCCESS, TestApplicationProtocols.RAFT_3.identifier(), TestApplicationProtocols.RAFT_3.version() ) ); + new ApplicationProtocolResponse( SUCCESS, TestApplicationProtocols.RAFT_3.category(), TestApplicationProtocols.RAFT_3.implementation() ) ); } @Test @@ -198,7 +198,7 @@ public void shouldExceptionallyCompleteProtocolStackForUnknownApplicationProtoco public void shouldSendModifierProtocolResponseForGivenProtocol() { // given - Set versions = asSet( TestModifierProtocols.allVersionsOf( COMPRESSION ) ); + Set versions = asSet( TestModifierProtocols.allVersionsOf( COMPRESSION ) ); server.handle( InitialMagicMessage.instance() ); // when @@ -207,14 +207,14 @@ public void shouldSendModifierProtocolResponseForGivenProtocol() // then ModifierProtocol expected = TestModifierProtocols.latest( COMPRESSION ); verify( channel ).writeAndFlush( - new ModifierProtocolResponse( SUCCESS, expected.identifier(), expected.version() ) ); + new ModifierProtocolResponse( SUCCESS, expected.category(), expected.implementation() ) ); } @Test public void shouldNotCloseConnectionForGivenModifierProtocol() { // given - Set versions = asSet( 1, 2, 3 ); + Set versions = asSet( SNAPPY.implementation(), LZO.implementation(), LZ4.implementation() ); server.handle( InitialMagicMessage.instance() ); // when @@ -228,7 +228,7 @@ public void shouldNotCloseConnectionForGivenModifierProtocol() public void shouldSendFailModifierProtocolResponseForUnknownVersion() { // given - Set versions = asSet( Integer.MAX_VALUE ); + Set versions = asSet( "Not a real protocol" ); server.handle( InitialMagicMessage.instance() ); // when @@ -237,14 +237,14 @@ public void shouldSendFailModifierProtocolResponseForUnknownVersion() // then verify( channel ).writeAndFlush( - new ModifierProtocolResponse( FAILURE, protocolName, 0 ) ); + new ModifierProtocolResponse( FAILURE, protocolName, "" ) ); } @Test public void shouldNotCloseConnectionIfUnknownModifierProtocolVersion() { // given - Set versions = asSet( Integer.MAX_VALUE ); + Set versions = asSet( "not a real algorithm" ); server.handle( InitialMagicMessage.instance() ); // when @@ -259,7 +259,7 @@ public void shouldNotCloseConnectionIfUnknownModifierProtocolVersion() public void shouldSendFailModifierProtocolResponseForUnknownProtocol() { // given - Set versions = asSet( 1, 2, 3 ); + Set versions = asSet( SNAPPY.implementation(), LZO.implementation(), LZ4.implementation() ); server.handle( InitialMagicMessage.instance() ); // when @@ -268,14 +268,14 @@ public void shouldSendFailModifierProtocolResponseForUnknownProtocol() // then verify( channel ).writeAndFlush( - new ModifierProtocolResponse( FAILURE, protocolName, 0 ) ); + new ModifierProtocolResponse( FAILURE, protocolName, "" ) ); } @Test public void shouldNotCloseConnectionIfUnknownModifierProtocol() { // given - Set versions = asSet( 1, 2, 3 ); + Set versions = asSet( SNAPPY.implementation(), LZO.implementation(), LZ4.implementation() ); server.handle( InitialMagicMessage.instance() ); // when @@ -328,7 +328,7 @@ public void shouldSendFailureIfSwitchOverBeforeNegotiation() server.handle( InitialMagicMessage.instance() ); // when - server.handle( new SwitchOverRequest( RAFT_1.identifier(), version, emptyList() ) ); + server.handle( new SwitchOverRequest( RAFT_1.category(), version, emptyList() ) ); // then InOrder inOrder = Mockito.inOrder( channel ); @@ -344,7 +344,7 @@ public void shouldExceptionallyCompleteProtocolStackIfSwitchOverBeforeNegotiatio server.handle( InitialMagicMessage.instance() ); // when - server.handle( new SwitchOverRequest( RAFT_1.identifier(), version, emptyList() ) ); + server.handle( new SwitchOverRequest( RAFT_1.category(), version, emptyList() ) ); // then assertExceptionallyCompletedProtocolStackFuture(); @@ -359,7 +359,7 @@ public void shouldSendFailureIfSwitchOverDiffersFromNegotiatedProtocol() server.handle( new ApplicationProtocolRequest( RAFT.canonicalName(), asSet( version ) ) ); // when - server.handle( new SwitchOverRequest( RAFT_1.identifier(), version + 1, emptyList() ) ); + server.handle( new SwitchOverRequest( RAFT_1.category(), version + 1, emptyList() ) ); // then InOrder inOrder = Mockito.inOrder( channel ); @@ -376,7 +376,7 @@ public void shouldExceptionallyCompleteProtocolStackIfSwitchOverDiffersFromNegot server.handle( new ApplicationProtocolRequest( RAFT.canonicalName(), asSet( version ) ) ); // when - server.handle( new SwitchOverRequest( RAFT_1.identifier(), version + 1, emptyList() ) ); + server.handle( new SwitchOverRequest( RAFT_1.category(), version + 1, emptyList() ) ); // then assertExceptionallyCompletedProtocolStackFuture(); @@ -386,16 +386,16 @@ public void shouldExceptionallyCompleteProtocolStackIfSwitchOverDiffersFromNegot public void shouldSendFailureIfSwitchOverDiffersByNameFromNegotiatedModifierProtocol() { // given - int version = 1; + String modifierVersion = ROT13.implementation(); + int applicationVersion = 1; server.handle( InitialMagicMessage.instance() ); - server.handle( new ApplicationProtocolRequest( RAFT.canonicalName(), asSet( version ) ) ); - server.handle( new ModifierProtocolRequest( COMPRESSION.canonicalName(), asSet( version ) ) ); + server.handle( new ApplicationProtocolRequest( RAFT.canonicalName(), asSet( applicationVersion ) ) ); + server.handle( new ModifierProtocolRequest( COMPRESSION.canonicalName(), asSet( modifierVersion ) ) ); // when server.handle( new SwitchOverRequest( - RAFT.canonicalName(), - version, - asList( Pair.of( ModifierProtocolIdentifier.GRATUITOUS_OBFUSCATION.canonicalName(), version) ) ) ); + RAFT.canonicalName(), applicationVersion, + asList( Pair.of( GRATUITOUS_OBFUSCATION.canonicalName(), modifierVersion ) ) ) ); // then InOrder inOrder = Mockito.inOrder( channel ); @@ -407,16 +407,17 @@ public void shouldSendFailureIfSwitchOverDiffersByNameFromNegotiatedModifierProt public void shouldExceptionallyCompleteProtocolStackIfSwitchOverDiffersByNameFromNegotiatedModifiedProtocol() { // given - int version = 1; + String modifierVersion = ROT13.implementation(); + int applicationVersion = 1; server.handle( InitialMagicMessage.instance() ); - server.handle( new ApplicationProtocolRequest( RAFT.canonicalName(), asSet( version ) ) ); - server.handle( new ModifierProtocolRequest( COMPRESSION.canonicalName(), asSet( version ) ) ); + server.handle( new ApplicationProtocolRequest( RAFT.canonicalName(), asSet( applicationVersion ) ) ); + server.handle( new ModifierProtocolRequest( COMPRESSION.canonicalName(), asSet( modifierVersion ) ) ); // when server.handle( new SwitchOverRequest( RAFT.canonicalName(), - version, - asList( Pair.of( ModifierProtocolIdentifier.GRATUITOUS_OBFUSCATION.canonicalName(), version) ) ) ); + applicationVersion, + asList( Pair.of( GRATUITOUS_OBFUSCATION.canonicalName(), modifierVersion ) ) ) ); // then assertExceptionallyCompletedProtocolStackFuture(); @@ -429,15 +430,15 @@ public void shouldSendFailureIfSwitchOverChangesOrderOfModifierProtocols() int version = 1; server.handle( InitialMagicMessage.instance() ); server.handle( new ApplicationProtocolRequest( RAFT.canonicalName(), asSet( version ) ) ); - server.handle( new ModifierProtocolRequest( COMPRESSION.canonicalName(), asSet( version ) ) ); - server.handle( new ModifierProtocolRequest( ModifierProtocolIdentifier.GRATUITOUS_OBFUSCATION.canonicalName(), asSet( version ) ) ); + server.handle( new ModifierProtocolRequest( COMPRESSION.canonicalName(), asSet( SNAPPY.implementation() ) ) ); + server.handle( new ModifierProtocolRequest( GRATUITOUS_OBFUSCATION.canonicalName(), asSet( ROT13.implementation() ) ) ); // when server.handle( new SwitchOverRequest( RAFT.canonicalName(), version, - asList( Pair.of( ModifierProtocolIdentifier.GRATUITOUS_OBFUSCATION.canonicalName(), version), - Pair.of( COMPRESSION.canonicalName(), version) ) ) ); + asList( Pair.of( GRATUITOUS_OBFUSCATION.canonicalName(), ROT13.implementation() ), + Pair.of( COMPRESSION.canonicalName(), SNAPPY.implementation() ) ) ) ); // then InOrder inOrder = Mockito.inOrder( channel ); @@ -452,15 +453,15 @@ public void shouldExceptionallyCompleteProtocolStackIfSwitchOverChangesOrderOfMo int version = 1; server.handle( InitialMagicMessage.instance() ); server.handle( new ApplicationProtocolRequest( RAFT.canonicalName(), asSet( version ) ) ); - server.handle( new ModifierProtocolRequest( COMPRESSION.canonicalName(), asSet( version ) ) ); - server.handle( new ModifierProtocolRequest( ModifierProtocolIdentifier.GRATUITOUS_OBFUSCATION.canonicalName(), asSet( version ) ) ); + server.handle( new ModifierProtocolRequest( COMPRESSION.canonicalName(), asSet( SNAPPY.implementation() ) ) ); + server.handle( new ModifierProtocolRequest( GRATUITOUS_OBFUSCATION.canonicalName(), asSet( ROT13.implementation() ) ) ); // when server.handle( new SwitchOverRequest( RAFT.canonicalName(), version, - asList( Pair.of( ModifierProtocolIdentifier.GRATUITOUS_OBFUSCATION.canonicalName(), version), - Pair.of( COMPRESSION.canonicalName(), version) ) ) ); + asList( Pair.of( GRATUITOUS_OBFUSCATION.canonicalName(), ROT13.implementation() ), + Pair.of( COMPRESSION.canonicalName(), SNAPPY.implementation() ) ) ) ); // then assertExceptionallyCompletedProtocolStackFuture(); @@ -473,13 +474,13 @@ public void shouldSendFailureIfSwitchOverDiffersByVersionFromNegotiatedModifierP int version = 1; server.handle( InitialMagicMessage.instance() ); server.handle( new ApplicationProtocolRequest( RAFT.canonicalName(), asSet( version ) ) ); - server.handle( new ModifierProtocolRequest( COMPRESSION.canonicalName(), asSet( version ) ) ); + server.handle( new ModifierProtocolRequest( COMPRESSION.canonicalName(), asSet( SNAPPY.implementation() ) ) ); // when server.handle( new SwitchOverRequest( - RAFT_1.identifier(), + RAFT_1.category(), version, - asList( Pair.of( COMPRESSION.canonicalName(), version + 1 ) ) + asList( Pair.of( COMPRESSION.canonicalName(), LZ4.implementation() ) ) ) ); // then @@ -495,13 +496,13 @@ public void shouldExceptionallyCompleteProtocolStackIfSwitchOverDiffersByVersion int version = 1; server.handle( InitialMagicMessage.instance() ); server.handle( new ApplicationProtocolRequest( RAFT.canonicalName(), asSet( version ) ) ); - server.handle( new ModifierProtocolRequest( COMPRESSION.canonicalName(), asSet( version ) ) ); + server.handle( new ModifierProtocolRequest( COMPRESSION.canonicalName(), asSet( SNAPPY.implementation() ) ) ); // when server.handle( new SwitchOverRequest( - RAFT_1.identifier(), + RAFT_1.category(), version, - asList( Pair.of( COMPRESSION.canonicalName(), version + 1 ) ) + asList( Pair.of( COMPRESSION.canonicalName(), LZ4.implementation() ) ) ) ); // then @@ -517,7 +518,7 @@ public void shouldCompleteProtocolStackOnSuccessfulSwitchOverWithNoModifierProto server.handle( new ApplicationProtocolRequest( RAFT.canonicalName(), asSet( version ) ) ); // when - server.handle( new SwitchOverRequest( RAFT_1.identifier(), version, emptyList() ) ); + server.handle( new SwitchOverRequest( RAFT_1.category(), version, emptyList() ) ); // then verify( channel ).writeAndFlush( InitialMagicMessage.instance() ); @@ -531,16 +532,16 @@ public void shouldCompleteProtocolStackOnSuccessfulSwitchOverWithModifierProtoco { // given server.handle( InitialMagicMessage.instance() ); - server.handle( new ApplicationProtocolRequest( RAFT.canonicalName(), asSet( RAFT_1.version()) ) ); - server.handle( new ModifierProtocolRequest( COMPRESSION.canonicalName(), asSet( SNAPPY.version() ) ) ); - server.handle( new ModifierProtocolRequest( ModifierProtocolIdentifier.GRATUITOUS_OBFUSCATION.canonicalName(), asSet( ROT13.version() ) ) ); + server.handle( new ApplicationProtocolRequest( RAFT.canonicalName(), asSet( RAFT_1.implementation()) ) ); + server.handle( new ModifierProtocolRequest( COMPRESSION.canonicalName(), asSet( SNAPPY.implementation() ) ) ); + server.handle( new ModifierProtocolRequest( GRATUITOUS_OBFUSCATION.canonicalName(), asSet( ROT13.implementation() ) ) ); // when - List> modifierRequest = asList( - Pair.of( SNAPPY.identifier(), SNAPPY.version() ), - Pair.of( ROT13.identifier(), ROT13.version() ) + List> modifierRequest = asList( + Pair.of( SNAPPY.category(), SNAPPY.implementation() ), + Pair.of( ROT13.category(), ROT13.implementation() ) ); - server.handle( new SwitchOverRequest( RAFT_1.identifier(), RAFT_1.version(), modifierRequest ) ); + server.handle( new SwitchOverRequest( RAFT_1.category(), RAFT_1.implementation(), modifierRequest ) ); // then verify( channel ).writeAndFlush( InitialMagicMessage.instance() ); @@ -554,12 +555,12 @@ public void shouldCompleteProtocolStackOnSuccessfulSwitchOverWithModifierProtoco public void shouldCompleteProtocolStackOnSuccessfulSwitchOverWithConfiguredModifierProtocols() { // given - Set requestedVersions = asSet( TestModifierProtocols.allVersionsOf( COMPRESSION ) ); - Integer expectedNegotiatedVersion = 1; - List configuredVersions = singletonList( expectedNegotiatedVersion ); + Set requestedVersions = asSet( TestModifierProtocols.allVersionsOf( COMPRESSION ) ); + String expectedNegotiatedVersion = SNAPPY.implementation(); + List configuredVersions = singletonList( expectedNegotiatedVersion ); - List> supportedModifierProtocols = - asList( new SupportedProtocols<>( COMPRESSION, configuredVersions ) ); + List supportedModifierProtocols = + asList( new ModifierSupportedProtocols( COMPRESSION, configuredVersions ) ); ModifierProtocolRepository modifierProtocolRepository = new ModifierProtocolRepository( TestModifierProtocols.values(), supportedModifierProtocols ); @@ -567,14 +568,14 @@ public void shouldCompleteProtocolStackOnSuccessfulSwitchOverWithConfiguredModif HandshakeServer server = new HandshakeServer( applicationProtocolRepository, modifierProtocolRepository, channel ); server.handle( InitialMagicMessage.instance() ); - server.handle( new ApplicationProtocolRequest( RAFT.canonicalName(), asSet( RAFT_1.version()) ) ); + server.handle( new ApplicationProtocolRequest( RAFT.canonicalName(), asSet( RAFT_1.implementation()) ) ); server.handle( new ModifierProtocolRequest( COMPRESSION.canonicalName(), requestedVersions ) ); // when - List> modifierRequest = asList( Pair.of( SNAPPY.identifier(), SNAPPY.version() ) ); - server.handle( new SwitchOverRequest( RAFT_1.identifier(), RAFT_1.version(), modifierRequest ) ); + List> modifierRequest = asList( Pair.of( SNAPPY.category(), SNAPPY.implementation() ) ); + server.handle( new SwitchOverRequest( RAFT_1.category(), RAFT_1.implementation(), modifierRequest ) ); // then verify( channel ).writeAndFlush( InitialMagicMessage.instance() ); @@ -591,7 +592,7 @@ public void shouldSuccessfullySwitchOverWhenServerHasConfiguredRaftVersions() Set requestedVersions = asSet( TestApplicationProtocols.allVersionsOf( RAFT ) ); Integer expectedNegotiatedVersion = 1; ApplicationProtocolRepository applicationProtocolRepository = new ApplicationProtocolRepository( - TestApplicationProtocols.values(), new SupportedProtocols<>( RAFT, singletonList( expectedNegotiatedVersion ) ) ); + TestApplicationProtocols.values(), new ApplicationSupportedProtocols( RAFT, singletonList( expectedNegotiatedVersion ) ) ); HandshakeServer server = new HandshakeServer( applicationProtocolRepository, modifierProtocolRepository, channel ); @@ -599,7 +600,7 @@ public void shouldSuccessfullySwitchOverWhenServerHasConfiguredRaftVersions() server.handle( new ApplicationProtocolRequest( RAFT.canonicalName(), requestedVersions ) ); // when - server.handle( new SwitchOverRequest( RAFT_1.identifier(), expectedNegotiatedVersion, emptyList() ) ); + server.handle( new SwitchOverRequest( RAFT_1.category(), expectedNegotiatedVersion, emptyList() ) ); // then verify( channel ).writeAndFlush( InitialMagicMessage.instance() ); diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ModifierProtocolRepositoryTest.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ModifierProtocolRepositoryTest.java index 36d5275b42da..d21d4ba74ac2 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ModifierProtocolRepositoryTest.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ModifierProtocolRepositoryTest.java @@ -31,8 +31,12 @@ import static java.util.Arrays.asList; import static org.junit.Assert.assertThat; -import static org.neo4j.causalclustering.protocol.Protocol.ModifierProtocolIdentifier.COMPRESSION; -import static org.neo4j.causalclustering.protocol.Protocol.ModifierProtocolIdentifier.GRATUITOUS_OBFUSCATION; +import static org.neo4j.causalclustering.protocol.Protocol.ModifierProtocolCategory.COMPRESSION; +import static org.neo4j.causalclustering.protocol.Protocol.ModifierProtocolCategory.GRATUITOUS_OBFUSCATION; +import static org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestModifierProtocols.LZ4; +import static org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestModifierProtocols.LZO; +import static org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestModifierProtocols.NAME_CLASH; +import static org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestModifierProtocols.SNAPPY; import static org.neo4j.helpers.collection.Iterators.asSet; /** @@ -44,25 +48,27 @@ public class ModifierProtocolRepositoryTest public void shouldReturnModifierProtocolOfFirstConfiguredVersionRequestedAndSupported() { // given - List> supportedProtocols = asList( - new SupportedProtocols<>( COMPRESSION, asList( 2, 1, 3 ) ), - new SupportedProtocols<>( GRATUITOUS_OBFUSCATION, asList( 1, 3, 2 ) ) ); + List supportedProtocols = asList( + new ModifierSupportedProtocols( COMPRESSION, asList( LZO.implementation(), SNAPPY.implementation(), LZ4.implementation() ) ), + new ModifierSupportedProtocols( GRATUITOUS_OBFUSCATION, asList( NAME_CLASH.implementation() ) ) ); ModifierProtocolRepository modifierProtocolRepository = new ModifierProtocolRepository( TestProtocols.TestModifierProtocols.values(), supportedProtocols ); // when - Optional modifierProtocol = - modifierProtocolRepository.select( COMPRESSION.canonicalName(), asSet( 9, 1, 3, 2, 7 ) ); + Optional modifierProtocol = modifierProtocolRepository.select( + COMPRESSION.canonicalName(), + asSet( "bzip2", SNAPPY.implementation(), LZ4.implementation(), LZO.implementation(), "fast_lz" ) + ); // then - assertThat( modifierProtocol.map( Protocol::version ), OptionalMatchers.contains( 2 ) ); + assertThat( modifierProtocol.map( Protocol::implementation), OptionalMatchers.contains( LZO.implementation() ) ); } @Test public void shouldReturnModifierProtocolOfSingleConfiguredVersionIfOthersRequested() { // given - List> supportedProtocols = asList( - new SupportedProtocols<>( COMPRESSION, asList( 2 ) ) ); + List supportedProtocols = asList( + new ModifierSupportedProtocols( COMPRESSION, asList( LZO.implementation() ) ) ); ModifierProtocolRepository modifierProtocolRepository = new ModifierProtocolRepository( TestProtocols.TestModifierProtocols.values(), supportedProtocols ); // when @@ -70,20 +76,20 @@ public void shouldReturnModifierProtocolOfSingleConfiguredVersionIfOthersRequest modifierProtocolRepository.select( COMPRESSION.canonicalName(), asSet( TestProtocols.TestModifierProtocols.allVersionsOf( COMPRESSION ) ) ); // then - assertThat( modifierProtocol.map( Protocol::version ), OptionalMatchers.contains( 2 ) ); + assertThat( modifierProtocol.map( Protocol::implementation), OptionalMatchers.contains( LZO.implementation() ) ); } @Test public void shouldCompareModifierProtocolsByListOrder() throws Throwable { - List> supportedProtocols = asList( - new SupportedProtocols<>( COMPRESSION, asList( 2, 1, 3 ) ) ); + List supportedProtocols = asList( + new ModifierSupportedProtocols( COMPRESSION, asList( LZO.implementation(), SNAPPY.implementation(), LZ4.implementation() ) ) ); Comparator comparator = ModifierProtocolRepository.getModifierProtocolComparator( supportedProtocols ) .apply( COMPRESSION.canonicalName() ); - assertThat( comparator.compare( TestProtocols.TestModifierProtocols.LZO, TestProtocols.TestModifierProtocols.SNAPPY ), Matchers.greaterThan( 0 ) ); + assertThat( comparator.compare( LZO, TestProtocols.TestModifierProtocols.SNAPPY ), Matchers.greaterThan( 0 ) ); assertThat( comparator.compare( TestProtocols.TestModifierProtocols.SNAPPY, TestProtocols.TestModifierProtocols.LZ4 ), Matchers.greaterThan( 0 ) ); } } diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/NettyInstalledProtocolsIT.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/NettyInstalledProtocolsIT.java index e7cccdfa2b4f..4342417dccff 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/NettyInstalledProtocolsIT.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/NettyInstalledProtocolsIT.java @@ -59,7 +59,6 @@ import org.neo4j.causalclustering.protocol.ModifierProtocolInstaller; import org.neo4j.causalclustering.protocol.NettyPipelineBuilderFactory; import org.neo4j.causalclustering.protocol.Protocol; -import org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocol; import org.neo4j.causalclustering.protocol.Protocol.ModifierProtocol; import org.neo4j.causalclustering.protocol.Protocol.ModifierProtocols; import org.neo4j.causalclustering.protocol.ProtocolInstaller; @@ -73,9 +72,9 @@ import static java.util.Collections.singletonList; import static java.util.concurrent.TimeUnit.SECONDS; import static org.hamcrest.Matchers.contains; -import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolIdentifier.RAFT; +import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolCategory.RAFT; import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocols.RAFT_1; -import static org.neo4j.causalclustering.protocol.Protocol.ModifierProtocolIdentifier.COMPRESSION; +import static org.neo4j.causalclustering.protocol.Protocol.ModifierProtocolCategory.COMPRESSION; @RunWith( Parameterized.class ) public class NettyInstalledProtocolsIT @@ -104,10 +103,10 @@ public static Collection data() private static Parameters raft1WithCompressionModifier( Optional protocol ) { - List versions = Streams.ofOptional( protocol ).map( Protocol::version ).collect( Collectors.toList() ); + List versions = Streams.ofOptional( protocol ).map( Protocol::implementation ).collect( Collectors.toList() ); return new Parameters( "Raft 1, modifiers: " + protocol, - new SupportedProtocols<>( RAFT, asList( RAFT_1.version() ) ), - asList( new SupportedProtocols<>( COMPRESSION, versions ) ) ); + new ApplicationSupportedProtocols( RAFT, asList( RAFT_1.implementation() ) ), + asList( new ModifierSupportedProtocols( COMPRESSION, versions ) ) ); } @Test @@ -162,11 +161,11 @@ public void tearDown() private static class Parameters { final String name; - final SupportedProtocols applicationSupportedProtocol; - final Collection> modifierSupportedProtocols; + final ApplicationSupportedProtocols applicationSupportedProtocol; + final Collection modifierSupportedProtocols; - Parameters( String name, SupportedProtocols applicationSupportedProtocol, - Collection> modifierSupportedProtocols ) + Parameters( String name, ApplicationSupportedProtocols applicationSupportedProtocol, + Collection modifierSupportedProtocols ) { this.name = name; this.applicationSupportedProtocol = applicationSupportedProtocol; diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/NettyProtocolHandshakeIT.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/NettyProtocolHandshakeIT.java index e9a036bb0fd8..f96c966a9988 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/NettyProtocolHandshakeIT.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/NettyProtocolHandshakeIT.java @@ -43,7 +43,6 @@ import java.util.concurrent.TimeUnit; import org.neo4j.causalclustering.messaging.SimpleNettyChannel; -import org.neo4j.causalclustering.protocol.Protocol; import org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestApplicationProtocols; import org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestModifierProtocols; import org.neo4j.logging.NullLog; @@ -55,19 +54,19 @@ import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; -import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolIdentifier.CATCHUP; -import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolIdentifier.RAFT; -import static org.neo4j.causalclustering.protocol.Protocol.ModifierProtocolIdentifier.COMPRESSION; +import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolCategory.CATCHUP; +import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolCategory.RAFT; +import static org.neo4j.causalclustering.protocol.Protocol.ModifierProtocolCategory.COMPRESSION; public class NettyProtocolHandshakeIT { - private SupportedProtocols supportedRaftApplicationProtocol = - new SupportedProtocols<>( RAFT, emptyList() ); - private SupportedProtocols supportedCatchupApplicationProtocol = - new SupportedProtocols<>( CATCHUP, emptyList() ); - private Collection> supportedCompressionModifierProtocols = - asList( new SupportedProtocols<>( COMPRESSION, TestModifierProtocols.listVersionsOf( COMPRESSION ) ) ); - private Collection> noSupportedModifierProtocols = emptyList(); + private ApplicationSupportedProtocols supportedRaftApplicationProtocol = + new ApplicationSupportedProtocols( RAFT, emptyList() ); + private ApplicationSupportedProtocols supportedCatchupApplicationProtocol = + new ApplicationSupportedProtocols( CATCHUP, emptyList() ); + private Collection supportedCompressionModifierProtocols = + asList( new ModifierSupportedProtocols( COMPRESSION, TestModifierProtocols.listVersionsOf( COMPRESSION ) ) ); + private Collection noSupportedModifierProtocols = emptyList(); private ApplicationProtocolRepository raftApplicationProtocolRepository = new ApplicationProtocolRepository( TestApplicationProtocols.values(), supportedRaftApplicationProtocol ); diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ProtocolHandshakeHappyTest.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ProtocolHandshakeHappyTest.java index 72bb9c89b842..61942e501fc0 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ProtocolHandshakeHappyTest.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ProtocolHandshakeHappyTest.java @@ -41,9 +41,9 @@ import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; -import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolIdentifier.RAFT; -import static org.neo4j.causalclustering.protocol.Protocol.ModifierProtocolIdentifier.COMPRESSION; -import static org.neo4j.causalclustering.protocol.Protocol.ModifierProtocolIdentifier.GRATUITOUS_OBFUSCATION; +import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolCategory.RAFT; +import static org.neo4j.causalclustering.protocol.Protocol.ModifierProtocolCategory.COMPRESSION; +import static org.neo4j.causalclustering.protocol.Protocol.ModifierProtocolCategory.GRATUITOUS_OBFUSCATION; import static org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestApplicationProtocols.RAFT_1; import static org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestModifierProtocols.LZ4; import static org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestModifierProtocols.LZO; @@ -63,43 +63,43 @@ public class ProtocolHandshakeHappyTest public static Collection data() { // Application protocols - SupportedProtocols allRaft = - new SupportedProtocols<>( RAFT, TestApplicationProtocols.listVersionsOf( RAFT ) ); - SupportedProtocols raft1 = - new SupportedProtocols<>( RAFT, singletonList( RAFT_1.version() ) ); - SupportedProtocols allRaftByDefault = - new SupportedProtocols<>( RAFT, emptyList() ); + ApplicationSupportedProtocols allRaft = + new ApplicationSupportedProtocols( RAFT, TestApplicationProtocols.listVersionsOf( RAFT ) ); + ApplicationSupportedProtocols raft1 = + new ApplicationSupportedProtocols( RAFT, singletonList( RAFT_1.implementation() ) ); + ApplicationSupportedProtocols allRaftByDefault = + new ApplicationSupportedProtocols( RAFT, emptyList() ); // Modifier protocols - Collection> allModifiers = asList( - new SupportedProtocols<>( COMPRESSION, TestModifierProtocols.listVersionsOf( COMPRESSION ) ), - new SupportedProtocols<>( GRATUITOUS_OBFUSCATION, TestModifierProtocols.listVersionsOf( GRATUITOUS_OBFUSCATION ) ) + Collection allModifiers = asList( + new ModifierSupportedProtocols( COMPRESSION, TestModifierProtocols.listVersionsOf( COMPRESSION ) ), + new ModifierSupportedProtocols( GRATUITOUS_OBFUSCATION, TestModifierProtocols.listVersionsOf( GRATUITOUS_OBFUSCATION ) ) ); - Collection> allCompressionModifiers = singletonList( - new SupportedProtocols<>( COMPRESSION, TestModifierProtocols.listVersionsOf( COMPRESSION ) ) ); - Collection> allObfuscationModifiers = singletonList( - new SupportedProtocols<>( GRATUITOUS_OBFUSCATION, TestModifierProtocols.listVersionsOf( GRATUITOUS_OBFUSCATION ) ) ); - Collection> allCompressionModifiersByDefault = singletonList( - new SupportedProtocols<>( COMPRESSION, emptyList() ) ); + Collection allCompressionModifiers = singletonList( + new ModifierSupportedProtocols( COMPRESSION, TestModifierProtocols.listVersionsOf( COMPRESSION ) ) ); + Collection allObfuscationModifiers = singletonList( + new ModifierSupportedProtocols( GRATUITOUS_OBFUSCATION, TestModifierProtocols.listVersionsOf( GRATUITOUS_OBFUSCATION ) ) ); + Collection allCompressionModifiersByDefault = singletonList( + new ModifierSupportedProtocols( COMPRESSION, emptyList() ) ); - List> onlyLzoCompressionModifiers = singletonList( - new SupportedProtocols<>( COMPRESSION, singletonList( LZO.version() ) ) ); - List> onlySnappyCompressionModifiers = singletonList( - new SupportedProtocols<>( COMPRESSION, singletonList( SNAPPY.version() ) ) ); + List onlyLzoCompressionModifiers = singletonList( + new ModifierSupportedProtocols( COMPRESSION, singletonList( LZO.implementation() ) ) ); + List onlySnappyCompressionModifiers = singletonList( + new ModifierSupportedProtocols( COMPRESSION, singletonList( SNAPPY.implementation() ) ) ); - Collection> noModifiers = emptyList(); + Collection noModifiers = emptyList(); // Ordered modifier protocols ModifierProtocolRepository modifierProtocolRepository = new ModifierProtocolRepository( TestModifierProtocols.values(), allModifiers ); - Integer[] lzoFirstVersions = { LZO.version(), LZ4.version(), SNAPPY.version() }; - List> lzoFirstCompressionModifiers = singletonList( - new SupportedProtocols<>( COMPRESSION, asList( lzoFirstVersions ) ) ); + String[] lzoFirstVersions = { LZO.implementation(), LZ4.implementation(), SNAPPY.implementation() }; + List lzoFirstCompressionModifiers = singletonList( + new ModifierSupportedProtocols( COMPRESSION, asList( lzoFirstVersions ) ) ); ModifierProtocol preferredLzoFirstCompressionModifier = modifierProtocolRepository.select( COMPRESSION.canonicalName(), asSet( lzoFirstVersions ) ).get(); - Integer[] snappyFirstVersions = { SNAPPY.version(), LZ4.version(), LZO.version() }; - List> snappyFirstCompressionModifiers = singletonList( - new SupportedProtocols<>( COMPRESSION, asList( snappyFirstVersions ) ) ); + String[] snappyFirstVersions = { SNAPPY.implementation(), LZ4.implementation(), LZO.implementation() }; + List snappyFirstCompressionModifiers = singletonList( + new ModifierSupportedProtocols( COMPRESSION, asList( snappyFirstVersions ) ) ); ModifierProtocol preferredSnappyFirstCompressionModifier = modifierProtocolRepository.select( COMPRESSION.canonicalName(), asSet( snappyFirstVersions ) ).get(); @@ -277,17 +277,17 @@ private CompletableFuture initiate() static class Parameters { - final SupportedProtocols clientApplicationProtocol; - final SupportedProtocols serverApplicationProtocol; - final Collection> clientModifierProtocols; - final Collection> serverModifierProtocols; + final ApplicationSupportedProtocols clientApplicationProtocol; + final ApplicationSupportedProtocols serverApplicationProtocol; + final Collection clientModifierProtocols; + final Collection serverModifierProtocols; final ApplicationProtocol expectedApplicationProtocol; final ModifierProtocol[] expectedModifierProtocols; - Parameters( SupportedProtocols clientApplicationProtocol, - SupportedProtocols serverApplicationProtocol, - Collection> clientModifierProtocols, - Collection> serverModifierProtocols, + Parameters( ApplicationSupportedProtocols clientApplicationProtocol, + ApplicationSupportedProtocols serverApplicationProtocol, + Collection clientModifierProtocols, + Collection serverModifierProtocols, ApplicationProtocol expectedApplicationProtocol, ModifierProtocol[] expectedModifierProtocols ) { diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ProtocolHandshakeSadTest.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ProtocolHandshakeSadTest.java index 79d91e1659bd..7f1c08de2303 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ProtocolHandshakeSadTest.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ProtocolHandshakeSadTest.java @@ -27,7 +27,6 @@ import org.neo4j.causalclustering.messaging.Channel; import org.neo4j.causalclustering.protocol.Protocol; -import org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolIdentifier; import org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestApplicationProtocols; import org.neo4j.causalclustering.protocol.handshake.TestProtocols.TestModifierProtocols; @@ -38,11 +37,11 @@ */ public class ProtocolHandshakeSadTest { - private SupportedProtocols supportedRaftApplicationProtocol = - new SupportedProtocols<>( ApplicationProtocolIdentifier.RAFT, emptyList() ); - private SupportedProtocols supportedCatchupApplicationProtocol = - new SupportedProtocols<>( ApplicationProtocolIdentifier.CATCHUP, emptyList() ); - private Collection> noModifiers = emptyList(); + private ApplicationSupportedProtocols supportedRaftApplicationProtocol = + new ApplicationSupportedProtocols( Protocol.ApplicationProtocolCategory.RAFT, emptyList() ); + private ApplicationSupportedProtocols supportedCatchupApplicationProtocol = + new ApplicationSupportedProtocols( Protocol.ApplicationProtocolCategory.CATCHUP, emptyList() ); + private Collection noModifiers = emptyList(); private ApplicationProtocolRepository raftApplicationProtocolRepository = new ApplicationProtocolRepository( TestApplicationProtocols.values(), supportedRaftApplicationProtocol ); diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ServerMessageEncodingTest.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ServerMessageEncodingTest.java index 0fa12125f27d..ee2867f8d571 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ServerMessageEncodingTest.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/ServerMessageEncodingTest.java @@ -62,10 +62,10 @@ public static Collection data() return asList( new ApplicationProtocolRequest( "protocol", asSet( 3,7,13 ) ), new InitialMagicMessage( "Magic string" ), - new ModifierProtocolRequest( "modifierProtocol", asSet( 1,4,7) ), + new ModifierProtocolRequest( "modifierProtocol", asSet( "Foo", "Bar", "Baz" ) ), new SwitchOverRequest( "protocol", 38, emptyList() ), new SwitchOverRequest( "protocol", 38, - asList( Pair.of( "mod1", 1 ), Pair.of( "mod2" , 2) ) ) + asList( Pair.of( "mod1", "Foo" ), Pair.of( "mod2" , "Quux" ) ) ) ); } diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/SupportedProtocolsTest.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/SupportedProtocolsTest.java index 4abeed51744b..d6755ac706be 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/SupportedProtocolsTest.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/SupportedProtocolsTest.java @@ -24,7 +24,6 @@ import java.util.Arrays; import java.util.Set; -import org.neo4j.causalclustering.protocol.Protocol; import org.neo4j.helpers.collection.Iterators; import static java.util.Collections.emptyList; @@ -32,7 +31,7 @@ import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.empty; import static org.junit.Assert.assertThat; -import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolIdentifier.RAFT; +import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolCategory.RAFT; public class SupportedProtocolsTest { @@ -40,7 +39,7 @@ public class SupportedProtocolsTest public void shouldMutuallySupportIntersectionOfParameterVersionsSuperset() throws Throwable { // given - SupportedProtocols supportedProtocols = new SupportedProtocols<>( RAFT, Arrays.asList( 1, 2 ) ); + ApplicationSupportedProtocols supportedProtocols = new ApplicationSupportedProtocols( RAFT, Arrays.asList( 1, 2 ) ); // when Set mutuallySupported = supportedProtocols.mutuallySupportedVersionsFor( Iterators.asSet( 1, 2, 3 ) ); @@ -53,7 +52,7 @@ public void shouldMutuallySupportIntersectionOfParameterVersionsSuperset() throw public void shouldMutuallySupportIntersectionOfParameterVersionsSubset() throws Throwable { // given - SupportedProtocols supportedProtocols = new SupportedProtocols<>( RAFT, Arrays.asList( 4, 5, 6 ) ); + ApplicationSupportedProtocols supportedProtocols = new ApplicationSupportedProtocols( RAFT, Arrays.asList( 4, 5, 6 ) ); // when Set mutuallySupported = supportedProtocols.mutuallySupportedVersionsFor( Iterators.asSet( 4, 5 ) ); @@ -66,7 +65,7 @@ public void shouldMutuallySupportIntersectionOfParameterVersionsSubset() throws public void shouldMutuallySupportParameterIfEmptyVersions() throws Throwable { // given - SupportedProtocols supportedProtocols = new SupportedProtocols<>( RAFT, emptyList() ); + ApplicationSupportedProtocols supportedProtocols = new ApplicationSupportedProtocols( RAFT, emptyList() ); // when Set mutuallySupported = supportedProtocols.mutuallySupportedVersionsFor( Iterators.asSet( 7, 8 ) ); @@ -79,7 +78,7 @@ public void shouldMutuallySupportParameterIfEmptyVersions() throws Throwable public void shouldMutuallySupportNothingIfParametersEmpty() throws Throwable { // given - SupportedProtocols supportedProtocols = new SupportedProtocols<>( RAFT, Arrays.asList( 1, 2 ) ); + ApplicationSupportedProtocols supportedProtocols = new ApplicationSupportedProtocols( RAFT, Arrays.asList( 1, 2 ) ); // when Set mutuallySupported = supportedProtocols.mutuallySupportedVersionsFor( emptySet() ); diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/TestProtocols.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/TestProtocols.java index fcc729bcf828..2297e99605b0 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/TestProtocols.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/protocol/handshake/TestProtocols.java @@ -22,71 +22,72 @@ import java.util.Arrays; import java.util.Comparator; import java.util.List; +import java.util.function.IntFunction; import java.util.stream.Stream; import org.neo4j.causalclustering.protocol.Protocol; public interface TestProtocols { - static T latest( Protocol.Identifier identifier, T[] values ) + static ,T extends Protocol> T latest( Protocol.Category category, T[] values ) { return Stream.of( values ) - .filter( protocol -> protocol.identifier().equals( identifier.canonicalName() ) ) - .max( Comparator.comparing( T::version ) ) + .filter( protocol -> protocol.category().equals( category.canonicalName() ) ) + .max( Comparator.comparing( T::implementation ) ) .get(); } - static Integer[] allVersionsOf( Protocol.Identifier identifier, T[] values ) + static ,T extends Protocol> U[] allVersionsOf( Protocol.Category category, T[] values, IntFunction constructor ) { return Stream.of( values ) - .filter( protocol -> protocol.identifier().equals( identifier.canonicalName() ) ) - .map( Protocol::version ) - .toArray( Integer[]::new ); + .filter( protocol -> protocol.category().equals( category.canonicalName() ) ) + .map( Protocol::implementation ) + .toArray( constructor ); } enum TestApplicationProtocols implements Protocol.ApplicationProtocol { - RAFT_1( ApplicationProtocolIdentifier.RAFT, 1 ), - RAFT_2( ApplicationProtocolIdentifier.RAFT, 2 ), - RAFT_3( ApplicationProtocolIdentifier.RAFT, 3 ), - RAFT_4( ApplicationProtocolIdentifier.RAFT, 4 ), - CATCHUP_1( ApplicationProtocolIdentifier.CATCHUP, 1 ), - CATCHUP_2( ApplicationProtocolIdentifier.CATCHUP, 2 ), - CATCHUP_3( ApplicationProtocolIdentifier.CATCHUP, 3 ), - CATCHUP_4( ApplicationProtocolIdentifier.CATCHUP, 4 ); - - private final int version; - - private final ApplicationProtocolIdentifier identifier; - TestApplicationProtocols( ApplicationProtocolIdentifier identifier, int version ) + RAFT_1( ApplicationProtocolCategory.RAFT, 1 ), + RAFT_2( ApplicationProtocolCategory.RAFT, 2 ), + RAFT_3( ApplicationProtocolCategory.RAFT, 3 ), + RAFT_4( ApplicationProtocolCategory.RAFT, 4 ), + CATCHUP_1( ApplicationProtocolCategory.CATCHUP, 1 ), + CATCHUP_2( ApplicationProtocolCategory.CATCHUP, 2 ), + CATCHUP_3( ApplicationProtocolCategory.CATCHUP, 3 ), + CATCHUP_4( ApplicationProtocolCategory.CATCHUP, 4 ); + + private final Integer version; + + private final ApplicationProtocolCategory identifier; + TestApplicationProtocols( ApplicationProtocolCategory identifier, int version ) { this.identifier = identifier; this.version = version; } @Override - public String identifier() + public String category() { return this.identifier.canonicalName(); } @Override - public int version() + public Integer implementation() { return version; } - public static ApplicationProtocol latest( ApplicationProtocolIdentifier identifier ) + public static ApplicationProtocol latest( ApplicationProtocolCategory identifier ) { return TestProtocols.latest( identifier, values() ); } - public static Integer[] allVersionsOf( ApplicationProtocolIdentifier identifier ) + public static Integer[] allVersionsOf( ApplicationProtocolCategory identifier ) { - return TestProtocols.allVersionsOf( identifier, TestApplicationProtocols.values() ); + return TestProtocols.allVersionsOf( identifier, TestApplicationProtocols.values(), Integer[]::new ); } - public static List listVersionsOf( ApplicationProtocolIdentifier identifier ) + public static List listVersionsOf( ApplicationProtocolCategory identifier ) { return Arrays.asList( allVersionsOf( identifier ) ); } @@ -94,56 +95,49 @@ public static List listVersionsOf( ApplicationProtocolIdentifier identi enum TestModifierProtocols implements Protocol.ModifierProtocol { - SNAPPY( ModifierProtocolIdentifier.COMPRESSION, 1, "TestSnappy" ), - LZO( ModifierProtocolIdentifier.COMPRESSION, 2, "TestLZO" ), - LZ4( ModifierProtocolIdentifier.COMPRESSION, 3, "TestLZ4" ), - LZ4_VALIDATING( ModifierProtocolIdentifier.COMPRESSION, 4, "TestLZ4Validating" ), - LZ4_HIGH_COMPRESSION( ModifierProtocolIdentifier.COMPRESSION, 5, "TestLZ4High" ), - LZ4_HIGH_COMPRESSION_VALIDATING( ModifierProtocolIdentifier.COMPRESSION, 6, "TestLZ4HighValidating" ), - ROT13( ModifierProtocolIdentifier.GRATUITOUS_OBFUSCATION, 1, "ROT13" ); - - private final int version; - private final ModifierProtocolIdentifier identifier; + SNAPPY( ModifierProtocolCategory.COMPRESSION, "TestSnappy" ), + LZO( ModifierProtocolCategory.COMPRESSION, "TestLZO" ), + LZ4( ModifierProtocolCategory.COMPRESSION, "TestLZ4" ), + LZ4_VALIDATING( ModifierProtocolCategory.COMPRESSION, "TestLZ4Validating" ), + LZ4_HIGH_COMPRESSION( ModifierProtocolCategory.COMPRESSION, "TestLZ4High" ), + LZ4_HIGH_COMPRESSION_VALIDATING( ModifierProtocolCategory.COMPRESSION, "TestLZ4HighValidating" ), + ROT13( ModifierProtocolCategory.GRATUITOUS_OBFUSCATION, "ROT13" ), + NAME_CLASH( ModifierProtocolCategory.GRATUITOUS_OBFUSCATION, "TestSnappy" ); + + private final ModifierProtocolCategory identifier; private final String friendlyName; - TestModifierProtocols( ModifierProtocolIdentifier identifier, int version, String friendlyName ) + TestModifierProtocols( ModifierProtocolCategory identifier, String friendlyName ) { - this.version = version; this.identifier = identifier; this.friendlyName = friendlyName; } @Override - public String identifier() + public String category() { return identifier.canonicalName(); } @Override - public int version() - { - return version; - } - - @Override - public String friendlyName() + public String implementation() { return friendlyName; } - public static ModifierProtocol latest( ModifierProtocolIdentifier identifier ) + public static ModifierProtocol latest( ModifierProtocolCategory identifier ) { return TestProtocols.latest( identifier, values() ); } - public static Integer[] allVersionsOf( ModifierProtocolIdentifier identifier ) + public static String[] allVersionsOf( ModifierProtocolCategory identifier ) { - return TestProtocols.allVersionsOf( identifier, TestModifierProtocols.values() ); + return TestProtocols.allVersionsOf( identifier, TestModifierProtocols.values(), String[]::new ); } - public static List listVersionsOf( ModifierProtocolIdentifier identifier ) + public static List listVersionsOf( ModifierProtocolCategory identifier ) { - List versions = Arrays.asList( allVersionsOf( identifier ) ); + List versions = Arrays.asList( allVersionsOf( identifier ) ); versions.sort( Comparator.reverseOrder() ); return versions; } diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/scenarios/InstalledProtocolsProcedureIT.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/scenarios/InstalledProtocolsProcedureIT.java index acf5a5f26ef0..c802fd9fdb12 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/scenarios/InstalledProtocolsProcedureIT.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/scenarios/InstalledProtocolsProcedureIT.java @@ -48,7 +48,7 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.hasSize; -import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolIdentifier.RAFT; +import static org.neo4j.causalclustering.protocol.Protocol.ApplicationProtocolCategory.RAFT; import static org.neo4j.causalclustering.protocol.Protocol.ModifierProtocols.COMPRESSION_SNAPPY; import static org.neo4j.causalclustering.protocol.ProtocolInstaller.Orientation.Client.OUTBOUND; import static org.neo4j.causalclustering.protocol.ProtocolInstaller.Orientation.Server.INBOUND; @@ -80,7 +80,7 @@ public void startUp() throws Exception public void shouldSeeOutboundInstalledProtocolsOnLeader() throws Throwable { String modifiers = new StringJoiner( ",", "[", "]" ) - .add( COMPRESSION_SNAPPY.friendlyName() ) + .add( COMPRESSION_SNAPPY.implementation() ) .toString(); ProtocolInfo[] expectedProtocolInfos = cluster.coreMembers()