Skip to content

Commit

Permalink
Allow aliased client to pass along options
Browse files Browse the repository at this point in the history
  • Loading branch information
ryn5 committed Mar 8, 2024
1 parent 259296b commit 9f5d222
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
* Fixed issue where server errors weren't being properly parsed when sending bytecode over HTTP.
* Improved bulkset contains check for elements if all elements in bulkset are of the same type
* Fixed bug in `EarlyLimitStrategy` which was too aggressive when promoting `limit()` before `map()`.
* Fixed aliased client to allow passing options via `with()` when submitting traversals.
* Fixed bug in mid-traversal `mergeE()` where mutations in `sideEffect()` were being applied to the current traverser rather than a `onMatch` edge.
[[release-3-6-6]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@
package org.apache.tinkerpop.gremlin.driver;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.driver.remote.DriverRemoteConnection;
import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.net.ssl.SSLException;
import java.net.ConnectException;
Expand All @@ -51,7 +52,6 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
* A {@code Client} is constructed from a {@link Cluster} and represents a way to send messages to Gremlin Server.
Expand Down Expand Up @@ -642,7 +642,7 @@ public static class AliasClusteredClient extends Client {

@Override
public CompletableFuture<ResultSet> submitAsync(final Bytecode bytecode) {
return submitAsync(bytecode, RequestOptions.EMPTY);
return submitAsync(bytecode, DriverRemoteConnection.getRequestOptions(bytecode));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ Optional<String> getSessionId() {
return Optional.empty();
}

protected static RequestOptions getRequestOptions(final Bytecode bytecode) {
public static RequestOptions getRequestOptions(final Bytecode bytecode) {
final Iterator<OptionsStrategy> itty = BytecodeHelper.findStrategies(bytecode, OptionsStrategy.class);
final RequestOptions.Builder builder = RequestOptions.build();
while (itty.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* 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.server;

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.remote.DriverRemoteConnection;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.junit.Test;

import java.util.List;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutionException;

import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.fail;

/**
* Tests for options sent by the client using with().
*
* @author Ryan Tan
*/
public class ClientWithOptionsTest extends AbstractGremlinServerIntegrationTest {

@Test
public void shouldTimeOutAliasedClientSendingBytecode() {
final Cluster cluster = TestClientFactory.build().create();
Client client = cluster.connect().alias("ggrateful");
GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using(client, "g"));
GraphTraversal traversal = g.with("evaluationTimeout", 1).V().both().both().both();
assertThrows(ExecutionException.class, () -> {
List<Result> res = client.submit(traversal).all().get();
fail("Failed to time out. Result: " + res);
});
}

@Test
public void shouldTimeOutnonAliasedClientSendingByteCode() {
final Cluster cluster = TestClientFactory.build().create();
Client client = cluster.connect();
GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using(client, "ggrateful"));
assertThrows(CompletionException.class, () -> {
List<Vertex> res = g.with("evaluationTimeout", 1).V().both().both().both().toList();
fail("Failed to time out. Result: " + res);
});
}

@Test
public void shouldTimeOutAliasedClientSubmittingScript() {
final Cluster cluster = TestClientFactory.build().create();
Client client = cluster.connect().alias("ggrateful");
assertThrows(ExecutionException.class, () -> {
List<Result> res = client.submit("g.with(\"evaluationTimeout\",1).V().both().both().both();").all().get();
fail("Failed to time out. Result: " + res);
});
}

@Test
public void shouldTimeOutNonAliasedClientSubmittingScript() {
final Cluster cluster = TestClientFactory.build().create();
Client client = cluster.connect();
assertThrows(ExecutionException.class, () -> {
List<Result> res = client.submit("ggrateful.with(\"evaluationTimeout\",1).V().both().both().both();").all().get();
fail("Failed to time out. Result: " + res);
});
}
}

0 comments on commit 9f5d222

Please sign in to comment.