Skip to content

Commit a46fd77

Browse files
committed
Merge branch '3.7-dev' into 3.8-dev
2 parents 47baf67 + e8446d2 commit a46fd77

File tree

13 files changed

+154
-90
lines changed

13 files changed

+154
-90
lines changed

gremlin-dotnet/Examples/BasicGremlin/BasicGremlin.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,32 @@ under the License.
2323

2424
public class BasicGremlinExample
2525
{
26+
static readonly string ServerHost = Environment.GetEnvironmentVariable("GREMLIN_SERVER_HOST") ?? "localhost";
27+
static readonly int ServerPort = int.Parse(Environment.GetEnvironmentVariable("GREMLIN_SERVER_PORT") ?? "8182");
28+
static readonly string VertexLabel = Environment.GetEnvironmentVariable("VERTEX_LABEL") ?? "person";
29+
2630
static async Task Main()
2731
{
28-
var server = new GremlinServer("localhost", 8182);
32+
var server = new GremlinServer(ServerHost, ServerPort);
2933
using var remoteConnection = new DriverRemoteConnection(new GremlinClient(server), "g");
3034
var g = Traversal().WithRemote(remoteConnection);
3135

3236
// Basic Gremlin: adding and retrieving data
33-
var v1 = g.AddV("person").Property("name", "marko").Next();
34-
var v2 = g.AddV("person").Property("name", "stephen").Next();
35-
var v3 = g.AddV("person").Property("name", "vadas").Next();
37+
var v1 = g.AddV(VertexLabel).Property("name", "marko").Next();
38+
var v2 = g.AddV(VertexLabel).Property("name", "stephen").Next();
39+
var v3 = g.AddV(VertexLabel).Property("name", "vadas").Next();
3640

3741
// Be sure to use a terminating step like Next() or Iterate() so that the traversal "executes"
3842
// Iterate() does not return any data and is used to just generate side-effects (i.e. write data to the database)
3943
g.V(v1).AddE("knows").To(v2).Property("weight", 0.75).Iterate();
4044
g.V(v1).AddE("knows").To(v3).Property("weight", 0.75).Iterate();
4145

4246
// Retrieve the data from the "marko" vertex
43-
var marko = await g.V().Has("person", "name", "marko").Values<string>("name").Promise(t => t.Next());
47+
var marko = await g.V().Has(VertexLabel, "name", "marko").Values<string>("name").Promise(t => t.Next());
4448
Console.WriteLine("name: " + marko);
4549

4650
// Find the "marko" vertex and then traverse to the people he "knows" and return their data
47-
var peopleMarkoKnows = await g.V().Has("person", "name", "marko").Out("knows").Values<string>("name").Promise(t => t.ToList());
51+
var peopleMarkoKnows = await g.V().Has(VertexLabel, "name", "marko").Out("knows").Values<string>("name").Promise(t => t.ToList());
4852
foreach (var person in peopleMarkoKnows)
4953
{
5054
Console.WriteLine("marko knows " + person);

gremlin-dotnet/Examples/Connections/Connections.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ under the License.
2424

2525
public class ConnectionExample
2626
{
27+
static readonly string ServerHost = Environment.GetEnvironmentVariable("GREMLIN_SERVER_HOST") ?? "localhost";
28+
static readonly int ServerPort = int.Parse(Environment.GetEnvironmentVariable("GREMLIN_SERVER_PORT") ?? "8182");
29+
static readonly string VertexLabel = Environment.GetEnvironmentVariable("VERTEX_LABEL") ?? "connection";
30+
2731
static void Main()
2832
{
2933
WithRemote();
@@ -34,41 +38,38 @@ static void Main()
3438
// Connecting to the server
3539
static void WithRemote()
3640
{
37-
var server = new GremlinServer("localhost", 8182);
41+
var server = new GremlinServer(ServerHost, ServerPort);
3842
using var remoteConnection = new DriverRemoteConnection(new GremlinClient(server), "g");
3943
var g = Traversal().WithRemote(remoteConnection);
4044

41-
// Drop existing vertices
42-
g.V().Drop().Iterate();
43-
4445
// Simple query to verify connection
45-
var v = g.AddV().Iterate();
46-
var count = g.V().Count().Next();
46+
var v = g.AddV(VertexLabel).Iterate();
47+
var count = g.V().HasLabel(VertexLabel).Count().Next();
4748
Console.WriteLine("Vertex count: " + count);
4849
}
4950

5051
// Connecting to the server with customized configurations
5152
static void WithConf()
5253
{
5354
using var remoteConnection = new DriverRemoteConnection(new GremlinClient(
54-
new GremlinServer(hostname: "localhost", port: 8182, enableSsl: false, username: "", password: "")), "g");
55+
new GremlinServer(hostname: ServerHost, port: ServerPort, enableSsl: false, username: "", password: "")), "g");
5556
var g = Traversal().WithRemote(remoteConnection);
5657

57-
var v = g.AddV().Iterate();
58-
var count = g.V().Count().Next();
58+
var v = g.AddV(VertexLabel).Iterate();
59+
var count = g.V().HasLabel(VertexLabel).Count().Next();
5960
Console.WriteLine("Vertex count: " + count);
6061
}
6162

6263
// Specifying a serializer
6364
static void WithSerializer()
6465
{
65-
var server = new GremlinServer("localhost", 8182);
66+
var server = new GremlinServer(ServerHost, ServerPort);
6667
var client = new GremlinClient(server, new GraphSON3MessageSerializer());
6768
using var remoteConnection = new DriverRemoteConnection(client, "g");
6869
var g = Traversal().WithRemote(remoteConnection);
6970

70-
var v = g.AddV().Iterate();
71-
var count = g.V().Count().Next();
71+
var v = g.AddV(VertexLabel).Iterate();
72+
var count = g.V().HasLabel(VertexLabel).Count().Next();
7273
Console.WriteLine("Vertex count: " + count);
7374
}
7475
}

gremlin-dotnet/Examples/ModernTraversals/ModernTraversals.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@ under the License.
2626

2727
public class ModernTraversalExample
2828
{
29+
static readonly string ServerHost = Environment.GetEnvironmentVariable("GREMLIN_SERVER_HOST") ?? "localhost";
30+
static readonly int ServerPort = int.Parse(Environment.GetEnvironmentVariable("GREMLIN_SERVER_PORT") ?? "8182");
31+
static readonly bool IsDocker = Environment.GetEnvironmentVariable("DOCKER_ENVIRONMENT") == "true";
32+
2933
static void Main()
3034
{
31-
var server = new GremlinServer("localhost", 8182);
32-
using var remoteConnection = new DriverRemoteConnection(new GremlinClient(server), "g");
35+
var server = new GremlinServer(ServerHost, ServerPort);
36+
// Use gmodern in CI environment, default connection locally
37+
var traversalSource = IsDocker ? "gmodern" : "g";
38+
using var remoteConnection = new DriverRemoteConnection(new GremlinClient(server), traversalSource);
3339
var g = Traversal().WithRemote(remoteConnection);
3440

3541
/*

gremlin-dotnet/docker-compose.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,19 @@ services:
5353
- ../gremlin-tools/gremlin-socket-server/conf:/gremlin-dotnet/gremlin-socket-server/conf/
5454
environment:
5555
- DOCKER_ENVIRONMENT=true
56+
- GREMLIN_SERVER_HOST=gremlin-server-test-dotnet
57+
- GREMLIN_SERVER_PORT=45940
58+
- VERTEX_LABEL=dotnet-example
5659
working_dir: /gremlin-dotnet
5760
command: >
5861
bash -c "dotnet tool update -g dotnet-trx; dotnet test ./Gremlin.Net.sln -c Release --logger trx; /root/.dotnet/tools/trx;
59-
EXIT_CODE=$$?; chown -R `stat -c "%u:%g" .` .; exit $$EXIT_CODE"
62+
EXIT_CODE=$$?;
63+
echo 'Running examples...';
64+
dotnet run --project Examples/BasicGremlin/BasicGremlin.csproj;
65+
dotnet run --project Examples/Connections/Connections.csproj;
66+
dotnet run --project Examples/ModernTraversals/ModernTraversals.csproj;
67+
echo 'All examples completed successfully';
68+
chown -R `stat -c \"%u:%g\" .` .; exit $$EXIT_CODE"
6069
depends_on:
6170
gremlin-server-test-dotnet:
6271
condition: service_healthy

gremlin-driver/src/main/java/examples/BasicGremlin.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,46 @@ Licensed to the Apache Software Foundation (ASF) under one
1919

2020
package examples;
2121

22+
import org.apache.tinkerpop.gremlin.driver.Cluster;
23+
import org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection;
2224
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
23-
import org.apache.tinkerpop.gremlin.structure.Graph;
2425
import org.apache.tinkerpop.gremlin.structure.Vertex;
25-
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
2626

2727
import java.util.List;
2828

2929
import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
3030

3131
public class BasicGremlin {
32-
public static void main(String[] args) {
33-
Graph graph = TinkerGraph.open();
34-
GraphTraversalSource g = traversal().withEmbedded(graph);
32+
static final String SERVER_HOST = System.getenv().getOrDefault("GREMLIN_SERVER_HOST", "localhost");
33+
static final int SERVER_PORT = Integer.parseInt(System.getenv().getOrDefault("GREMLIN_SERVER_PORT", "8182"));
34+
static final String VERTEX_LABEL = System.getenv().getOrDefault("VERTEX_LABEL", "person");
35+
36+
public static void main(String[] args) throws Exception {
37+
Cluster cluster = Cluster.build(SERVER_HOST).port(SERVER_PORT).create();
38+
GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using(cluster, "g"));
3539

3640
// Basic Gremlin: adding and retrieving data
37-
Vertex v1 = g.addV("person").property("name","marko").next();
38-
Vertex v2 = g.addV("person").property("name","stephen").next();
39-
Vertex v3 = g.addV("person").property("name","vadas").next();
41+
Vertex v1 = g.addV(VERTEX_LABEL).property("name","marko").next();
42+
Vertex v2 = g.addV(VERTEX_LABEL).property("name","stephen").next();
43+
Vertex v3 = g.addV(VERTEX_LABEL).property("name","vadas").next();
4044

4145
// Be sure to use a terminating step like next() or iterate() so that the traversal "executes"
4246
// Iterate() does not return any data and is used to just generate side-effects (i.e. write data to the database)
4347
g.V(v1).addE("knows").to(v2).property("weight",0.75).iterate();
4448
g.V(v1).addE("knows").to(v3).property("weight",0.75).iterate();
4549

4650
// Retrieve the data from the "marko" vertex
47-
Object marko = g.V().has("person","name","marko").values("name").next();
51+
Object marko = g.V().has(VERTEX_LABEL,"name","marko").values("name").next();
4852
System.out.println("name: " + marko);
4953

5054
// Find the "marko" vertex and then traverse to the people he "knows" and return their data
51-
List<Object> peopleMarkoKnows = g.V().has("person","name","marko").out("knows").values("name").toList();
55+
List<Object> peopleMarkoKnows = g.V().has(VERTEX_LABEL,"name","marko").out("knows").values("name").toList();
5256
for (Object person : peopleMarkoKnows) {
5357
System.out.println("marko knows " + person);
5458
}
59+
60+
// Cleanup
61+
cluster.close();
62+
g.close();
5563
}
5664
}

gremlin-driver/src/main/java/examples/Connections.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ Licensed to the Apache Software Foundation (ASF) under one
3535
import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
3636

3737
public class Connections {
38+
static final String SERVER_HOST = System.getenv().getOrDefault("GREMLIN_SERVER_HOST", "localhost");
39+
static final int SERVER_PORT = Integer.parseInt(System.getenv().getOrDefault("GREMLIN_SERVER_PORT", "8182"));
40+
static final String VERTEX_LABEL = System.getenv().getOrDefault("VERTEX_LABEL", "connection");
41+
3842
public static void main(String[] args) throws Exception {
3943
withEmbedded();
4044
withRemote();
@@ -56,15 +60,12 @@ private static void withEmbedded() throws Exception {
5660

5761
// Connecting to the server
5862
private static void withRemote() throws Exception {
59-
Cluster cluster = Cluster.build("localhost").port(8182).create();
63+
Cluster cluster = Cluster.build(SERVER_HOST).port(SERVER_PORT).create();
6064
GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using(cluster, "g"));
6165

62-
// Drop existing vertices
63-
g.V().drop().iterate();
64-
6566
// Simple query to verify connection
66-
g.addV().iterate();
67-
long count = g.V().count().next();
67+
g.addV(VERTEX_LABEL).iterate();
68+
long count = g.V().hasLabel(VERTEX_LABEL).count().next();
6869
System.out.println("Vertex count: " + count);
6970

7071
// Cleanup
@@ -75,12 +76,12 @@ private static void withRemote() throws Exception {
7576
// Connecting and customizing configurations with a cluster
7677
// See reference/#gremlin-java-configuration for full list of configurations
7778
private static void withCluster() throws Exception {
78-
Cluster cluster = Cluster.build("localhost").
79+
Cluster cluster = Cluster.build(SERVER_HOST).
7980
channelizer(Channelizer.WebSocketChannelizer.class).
8081
keepAliveInterval(180000).
8182
maxConnectionPoolSize(8).
8283
path("/gremlin").
83-
port(8182).
84+
port(SERVER_PORT).
8485
serializer(new GraphBinaryMessageSerializerV1()).
8586
create();
8687
GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using(cluster, "g"));
@@ -98,7 +99,8 @@ private static void withSerializer() throws Exception {
9899
IoRegistry registry = new FakeIoRegistry(); // an IoRegistry instance exposed by a specific graph provider
99100
TypeSerializerRegistry typeSerializerRegistry = TypeSerializerRegistry.build().addRegistry(registry).create();
100101
MessageSerializer serializer = new GraphBinaryMessageSerializerV1(typeSerializerRegistry);
101-
Cluster cluster = Cluster.build("localhost").
102+
Cluster cluster = Cluster.build(SERVER_HOST).
103+
port(SERVER_PORT).
102104
serializer(serializer).
103105
create();
104106
Client client = cluster.connect();

gremlin-driver/src/main/java/examples/ModernTraversals.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ Licensed to the Apache Software Foundation (ASF) under one
1919

2020
package examples;
2121

22+
import org.apache.tinkerpop.gremlin.driver.Cluster;
23+
import org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection;
2224
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
2325
import org.apache.tinkerpop.gremlin.structure.Edge;
24-
import org.apache.tinkerpop.gremlin.structure.Graph;
2526
import org.apache.tinkerpop.gremlin.structure.Vertex;
26-
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
2727

2828
import java.util.List;
2929

@@ -33,10 +33,13 @@ Licensed to the Apache Software Foundation (ASF) under one
3333
import static org.apache.tinkerpop.gremlin.structure.T.id;
3434

3535
public class ModernTraversals {
36-
public static void main(String[] args) {
37-
// Performs basic traversals on the Modern toy graph which can be created using TinkerFactory
38-
Graph modern = TinkerFactory.createModern();
39-
GraphTraversalSource g = traversal().withEmbedded(modern);
36+
static final String SERVER_HOST = System.getenv().getOrDefault("GREMLIN_SERVER_HOST", "localhost");
37+
static final int SERVER_PORT = Integer.parseInt(System.getenv().getOrDefault("GREMLIN_SERVER_PORT", "8182"));
38+
39+
public static void main(String[] args) throws Exception {
40+
// Performs basic traversals on the Modern toy graph loaded on the server
41+
Cluster cluster = Cluster.build(SERVER_HOST).port(SERVER_PORT).create();
42+
GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using(cluster, "g"));
4043

4144
List<Edge> e1 = g.V(1).bothE().toList(); // (1)
4245
List<Edge> e2 = g.V(1).bothE().where(otherV().hasId(2)).toList(); // (2)
@@ -54,6 +57,10 @@ public static void main(String[] args) {
5457
System.out.println("5: " + e5.toString());
5558
System.out.println("6: " + e6.toString());
5659

60+
// Cleanup
61+
cluster.close();
62+
g.close();
63+
5764
/*
5865
1. There are three edges from the vertex with the identifier of "1".
5966
2. Filter those three edges using the where()-step using the identifier of the vertex returned by otherV() to
@@ -69,3 +76,5 @@ steps of outE() and inV() since the schema allows it.
6976
*/
7077
}
7178
}
79+
80+

gremlin-examples/gremlin-dotnet/BasicGremlin/BasicGremlin.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,32 @@ under the License.
2323

2424
public class BasicGremlinExample
2525
{
26+
static readonly string ServerHost = "localhost";
27+
static readonly int ServerPort = 8182;
28+
static readonly string VertexLabel = "person";
29+
2630
static async Task Main()
2731
{
28-
var server = new GremlinServer("localhost", 8182);
32+
var server = new GremlinServer(ServerHost, ServerPort);
2933
using var remoteConnection = new DriverRemoteConnection(new GremlinClient(server), "g");
3034
var g = Traversal().WithRemote(remoteConnection);
3135

3236
// Basic Gremlin: adding and retrieving data
33-
var v1 = g.AddV("person").Property("name", "marko").Next();
34-
var v2 = g.AddV("person").Property("name", "stephen").Next();
35-
var v3 = g.AddV("person").Property("name", "vadas").Next();
37+
var v1 = g.AddV(VertexLabel).Property("name", "marko").Next();
38+
var v2 = g.AddV(VertexLabel).Property("name", "stephen").Next();
39+
var v3 = g.AddV(VertexLabel).Property("name", "vadas").Next();
3640

3741
// Be sure to use a terminating step like Next() or Iterate() so that the traversal "executes"
3842
// Iterate() does not return any data and is used to just generate side-effects (i.e. write data to the database)
3943
g.V(v1).AddE("knows").To(v2).Property("weight", 0.75).Iterate();
4044
g.V(v1).AddE("knows").To(v3).Property("weight", 0.75).Iterate();
4145

4246
// Retrieve the data from the "marko" vertex
43-
var marko = await g.V().Has("person", "name", "marko").Values<string>("name").Promise(t => t.Next());
47+
var marko = await g.V().Has(VertexLabel, "name", "marko").Values<string>("name").Promise(t => t.Next());
4448
Console.WriteLine("name: " + marko);
4549

4650
// Find the "marko" vertex and then traverse to the people he "knows" and return their data
47-
var peopleMarkoKnows = await g.V().Has("person", "name", "marko").Out("knows").Values<string>("name").Promise(t => t.ToList());
51+
var peopleMarkoKnows = await g.V().Has(VertexLabel, "name", "marko").Out("knows").Values<string>("name").Promise(t => t.ToList());
4852
foreach (var person in peopleMarkoKnows)
4953
{
5054
Console.WriteLine("marko knows " + person);

0 commit comments

Comments
 (0)