diff --git a/driver-core/src/main/java/com/datastax/driver/core/Cluster.java b/driver-core/src/main/java/com/datastax/driver/core/Cluster.java index bf8e02fd295..d6c5489f0f7 100644 --- a/driver-core/src/main/java/com/datastax/driver/core/Cluster.java +++ b/driver-core/src/main/java/com/datastax/driver/core/Cluster.java @@ -1406,7 +1406,7 @@ protected Builder withScyllaCloudConnectionConfig(ScyllaCloudConnectionConfig co Builder builder = withEndPointFactory( new ScyllaCloudSniEndPointFactory( - currentDatacenter.getNodeDomain(), proxyAddress.getPort())) + proxyAddress, currentDatacenter.getNodeDomain())) .withSSL( (config.getCurrentAuthInfo().isInsecureSkipTlsVerify() ? config.createBundle().getInsecureSSLOptions() @@ -1423,7 +1423,7 @@ protected Builder withScyllaCloudConnectionConfig(ScyllaCloudConnectionConfig co throw new IllegalStateException( "Can't use withCloudSecureConnectBundle if you've already called addContactPoint(s)"); } - builder.addContactPoint(new SniEndPoint(proxyAddress, proxyAddress.getHostName())); + builder.addContactPoint(new SniEndPoint(proxyAddress, currentDatacenter.getNodeDomain())); return builder; } catch (IOException e) { diff --git a/driver-core/src/main/java/com/datastax/driver/core/ScyllaCloudSniEndPointFactory.java b/driver-core/src/main/java/com/datastax/driver/core/ScyllaCloudSniEndPointFactory.java index a373dd9abe5..81a009b4a05 100644 --- a/driver-core/src/main/java/com/datastax/driver/core/ScyllaCloudSniEndPointFactory.java +++ b/driver-core/src/main/java/com/datastax/driver/core/ScyllaCloudSniEndPointFactory.java @@ -25,11 +25,12 @@ class ScyllaCloudSniEndPointFactory implements EndPointFactory { private final String nodeDomain; - private final int port; - public ScyllaCloudSniEndPointFactory(String nodeDomain, int port) { + private final InetSocketAddress proxy; + + public ScyllaCloudSniEndPointFactory(InetSocketAddress proxy, String nodeDomain) { + this.proxy = proxy; this.nodeDomain = nodeDomain; - this.port = port; } @Override @@ -39,7 +40,6 @@ public void init(Cluster cluster) {} public EndPoint create(Row row) { UUID host_id = row.getUUID("host_id"); String sni = host_id.toString() + "." + nodeDomain; - InetSocketAddress proxy = InetSocketAddress.createUnresolved(sni, port); return new SniEndPoint(proxy, sni); } } diff --git a/driver-core/src/test/java/com/datastax/driver/core/CCMTestsSupport.java b/driver-core/src/test/java/com/datastax/driver/core/CCMTestsSupport.java index 3b0f0e9f88d..6200fc2338b 100644 --- a/driver-core/src/test/java/com/datastax/driver/core/CCMTestsSupport.java +++ b/driver-core/src/test/java/com/datastax/driver/core/CCMTestsSupport.java @@ -24,7 +24,6 @@ import static com.datastax.driver.core.CreateCCM.TestMode.PER_CLASS; import static com.datastax.driver.core.CreateCCM.TestMode.PER_METHOD; import static com.datastax.driver.core.TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT; -import static com.datastax.driver.core.TestUtils.addressOfNode; import static com.datastax.driver.core.TestUtils.executeNoFail; import static com.datastax.driver.core.TestUtils.ipOfNode; import static org.assertj.core.api.Assertions.fail; @@ -40,7 +39,6 @@ import com.google.common.util.concurrent.Uninterruptibles; import java.io.Closeable; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Constructor; @@ -778,26 +776,7 @@ public Cluster.Builder createClusterBuilderScyllaCloud() throws IOException { File clusterFile = new File(ccmdir, ccm.getClusterName()); File yamlFile = new File(clusterFile, "config_data.yaml"); - final ScyllaCloudConnectionConfig cloudConfig = - ScyllaCloudConnectionConfig.fromInputStream(new FileInputStream(yamlFile)); - - builder.withScyllaCloudConnectionConfig(cloudConfig); - builder.withEndPointFactory( - new MockSniEndPointFactory( - InetSocketAddress.createUnresolved( - addressOfNode(1).getHostAddress(), - cloudConfig.getCurrentDatacenter().getServer().getPort()), - builder.getConfiguration().getPolicies().getEndPointFactory())); - builder.addContactPoint( - new SniEndPoint( - InetSocketAddress.createUnresolved( - addressOfNode(1).getHostAddress(), - cloudConfig.getCurrentDatacenter().getServer().getPort()), - cloudConfig.getCurrentDatacenter().getServer().getHostName())); - - builder - .withCodecRegistry(new CodecRegistry()) - .withPort(cloudConfig.getCurrentDatacenter().getServer().getPort()); + builder.withScyllaCloudConnectionConfig(yamlFile); return builder; } diff --git a/driver-core/src/test/java/com/datastax/driver/core/MockSniEndPointFactory.java b/driver-core/src/test/java/com/datastax/driver/core/MockSniEndPointFactory.java deleted file mode 100644 index 9ac70436820..00000000000 --- a/driver-core/src/test/java/com/datastax/driver/core/MockSniEndPointFactory.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2022 ScyllaDB - * - * 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 com.datastax.driver.core; - -import java.net.InetSocketAddress; - -class MockSniEndPointFactory implements EndPointFactory { - private final InetSocketAddress proxyAddress; - private final EndPointFactory childSniFactory; - - public MockSniEndPointFactory(InetSocketAddress proxyAddress, EndPointFactory childSniFactory) { - this.proxyAddress = proxyAddress; - this.childSniFactory = childSniFactory; - } - - @Override - public void init(Cluster cluster) { - childSniFactory.init(cluster); - } - - @Override - public EndPoint create(Row peersRow) { - SniEndPoint originalEndPoint = (SniEndPoint) childSniFactory.create(peersRow); - return new SniEndPoint(proxyAddress, originalEndPoint.getServerName()); - } -}