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 2021/04/29 13:55:18 UTC

[tinkerpop] branch master updated: Replaced blocking calls on the test client with timeouts.

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

spmallette pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


The following commit(s) were added to refs/heads/master by this push:
     new e71a7a9  Replaced blocking calls on the test client with timeouts.
e71a7a9 is described below

commit e71a7a9b68c318f54c17961c0c79828d7bbaff04
Author: Stephen Mallette <st...@amazon.com>
AuthorDate: Thu Apr 29 09:54:04 2021 -0400

    Replaced blocking calls on the test client with timeouts.
    
    Might make it easier to identify problems in Travis if a test hangs related to test client usage. CTR
---
 .../gremlin/driver/simple/AbstractClient.java          | 10 +++++++---
 .../gremlin/driver/simple/WebSocketClient.java         | 18 ++++++++++++------
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/simple/AbstractClient.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/simple/AbstractClient.java
index e991e3e..270277b 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/simple/AbstractClient.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/simple/AbstractClient.java
@@ -30,6 +30,7 @@ import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
 import java.util.function.Consumer;
 
 /**
@@ -41,7 +42,7 @@ public abstract class AbstractClient implements SimpleClient {
 
     public AbstractClient(final String threadPattern) {
         final BasicThreadFactory threadFactory = new BasicThreadFactory.Builder().namingPattern(threadPattern).build();
-        group = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors(), threadFactory);
+        group = new NioEventLoopGroup(1, threadFactory);
     }
 
     public abstract void writeAndFlush(final RequestMessage requestMessage) throws Exception;
@@ -54,7 +55,10 @@ public abstract class AbstractClient implements SimpleClient {
 
     @Override
     public List<ResponseMessage> submit(final RequestMessage requestMessage) throws Exception {
-        return submitAsync(requestMessage).get();
+        // this is just a test client to force certain behaviors of the server. hanging tests are a pain to deal with
+        // especially in travis as it's not always clear where the hang is. a few reasonable timeouts might help
+        // make debugging easier when we look at logs
+        return submitAsync(requestMessage).get(180, TimeUnit.SECONDS);
     }
 
     @Override
@@ -68,7 +72,7 @@ public abstract class AbstractClient implements SimpleClient {
             results.add(response);
 
             // check if the current message is terminating - if it is then we can mark complete
-            if (!response.getStatus().getCode().equals(ResponseStatusCode.PARTIAL_CONTENT)) {
+            if (response.getStatus().getCode().isFinalResponse()) {
                 f.complete(results);
             }
         };
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/simple/WebSocketClient.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/simple/WebSocketClient.java
index 4cc6817..767f5a8 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/simple/WebSocketClient.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/simple/WebSocketClient.java
@@ -38,9 +38,12 @@ import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakerFactory;
 import io.netty.handler.codec.http.websocketx.WebSocketVersion;
 import org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1;
 import org.apache.tinkerpop.gremlin.structure.io.binary.GraphBinaryMapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
 import java.net.URI;
+import java.util.concurrent.TimeUnit;
 
 /**
  * A simple, non-thread safe Gremlin Server client using websockets.  Typical use is for testing and demonstration.
@@ -48,6 +51,7 @@ import java.net.URI;
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 public class WebSocketClient extends AbstractClient {
+    private static final Logger logger = LoggerFactory.getLogger(WebSocketClient.class);
     private final Channel channel;
 
     public WebSocketClient() {
@@ -83,7 +87,7 @@ public class WebSocketClient extends AbstractClient {
                     });
 
             channel = b.connect(uri.getHost(), uri.getPort()).sync().channel();
-            wsHandler.handshakeFuture().get();
+            wsHandler.handshakeFuture().get(30, TimeUnit.SECONDS);
         } catch (Exception ex) {
             throw new RuntimeException(ex);
         }
@@ -91,17 +95,19 @@ public class WebSocketClient extends AbstractClient {
 
     @Override
     public void writeAndFlush(final RequestMessage requestMessage) throws Exception {
-        channel.writeAndFlush(requestMessage).get();
+        channel.writeAndFlush(requestMessage);
     }
 
     @Override
     public void close() throws IOException {
         try {
-            channel.close().get();
-        } catch (Exception ignored) {
-
+            channel.close().get(30, TimeUnit.SECONDS);
+        } catch (Exception ex) {
+            logger.error("Failure closing simple WebSocketClient", ex);
         } finally {
-            group.shutdownGracefully().awaitUninterruptibly();
+            if (!group.shutdownGracefully().awaitUninterruptibly(30, TimeUnit.SECONDS)) {
+                logger.error("Could not cleanly shutdown thread pool on WebSocketClient");
+            }
         }
     }
 }