You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2019/09/20 18:43:05 UTC
[tinkerpop] 01/01: Revert "Replace TimeoutException with
NoHostAvailableException"
This is an automated email from the ASF dual-hosted git repository.
spmallette pushed a commit to branch TINKERPOP-2132-revert
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 269307698d4222f8f1acc308ef141bcfa87f00ff
Author: Stephen Mallette <sp...@genoprime.com>
AuthorDate: Fri Sep 20 14:42:32 2019 -0400
Revert "Replace TimeoutException with NoHostAvailableException"
This reverts commit 52d604d83ac7ab853db5e17cb74913685693420c.
---
.../apache/tinkerpop/gremlin/driver/Client.java | 5 +-
.../tinkerpop/gremlin/driver/Connection.java | 23 -------
.../tinkerpop/gremlin/driver/ConnectionPool.java | 16 +++--
.../apache/tinkerpop/gremlin/driver/Handler.java | 45 ++-----------
.../driver/exception/NoHostAvailableException.java | 31 ---------
.../server/handler/SaslAuthenticationHandler.java | 15 ++---
.../gremlin/server/GremlinDriverIntegrateTest.java | 11 ++--
.../server/GremlinServerAuthIntegrateTest.java | 66 ++-----------------
.../server/GremlinServerAuthKrb5IntegrateTest.java | 76 ++--------------------
.../gremlin/server/GremlinServerIntegrateTest.java | 15 ++---
...tractGremlinServerChannelizerIntegrateTest.java | 13 ++++
11 files changed, 60 insertions(+), 256 deletions(-)
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java
index a892d69..fe7fe61 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java
@@ -19,7 +19,6 @@
package org.apache.tinkerpop.gremlin.driver;
import org.apache.tinkerpop.gremlin.driver.exception.ConnectionException;
-import org.apache.tinkerpop.gremlin.driver.exception.NoHostAvailableException;
import org.apache.tinkerpop.gremlin.driver.message.RequestMessage;
import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
@@ -508,7 +507,7 @@ public abstract class Client {
// you can get no possible hosts in more than a few situations. perhaps the servers are just all down.
// or perhaps the client is not configured properly (disables ssl when ssl is enabled on the server).
if (!possibleHosts.hasNext())
- throw new NoHostAvailableException();
+ throw new TimeoutException("Timed out while waiting for an available host - check the client configuration and connectivity to the server if this message persists");
final Host bestHost = possibleHosts.next();
final ConnectionPool pool = hostConnectionPools.get(bestHost);
@@ -721,7 +720,7 @@ public abstract class Client {
// chooses an available host at random
final List<Host> hosts = cluster.allHosts()
.stream().filter(Host::isAvailable).collect(Collectors.toList());
- if (hosts.isEmpty()) new NoHostAvailableException();
+ if (hosts.isEmpty()) throw new IllegalStateException("No available host in the cluster");
Collections.shuffle(hosts);
final Host host = hosts.get(0);
connectionPool = new ConnectionPool(host, this, Optional.of(1), Optional.of(1));
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Connection.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Connection.java
index 8c51b53..e700d49 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Connection.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Connection.java
@@ -19,9 +19,7 @@
package org.apache.tinkerpop.gremlin.driver;
import io.netty.handler.codec.CodecException;
-import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.tinkerpop.gremlin.driver.exception.ConnectionException;
-import org.apache.tinkerpop.gremlin.driver.exception.ResponseException;
import org.apache.tinkerpop.gremlin.driver.message.RequestMessage;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
@@ -119,27 +117,6 @@ final class Connection {
logger.debug("Error opening connection on {}", uri);
throw new ConnectionException(uri, "Could not open connection", ie);
}
-
- // Trigger authentication early to avoid unauthorized response to concurrent requests from an
- // authenticating client.
- validateConnection();
- }
-
- /**
- * Sends a message to determine if the host is available. The message sent is determined by the
- * {@link Cluster#validationRequest()}.
- */
- void validateConnection() throws ConnectionException {
- try {
- final CompletableFuture<ResultSet> future = new CompletableFuture<>();
- write(cluster.validationRequest().create(), future);
- future.get().all().get();
- } catch (Exception ex) {
- final Throwable rootCause = ExceptionUtils.getRootCause(ex);
- if (!(rootCause instanceof ResponseException)) {
- throw new ConnectionException(uri, "Validation failed", rootCause);
- }
- }
}
/**
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ConnectionPool.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ConnectionPool.java
index 2ba4cca..332731e 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ConnectionPool.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ConnectionPool.java
@@ -19,6 +19,7 @@
package org.apache.tinkerpop.gremlin.driver;
import org.apache.tinkerpop.gremlin.driver.exception.ConnectionException;
+import org.apache.tinkerpop.gremlin.driver.message.RequestMessage;
import org.apache.tinkerpop.gremlin.util.TimeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -96,9 +97,7 @@ final class ConnectionPool {
} catch (ConnectionException ce) {
// ok if we don't get it initialized here - when a request is attempted in a connection from the
// pool it will try to create new connections as needed.
- if (logger.isErrorEnabled()) {
- logger.error(String.format("Could not initialize connections in pool for %s - pool size at %d", host, this.connections.size()), ce);
- }
+ logger.debug("Could not initialize connections in pool for {} - pool size at {}", host, this.connections.size());
considerHostUnavailable();
}
@@ -300,7 +299,7 @@ final class ConnectionPool {
try {
connections.add(new Connection(host.getHostUri(), this, settings().maxInProcessPerConnection));
} catch (ConnectionException ce) {
- logger.error("Connections were under max, but there was an error creating the connection.", ce);
+ logger.debug("Connections were under max, but there was an error creating the connection.", ce);
open.decrementAndGet();
considerHostUnavailable();
return false;
@@ -379,7 +378,7 @@ final class ConnectionPool {
logger.debug("Continue to wait for connection on {} if {} > 0", host, remaining);
} while (remaining > 0);
- logger.error("Timed-out ({} {}) waiting for connection on {} - possibly unavailable", timeout, unit, host);
+ logger.debug("Timed-out waiting for connection on {} - possibly unavailable", host);
// if we timeout borrowing a connection that might mean the host is dead (or the timeout was super short).
// either way supply a function to reconnect
@@ -388,7 +387,7 @@ final class ConnectionPool {
throw new TimeoutException("Timed-out waiting for connection on " + host + " - possibly unavailable");
}
- void considerHostUnavailable() {
+ public void considerHostUnavailable() {
// called when a connection is "dead" due to a non-recoverable error.
host.makeUnavailable(this::tryReconnect);
@@ -409,7 +408,10 @@ final class ConnectionPool {
Connection connection = null;
try {
connection = borrowConnection(cluster.connectionPoolSettings().maxWaitForConnection, TimeUnit.MILLISECONDS);
- connection.validateConnection();
+ final RequestMessage ping = client.buildMessage(cluster.validationRequest()).create();
+ final CompletableFuture<ResultSet> f = new CompletableFuture<>();
+ connection.write(ping, f);
+ f.get().all().get();
// host is reconnected and a connection is now available
this.cluster.loadBalancingStrategy().onAvailable(h);
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Handler.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Handler.java
index 18655ce..7b12890 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Handler.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Handler.java
@@ -30,7 +30,6 @@ import io.netty.util.AttributeKey;
import io.netty.util.ReferenceCountUtil;
import org.apache.tinkerpop.gremlin.driver.ser.SerializationException;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
-import org.ietf.jgss.GSSException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,7 +53,6 @@ import javax.security.auth.login.LoginException;
import javax.security.sasl.Sasl;
import javax.security.sasl.SaslClient;
import javax.security.sasl.SaslException;
-import javax.xml.ws.Response;
/**
* Holder for internal handler classes used in constructing the channel pipeline.
@@ -84,29 +82,15 @@ final class Handler {
@Override
protected void channelRead0(final ChannelHandlerContext channelHandlerContext, final ResponseMessage response) throws Exception {
- // We are only interested in AUTHENTICATE or UNAUTHORIZED responses here. Everything else can
- // get passed down the pipeline.
- if (response.getStatus().getCode() == ResponseStatusCode.UNAUTHORIZED)
- channelHandlerContext.attr(saslClientKey).set(null);
-
+ // We are only interested in AUTHENTICATE responses here. Everything else can
+ // get passed down the pipeline
if (response.getStatus().getCode() == ResponseStatusCode.AUTHENTICATE) {
final Attribute<SaslClient> saslClient = channelHandlerContext.attr(saslClientKey);
final Attribute<Subject> subject = channelHandlerContext.attr(subjectKey);
final RequestMessage.Builder messageBuilder = RequestMessage.build(Tokens.OPS_AUTHENTICATION);
-
// First time through we don't have a sasl client
if (saslClient.get() == null) {
- try {
- subject.set(login());
- } catch (LoginException le) {
- // prevent the client side LoginException from bubbling up since Connection.validate() swallows
- // the LoginException and doesn't give feedback to the user.
- final ResponseMessage clientSideError = ResponseMessage.build(response.getRequestId())
- .code(ResponseStatusCode.FORBIDDEN).statusMessage(le.getMessage()).create();
- channelHandlerContext.fireChannelRead(clientSideError);
- return;
- }
-
+ subject.set(login());
try {
saslClient.set(saslClient(getHostName(channelHandlerContext)));
} catch (SaslException saslException) {
@@ -121,26 +105,9 @@ final class Handler {
return;
}
- try {
- messageBuilder.addArg(Tokens.ARGS_SASL_MECHANISM, getMechanism());
- messageBuilder.addArg(Tokens.ARGS_SASL, saslClient.get().hasInitialResponse() ?
- BASE64_ENCODER.encodeToString(evaluateChallenge(subject, saslClient, NULL_CHALLENGE)) : null);
- } catch (SaslException saslException) {
- saslClient.set(null);
-
- // Build message from SASL and the underlying GSSException if there is one. Perhaps we
- // shouldn't include the GSSException message and keep that for the server, but past versions
- // have leaked this so for now we'll maintain it
- String errorMessage = saslException.getMessage();
- final Throwable cause = saslException.getCause();
- if (cause instanceof GSSException)
- errorMessage = errorMessage + " - " + cause.getMessage();
-
- final ResponseMessage clientSideError = ResponseMessage.build(response.getRequestId())
- .code(ResponseStatusCode.FORBIDDEN).statusMessage(errorMessage).create();
- channelHandlerContext.fireChannelRead(clientSideError);
- return;
- }
+ messageBuilder.addArg(Tokens.ARGS_SASL_MECHANISM, getMechanism());
+ messageBuilder.addArg(Tokens.ARGS_SASL, saslClient.get().hasInitialResponse() ?
+ BASE64_ENCODER.encodeToString(evaluateChallenge(subject, saslClient, NULL_CHALLENGE)) : null);
} else {
// the server sends base64 encoded sasl as well as the byte array. the byte array will eventually be
// phased out, but is present now for backward compatibility in 3.2.x
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/exception/NoHostAvailableException.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/exception/NoHostAvailableException.java
deleted file mode 100644
index e8b3b87..0000000
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/exception/NoHostAvailableException.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.tinkerpop.gremlin.driver.exception;
-
-public class NoHostAvailableException extends RuntimeException {
-
- public NoHostAvailableException() {
- super("All hosts are considered unavailable due to previous exceptions. Check the error log to find the actual reason.");
- }
-
- @Override
- public synchronized Throwable fillInStackTrace() {
- return this;
- }
-}
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/SaslAuthenticationHandler.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/SaslAuthenticationHandler.java
index 788da23..ed3ddc9 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/SaslAuthenticationHandler.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/SaslAuthenticationHandler.java
@@ -21,6 +21,8 @@ package org.apache.tinkerpop.gremlin.server.handler;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.handler.codec.base64.Base64Decoder;
import io.netty.util.Attribute;
import java.net.InetAddress;
@@ -34,6 +36,7 @@ import org.apache.tinkerpop.gremlin.driver.Tokens;
import org.apache.tinkerpop.gremlin.driver.message.RequestMessage;
import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage;
import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode;
+import org.apache.tinkerpop.gremlin.server.Context;
import org.apache.tinkerpop.gremlin.server.GremlinServer;
import org.apache.tinkerpop.gremlin.server.Settings;
import org.apache.tinkerpop.gremlin.server.auth.AuthenticatedUser;
@@ -141,14 +144,10 @@ public class SaslAuthenticationHandler extends AbstractAuthenticationHandler {
ctx.writeAndFlush(error);
}
} else {
- // the authenticator has been set for the context, but for some reason the client isn't sending
- // the required keys to complete the handshake. this could be related to an initial failure on
- // the client side with the first authentication process so just fire more authentication
- // challenges at it.
- request.set(requestMessage);
- final ResponseMessage authenticate = ResponseMessage.build(requestMessage)
- .code(ResponseStatusCode.AUTHENTICATE).create();
- ctx.writeAndFlush(authenticate);
+ final ResponseMessage error = ResponseMessage.build(requestMessage)
+ .statusMessage("Failed to authenticate")
+ .code(ResponseStatusCode.UNAUTHORIZED).create();
+ ctx.writeAndFlush(error);
}
}
}
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
index 224f0ca..817b8a6 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
@@ -26,7 +26,6 @@ import org.apache.tinkerpop.gremlin.driver.Client;
import org.apache.tinkerpop.gremlin.driver.Cluster;
import org.apache.tinkerpop.gremlin.driver.Result;
import org.apache.tinkerpop.gremlin.driver.ResultSet;
-import org.apache.tinkerpop.gremlin.driver.exception.NoHostAvailableException;
import org.apache.tinkerpop.gremlin.driver.exception.ResponseException;
import org.apache.tinkerpop.gremlin.driver.handler.WebSocketClientHandler;
import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode;
@@ -67,6 +66,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
@@ -323,7 +323,7 @@ public class GremlinDriverIntegrateTest extends AbstractGremlinServerIntegration
fail("Should not have gone through because the server is not running");
} catch (Exception i) {
final Throwable root = ExceptionUtils.getRootCause(i);
- assertThat(root, instanceOf(NoHostAvailableException.class));
+ assertThat(root, instanceOf(TimeoutException.class));
}
startServer();
@@ -357,7 +357,7 @@ public class GremlinDriverIntegrateTest extends AbstractGremlinServerIntegration
fail("Should not have gone through because the server is not running");
} catch (Exception i) {
final Throwable root = ExceptionUtils.getRootCause(i);
- assertThat(root, instanceOf(NoHostAvailableException.class));
+ assertThat(root, instanceOf(TimeoutException.class));
}
startServer();
@@ -938,8 +938,7 @@ public class GremlinDriverIntegrateTest extends AbstractGremlinServerIntegration
@Test
public void shouldFailClientSideWithTooLargeAResponse() {
- final int maxContentLength = 128;
- final Cluster cluster = TestClientFactory.build().maxContentLength(maxContentLength).create();
+ final Cluster cluster = TestClientFactory.build().maxContentLength(1).create();
final Client client = cluster.connect();
try {
@@ -948,7 +947,7 @@ public class GremlinDriverIntegrateTest extends AbstractGremlinServerIntegration
fail("Should throw an exception.");
} catch (Exception re) {
final Throwable root = ExceptionUtils.getRootCause(re);
- assertTrue(root.getMessage().equals("Max frame length of " + maxContentLength + " has been exceeded."));
+ assertTrue(root.getMessage().equals("Max frame length of 1 has been exceeded."));
} finally {
cluster.close();
}
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthIntegrateTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthIntegrateTest.java
index 86f2508..0ca73a5 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthIntegrateTest.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthIntegrateTest.java
@@ -21,30 +21,22 @@ package org.apache.tinkerpop.gremlin.server;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.tinkerpop.gremlin.driver.Client;
import org.apache.tinkerpop.gremlin.driver.Cluster;
-import org.apache.tinkerpop.gremlin.driver.exception.NoHostAvailableException;
import org.apache.tinkerpop.gremlin.driver.exception.ResponseException;
-import org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection;
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.server.auth.SimpleAuthenticator;
import org.ietf.jgss.GSSException;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.junit.Test;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeoutException;
import org.apache.tinkerpop.gremlin.driver.ser.Serializers;
-import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
+import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.AnyOf.anyOf;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
@@ -87,54 +79,6 @@ public class GremlinServerAuthIntegrateTest extends AbstractGremlinServerIntegra
}
@Test
- public void shouldAuthenticateTraversalWithThreads() throws Exception {
- final Cluster cluster = TestClientFactory.build()
- .nioPoolSize(1).credentials("stephen", "password").create();
- final GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using(cluster, "gmodern"));
-
- final ExecutorService executor = Executors.newFixedThreadPool(4);
- final Callable<Long> countTraversalJob = () -> g.V().both().both().count().next();
- final List<Future<Long>> results = executor.invokeAll(Collections.nCopies(100, countTraversalJob));
-
- assertEquals(100, results.size());
- for (int ix = 0; ix < results.size(); ix++) {
- try {
- assertEquals(30L, results.get(ix).get(1000, TimeUnit.MILLISECONDS).longValue());
- } catch (Exception ex) {
- // failure but shouldn't have
- cluster.close();
- fail("Exception halted assertions - " + ex.getMessage());
- }
- }
-
- cluster.close();
- }
-
- @Test
- public void shouldAuthenticateScriptWithThreads() throws Exception {
- final Cluster cluster = TestClientFactory.build()
- .nioPoolSize(1).credentials("stephen", "password").create();
- final Client client = cluster.connect();
-
- final ExecutorService executor = Executors.newFixedThreadPool(4);
- final Callable<Long> countTraversalJob = () -> client.submit("gmodern.V().both().both().count()").all().get().get(0).getLong();
- final List<Future<Long>> results = executor.invokeAll(Collections.nCopies(100, countTraversalJob));
-
- assertEquals(100, results.size());
- for (int ix = 0; ix < results.size(); ix++) {
- try {
- assertEquals(30L, results.get(ix).get(1000, TimeUnit.MILLISECONDS).longValue());
- } catch (Exception ex) {
- // failure but shouldn't have
- cluster.close();
- fail("Exception halted assertions - " + ex.getMessage());
- }
- }
-
- cluster.close();
- }
-
- @Test
public void shouldFailIfSslEnabledOnServerButNotClient() throws Exception {
final Cluster cluster = TestClientFactory.open();
final Client client = cluster.connect();
@@ -144,7 +88,8 @@ public class GremlinServerAuthIntegrateTest extends AbstractGremlinServerIntegra
fail("This should not succeed as the client did not enable SSL");
} catch(Exception ex) {
final Throwable root = ExceptionUtils.getRootCause(ex);
- assertEquals(NoHostAvailableException.class, root.getClass());
+ assertEquals(TimeoutException.class, root.getClass());
+ assertThat(root.getMessage(), startsWith("Timed out while waiting for an available host"));
} finally {
cluster.close();
}
@@ -180,8 +125,7 @@ public class GremlinServerAuthIntegrateTest extends AbstractGremlinServerIntegra
final Throwable root = ExceptionUtils.getRootCause(ex);
// depending on the configuration of the system environment you might get either of these
- assertThat(root, anyOf(instanceOf(GSSException.class), instanceOf(ResponseException.class),
- instanceOf(NoHostAvailableException.class)));
+ assertThat(root, anyOf(instanceOf(GSSException.class), instanceOf(ResponseException.class)));
} finally {
cluster.close();
}
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthKrb5IntegrateTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthKrb5IntegrateTest.java
index 7205c7b..29dab88 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthKrb5IntegrateTest.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthKrb5IntegrateTest.java
@@ -23,33 +23,24 @@ import org.apache.tinkerpop.gremlin.driver.Client;
import org.apache.tinkerpop.gremlin.driver.Cluster;
import org.apache.tinkerpop.gremlin.driver.MessageSerializer;
import org.apache.tinkerpop.gremlin.driver.exception.ResponseException;
-import org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection;
import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode;
import org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0;
import org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0;
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.server.auth.Krb5Authenticator;
+import org.ietf.jgss.GSSException;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.LoggerFactory;
import java.io.File;
-import java.util.Collections;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
import java.util.concurrent.ExecutionException;
+import javax.security.auth.login.LoginException;
+import java.util.concurrent.TimeoutException;
-import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
-import static org.hamcrest.core.IsInstanceOf.instanceOf;
-import static org.hamcrest.core.StringContains.containsString;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
@@ -96,7 +87,6 @@ public class GremlinServerAuthKrb5IntegrateTest extends AbstractGremlinServerInt
final String nameOfTest = name.getMethodName();
switch (nameOfTest) {
- case "shouldAuthenticateWithThreads":
case "shouldAuthenticateWithDefaults":
case "shouldFailWithoutClientJaasEntry":
case "shouldFailWithoutClientTicketCache":
@@ -128,59 +118,6 @@ public class GremlinServerAuthKrb5IntegrateTest extends AbstractGremlinServerInt
}
@Test
- public void shouldAuthenticateTraversalWithThreads() throws Exception {
- final Cluster cluster = TestClientFactory.build()
- .nioPoolSize(1)
- .jaasEntry(TESTCONSOLE)
- .protocol(kdcServer.serverPrincipalName).addContactPoint(kdcServer.hostname).create();
- final GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using(cluster, "gmodern"));
-
- final ExecutorService executor = Executors.newFixedThreadPool(4);
- final Callable<Long> countTraversalJob = () -> g.V().both().both().count().next();
- final List<Future<Long>> results = executor.invokeAll(Collections.nCopies(100, countTraversalJob));
-
- assertEquals(100, results.size());
- for (int ix = 0; ix < results.size(); ix++) {
- try {
- assertEquals(30L, results.get(ix).get(1000, TimeUnit.MILLISECONDS).longValue());
- } catch (Exception ex) {
- // failure but shouldn't have
- cluster.close();
- fail("Exception halted assertions - " + ex.getMessage());
- }
- }
-
- cluster.close();
- }
-
- @Test
- public void shouldAuthenticateScriptWithThreads() throws Exception {
- final Cluster cluster = TestClientFactory.build()
- .nioPoolSize(1)
- .jaasEntry(TESTCONSOLE)
- .protocol(kdcServer.serverPrincipalName).addContactPoint(kdcServer.hostname).create();
- final Client client = cluster.connect();
-
- final ExecutorService executor = Executors.newFixedThreadPool(4);
- final Callable<Long> countTraversalJob = () -> client.submit("gmodern.V().both().both().count()").all().get().get(0).getLong();
- final List<Future<Long>> results = executor.invokeAll(Collections.nCopies(100, countTraversalJob));
-
- assertEquals(100, results.size());
- for (int ix = 0; ix < results.size(); ix++) {
- try {
- assertEquals(30L, results.get(ix).get(1000, TimeUnit.MILLISECONDS).longValue());
- } catch (Exception ex) {
- // failure but shouldn't have
- cluster.close();
- fail("Exception halted assertions - " + ex.getMessage());
- }
- }
-
- cluster.close();
- }
-
-
- @Test
public void shouldAuthenticateWithDefaults() throws Exception {
final Cluster cluster = TestClientFactory.build().jaasEntry(TESTCONSOLE)
.protocol(kdcServer.serverPrincipalName).addContactPoint(kdcServer.hostname).create();
@@ -198,8 +135,7 @@ public class GremlinServerAuthKrb5IntegrateTest extends AbstractGremlinServerInt
fail("This should not succeed as the client config does not contain a JaasEntry");
} catch(Exception ex) {
final Throwable root = ExceptionUtils.getRootCause(ex);
- assertThat(root, instanceOf(ResponseException.class));
- assertThat(root.getMessage(), containsString("Failed to find any Kerberos tgt"));
+ assertTrue(root instanceof ResponseException || root instanceof GSSException);
} finally {
cluster.close();
}
@@ -215,7 +151,7 @@ public class GremlinServerAuthKrb5IntegrateTest extends AbstractGremlinServerInt
fail("This should not succeed as the client config does not contain a valid ticket cache");
} catch(Exception ex) {
final Throwable root = ExceptionUtils.getRootCause(ex);
- assertThat(root, instanceOf(ResponseException.class));
+ assertEquals(LoginException.class, root.getClass());
} finally {
cluster.close();
}
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
index a8e7b3e..2887a6f 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
@@ -35,7 +35,6 @@ import org.apache.tinkerpop.gremlin.driver.Cluster;
import org.apache.tinkerpop.gremlin.driver.Result;
import org.apache.tinkerpop.gremlin.driver.ResultSet;
import org.apache.tinkerpop.gremlin.driver.Tokens;
-import org.apache.tinkerpop.gremlin.driver.exception.NoHostAvailableException;
import org.apache.tinkerpop.gremlin.driver.exception.ResponseException;
import org.apache.tinkerpop.gremlin.driver.message.RequestMessage;
import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage;
@@ -624,7 +623,7 @@ public class GremlinServerIntegrateTest extends AbstractGremlinServerIntegration
fail("Should throw exception because ssl is enabled on the server but not on client");
} catch(Exception x) {
final Throwable root = ExceptionUtils.getRootCause(x);
- assertThat(root, instanceOf(NoHostAvailableException.class));
+ assertThat(root, instanceOf(TimeoutException.class));
} finally {
cluster.close();
}
@@ -654,7 +653,7 @@ public class GremlinServerIntegrateTest extends AbstractGremlinServerIntegration
fail("Should throw exception because ssl client auth is enabled on the server but client does not have a cert");
} catch(Exception x) {
final Throwable root = ExceptionUtils.getRootCause(x);
- assertThat(root, instanceOf(NoHostAvailableException.class));
+ assertThat(root, instanceOf(TimeoutException.class));
} finally {
cluster.close();
}
@@ -672,7 +671,7 @@ public class GremlinServerIntegrateTest extends AbstractGremlinServerIntegration
fail("Should throw exception because ssl client auth is enabled on the server but does not trust client's cert");
} catch(Exception x) {
final Throwable root = ExceptionUtils.getRootCause(x);
- assertThat(root, instanceOf(NoHostAvailableException.class));
+ assertThat(root, instanceOf(TimeoutException.class));
} finally {
cluster.close();
}
@@ -715,7 +714,7 @@ public class GremlinServerIntegrateTest extends AbstractGremlinServerIntegration
fail("Should throw exception because ssl client auth is enabled on the server but client does not have a cert");
} catch (Exception x) {
final Throwable root = ExceptionUtils.getRootCause(x);
- assertThat(root, instanceOf(NoHostAvailableException.class));
+ assertThat(root, instanceOf(TimeoutException.class));
} finally {
cluster.close();
}
@@ -732,7 +731,7 @@ public class GremlinServerIntegrateTest extends AbstractGremlinServerIntegration
fail("Should throw exception because ssl client auth is enabled on the server but does not trust client's cert");
} catch (Exception x) {
final Throwable root = ExceptionUtils.getRootCause(x);
- assertThat(root, instanceOf(NoHostAvailableException.class));
+ assertThat(root, instanceOf(TimeoutException.class));
} finally {
cluster.close();
}
@@ -749,7 +748,7 @@ public class GremlinServerIntegrateTest extends AbstractGremlinServerIntegration
fail("Should throw exception because ssl client requires TLSv1.2 whereas server supports only TLSv1.1");
} catch (Exception x) {
final Throwable root = ExceptionUtils.getRootCause(x);
- assertThat(root, instanceOf(NoHostAvailableException.class));
+ assertThat(root, instanceOf(TimeoutException.class));
} finally {
cluster.close();
}
@@ -766,7 +765,7 @@ public class GremlinServerIntegrateTest extends AbstractGremlinServerIntegration
fail("Should throw exception because ssl client requires TLSv1.2 whereas server supports only TLSv1.1");
} catch (Exception x) {
final Throwable root = ExceptionUtils.getRootCause(x);
- assertThat(root, instanceOf(NoHostAvailableException.class));
+ assertThat(root, instanceOf(TimeoutException.class));
} finally {
cluster.close();
}
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/channel/AbstractGremlinServerChannelizerIntegrateTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/channel/AbstractGremlinServerChannelizerIntegrateTest.java
index 3c0b420..d68d890 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/channel/AbstractGremlinServerChannelizerIntegrateTest.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/channel/AbstractGremlinServerChannelizerIntegrateTest.java
@@ -21,14 +21,18 @@ package org.apache.tinkerpop.gremlin.server.channel;
import org.apache.tinkerpop.gremlin.driver.AuthProperties;
import org.apache.tinkerpop.gremlin.driver.Client;
import org.apache.tinkerpop.gremlin.driver.Cluster;
+import org.apache.tinkerpop.gremlin.driver.Client;
+import org.apache.tinkerpop.gremlin.driver.simple.SimpleClient;
import org.apache.tinkerpop.gremlin.driver.Channelizer;
import org.apache.tinkerpop.gremlin.server.AbstractGremlinServerIntegrationTest;
+import org.apache.tinkerpop.gremlin.server.channel.WsAndHttpChannelizer;
import org.apache.tinkerpop.gremlin.server.Settings;
import org.apache.tinkerpop.gremlin.server.TestClientFactory;
import org.apache.http.Consts;
import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
@@ -36,6 +40,7 @@ import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.ssl.AllowAllHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLContextBuilder;
+import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
@@ -44,11 +49,19 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.util.EntityUtils;
import org.apache.tinkerpop.shaded.jackson.databind.JsonNode;
import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.rules.ExternalResource;
+import java.io.File;
+import java.io.InputStream;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Base64;
+import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;