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()
103
103
return format ( "%s:%d" , host , port );
104
104
}
105
105
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
+ */
106
113
public SocketAddress toSocketAddress ()
107
114
{
108
- if (socketAddress == null )
109
- {
110
- socketAddress = new InetSocketAddress ( host , port );
111
- }
112
- return socketAddress ;
115
+ return new InetSocketAddress ( host , port );
113
116
}
114
117
115
118
/**
116
119
* Resolve the host name down to an IP address, if not already resolved.
117
120
*
118
121
* @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)
120
124
*/
121
125
public BoltServerAddress resolve () throws UnknownHostException
122
126
{
Original file line number Diff line number Diff line change 19
19
package org .neo4j .driver .internal .net ;
20
20
21
21
import org .junit .Test ;
22
- import org .neo4j .driver .internal .net .BoltServerAddress ;
22
+
23
+ import java .net .SocketAddress ;
23
24
24
25
import 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 ;
26
28
27
29
public class BoltServerAddressTest
28
30
{
@@ -38,4 +40,14 @@ public void portShouldUseDefaultIfNotSupplied()
38
40
assertThat ( new BoltServerAddress ( "localhost" ).port (), equalTo ( BoltServerAddress .DEFAULT_PORT ) );
39
41
}
40
42
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