You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by rd...@apache.org on 2019/11/06 03:40:41 UTC

[tinkerpop] 01/01: Reverts TINKERPOP-2289 resolve ip address

This is an automated email from the ASF dual-hosted git repository.

rdale pushed a commit to branch revert_tinkerpop-2289
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit eaf39f434339122cd1974d8ef6a6f151568aa4d0
Author: Robert Dale <ro...@gmail.com>
AuthorDate: Tue Nov 5 22:39:40 2019 -0500

    Reverts TINKERPOP-2289 resolve ip address
---
 gremlin-driver/pom.xml                             | 18 ---------
 .../apache/tinkerpop/gremlin/driver/Cluster.java   | 24 ++++-------
 .../org/apache/tinkerpop/gremlin/driver/Host.java  |  3 +-
 .../apache/tinkerpop/gremlin/driver/HostTest.java  | 46 +---------------------
 4 files changed, 10 insertions(+), 81 deletions(-)

diff --git a/gremlin-driver/pom.xml b/gremlin-driver/pom.xml
index 870bf6b..1bb7566 100644
--- a/gremlin-driver/pom.xml
+++ b/gremlin-driver/pom.xml
@@ -104,24 +104,6 @@ limitations under the License.
             <artifactId>hamcrest-all</artifactId>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.powermock</groupId>
-            <artifactId>powermock-api-mockito</artifactId>
-            <version>1.6.2</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.powermock</groupId>
-            <artifactId>powermock-module-junit4</artifactId>
-            <version>1.6.2</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.powermock</groupId>
-            <artifactId>powermock-module-junit4-rule</artifactId>
-            <version>1.6.2</version>
-            <scope>test</scope>
-        </dependency>
     </dependencies>
 
     <build>
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java
index b424c5a..113f081 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java
@@ -54,7 +54,6 @@ import java.security.NoSuchAlgorithmException;
 import java.security.UnrecoverableKeyException;
 import java.security.cert.CertificateException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -965,21 +964,13 @@ public final class Cluster {
         }
 
         /**
-         * Adds an address representing a group of Gremlin Servers, which will be added to the list of servers a
-         * {@link Client} will try to contact to send requests to. The address should be parseable by
-         * {@code InetAddress#getAllByName(String)}. That's the only validation performed at this point.
-         * No connection to the hosts is attempted.
-         * <p/>
-         * Note that if the address argument is a hostname that resolves to multiple {@code INetAddress} objects that
-         * happen to point to the same physical Gremlin Server instance the driver will think that it has more hosts
-         * for it to send requests to than there are in reality. A common situation in which this issue may occur is
-         * when IPv6 addressing is present as {@code InetAddress#getAllByName(String)} will return both the IPv6 and
-         * the IPv4 addresses. In these cases, the issue can be resolved by simply using the IP address directly or
-         * setting the Java system property {@code -Djava.net.preferIPv4Stack=true}.
+         * Adds the address of a Gremlin Server to the list of servers a {@link Client} will try to contact to send
+         * requests to.  The address should be parseable by {@link InetAddress#getByName(String)}.  That's the only
+         * validation performed at this point.  No connection to the host is attempted.
          */
         public Builder addContactPoint(final String address) {
             try {
-                this.addresses.addAll(Arrays.asList(InetAddress.getAllByName(address)));
+                this.addresses.add(InetAddress.getByName(address));
                 return this;
             } catch (UnknownHostException e) {
                 throw new IllegalArgumentException(e.getMessage());
@@ -987,10 +978,9 @@ public final class Cluster {
         }
 
         /**
-         * Add one or more addresses representing groups of Gremlin Servers, which will be added to the list of
-         * servers a {@link Client} will try to contact to send requests to. The address should be parseable by
-         * {@link InetAddress#getByName(String)}. That's the only validation performed at this point.
-         * No connection to the host is attempted.
+         * Add one or more the addresses of a Gremlin Servers to the list of servers a {@link Client} will try to
+         * contact to send requests to.  The address should be parseable by {@link InetAddress#getByName(String)}.
+         * That's the only validation performed at this point.  No connection to the host is attempted.
          */
         public Builder addContactPoints(final String... addresses) {
             for (String address : addresses)
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Host.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Host.java
index 5fd2b40..e225365 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Host.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Host.java
@@ -46,7 +46,6 @@ public final class Host {
     ScheduledFuture<?> retryThread = null;
 
     Host(final InetSocketAddress address, final Cluster cluster) {
-        assert(!address.isUnresolved());
         this.cluster = cluster;
         this.address = address;
         this.hostUri = makeUriFromAddress(address, cluster.getPath(), cluster.connectionPoolSettings().enableSsl);
@@ -98,7 +97,7 @@ public final class Host {
     private static URI makeUriFromAddress(final InetSocketAddress addy, final String path, final boolean ssl) {
         try {
             final String scheme = ssl ? "wss" : "ws";
-            return new URI(scheme, null, addy.getAddress().getHostAddress(), addy.getPort(), path, null, null);
+            return new URI(scheme, null, addy.getHostName(), addy.getPort(), path, null, null);
         } catch (URISyntaxException use) {
             throw new RuntimeException(String.format("URI for host could not be constructed from: %s", addy), use);
         }
diff --git a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/HostTest.java b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/HostTest.java
index 321e843..2c20261 100644
--- a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/HostTest.java
+++ b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/HostTest.java
@@ -19,26 +19,15 @@
 package org.apache.tinkerpop.gremlin.driver;
 
 import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
 
-import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.URI;
-import java.net.UnknownHostException;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 
 /**
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
-@RunWith(PowerMockRunner.class)
 public class HostTest {
 
     @Test
@@ -46,7 +35,7 @@ public class HostTest {
         final InetSocketAddress addy = new InetSocketAddress("localhost", 8182);
         final Host host = new Host(addy, Cluster.open());
         final URI webSocketUri = host.getHostUri();
-        assertEquals("ws://" + addy.getAddress().getHostAddress() + ":8182/gremlin", webSocketUri.toString());
+        assertEquals("ws://localhost:8182/gremlin", webSocketUri.toString());
     }
 
     @Test
@@ -54,38 +43,7 @@ public class HostTest {
         final InetSocketAddress addy = new InetSocketAddress("localhost", 8183);
         final Host host = new Host(addy, Cluster.build().port(8183).path("/argh").create());
         final URI webSocketUri = host.getHostUri();
-        assertEquals("ws://" + addy.getAddress().getHostAddress() + ":8183/argh", webSocketUri.toString());
+        assertEquals("ws://localhost:8183/argh", webSocketUri.toString());
     }
 
-    @Test
-    @PrepareForTest(Cluster.Builder.class)
-    public void shouldFindAllHostsWithDeterministicAddress() throws Exception {
-        final String hostname = "test.tinkerpop.apache.org";
-        final Set<String> addresses = new HashSet<>(Arrays.asList("10.10.0.1", "10.10.0.2", "10.10.0.3"));
-        final InetAddress[] hosts = addresses.stream().map(addr -> inetAddress(hostname, addr)).toArray(InetAddress[]::new);
-
-        PowerMockito.mockStatic(InetAddress.class);
-        PowerMockito.when(InetAddress.getAllByName(hostname)).thenReturn(hosts);
-
-        final Cluster cluster = Cluster.build().addContactPoint(hostname).create();
-
-        cluster.init();
-
-        assertEquals(addresses.size(), cluster.allHosts().size());
-
-        cluster.allHosts().forEach(host -> {
-            final String uriHost = host.getHostUri().getHost();
-            final String address = host.getAddress().getAddress().getHostAddress();
-            assertEquals(address, uriHost);
-            assertTrue(addresses.contains(address));
-        });
-    }
-
-    private InetAddress inetAddress(final String hostname, final String address) {
-        try {
-            return InetAddress.getByAddress(hostname, InetAddress.getByName(address).getAddress());
-        } catch (UnknownHostException ex) {
-            throw new RuntimeException(ex);
-        }
-    }
 }