Skip to content

Commit ba37580

Browse files
committed
refactor: clarify client route address override naming
1 parent 0413c53 commit ba37580

4 files changed

Lines changed: 51 additions & 32 deletions

File tree

core/src/main/java/com/datastax/oss/driver/api/core/config/ClientRouteProxy.java

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public final class ClientRouteProxy {
4242
private static final Pattern VALID_HOSTNAME_OR_IP = Pattern.compile("^[a-zA-Z0-9._:\\[\\]-]+$");
4343

4444
private final String connectionId;
45-
private final String connectionAddr;
45+
private final String connectionAddrOverride;
4646

4747
/**
4848
* Creates a new endpoint with the given connection ID and no connection address.
@@ -57,35 +57,35 @@ public ClientRouteProxy(@NonNull String connectionId) {
5757
* Creates a new endpoint with the given connection ID and connection address.
5858
*
5959
* @param connectionId the connection ID (must not be null).
60-
* @param connectionAddr the DNS name or IP address used to override the {@code address} column
61-
* from the {@code system.client_routes} table for the matching {@code connection_id} (may be
62-
* null). Must be a plain hostname or IP address without a port (e.g. {@code
60+
* @param connectionAddrOverride the DNS name or IP address used to override the {@code address}
61+
* column from the {@code system.client_routes} table for the matching {@code connection_id}
62+
* (may be null). Must be a plain hostname or IP address without a port (e.g. {@code
6363
* "my-cluster.example.com"} or {@code "10.0.1.5"}).
6464
*/
65-
public ClientRouteProxy(@NonNull String connectionId, @Nullable String connectionAddr) {
65+
public ClientRouteProxy(@NonNull String connectionId, @Nullable String connectionAddrOverride) {
6666
this.connectionId = Objects.requireNonNull(connectionId, "connectionId must not be null");
6767
if (connectionId.trim().isEmpty()) {
6868
throw new IllegalArgumentException("connectionId must not be empty");
6969
}
70-
if (connectionAddr != null) {
71-
if (connectionAddr.trim().isEmpty()) {
70+
if (connectionAddrOverride != null) {
71+
if (connectionAddrOverride.trim().isEmpty()) {
7272
throw new IllegalArgumentException(
73-
"connectionAddr must not be empty or blank when non-null");
73+
"connectionAddrOverride must not be empty or blank when non-null");
7474
}
75-
if (containsPort(connectionAddr)) {
75+
if (containsPort(connectionAddrOverride)) {
7676
throw new IllegalArgumentException(
77-
"connectionAddr must be a plain hostname or IP address without a port, got: "
78-
+ connectionAddr);
77+
"connectionAddrOverride must be a plain hostname or IP address without a port, got: "
78+
+ connectionAddrOverride);
7979
}
80-
if (!VALID_HOSTNAME_OR_IP.matcher(connectionAddr).matches()) {
80+
if (!VALID_HOSTNAME_OR_IP.matcher(connectionAddrOverride).matches()) {
8181
throw new IllegalArgumentException(
82-
"connectionAddr contains invalid characters "
82+
"connectionAddrOverride contains invalid characters "
8383
+ "(expected hostname or IP address with only alphanumeric characters, "
8484
+ "dots, hyphens, underscores, colons, or brackets): "
85-
+ connectionAddr);
85+
+ connectionAddrOverride);
8686
}
8787
}
88-
this.connectionAddr = connectionAddr;
88+
this.connectionAddrOverride = connectionAddrOverride;
8989
}
9090

9191
/**
@@ -124,10 +124,25 @@ public String getConnectionId() {
124124
* <p>This is a plain hostname or IP address (e.g. {@code "my-cluster.example.com"} or {@code
125125
* "10.0.1.5"}). When provided, the {@code address} column from the {@code system.client_routes}
126126
* table is overridden with this value for the matching {@code connection_id}.
127+
*
128+
* @deprecated use {@link ClientRouteProxy#getConnectionAddrOverride()} instead
127129
*/
128130
@Nullable
131+
@Deprecated
129132
public String getConnectionAddr() {
130-
return connectionAddr;
133+
return connectionAddrOverride;
134+
}
135+
136+
/**
137+
* Returns the connection address override for this endpoint, or null if not specified.
138+
*
139+
* <p>This is a plain hostname or IP address (e.g. {@code "my-cluster.example.com"} or {@code
140+
* "10.0.1.5"}). When provided, the {@code address} column from the {@code system.client_routes}
141+
* table is overridden with this value for the matching {@code connection_id}.
142+
*/
143+
@Nullable
144+
public String getConnectionAddrOverride() {
145+
return connectionAddrOverride;
131146
}
132147

133148
@Override
@@ -140,12 +155,12 @@ public boolean equals(Object o) {
140155
}
141156
ClientRouteProxy that = (ClientRouteProxy) o;
142157
return connectionId.equals(that.connectionId)
143-
&& Objects.equals(connectionAddr, that.connectionAddr);
158+
&& Objects.equals(connectionAddrOverride, that.connectionAddrOverride);
144159
}
145160

146161
@Override
147162
public int hashCode() {
148-
return Objects.hash(connectionId, connectionAddr);
163+
return Objects.hash(connectionId, connectionAddrOverride);
149164
}
150165

151166
@Override
@@ -154,7 +169,9 @@ public String toString() {
154169
+ "connectionId='"
155170
+ connectionId
156171
+ "'"
157-
+ (connectionAddr != null ? ", connectionAddr='" + connectionAddr + "'" : "")
172+
+ (connectionAddrOverride != null
173+
? ", connectionAddrOverride='" + connectionAddrOverride + "'"
174+
: "")
158175
+ "}";
159176
}
160177
}

core/src/main/java/com/datastax/oss/driver/internal/core/metadata/ClientRoutesTopologyMonitor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,11 @@ public ClientRoutesTopologyMonitor(
139139
this.connectionAddrOverrides =
140140
Collections.unmodifiableMap(
141141
config.getEndpoints().stream()
142-
.filter(ep -> ep.getConnectionAddr() != null)
142+
.filter(ep -> ep.getConnectionAddrOverride() != null)
143143
.collect(
144144
Collectors.toMap(
145-
ClientRouteProxy::getConnectionId, ClientRouteProxy::getConnectionAddr)));
145+
ClientRouteProxy::getConnectionId,
146+
ClientRouteProxy::getConnectionAddrOverride)));
146147
this.logPrefix = context.getSessionName();
147148
this.resolvedRoutesCache = new AtomicReference<>(Collections.emptyMap());
148149
this.useSSL = context.getSslEngineFactory().isPresent();

core/src/test/java/com/datastax/oss/driver/api/core/config/ClientRoutesConfigTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void should_build_config_with_single_endpoint() {
3636

3737
assertThat(config.getEndpoints()).hasSize(1);
3838
assertThat(config.getEndpoints().get(0).getConnectionId()).isEqualTo(connectionId);
39-
assertThat(config.getEndpoints().get(0).getConnectionAddr()).isEqualTo(connectionAddr);
39+
assertThat(config.getEndpoints().get(0).getConnectionAddrOverride()).isEqualTo(connectionAddr);
4040
assertThat(config.getTableName()).isEqualTo("system.client_routes");
4141
}
4242

@@ -80,7 +80,7 @@ public void should_create_endpoint_without_connection_address() {
8080
ClientRouteProxy endpoint = new ClientRouteProxy(connectionId);
8181

8282
assertThat(endpoint.getConnectionId()).isEqualTo(connectionId);
83-
assertThat(endpoint.getConnectionAddr()).isNull();
83+
assertThat(endpoint.getConnectionAddrOverride()).isNull();
8484
}
8585

8686
@Test
@@ -90,7 +90,7 @@ public void should_create_endpoint_with_connection_address() {
9090
ClientRouteProxy endpoint = new ClientRouteProxy(connectionId, connectionAddr);
9191

9292
assertThat(endpoint.getConnectionId()).isEqualTo(connectionId);
93-
assertThat(endpoint.getConnectionAddr()).isEqualTo(connectionAddr);
93+
assertThat(endpoint.getConnectionAddrOverride()).isEqualTo(connectionAddr);
9494
}
9595

9696
@Test
@@ -118,7 +118,7 @@ public void should_reject_blank_connection_id() {
118118
public void should_reject_blank_connection_addr() {
119119
assertThatThrownBy(() -> new ClientRouteProxy("conn-id-1", " "))
120120
.isInstanceOf(IllegalArgumentException.class)
121-
.hasMessageContaining("connectionAddr must not be empty");
121+
.hasMessageContaining("connectionAddrOverride must not be empty");
122122
}
123123

124124
@Test
@@ -220,20 +220,20 @@ public void should_reject_connection_addr_with_leading_colon_port() {
220220
@Test
221221
public void should_accept_plain_hostname_connection_addr() {
222222
ClientRouteProxy ep = new ClientRouteProxy("conn-id-1", "host.example.com");
223-
assertThat(ep.getConnectionAddr()).isEqualTo("host.example.com");
223+
assertThat(ep.getConnectionAddrOverride()).isEqualTo("host.example.com");
224224
}
225225

226226
@Test
227227
public void should_accept_ipv4_connection_addr() {
228228
ClientRouteProxy ep = new ClientRouteProxy("conn-id-1", "10.0.1.5");
229-
assertThat(ep.getConnectionAddr()).isEqualTo("10.0.1.5");
229+
assertThat(ep.getConnectionAddrOverride()).isEqualTo("10.0.1.5");
230230
}
231231

232232
@Test
233233
public void should_accept_bare_ipv6_connection_addr() {
234234
// Bare IPv6 contains multiple colons — should NOT be treated as host:port
235235
ClientRouteProxy ep = new ClientRouteProxy("conn-id-1", "::1");
236-
assertThat(ep.getConnectionAddr()).isEqualTo("::1");
236+
assertThat(ep.getConnectionAddrOverride()).isEqualTo("::1");
237237
}
238238

239239
@Test

core/src/test/java/com/datastax/oss/driver/internal/core/context/ClientRoutesConfigFromFileTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void should_parse_single_endpoint_without_addr() {
109109
assertThat(cfg.getEndpoints()).hasSize(1);
110110
ClientRouteProxy ep = cfg.getEndpoints().get(0);
111111
assertThat(ep.getConnectionId()).isEqualTo("11111111-1111-1111-1111-111111111111");
112-
assertThat(ep.getConnectionAddr()).isNull();
112+
assertThat(ep.getConnectionAddrOverride()).isNull();
113113
}
114114

115115
@Test
@@ -128,7 +128,7 @@ public void should_parse_single_endpoint_with_addr() {
128128
List<ClientRouteProxy> eps = cfg.getEndpoints();
129129
assertThat(eps).hasSize(1);
130130
assertThat(eps.get(0).getConnectionId()).isEqualTo("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa");
131-
assertThat(eps.get(0).getConnectionAddr()).isEqualTo("cluster.example.com");
131+
assertThat(eps.get(0).getConnectionAddrOverride()).isEqualTo("cluster.example.com");
132132
}
133133

134134
@Test
@@ -147,10 +147,11 @@ public void should_parse_multiple_endpoints() {
147147
assertThat(cfg.getEndpoints()).hasSize(2);
148148
assertThat(cfg.getEndpoints().get(0).getConnectionId())
149149
.isEqualTo("11111111-1111-1111-1111-111111111111");
150-
assertThat(cfg.getEndpoints().get(0).getConnectionAddr()).isEqualTo("node1.example.com");
150+
assertThat(cfg.getEndpoints().get(0).getConnectionAddrOverride())
151+
.isEqualTo("node1.example.com");
151152
assertThat(cfg.getEndpoints().get(1).getConnectionId())
152153
.isEqualTo("22222222-2222-2222-2222-222222222222");
153-
assertThat(cfg.getEndpoints().get(1).getConnectionAddr()).isNull();
154+
assertThat(cfg.getEndpoints().get(1).getConnectionAddrOverride()).isNull();
154155
}
155156

156157
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)