This is an automated email from the ASF dual-hosted git repository.
xiazcy pushed a commit to branch dotnet-http-interceptors
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
The following commit(s) were added to refs/heads/dotnet-http-interceptors by
this push:
new 7c4b05f6c2 Fix examples
7c4b05f6c2 is described below
commit 7c4b05f6c25bb2211503be2a0bc6503bd8ea63b7
Author: Yang Xia <[email protected]>
AuthorDate: Thu Mar 19 09:49:52 2026 -0700
Fix examples
---
.../Examples/BasicGremlin/BasicGremlin.cs | 5 +++--
gremlin-dotnet/Examples/Connections/Connections.cs | 25 ++++++++++++++--------
gremlin-dotnet/docker-compose.yml | 2 +-
3 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/gremlin-dotnet/Examples/BasicGremlin/BasicGremlin.cs
b/gremlin-dotnet/Examples/BasicGremlin/BasicGremlin.cs
index fc97a24ab1..d642d96f0d 100644
--- a/gremlin-dotnet/Examples/BasicGremlin/BasicGremlin.cs
+++ b/gremlin-dotnet/Examples/BasicGremlin/BasicGremlin.cs
@@ -20,6 +20,7 @@ under the License.
using Gremlin.Net.Driver;
using Gremlin.Net.Driver.Remote;
using static Gremlin.Net.Process.Traversal.AnonymousTraversalSource;
+using static Gremlin.Net.Process.Traversal.__;
public class BasicGremlinExample
{
@@ -40,8 +41,8 @@ public class BasicGremlinExample
// Be sure to use a terminating step like Next() or Iterate() so that
the traversal "executes"
// Iterate() does not return any data and is used to just generate
side-effects (i.e. write data to the database)
- g.V(v1).AddE("knows").To(v2).Property("weight", 0.75).Iterate();
- g.V(v1).AddE("knows").To(v3).Property("weight", 0.75).Iterate();
+ g.V(v1).AddE("knows").To(Constant(v2)).Property("weight",
0.75).Iterate();
+ g.V(v1).AddE("knows").To(Constant(v3)).Property("weight",
0.75).Iterate();
// Retrieve the data from the "marko" vertex
var marko = await g.V().Has(VertexLabel, "name",
"marko").Values<string>("name").Promise(t => t.Next());
diff --git a/gremlin-dotnet/Examples/Connections/Connections.cs
b/gremlin-dotnet/Examples/Connections/Connections.cs
index 519eb70363..bc1eb42af3 100644
--- a/gremlin-dotnet/Examples/Connections/Connections.cs
+++ b/gremlin-dotnet/Examples/Connections/Connections.cs
@@ -19,20 +19,20 @@ under the License.
using Gremlin.Net.Driver;
using Gremlin.Net.Driver.Remote;
-using Gremlin.Net.Structure.IO.GraphSON;
using static Gremlin.Net.Process.Traversal.AnonymousTraversalSource;
public class ConnectionExample
{
static readonly string ServerHost =
Environment.GetEnvironmentVariable("GREMLIN_SERVER_HOST") ?? "localhost";
static readonly int ServerPort =
int.Parse(Environment.GetEnvironmentVariable("GREMLIN_SERVER_PORT") ?? "8182");
+ static readonly int SecureServerPort =
int.Parse(Environment.GetEnvironmentVariable("GREMLIN_SECURE_SERVER_PORT") ??
"8183");
static readonly string VertexLabel =
Environment.GetEnvironmentVariable("VERTEX_LABEL") ?? "connection";
static void Main()
{
WithRemoteConnection();
WithConf();
- WithSerializer();
+ WithBasicAuth();
}
// Connecting to the server
@@ -48,11 +48,16 @@ public class ConnectionExample
Console.WriteLine("Vertex count: " + count);
}
- // Connecting to the server with customized configurations
+ // Connecting to the server with customized connection settings
static void WithConf()
{
- using var remoteConnection = new DriverRemoteConnection(new
GremlinClient(
- new GremlinServer(hostname: ServerHost, port: ServerPort, enableSsl:
false)), "g");
+ var server = new GremlinServer(ServerHost, ServerPort);
+ var settings = new ConnectionSettings
+ {
+ ConnectionTimeout = TimeSpan.FromSeconds(30),
+ };
+ using var remoteConnection = new DriverRemoteConnection(
+ new GremlinClient(server, connectionSettings: settings), "g");
var g = Traversal().With(remoteConnection);
var v = g.AddV(VertexLabel).Iterate();
@@ -60,11 +65,13 @@ public class ConnectionExample
Console.WriteLine("Vertex count: " + count);
}
- // Specifying a serializer
- static void WithSerializer()
+ // Connecting with basic authentication using a request interceptor
+ static void WithBasicAuth()
{
- var server = new GremlinServer(ServerHost, ServerPort);
- var client = new GremlinClient(server, new
GraphSON3MessageSerializer());
+ var server = new GremlinServer(ServerHost, SecureServerPort,
enableSsl: true);
+ var client = new GremlinClient(server,
+ connectionSettings: new ConnectionSettings {
SkipCertificateValidation = true },
+ interceptors: new[] { Auth.BasicAuth("stephen", "password") });
using var remoteConnection = new DriverRemoteConnection(client, "g");
var g = Traversal().With(remoteConnection);
diff --git a/gremlin-dotnet/docker-compose.yml
b/gremlin-dotnet/docker-compose.yml
index b29e9036f6..1037ab0f92 100644
--- a/gremlin-dotnet/docker-compose.yml
+++ b/gremlin-dotnet/docker-compose.yml
@@ -54,9 +54,9 @@ services:
- DOCKER_ENVIRONMENT=true
- GREMLIN_SERVER_HOST=gremlin-server-test-dotnet
- GREMLIN_SERVER_PORT=45940
+ - GREMLIN_SECURE_SERVER_PORT=45941
- VERTEX_LABEL=dotnet-example
working_dir: /gremlin-dotnet
- # TODO: fix examples issue after feature-completion
command: >
bash -c "find . -path '*/TestResults/*.trx' -delete 2>/dev/null || true;
dotnet tool update -g dotnet-trx; dotnet test ./Gremlin.Net.sln -c
Release --logger trx;