File tree Expand file tree Collapse file tree 2 files changed +25
-9
lines changed
main/java/org/neo4j/driver/internal/net
test/java/org/neo4j/driver/internal/net Expand file tree Collapse file tree 2 files changed +25
-9
lines changed Original file line number Diff line number Diff line change @@ -103,20 +103,24 @@ public String toString()
103103 return format ( "%s:%d" , host , port );
104104 }
105105
106+ /**
107+ * Create a {@link SocketAddress} from this bolt address. This method always attempts to resolve the hostname into
108+ * an {@link InetAddress}.
109+ *
110+ * @return new socket address.
111+ * @see InetSocketAddress
112+ */
106113 public SocketAddress toSocketAddress ()
107114 {
108- if (socketAddress == null )
109- {
110- socketAddress = new InetSocketAddress ( host , port );
111- }
112- return socketAddress ;
115+ return new InetSocketAddress ( host , port );
113116 }
114117
115118 /**
116119 * Resolve the host name down to an IP address, if not already resolved.
117120 *
118121 * @return this instance if already resolved, otherwise a new address instance
119- * @throws UnknownHostException
122+ * @throws UnknownHostException if no IP address for the host could be found
123+ * @see InetAddress#getByName(String)
120124 */
121125 public BoltServerAddress resolve () throws UnknownHostException
122126 {
Original file line number Diff line number Diff line change 1919package org .neo4j .driver .internal .net ;
2020
2121import org .junit .Test ;
22- import org .neo4j .driver .internal .net .BoltServerAddress ;
22+
23+ import java .net .SocketAddress ;
2324
2425import static org .hamcrest .CoreMatchers .equalTo ;
25- import static org .junit .Assert .*;
26+ import static org .junit .Assert .assertNotSame ;
27+ import static org .junit .Assert .assertThat ;
2628
2729public class BoltServerAddressTest
2830{
@@ -38,4 +40,14 @@ public void portShouldUseDefaultIfNotSupplied()
3840 assertThat ( new BoltServerAddress ( "localhost" ).port (), equalTo ( BoltServerAddress .DEFAULT_PORT ) );
3941 }
4042
41- }
43+ @ Test
44+ public void shouldAlwaysResolveAddress ()
45+ {
46+ BoltServerAddress boltAddress = new BoltServerAddress ( "localhost" );
47+
48+ SocketAddress socketAddress1 = boltAddress .toSocketAddress ();
49+ SocketAddress socketAddress2 = boltAddress .toSocketAddress ();
50+
51+ assertNotSame ( socketAddress1 , socketAddress2 );
52+ }
53+ }
You can’t perform that action at this time.
0 commit comments