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 2015/05/12 15:44:18 UTC
[1/2] incubator-tinkerpop git commit: Add integration test for
ensuring re-use of a Client over multiple threads.
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/master 3056d54f9 -> 0631f58c9
Add integration test for ensuring re-use of a Client over multiple threads.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/53025f83
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/53025f83
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/53025f83
Branch: refs/heads/master
Commit: 53025f83e843b5ed44cea1a9d57dd9bb6e0f1f9a
Parents: 3056d54
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 12 09:41:13 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 12 09:41:13 2015 -0400
----------------------------------------------------------------------
.../server/GremlinDriverIntegrateTest.java | 33 +++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/53025f83/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
----------------------------------------------------------------------
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 2a2a7de..4f4ebab 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
@@ -31,15 +31,18 @@ import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
import org.apache.tinkerpop.gremlin.util.TimeUtil;
import groovy.json.JsonBuilder;
+import org.apache.tinkerpop.gremlin.util.function.FunctionUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@@ -169,7 +172,7 @@ public class GremlinDriverIntegrateTest extends AbstractGremlinServerIntegration
final List<Integer> expected = IntStream.range(1, 10).boxed().collect(Collectors.toList());
IntStream.range(0, requests).forEach(r ->
- assertTrue(expected.containsAll(((List<Result>) refs[r].get()).stream().map(resultItem -> new Integer(resultItem.getInt())).collect(Collectors.toList()))));
+ assertTrue(expected.containsAll(((List<Result>) refs[r].get()).stream().map(resultItem -> new Integer(resultItem.getInt())).collect(Collectors.toList()))));
}
@Test
@@ -408,4 +411,32 @@ public class GremlinDriverIntegrateTest extends AbstractGremlinServerIntegration
cluster.close();
}
+
+ @Test
+ public void shouldBeThreadSafeToUseOneClient() throws Exception {
+ final Cluster cluster = Cluster.build().create();
+ final Client client = cluster.connect();
+
+ final Map<Integer, Integer> results = new ConcurrentHashMap<>();
+ final List<Thread> threads = new ArrayList<>();
+ for (int ix = 0; ix < 100; ix++) {
+ final int otherNum = ix;
+ final Thread t = new Thread(()->{
+ try {
+ results.put(otherNum, client.submit("1000+" + otherNum).all().get().get(0).getInt());
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }, name.getMethodName() + "-" + ix);
+
+ t.start();
+ threads.add(t);
+ }
+
+ threads.forEach(FunctionUtils.wrapConsumer(Thread::join));
+
+ for (int ix = 0; ix < results.size(); ix++) {
+ assertEquals(1000 + ix, results.get(ix).intValue());
+ }
+ }
}
[2/2] incubator-tinkerpop git commit: Update Client javadocs.
Posted by sp...@apache.org.
Update Client javadocs.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/0631f58c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/0631f58c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/0631f58c
Branch: refs/heads/master
Commit: 0631f58c9c1686c2cfdbafdd39451ab7dcddcf04
Parents: 53025f8
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 12 09:43:56 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 12 09:43:56 2015 -0400
----------------------------------------------------------------------
.../src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/0631f58c/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java
----------------------------------------------------------------------
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 8eae6a9..e3d84a9 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
@@ -39,6 +39,8 @@ import java.util.stream.Collectors;
* A {@code Client} is constructed from a {@link Cluster} and represents a way to send messages to Gremlin Server.
* This class itself is a base class as there are different implementations that provide differing kinds of
* functionality. See the implementations for specifics on their individual usage.
+ * <p/>
+ * The {@code Client} is designed to be re-used and shared across threads.
*
* @author Stephen Mallette (http://stephen.genoprime.com)
*/