Skip to content

Commit cede190

Browse files
committed
TINKERPOP-3154 Added docs/tests for subgraph() CTR
1 parent b8f7c24 commit cede190

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

docs/src/reference/gremlin-variants.asciidoc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,24 @@ ensure compatibility when making requests. Obviously, it is possible to switch t
860860
the appropriate `MessageSerializer` (e.g. `GraphSONMessageSerializerV3` or `GraphBinaryMessageSerializerV1` respectively)
861861
in the same way and building that into the `Cluster` object.
862862
863+
A particularly important configuration along these lines is easily overlooked when choosing to use GraphSON rather than
864+
GraphBinary. GraphBinary offers a bit of help in dynamically detecting available classpath items and will dynamically
865+
include `TinkerGraph` as a serialization target which allows the <<subgraph-step>> to work properly in remote contexts.
866+
GraphSON does not. When using GraphSON, you must manually include the `TinkerIoRegistryV3` in the configuration for the
867+
driver.
868+
869+
[source,java]
870+
----
871+
GraphSONMapper.Builder builder = GraphSONMapper.build().addRegistry(TinkerIoRegistryV3.instance());
872+
GraphSONMessageSerializerV3 serializer = new GraphSONMessageSerializerV3(builder);
873+
Cluster cluster = TestClientFactory.build().serializer(serializer).create();
874+
Client client = cluster.connect();
875+
GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using(client, "g"));
876+
----
877+
878+
IMPORTANT: Prefer GraphBinary over GraphSON when using the driver. If you do choose GraphSON, prefer GraphSON 3 and
879+
know that GraphSON 2 is not compatible with <<subgraph-step>.
880+
863881
[[gremlin-java-lambda]]
864882
=== The Lambda Solution
865883

gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
import nl.altindag.log.LogCaptor;
2424
import org.apache.tinkerpop.gremlin.driver.Channelizer;
2525
import org.apache.tinkerpop.gremlin.server.channel.HttpChannelizer;
26+
import org.apache.tinkerpop.gremlin.structure.Graph;
27+
import org.apache.tinkerpop.gremlin.structure.io.Mapper;
28+
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper;
29+
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV2;
30+
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV3;
2631
import org.apache.tinkerpop.gremlin.util.ExceptionHelper;
2732
import org.apache.tinkerpop.gremlin.TestHelper;
2833
import org.apache.tinkerpop.gremlin.driver.Client;
@@ -39,6 +44,8 @@
3944
import org.apache.tinkerpop.gremlin.util.message.ResponseStatusCode;
4045
import org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection;
4146
import org.apache.tinkerpop.gremlin.util.ser.GraphBinaryMessageSerializerV1;
47+
import org.apache.tinkerpop.gremlin.util.ser.GraphSONMessageSerializerV2;
48+
import org.apache.tinkerpop.gremlin.util.ser.GraphSONMessageSerializerV3;
4249
import org.apache.tinkerpop.gremlin.util.ser.Serializers;
4350
import org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin;
4451
import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
@@ -209,6 +216,46 @@ public Settings overrideSettings(final Settings settings) {
209216
return settings;
210217
}
211218

219+
@Test
220+
public void shouldSubgraphWithGraphSONV3Serialization() throws Exception {
221+
// validating subgraph() serialization here b/c we don't have feature tests for it yet in gherkin
222+
final GraphSONMapper.Builder builder = GraphSONMapper.build().addRegistry(TinkerIoRegistryV3.instance());
223+
final GraphSONMessageSerializerV3 serializer = new GraphSONMessageSerializerV3(builder);
224+
final Cluster cluster = TestClientFactory.build().serializer(serializer).create();
225+
final Client client = cluster.connect();
226+
227+
try {
228+
final List<Result> r = client.submit("TinkerFactory.createModern().traversal().E().hasLabel('knows').subgraph('x').cap('x')").all().join();
229+
assertEquals(1, r.size());
230+
231+
final Graph graph = r.get(0).get(Graph.class);
232+
final GraphTraversalSource g = traversal().withEmbedded(graph);
233+
assertEquals(2, g.E().count().next().longValue());
234+
assertEquals(3, g.V().count().next().longValue());
235+
} finally {
236+
cluster.close();
237+
}
238+
}
239+
240+
@Test
241+
public void shouldSubgraphWithGraphBinaryV1Serialization() throws Exception {
242+
// validating subgraph() serialization here b/c we don't have feature tests for it yet in gherkin
243+
final Cluster cluster = TestClientFactory.build().serializer(Serializers.GRAPHBINARY_V1).create();
244+
final Client client = cluster.connect();
245+
246+
try {
247+
final List<Result> r = client.submit("TinkerFactory.createModern().traversal().E().hasLabel('knows').subgraph('x').cap('x')").all().join();
248+
assertEquals(1, r.size());
249+
250+
final Graph graph = r.get(0).get(Graph.class);
251+
final GraphTraversalSource g = traversal().withEmbedded(graph);
252+
assertEquals(2, g.E().count().next().longValue());
253+
assertEquals(3, g.V().count().next().longValue());
254+
} finally {
255+
cluster.close();
256+
}
257+
}
258+
212259
@Test
213260
public void shouldInterceptRequests() throws Exception {
214261
final int requestsToMake = 32;

0 commit comments

Comments
 (0)