-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This update fixes a number of SSL-related tests in testkit and CausalClusteringIT.shouldDropBrokenOldConnections test. The connection pooling strategy has been updated to use the same connection pool when the connection host is unambiguous. Removed hardcoded domain name resolution from the BoltServerAddress and moved the logic to ChannelConnectorImpl that uses the DomainNameResolver.
- Loading branch information
1 parent
b98b697
commit 8727aae
Showing
10 changed files
with
197 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
driver/src/main/java/org/neo4j/driver/internal/ResolvedBoltServerAddress.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.neo4j.driver.internal; | ||
|
||
import java.net.InetAddress; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.LinkedHashSet; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static java.util.stream.Collectors.joining; | ||
|
||
/** | ||
* An explicitly resolved version of {@link BoltServerAddress} that always contains one or more resolved IP addresses. | ||
*/ | ||
public class ResolvedBoltServerAddress extends BoltServerAddress | ||
{ | ||
private static final String HOST_ADDRESSES_FORMAT = "%s%s:%d"; | ||
private static final int MAX_HOST_ADDRESSES_IN_STRING_VALUE = 5; | ||
private static final String HOST_ADDRESS_DELIMITER = ","; | ||
private static final String HOST_ADDRESSES_PREFIX = "("; | ||
private static final String HOST_ADDRESSES_SUFFIX = ")"; | ||
private static final String TRIMMED_HOST_ADDRESSES_SUFFIX = ",..." + HOST_ADDRESSES_SUFFIX; | ||
|
||
private final Set<InetAddress> resolvedAddresses; | ||
private final String stringValue; | ||
|
||
public ResolvedBoltServerAddress( String host, int port, InetAddress[] resolvedAddressesArr ) | ||
{ | ||
super( host, port ); | ||
requireNonNull( resolvedAddressesArr, "resolvedAddressesArr" ); | ||
if ( resolvedAddressesArr.length == 0 ) | ||
{ | ||
throw new IllegalArgumentException( | ||
"The resolvedAddressesArr must not be empty, check your DomainNameResolver is compliant with the interface contract" ); | ||
} | ||
resolvedAddresses = Collections.unmodifiableSet( new LinkedHashSet<>( Arrays.asList( resolvedAddressesArr ) ) ); | ||
stringValue = createStringRepresentation(); | ||
} | ||
|
||
/** | ||
* Create a stream of unicast addresses. | ||
* <p> | ||
* The stream is created from the list of resolved IP addresses. Each unicast address is given a unique IP address as the connectionHost value. | ||
* | ||
* @return stream of unicast addresses. | ||
*/ | ||
@Override | ||
public Stream<BoltServerAddress> unicastStream() | ||
{ | ||
return resolvedAddresses.stream().map( address -> new BoltServerAddress( host, address.getHostAddress(), port ) ); | ||
} | ||
|
||
@Override | ||
public boolean equals( Object o ) | ||
{ | ||
if ( this == o ) | ||
{ | ||
return true; | ||
} | ||
if ( o == null || getClass() != o.getClass() ) | ||
{ | ||
return false; | ||
} | ||
if ( !super.equals( o ) ) | ||
{ | ||
return false; | ||
} | ||
ResolvedBoltServerAddress that = (ResolvedBoltServerAddress) o; | ||
return resolvedAddresses.equals( that.resolvedAddresses ); | ||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
return Objects.hash( super.hashCode(), resolvedAddresses ); | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return stringValue; | ||
} | ||
|
||
private String createStringRepresentation() | ||
{ | ||
String hostAddresses = resolvedAddresses.stream() | ||
.limit( MAX_HOST_ADDRESSES_IN_STRING_VALUE ) | ||
.map( InetAddress::getHostAddress ) | ||
.collect( joining( HOST_ADDRESS_DELIMITER, HOST_ADDRESSES_PREFIX, | ||
resolvedAddresses.size() > MAX_HOST_ADDRESSES_IN_STRING_VALUE | ||
? TRIMMED_HOST_ADDRESSES_SUFFIX | ||
: HOST_ADDRESSES_SUFFIX ) ); | ||
return String.format( HOST_ADDRESSES_FORMAT, host, hostAddresses, port ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.