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 2016/04/21 13:21:00 UTC
[5/8] incubator-tinkerpop git commit: Accidentally commented out some
tests on the last commit - added them back.
Accidentally commented out some tests on the last commit - added them back.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/ae8716ac
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/ae8716ac
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/ae8716ac
Branch: refs/heads/master
Commit: ae8716acc0e0d88f2f22417a512f514ba9a833bc
Parents: 75e8757
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Apr 20 16:22:52 2016 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Apr 20 16:22:52 2016 -0400
----------------------------------------------------------------------
.../server/GremlinServerIntegrateTest.java | 834 +++++++++----------
1 file changed, 417 insertions(+), 417 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/ae8716ac/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
----------------------------------------------------------------------
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 c438e63..99bb745 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
@@ -329,421 +329,421 @@ public class GremlinServerIntegrateTest extends AbstractGremlinServerIntegration
}
}
-// @Test
-// public void shouldRespectHighWaterMarkSettingAndSucceed() throws Exception {
-// // the highwatermark should get exceeded on the server and thus pause the writes, but have no problem catching
-// // itself up - this is a tricky tests to get passing on all environments so this assumption will deny the
-// // test for most cases
-// assumeThat("Set the 'assertNonDeterministic' property to true to execute this test",
-// System.getProperty("assertNonDeterministic"), is("true"));
-//
-// final Cluster cluster = Cluster.open();
-// final Client client = cluster.connect();
-//
-// try {
-// final int resultCountToGenerate = 1000;
-// final int batchSize = 3;
-// final String fatty = IntStream.range(0, 175).mapToObj(String::valueOf).collect(Collectors.joining());
-// final String fattyX = "['" + fatty + "'] * " + resultCountToGenerate;
-//
-// // don't allow the thread to proceed until all results are accounted for
-// final CountDownLatch latch = new CountDownLatch(resultCountToGenerate);
-// final AtomicBoolean expected = new AtomicBoolean(false);
-// final AtomicBoolean faulty = new AtomicBoolean(false);
-// final RequestMessage request = RequestMessage.build(Tokens.OPS_EVAL)
-// .addArg(Tokens.ARGS_BATCH_SIZE, batchSize)
-// .addArg(Tokens.ARGS_GREMLIN, fattyX).create();
-//
-// client.submitAsync(request).thenAcceptAsync(r -> {
-// r.stream().forEach(item -> {
-// try {
-// final String aFattyResult = item.getString();
-// expected.set(aFattyResult.equals(fatty));
-// } catch (Exception ex) {
-// ex.printStackTrace();
-// faulty.set(true);
-// } finally {
-// latch.countDown();
-// }
-// });
-// });
-//
-// assertTrue(latch.await(30000, TimeUnit.MILLISECONDS));
-// assertEquals(0, latch.getCount());
-// assertFalse(faulty.get());
-// assertTrue(expected.get());
-//
-// assertTrue(recordingAppender.getMessages().stream().anyMatch(m -> m.contains("Pausing response writing as writeBufferHighWaterMark exceeded on")));
-// } catch (Exception ex) {
-// fail("Shouldn't have tossed an exception");
-// } finally {
-// cluster.close();
-// }
-// }
-//
-// @Test
-// public void shouldReturnInvalidRequestArgsWhenGremlinArgIsNotSupplied() throws Exception {
-// try (SimpleClient client = new WebSocketClient()) {
-// final RequestMessage request = RequestMessage.build(Tokens.OPS_EVAL).create();
-// final ResponseMessage result = client.submit(request).get(0);
-// assertThat(result.getStatus().getCode(), is(not(ResponseStatusCode.PARTIAL_CONTENT)));
-// assertEquals(result.getStatus().getCode(), ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS);
-// }
-// }
-//
-// @Test
-// public void shouldReturnInvalidRequestArgsWhenInvalidReservedBindingKeyIsUsed() throws Exception {
-// try (SimpleClient client = new WebSocketClient()) {
-// final Map<String, Object> bindings = new HashMap<>();
-// bindings.put(T.id.getAccessor(), "123");
-// final RequestMessage request = RequestMessage.build(Tokens.OPS_EVAL)
-// .addArg(Tokens.ARGS_GREMLIN, "[1,2,3,4,5,6,7,8,9,0]")
-// .addArg(Tokens.ARGS_BINDINGS, bindings).create();
-// final CountDownLatch latch = new CountDownLatch(1);
-// final AtomicBoolean pass = new AtomicBoolean(false);
-// client.submit(request, result -> {
-// if (result.getStatus().getCode() != ResponseStatusCode.PARTIAL_CONTENT) {
-// pass.set(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS == result.getStatus().getCode());
-// latch.countDown();
-// }
-// });
-//
-// if (!latch.await(3000, TimeUnit.MILLISECONDS))
-// fail("Request should have returned error, but instead timed out");
-// assertTrue(pass.get());
-// }
-// }
-//
-// @Test
-// public void shouldReturnInvalidRequestArgsWhenInvalidTypeBindingKeyIsUsed() throws Exception {
-// try (SimpleClient client = new WebSocketClient()) {
-// final Map<Object, Object> bindings = new HashMap<>();
-// bindings.put(1, "123");
-// final RequestMessage request = RequestMessage.build(Tokens.OPS_EVAL)
-// .addArg(Tokens.ARGS_GREMLIN, "[1,2,3,4,5,6,7,8,9,0]")
-// .addArg(Tokens.ARGS_BINDINGS, bindings).create();
-// final CountDownLatch latch = new CountDownLatch(1);
-// final AtomicBoolean pass = new AtomicBoolean(false);
-// client.submit(request, result -> {
-// if (result.getStatus().getCode() != ResponseStatusCode.PARTIAL_CONTENT) {
-// pass.set(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS == result.getStatus().getCode());
-// latch.countDown();
-// }
-// });
-//
-// if (!latch.await(3000, TimeUnit.MILLISECONDS))
-// fail("Request should have returned error, but instead timed out");
-// assertTrue(pass.get());
-// }
-// }
-//
-// @Test
-// public void shouldReturnInvalidRequestArgsWhenInvalidNullBindingKeyIsUsed() throws Exception {
-// try (SimpleClient client = new WebSocketClient()) {
-// final Map<String, Object> bindings = new HashMap<>();
-// bindings.put(null, "123");
-// final RequestMessage request = RequestMessage.build(Tokens.OPS_EVAL)
-// .addArg(Tokens.ARGS_GREMLIN, "[1,2,3,4,5,6,7,8,9,0]")
-// .addArg(Tokens.ARGS_BINDINGS, bindings).create();
-// final CountDownLatch latch = new CountDownLatch(1);
-// final AtomicBoolean pass = new AtomicBoolean(false);
-// client.submit(request, result -> {
-// if (result.getStatus().getCode() != ResponseStatusCode.PARTIAL_CONTENT) {
-// pass.set(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS == result.getStatus().getCode());
-// latch.countDown();
-// }
-// });
-//
-// if (!latch.await(3000, TimeUnit.MILLISECONDS))
-// fail("Request should have returned error, but instead timed out");
-// assertTrue(pass.get());
-// }
-// }
-//
-// @Test
-// @SuppressWarnings("unchecked")
-// public void shouldBatchResultsByTwos() throws Exception {
-// try (SimpleClient client = new WebSocketClient()) {
-// final RequestMessage request = RequestMessage.build(Tokens.OPS_EVAL)
-// .addArg(Tokens.ARGS_GREMLIN, "[0,1,2,3,4,5,6,7,8,9]").create();
-//
-// final List<ResponseMessage> msgs = client.submit(request);
-// assertEquals(5, client.submit(request).size());
-// assertEquals(0, ((List<Integer>) msgs.get(0).getResult().getData()).get(0).intValue());
-// assertEquals(1, ((List<Integer>) msgs.get(0).getResult().getData()).get(1).intValue());
-// assertEquals(2, ((List<Integer>) msgs.get(1).getResult().getData()).get(0).intValue());
-// assertEquals(3, ((List<Integer>) msgs.get(1).getResult().getData()).get(1).intValue());
-// assertEquals(4, ((List<Integer>) msgs.get(2).getResult().getData()).get(0).intValue());
-// assertEquals(5, ((List<Integer>) msgs.get(2).getResult().getData()).get(1).intValue());
-// assertEquals(6, ((List<Integer>) msgs.get(3).getResult().getData()).get(0).intValue());
-// assertEquals(7, ((List<Integer>) msgs.get(3).getResult().getData()).get(1).intValue());
-// assertEquals(8, ((List<Integer>) msgs.get(4).getResult().getData()).get(0).intValue());
-// assertEquals(9, ((List<Integer>) msgs.get(4).getResult().getData()).get(1).intValue());
-// }
-// }
-//
-// @Test
-// @SuppressWarnings("unchecked")
-// public void shouldBatchResultsByOnesByOverridingFromClientSide() throws Exception {
-// try (SimpleClient client = new WebSocketClient()) {
-// final RequestMessage request = RequestMessage.build(Tokens.OPS_EVAL)
-// .addArg(Tokens.ARGS_GREMLIN, "[0,1,2,3,4,5,6,7,8,9]")
-// .addArg(Tokens.ARGS_BATCH_SIZE, 1).create();
-//
-// final List<ResponseMessage> msgs = client.submit(request);
-// assertEquals(10, msgs.size());
-// IntStream.rangeClosed(0, 9).forEach(i -> assertEquals(i, ((List<Integer>) msgs.get(i).getResult().getData()).get(0).intValue()));
-// }
-// }
-//
-// @Test
-// @SuppressWarnings("unchecked")
-// public void shouldWorkOverNioTransport() throws Exception {
-// try (SimpleClient client = new NioClient()) {
-// final RequestMessage request = RequestMessage.build(Tokens.OPS_EVAL)
-// .addArg(Tokens.ARGS_GREMLIN, "[0,1,2,3,4,5,6,7,8,9,]").create();
-//
-// final List<ResponseMessage> msg = client.submit(request);
-// assertEquals(1, msg.size());
-// final List<Integer> integers = (List<Integer>) msg.get(0).getResult().getData();
-// IntStream.rangeClosed(0, 9).forEach(i -> assertEquals(i, integers.get(i).intValue()));
-// }
-// }
-//
-// @Test
-// public void shouldNotThrowNoSuchElementException() throws Exception {
-// try (SimpleClient client = new WebSocketClient()){
-// // this should return "nothing" - there should be no exception
-// final List<ResponseMessage> responses = client.submit("g.V().has('name','kadfjaldjfla')");
-// assertNull(responses.get(0).getResult().getData());
-// }
-// }
-//
-// @Test
-// @SuppressWarnings("unchecked")
-// public void shouldReceiveFailureTimeOutOnScriptEval() throws Exception {
-// try (SimpleClient client = new WebSocketClient()){
-// final List<ResponseMessage> responses = client.submit("Thread.sleep(3000);'some-stuff-that-should not return'");
-// assertThat(responses.get(0).getStatus().getMessage(), startsWith("Script evaluation exceeded the configured 'scriptEvaluationTimeout' threshold of 200 ms for request"));
-//
-// // validate that we can still send messages to the server
-// assertEquals(2, ((List<Integer>) client.submit("1+1").get(0).getResult().getData()).get(0).intValue());
-// }
-// }
-//
-// @Test
-// @SuppressWarnings("unchecked")
-// public void shouldReceiveFailureTimeOutOnScriptEvalUsingOverride() throws Exception {
-// try (SimpleClient client = new WebSocketClient()) {
-// final RequestMessage msg = RequestMessage.build("eval")
-// .addArg(Tokens.ARGS_SCRIPT_EVAL_TIMEOUT, 100)
-// .addArg(Tokens.ARGS_GREMLIN, "Thread.sleep(3000);'some-stuff-that-should not return'")
-// .create();
-// final List<ResponseMessage> responses = client.submit(msg);
-// assertThat(responses.get(0).getStatus().getMessage(), startsWith("Script evaluation exceeded the configured 'scriptEvaluationTimeout' threshold of 100 ms for request"));
-//
-// // validate that we can still send messages to the server
-// assertEquals(2, ((List<Integer>) client.submit("1+1").get(0).getResult().getData()).get(0).intValue());
-// }
-// }
-//
-// @Test
-// public void shouldReceiveFailureTimeOutOnScriptEvalOfOutOfControlLoop() throws Exception {
-// try (SimpleClient client = new WebSocketClient()){
-// // timeout configured for 1 second so the timed interrupt should trigger prior to the
-// // scriptEvaluationTimeout which is at 30 seconds by default
-// final List<ResponseMessage> responses = client.submit("while(true){}");
-// assertThat(responses.get(0).getStatus().getMessage(), startsWith("Timeout during script evaluation triggered by TimedInterruptCustomizerProvider"));
-//
-// // validate that we can still send messages to the server
-// assertEquals(2, ((List<Integer>) client.submit("1+1").get(0).getResult().getData()).get(0).intValue());
-// }
-// }
-//
-// @Test
-// @SuppressWarnings("unchecked")
-// public void shouldReceiveFailureTimeOutOnTotalSerialization() throws Exception {
-// try (SimpleClient client = new WebSocketClient()){
-// final List<ResponseMessage> responses = client.submit("(0..<100000)");
-//
-// // the last message should contain the error
-// assertThat(responses.get(responses.size() - 1).getStatus().getMessage(), endsWith("Serialization of the entire response exceeded the 'serializeResponseTimeout' setting"));
-//
-// // validate that we can still send messages to the server
-// assertEquals(2, ((List<Integer>) client.submit("1+1").get(0).getResult().getData()).get(0).intValue());
-// }
-// }
-//
-// @Test
-// @SuppressWarnings("unchecked")
-// public void shouldLoadInitScript() throws Exception {
-// try (SimpleClient client = new WebSocketClient()){
-// assertEquals(2, ((List<Integer>) client.submit("addItUp(1,1)").get(0).getResult().getData()).get(0).intValue());
-// }
-// }
-//
-// @Test
-// public void shouldGarbageCollectPhantomButNotHard() throws Exception {
-// final Cluster cluster = Cluster.open();
-// final Client client = cluster.connect();
-//
-// assertEquals(2, client.submit("addItUp(1,1)").all().join().get(0).getInt());
-// assertEquals(0, client.submit("def subtract(x,y){x-y};subtract(1,1)").all().join().get(0).getInt());
-// assertEquals(0, client.submit("subtract(1,1)").all().join().get(0).getInt());
-//
-// final Map<String, Object> bindings = new HashMap<>();
-// bindings.put(GremlinGroovyScriptEngine.KEY_REFERENCE_TYPE, GremlinGroovyScriptEngine.REFERENCE_TYPE_PHANTOM);
-// assertEquals(4, client.submit("def multiply(x,y){x*y};multiply(2,2)", bindings).all().join().get(0).getInt());
-//
-// try {
-// client.submit("multiply(2,2)").all().join().get(0).getInt();
-// fail("Should throw an exception since reference is phantom.");
-// } catch (RuntimeException ignored) {
-//
-// } finally {
-// cluster.close();
-// }
-// }
-//
-// @Test
-// public void shouldReceiveFailureOnBadGraphSONSerialization() throws Exception {
-// final Cluster cluster = Cluster.build("localhost").serializer(Serializers.GRAPHSON_V1D0).create();
-// final Client client = cluster.connect();
-//
-// try {
-// client.submit("def class C { def C getC(){return this}}; new C()").all().join();
-// fail("Should throw an exception.");
-// } catch (RuntimeException re) {
-// final Throwable root = ExceptionUtils.getRootCause(re);
-// assertThat(root.getMessage(), CoreMatchers.startsWith("Error during serialization: Direct self-reference leading to cycle (through reference chain:"));
-//
-// // validate that we can still send messages to the server
-// assertEquals(2, client.submit("1+1").all().join().get(0).getInt());
-// } finally {
-// cluster.close();
-// }
-// }
-//
-// @Test
-// public void shouldReceiveFailureOnBadGryoSerialization() throws Exception {
-// final Cluster cluster = Cluster.build("localhost").serializer(Serializers.GRYO_V1D0).create();
-// final Client client = cluster.connect();
-//
-// try {
-// client.submit("java.awt.Color.RED").all().join();
-// fail("Should throw an exception.");
-// } catch (RuntimeException re) {
-// final Throwable root = ExceptionUtils.getRootCause(re);
-// assertThat(root.getMessage(), CoreMatchers.startsWith("Error during serialization: Class is not registered: java.awt.Color"));
-//
-// // validate that we can still send messages to the server
-// assertEquals(2, client.submit("1+1").all().join().get(0).getInt());
-// } finally {
-// cluster.close();
-// }
-// }
-//
-// @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
-// @Test
-// public void shouldBlockRequestWhenTooBig() throws Exception {
-// final Cluster cluster = Cluster.open();
-// final Client client = cluster.connect();
-//
-// try {
-// final String fatty = IntStream.range(0, 1024).mapToObj(String::valueOf).collect(Collectors.joining());
-// final CompletableFuture<ResultSet> result = client.submitAsync("'" + fatty + "';'test'");
-// final ResultSet resultSet = result.get(10000, TimeUnit.MILLISECONDS);
-// resultSet.all().get(10000, TimeUnit.MILLISECONDS);
-// fail("Should throw an exception.");
-// } catch (TimeoutException te) {
-// // the request should not have timed-out - the connection should have been reset, but it seems that
-// // timeout seems to occur as well on some systems (it's not clear why). however, the nature of this
-// // test is to ensure that the script isn't processed if it exceeds a certain size, so in this sense
-// // it seems ok to pass in this case.
-// } catch (Exception re) {
-// final Throwable root = ExceptionUtils.getRootCause(re);
-// assertEquals("Connection reset by peer", root.getMessage());
-//
-// // validate that we can still send messages to the server
-// assertEquals(2, client.submit("1+1").all().join().get(0).getInt());
-// } finally {
-// cluster.close();
-// }
-// }
-//
-// @Test
-// public void shouldFailOnDeadHost() throws Exception {
-// final Cluster cluster = Cluster.build("localhost").create();
-// final Client client = cluster.connect();
-//
-// // ensure that connection to server is good
-// assertEquals(2, client.submit("1+1").all().join().get(0).getInt());
-//
-// // kill the server which will make the client mark the host as unavailable
-// this.stopServer();
-//
-// try {
-// // try to re-issue a request now that the server is down
-// client.submit("1+1").all().join();
-// fail();
-// } catch (RuntimeException re) {
-// assertTrue(re.getCause().getCause() instanceof ClosedChannelException);
-//
-// //
-// // should recover when the server comes back
-// //
-//
-// // restart server
-// this.startServer();
-// // the retry interval is 1 second, wait a bit longer
-// TimeUnit.SECONDS.sleep(5);
-//
-// List<Result> results = client.submit("1+1").all().join();
-// assertEquals(1, results.size());
-// assertEquals(2, results.get(0).getInt());
-//
-// } finally {
-// cluster.close();
-// }
-// }
-//
-// @Test
-// public void shouldNotHavePartialContentWithOneResult() throws Exception {
-// try (SimpleClient client = new WebSocketClient()) {
-// final RequestMessage request = RequestMessage.build(Tokens.OPS_EVAL)
-// .addArg(Tokens.ARGS_GREMLIN, "10").create();
-// final List<ResponseMessage> responses = client.submit(request);
-// assertEquals(1, responses.size());
-// assertEquals(ResponseStatusCode.SUCCESS, responses.get(0).getStatus().getCode());
-// }
-// }
-//
-// @Test
-// public void shouldFailWithBadScriptEval() throws Exception {
-// try (SimpleClient client = new WebSocketClient()) {
-// final RequestMessage request = RequestMessage.build(Tokens.OPS_EVAL)
-// .addArg(Tokens.ARGS_GREMLIN, "new String().doNothingAtAllBecauseThis is a syntax error").create();
-// final List<ResponseMessage> responses = client.submit(request);
-// assertEquals(ResponseStatusCode.SERVER_ERROR_SCRIPT_EVALUATION, responses.get(0).getStatus().getCode());
-// assertEquals(1, responses.size());
-// }
-// }
-//
-// @Test
-// @SuppressWarnings("unchecked")
-// public void shouldStillSupportDeprecatedRebindingsParameterOnServer() throws Exception {
-// // this test can be removed when the rebindings arg is removed
-// try (SimpleClient client = new WebSocketClient()) {
-// final Map<String,String> rebindings = new HashMap<>();
-// rebindings.put("xyz", "graph");
-// final RequestMessage request = RequestMessage.build(Tokens.OPS_EVAL)
-// .addArg(Tokens.ARGS_GREMLIN, "xyz.addVertex('name','jason')")
-// .addArg(Tokens.ARGS_REBINDINGS, rebindings).create();
-// final List<ResponseMessage> responses = client.submit(request);
-// assertEquals(1, responses.size());
-//
-// final DetachedVertex v = ((ArrayList<DetachedVertex>) responses.get(0).getResult().getData()).get(0);
-// assertEquals("jason", v.value("name"));
-// }
-// }
+ @Test
+ public void shouldRespectHighWaterMarkSettingAndSucceed() throws Exception {
+ // the highwatermark should get exceeded on the server and thus pause the writes, but have no problem catching
+ // itself up - this is a tricky tests to get passing on all environments so this assumption will deny the
+ // test for most cases
+ assumeThat("Set the 'assertNonDeterministic' property to true to execute this test",
+ System.getProperty("assertNonDeterministic"), is("true"));
+
+ final Cluster cluster = Cluster.open();
+ final Client client = cluster.connect();
+
+ try {
+ final int resultCountToGenerate = 1000;
+ final int batchSize = 3;
+ final String fatty = IntStream.range(0, 175).mapToObj(String::valueOf).collect(Collectors.joining());
+ final String fattyX = "['" + fatty + "'] * " + resultCountToGenerate;
+
+ // don't allow the thread to proceed until all results are accounted for
+ final CountDownLatch latch = new CountDownLatch(resultCountToGenerate);
+ final AtomicBoolean expected = new AtomicBoolean(false);
+ final AtomicBoolean faulty = new AtomicBoolean(false);
+ final RequestMessage request = RequestMessage.build(Tokens.OPS_EVAL)
+ .addArg(Tokens.ARGS_BATCH_SIZE, batchSize)
+ .addArg(Tokens.ARGS_GREMLIN, fattyX).create();
+
+ client.submitAsync(request).thenAcceptAsync(r -> {
+ r.stream().forEach(item -> {
+ try {
+ final String aFattyResult = item.getString();
+ expected.set(aFattyResult.equals(fatty));
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ faulty.set(true);
+ } finally {
+ latch.countDown();
+ }
+ });
+ });
+
+ assertTrue(latch.await(30000, TimeUnit.MILLISECONDS));
+ assertEquals(0, latch.getCount());
+ assertFalse(faulty.get());
+ assertTrue(expected.get());
+
+ assertTrue(recordingAppender.getMessages().stream().anyMatch(m -> m.contains("Pausing response writing as writeBufferHighWaterMark exceeded on")));
+ } catch (Exception ex) {
+ fail("Shouldn't have tossed an exception");
+ } finally {
+ cluster.close();
+ }
+ }
+
+ @Test
+ public void shouldReturnInvalidRequestArgsWhenGremlinArgIsNotSupplied() throws Exception {
+ try (SimpleClient client = new WebSocketClient()) {
+ final RequestMessage request = RequestMessage.build(Tokens.OPS_EVAL).create();
+ final ResponseMessage result = client.submit(request).get(0);
+ assertThat(result.getStatus().getCode(), is(not(ResponseStatusCode.PARTIAL_CONTENT)));
+ assertEquals(result.getStatus().getCode(), ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS);
+ }
+ }
+
+ @Test
+ public void shouldReturnInvalidRequestArgsWhenInvalidReservedBindingKeyIsUsed() throws Exception {
+ try (SimpleClient client = new WebSocketClient()) {
+ final Map<String, Object> bindings = new HashMap<>();
+ bindings.put(T.id.getAccessor(), "123");
+ final RequestMessage request = RequestMessage.build(Tokens.OPS_EVAL)
+ .addArg(Tokens.ARGS_GREMLIN, "[1,2,3,4,5,6,7,8,9,0]")
+ .addArg(Tokens.ARGS_BINDINGS, bindings).create();
+ final CountDownLatch latch = new CountDownLatch(1);
+ final AtomicBoolean pass = new AtomicBoolean(false);
+ client.submit(request, result -> {
+ if (result.getStatus().getCode() != ResponseStatusCode.PARTIAL_CONTENT) {
+ pass.set(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS == result.getStatus().getCode());
+ latch.countDown();
+ }
+ });
+
+ if (!latch.await(3000, TimeUnit.MILLISECONDS))
+ fail("Request should have returned error, but instead timed out");
+ assertTrue(pass.get());
+ }
+ }
+
+ @Test
+ public void shouldReturnInvalidRequestArgsWhenInvalidTypeBindingKeyIsUsed() throws Exception {
+ try (SimpleClient client = new WebSocketClient()) {
+ final Map<Object, Object> bindings = new HashMap<>();
+ bindings.put(1, "123");
+ final RequestMessage request = RequestMessage.build(Tokens.OPS_EVAL)
+ .addArg(Tokens.ARGS_GREMLIN, "[1,2,3,4,5,6,7,8,9,0]")
+ .addArg(Tokens.ARGS_BINDINGS, bindings).create();
+ final CountDownLatch latch = new CountDownLatch(1);
+ final AtomicBoolean pass = new AtomicBoolean(false);
+ client.submit(request, result -> {
+ if (result.getStatus().getCode() != ResponseStatusCode.PARTIAL_CONTENT) {
+ pass.set(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS == result.getStatus().getCode());
+ latch.countDown();
+ }
+ });
+
+ if (!latch.await(3000, TimeUnit.MILLISECONDS))
+ fail("Request should have returned error, but instead timed out");
+ assertTrue(pass.get());
+ }
+ }
+
+ @Test
+ public void shouldReturnInvalidRequestArgsWhenInvalidNullBindingKeyIsUsed() throws Exception {
+ try (SimpleClient client = new WebSocketClient()) {
+ final Map<String, Object> bindings = new HashMap<>();
+ bindings.put(null, "123");
+ final RequestMessage request = RequestMessage.build(Tokens.OPS_EVAL)
+ .addArg(Tokens.ARGS_GREMLIN, "[1,2,3,4,5,6,7,8,9,0]")
+ .addArg(Tokens.ARGS_BINDINGS, bindings).create();
+ final CountDownLatch latch = new CountDownLatch(1);
+ final AtomicBoolean pass = new AtomicBoolean(false);
+ client.submit(request, result -> {
+ if (result.getStatus().getCode() != ResponseStatusCode.PARTIAL_CONTENT) {
+ pass.set(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS == result.getStatus().getCode());
+ latch.countDown();
+ }
+ });
+
+ if (!latch.await(3000, TimeUnit.MILLISECONDS))
+ fail("Request should have returned error, but instead timed out");
+ assertTrue(pass.get());
+ }
+ }
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void shouldBatchResultsByTwos() throws Exception {
+ try (SimpleClient client = new WebSocketClient()) {
+ final RequestMessage request = RequestMessage.build(Tokens.OPS_EVAL)
+ .addArg(Tokens.ARGS_GREMLIN, "[0,1,2,3,4,5,6,7,8,9]").create();
+
+ final List<ResponseMessage> msgs = client.submit(request);
+ assertEquals(5, client.submit(request).size());
+ assertEquals(0, ((List<Integer>) msgs.get(0).getResult().getData()).get(0).intValue());
+ assertEquals(1, ((List<Integer>) msgs.get(0).getResult().getData()).get(1).intValue());
+ assertEquals(2, ((List<Integer>) msgs.get(1).getResult().getData()).get(0).intValue());
+ assertEquals(3, ((List<Integer>) msgs.get(1).getResult().getData()).get(1).intValue());
+ assertEquals(4, ((List<Integer>) msgs.get(2).getResult().getData()).get(0).intValue());
+ assertEquals(5, ((List<Integer>) msgs.get(2).getResult().getData()).get(1).intValue());
+ assertEquals(6, ((List<Integer>) msgs.get(3).getResult().getData()).get(0).intValue());
+ assertEquals(7, ((List<Integer>) msgs.get(3).getResult().getData()).get(1).intValue());
+ assertEquals(8, ((List<Integer>) msgs.get(4).getResult().getData()).get(0).intValue());
+ assertEquals(9, ((List<Integer>) msgs.get(4).getResult().getData()).get(1).intValue());
+ }
+ }
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void shouldBatchResultsByOnesByOverridingFromClientSide() throws Exception {
+ try (SimpleClient client = new WebSocketClient()) {
+ final RequestMessage request = RequestMessage.build(Tokens.OPS_EVAL)
+ .addArg(Tokens.ARGS_GREMLIN, "[0,1,2,3,4,5,6,7,8,9]")
+ .addArg(Tokens.ARGS_BATCH_SIZE, 1).create();
+
+ final List<ResponseMessage> msgs = client.submit(request);
+ assertEquals(10, msgs.size());
+ IntStream.rangeClosed(0, 9).forEach(i -> assertEquals(i, ((List<Integer>) msgs.get(i).getResult().getData()).get(0).intValue()));
+ }
+ }
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void shouldWorkOverNioTransport() throws Exception {
+ try (SimpleClient client = new NioClient()) {
+ final RequestMessage request = RequestMessage.build(Tokens.OPS_EVAL)
+ .addArg(Tokens.ARGS_GREMLIN, "[0,1,2,3,4,5,6,7,8,9,]").create();
+
+ final List<ResponseMessage> msg = client.submit(request);
+ assertEquals(1, msg.size());
+ final List<Integer> integers = (List<Integer>) msg.get(0).getResult().getData();
+ IntStream.rangeClosed(0, 9).forEach(i -> assertEquals(i, integers.get(i).intValue()));
+ }
+ }
+
+ @Test
+ public void shouldNotThrowNoSuchElementException() throws Exception {
+ try (SimpleClient client = new WebSocketClient()){
+ // this should return "nothing" - there should be no exception
+ final List<ResponseMessage> responses = client.submit("g.V().has('name','kadfjaldjfla')");
+ assertNull(responses.get(0).getResult().getData());
+ }
+ }
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void shouldReceiveFailureTimeOutOnScriptEval() throws Exception {
+ try (SimpleClient client = new WebSocketClient()){
+ final List<ResponseMessage> responses = client.submit("Thread.sleep(3000);'some-stuff-that-should not return'");
+ assertThat(responses.get(0).getStatus().getMessage(), startsWith("Script evaluation exceeded the configured 'scriptEvaluationTimeout' threshold of 200 ms for request"));
+
+ // validate that we can still send messages to the server
+ assertEquals(2, ((List<Integer>) client.submit("1+1").get(0).getResult().getData()).get(0).intValue());
+ }
+ }
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void shouldReceiveFailureTimeOutOnScriptEvalUsingOverride() throws Exception {
+ try (SimpleClient client = new WebSocketClient()) {
+ final RequestMessage msg = RequestMessage.build("eval")
+ .addArg(Tokens.ARGS_SCRIPT_EVAL_TIMEOUT, 100)
+ .addArg(Tokens.ARGS_GREMLIN, "Thread.sleep(3000);'some-stuff-that-should not return'")
+ .create();
+ final List<ResponseMessage> responses = client.submit(msg);
+ assertThat(responses.get(0).getStatus().getMessage(), startsWith("Script evaluation exceeded the configured 'scriptEvaluationTimeout' threshold of 100 ms for request"));
+
+ // validate that we can still send messages to the server
+ assertEquals(2, ((List<Integer>) client.submit("1+1").get(0).getResult().getData()).get(0).intValue());
+ }
+ }
+
+ @Test
+ public void shouldReceiveFailureTimeOutOnScriptEvalOfOutOfControlLoop() throws Exception {
+ try (SimpleClient client = new WebSocketClient()){
+ // timeout configured for 1 second so the timed interrupt should trigger prior to the
+ // scriptEvaluationTimeout which is at 30 seconds by default
+ final List<ResponseMessage> responses = client.submit("while(true){}");
+ assertThat(responses.get(0).getStatus().getMessage(), startsWith("Timeout during script evaluation triggered by TimedInterruptCustomizerProvider"));
+
+ // validate that we can still send messages to the server
+ assertEquals(2, ((List<Integer>) client.submit("1+1").get(0).getResult().getData()).get(0).intValue());
+ }
+ }
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void shouldReceiveFailureTimeOutOnTotalSerialization() throws Exception {
+ try (SimpleClient client = new WebSocketClient()){
+ final List<ResponseMessage> responses = client.submit("(0..<100000)");
+
+ // the last message should contain the error
+ assertThat(responses.get(responses.size() - 1).getStatus().getMessage(), endsWith("Serialization of the entire response exceeded the 'serializeResponseTimeout' setting"));
+
+ // validate that we can still send messages to the server
+ assertEquals(2, ((List<Integer>) client.submit("1+1").get(0).getResult().getData()).get(0).intValue());
+ }
+ }
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void shouldLoadInitScript() throws Exception {
+ try (SimpleClient client = new WebSocketClient()){
+ assertEquals(2, ((List<Integer>) client.submit("addItUp(1,1)").get(0).getResult().getData()).get(0).intValue());
+ }
+ }
+
+ @Test
+ public void shouldGarbageCollectPhantomButNotHard() throws Exception {
+ final Cluster cluster = Cluster.open();
+ final Client client = cluster.connect();
+
+ assertEquals(2, client.submit("addItUp(1,1)").all().join().get(0).getInt());
+ assertEquals(0, client.submit("def subtract(x,y){x-y};subtract(1,1)").all().join().get(0).getInt());
+ assertEquals(0, client.submit("subtract(1,1)").all().join().get(0).getInt());
+
+ final Map<String, Object> bindings = new HashMap<>();
+ bindings.put(GremlinGroovyScriptEngine.KEY_REFERENCE_TYPE, GremlinGroovyScriptEngine.REFERENCE_TYPE_PHANTOM);
+ assertEquals(4, client.submit("def multiply(x,y){x*y};multiply(2,2)", bindings).all().join().get(0).getInt());
+
+ try {
+ client.submit("multiply(2,2)").all().join().get(0).getInt();
+ fail("Should throw an exception since reference is phantom.");
+ } catch (RuntimeException ignored) {
+
+ } finally {
+ cluster.close();
+ }
+ }
+
+ @Test
+ public void shouldReceiveFailureOnBadGraphSONSerialization() throws Exception {
+ final Cluster cluster = Cluster.build("localhost").serializer(Serializers.GRAPHSON_V1D0).create();
+ final Client client = cluster.connect();
+
+ try {
+ client.submit("def class C { def C getC(){return this}}; new C()").all().join();
+ fail("Should throw an exception.");
+ } catch (RuntimeException re) {
+ final Throwable root = ExceptionUtils.getRootCause(re);
+ assertThat(root.getMessage(), CoreMatchers.startsWith("Error during serialization: Direct self-reference leading to cycle (through reference chain:"));
+
+ // validate that we can still send messages to the server
+ assertEquals(2, client.submit("1+1").all().join().get(0).getInt());
+ } finally {
+ cluster.close();
+ }
+ }
+
+ @Test
+ public void shouldReceiveFailureOnBadGryoSerialization() throws Exception {
+ final Cluster cluster = Cluster.build("localhost").serializer(Serializers.GRYO_V1D0).create();
+ final Client client = cluster.connect();
+
+ try {
+ client.submit("java.awt.Color.RED").all().join();
+ fail("Should throw an exception.");
+ } catch (RuntimeException re) {
+ final Throwable root = ExceptionUtils.getRootCause(re);
+ assertThat(root.getMessage(), CoreMatchers.startsWith("Error during serialization: Class is not registered: java.awt.Color"));
+
+ // validate that we can still send messages to the server
+ assertEquals(2, client.submit("1+1").all().join().get(0).getInt());
+ } finally {
+ cluster.close();
+ }
+ }
+
+ @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
+ @Test
+ public void shouldBlockRequestWhenTooBig() throws Exception {
+ final Cluster cluster = Cluster.open();
+ final Client client = cluster.connect();
+
+ try {
+ final String fatty = IntStream.range(0, 1024).mapToObj(String::valueOf).collect(Collectors.joining());
+ final CompletableFuture<ResultSet> result = client.submitAsync("'" + fatty + "';'test'");
+ final ResultSet resultSet = result.get(10000, TimeUnit.MILLISECONDS);
+ resultSet.all().get(10000, TimeUnit.MILLISECONDS);
+ fail("Should throw an exception.");
+ } catch (TimeoutException te) {
+ // the request should not have timed-out - the connection should have been reset, but it seems that
+ // timeout seems to occur as well on some systems (it's not clear why). however, the nature of this
+ // test is to ensure that the script isn't processed if it exceeds a certain size, so in this sense
+ // it seems ok to pass in this case.
+ } catch (Exception re) {
+ final Throwable root = ExceptionUtils.getRootCause(re);
+ assertEquals("Connection reset by peer", root.getMessage());
+
+ // validate that we can still send messages to the server
+ assertEquals(2, client.submit("1+1").all().join().get(0).getInt());
+ } finally {
+ cluster.close();
+ }
+ }
+
+ @Test
+ public void shouldFailOnDeadHost() throws Exception {
+ final Cluster cluster = Cluster.build("localhost").create();
+ final Client client = cluster.connect();
+
+ // ensure that connection to server is good
+ assertEquals(2, client.submit("1+1").all().join().get(0).getInt());
+
+ // kill the server which will make the client mark the host as unavailable
+ this.stopServer();
+
+ try {
+ // try to re-issue a request now that the server is down
+ client.submit("1+1").all().join();
+ fail();
+ } catch (RuntimeException re) {
+ assertTrue(re.getCause().getCause() instanceof ClosedChannelException);
+
+ //
+ // should recover when the server comes back
+ //
+
+ // restart server
+ this.startServer();
+ // the retry interval is 1 second, wait a bit longer
+ TimeUnit.SECONDS.sleep(5);
+
+ List<Result> results = client.submit("1+1").all().join();
+ assertEquals(1, results.size());
+ assertEquals(2, results.get(0).getInt());
+
+ } finally {
+ cluster.close();
+ }
+ }
+
+ @Test
+ public void shouldNotHavePartialContentWithOneResult() throws Exception {
+ try (SimpleClient client = new WebSocketClient()) {
+ final RequestMessage request = RequestMessage.build(Tokens.OPS_EVAL)
+ .addArg(Tokens.ARGS_GREMLIN, "10").create();
+ final List<ResponseMessage> responses = client.submit(request);
+ assertEquals(1, responses.size());
+ assertEquals(ResponseStatusCode.SUCCESS, responses.get(0).getStatus().getCode());
+ }
+ }
+
+ @Test
+ public void shouldFailWithBadScriptEval() throws Exception {
+ try (SimpleClient client = new WebSocketClient()) {
+ final RequestMessage request = RequestMessage.build(Tokens.OPS_EVAL)
+ .addArg(Tokens.ARGS_GREMLIN, "new String().doNothingAtAllBecauseThis is a syntax error").create();
+ final List<ResponseMessage> responses = client.submit(request);
+ assertEquals(ResponseStatusCode.SERVER_ERROR_SCRIPT_EVALUATION, responses.get(0).getStatus().getCode());
+ assertEquals(1, responses.size());
+ }
+ }
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void shouldStillSupportDeprecatedRebindingsParameterOnServer() throws Exception {
+ // this test can be removed when the rebindings arg is removed
+ try (SimpleClient client = new WebSocketClient()) {
+ final Map<String,String> rebindings = new HashMap<>();
+ rebindings.put("xyz", "graph");
+ final RequestMessage request = RequestMessage.build(Tokens.OPS_EVAL)
+ .addArg(Tokens.ARGS_GREMLIN, "xyz.addVertex('name','jason')")
+ .addArg(Tokens.ARGS_REBINDINGS, rebindings).create();
+ final List<ResponseMessage> responses = client.submit(request);
+ assertEquals(1, responses.size());
+
+ final DetachedVertex v = ((ArrayList<DetachedVertex>) responses.get(0).getResult().getData()).get(0);
+ assertEquals("jason", v.value("name"));
+ }
+ }
}