This is an automated email from the ASF dual-hosted git repository.
colegreer pushed a commit to branch 3.7-dev
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
The following commit(s) were added to refs/heads/3.7-dev by this push:
new c8665d6852 Integrate Go driver examples into automated build process
(#3239)
c8665d6852 is described below
commit c8665d6852f5445bb5ac5e8527d4ea413ad70f41
Author: kirill-stepanishin <[email protected]>
AuthorDate: Mon Jan 12 12:04:36 2026 -0800
Integrate Go driver examples into automated build process (#3239)
Summary
Integrates Go Gremlin examples into CI to ensure they remain functional in
future releases. Examples now execute automatically after integration tests and
fail the build if broken.
Changes Made
- Added example execution to gremlin-go-integration-tests container in
docker-compose.yml
- Made server URLs configurable via environment variables (replaces
hardcoded localhost:8182)
- Use specialized labels to isolate test data- Build fails if any example
fails to execute
---
gremlin-examples/gremlin-go/basic_gremlin.go | 17 ++++++-----
gremlin-examples/gremlin-go/connections.go | 31 +++++++++----------
gremlin-examples/gremlin-go/modern_traversals.go | 3 +-
gremlin-go/docker-compose.yml | 8 ++++-
gremlin-go/examples/basic_gremlin.go | 25 ++++++++++-----
gremlin-go/examples/connections.go | 39 ++++++++++++++----------
gremlin-go/examples/modern_traversals.go | 14 ++++++++-
7 files changed, 88 insertions(+), 49 deletions(-)
diff --git a/gremlin-examples/gremlin-go/basic_gremlin.go
b/gremlin-examples/gremlin-go/basic_gremlin.go
index 0ab2b1117f..2480ebd424 100644
--- a/gremlin-examples/gremlin-go/basic_gremlin.go
+++ b/gremlin-examples/gremlin-go/basic_gremlin.go
@@ -25,8 +25,11 @@ import (
"github.com/apache/tinkerpop/gremlin-go/v3/driver"
)
+var serverURL = "ws://localhost:8182/gremlin"
+var vertexLabel = "person"
+
func main() {
- driverRemoteConnection, err :=
gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin")
+ driverRemoteConnection, err :=
gremlingo.NewDriverRemoteConnection(serverURL)
if err != nil {
fmt.Println(err)
return
@@ -35,9 +38,9 @@ func main() {
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)
// Basic Gremlin: adding and retrieving data
- v1, err := g.AddV("person").Property("name", "marko").Next()
- v2, err := g.AddV("person").Property("name", "stephen").Next()
- v3, err := g.AddV("person").Property("name", "vadas").Next()
+ v1, err := g.AddV(vertexLabel).Property("name", "marko").Next()
+ v2, err := g.AddV(vertexLabel).Property("name", "stephen").Next()
+ v3, err := g.AddV(vertexLabel).Property("name", "vadas").Next()
v1Vertex, err := v1.GetVertex()
v2Vertex, err := v2.GetVertex()
v3Vertex, err := v3.GetVertex()
@@ -58,12 +61,12 @@ func main() {
}
// Retrieve the data from the "marko" vertex
- marko, err := g.V().Has("person", "name", "marko").Values("name").Next()
+ marko, err := g.V().Has(vertexLabel, "name",
"marko").Values("name").Next()
fmt.Println("name:", marko.GetString())
// Find the "marko" vertex and then traverse to the people he "knows"
and return their data
- peopleMarkoKnows, err := g.V().Has("person", "name",
"marko").Out("knows").Values("name").ToList()
+ peopleMarkoKnows, err := g.V().Has(vertexLabel, "name",
"marko").Out("knows").Values("name").ToList()
for _, person := range peopleMarkoKnows {
fmt.Println("marko knows", person.GetString())
}
-}
\ No newline at end of file
+}
diff --git a/gremlin-examples/gremlin-go/connections.go
b/gremlin-examples/gremlin-go/connections.go
index 3e1f1de174..467cc94645 100644
--- a/gremlin-examples/gremlin-go/connections.go
+++ b/gremlin-examples/gremlin-go/connections.go
@@ -25,14 +25,17 @@ import (
"github.com/apache/tinkerpop/gremlin-go/v3/driver"
)
+var serverURL = "ws://localhost:8182/gremlin"
+var vertexLabel = "connection"
+
func main() {
withRemote()
withConfigs()
}
func withRemote() {
- // Creating the connection to the server
- driverRemoteConnection, err :=
gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin")
+ // Creating the connection to the server
+ driverRemoteConnection, err :=
gremlingo.NewDriverRemoteConnection(serverURL)
// Error handling
if err != nil {
@@ -43,22 +46,18 @@ func withRemote() {
// Cleanup
defer driverRemoteConnection.Close()
- // Creating the graph traversal
+ // Creating the graph traversal
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)
- // Drop existing vertices
- prom := g.V().Drop().Iterate()
- <-prom
-
- // Simple query to verify connection
- g.AddV().Iterate()
- count, _ := g.V().Count().Next()
- fmt.Println("Vertex count:", *count)
+ // Simple query to verify connection
+ g.AddV(vertexLabel).Iterate()
+ count, _ := g.V().HasLabel(vertexLabel).Count().Next()
+ fmt.Println("Vertex count:", *count)
}
func withConfigs() {
// Connecting to the server with customized configurations
- driverRemoteConnection, err :=
gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin",
+ driverRemoteConnection, err :=
gremlingo.NewDriverRemoteConnection(serverURL,
func(settings *gremlingo.DriverRemoteConnectionSettings) {
settings.TraversalSource = "g"
settings.NewConnectionThreshold = 4
@@ -75,7 +74,7 @@ func withConfigs() {
defer driverRemoteConnection.Close()
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)
- g.AddV().Iterate()
- count, _ := g.V().Count().Next()
- fmt.Println("Vertex count:", *count)
-}
\ No newline at end of file
+ g.AddV(vertexLabel).Iterate()
+ count, _ := g.V().HasLabel(vertexLabel).Count().Next()
+ fmt.Println("Vertex count:", *count)
+}
diff --git a/gremlin-examples/gremlin-go/modern_traversals.go
b/gremlin-examples/gremlin-go/modern_traversals.go
index a1c9ad8320..7781d3e11c 100644
--- a/gremlin-examples/gremlin-go/modern_traversals.go
+++ b/gremlin-examples/gremlin-go/modern_traversals.go
@@ -28,9 +28,10 @@ import (
var __ = gremlingo.T__
var T = gremlingo.T
var P = gremlingo.P
+var serverURL = "ws://localhost:8182/gremlin"
func main() {
- driverRemoteConnection, err :=
gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin")
+ driverRemoteConnection, err :=
gremlingo.NewDriverRemoteConnection(serverURL)
if err != nil {
fmt.Println(err)
return
diff --git a/gremlin-go/docker-compose.yml b/gremlin-go/docker-compose.yml
index 36fafcb424..611b15dde0 100644
--- a/gremlin-go/docker-compose.yml
+++ b/gremlin-go/docker-compose.yml
@@ -60,10 +60,16 @@ services:
- RUN_BASIC_AUTH_INTEGRATION_TESTS=true
- GREMLIN_SOCKET_SERVER_URL=ws://gremlin-socket-server-go
-
GREMLIN_SOCKET_SERVER_CONFIG_PATH=/go_app/gremlin-socket-server/conf/test-ws-gremlin.yaml
+ - VERTEX_LABEL=go-example
working_dir: /go_app
command: >
bash -c "go install
github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
- && go test -v -json ./... -race -covermode=atomic
-coverprofile=\"coverage.out\" -coverpkg=./... | gotestfmt"
+ && go test -v -json ./... -race -covermode=atomic
-coverprofile=\"coverage.out\" -coverpkg=./... | gotestfmt
+ && echo 'Running examples...'
+ && go run examples/basic_gremlin.go
+ && go run examples/connections.go
+ && go run examples/modern_traversals.go
+ && echo 'All examples completed successfully'"
depends_on:
gremlin-server-test:
condition: service_healthy
diff --git a/gremlin-go/examples/basic_gremlin.go
b/gremlin-go/examples/basic_gremlin.go
index 0ab2b1117f..4220b96a4b 100644
--- a/gremlin-go/examples/basic_gremlin.go
+++ b/gremlin-go/examples/basic_gremlin.go
@@ -21,12 +21,23 @@ package main
import (
"fmt"
+ "os"
"github.com/apache/tinkerpop/gremlin-go/v3/driver"
)
+var serverURL = getEnv("GREMLIN_SERVER_URL", "ws://localhost:8182/gremlin")
+var vertexLabel = getEnv("VERTEX_LABEL", "person")
+
+func getEnv(key, defaultValue string) string {
+ if value := os.Getenv(key); value != "" {
+ return value
+ }
+ return defaultValue
+}
+
func main() {
- driverRemoteConnection, err :=
gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin")
+ driverRemoteConnection, err :=
gremlingo.NewDriverRemoteConnection(serverURL)
if err != nil {
fmt.Println(err)
return
@@ -35,9 +46,9 @@ func main() {
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)
// Basic Gremlin: adding and retrieving data
- v1, err := g.AddV("person").Property("name", "marko").Next()
- v2, err := g.AddV("person").Property("name", "stephen").Next()
- v3, err := g.AddV("person").Property("name", "vadas").Next()
+ v1, err := g.AddV(vertexLabel).Property("name", "marko").Next()
+ v2, err := g.AddV(vertexLabel).Property("name", "stephen").Next()
+ v3, err := g.AddV(vertexLabel).Property("name", "vadas").Next()
v1Vertex, err := v1.GetVertex()
v2Vertex, err := v2.GetVertex()
v3Vertex, err := v3.GetVertex()
@@ -58,12 +69,12 @@ func main() {
}
// Retrieve the data from the "marko" vertex
- marko, err := g.V().Has("person", "name", "marko").Values("name").Next()
+ marko, err := g.V().Has(vertexLabel, "name",
"marko").Values("name").Next()
fmt.Println("name:", marko.GetString())
// Find the "marko" vertex and then traverse to the people he "knows"
and return their data
- peopleMarkoKnows, err := g.V().Has("person", "name",
"marko").Out("knows").Values("name").ToList()
+ peopleMarkoKnows, err := g.V().Has(vertexLabel, "name",
"marko").Out("knows").Values("name").ToList()
for _, person := range peopleMarkoKnows {
fmt.Println("marko knows", person.GetString())
}
-}
\ No newline at end of file
+}
diff --git a/gremlin-go/examples/connections.go
b/gremlin-go/examples/connections.go
index 3e1f1de174..f2883e371d 100644
--- a/gremlin-go/examples/connections.go
+++ b/gremlin-go/examples/connections.go
@@ -21,18 +21,29 @@ package main
import (
"fmt"
+ "os"
"github.com/apache/tinkerpop/gremlin-go/v3/driver"
)
+var serverURL = getEnv("GREMLIN_SERVER_URL", "ws://localhost:8182/gremlin")
+var vertexLabel = getEnv("VERTEX_LABEL", "connection")
+
+func getEnv(key, defaultValue string) string {
+ if value := os.Getenv(key); value != "" {
+ return value
+ }
+ return defaultValue
+}
+
func main() {
withRemote()
withConfigs()
}
func withRemote() {
- // Creating the connection to the server
- driverRemoteConnection, err :=
gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin")
+ // Creating the connection to the server
+ driverRemoteConnection, err :=
gremlingo.NewDriverRemoteConnection(serverURL)
// Error handling
if err != nil {
@@ -43,22 +54,18 @@ func withRemote() {
// Cleanup
defer driverRemoteConnection.Close()
- // Creating the graph traversal
+ // Creating the graph traversal
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)
- // Drop existing vertices
- prom := g.V().Drop().Iterate()
- <-prom
-
- // Simple query to verify connection
- g.AddV().Iterate()
- count, _ := g.V().Count().Next()
- fmt.Println("Vertex count:", *count)
+ // Simple query to verify connection
+ g.AddV(vertexLabel).Iterate()
+ count, _ := g.V().HasLabel(vertexLabel).Count().Next()
+ fmt.Println("Vertex count:", *count)
}
func withConfigs() {
// Connecting to the server with customized configurations
- driverRemoteConnection, err :=
gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin",
+ driverRemoteConnection, err :=
gremlingo.NewDriverRemoteConnection(serverURL,
func(settings *gremlingo.DriverRemoteConnectionSettings) {
settings.TraversalSource = "g"
settings.NewConnectionThreshold = 4
@@ -75,7 +82,7 @@ func withConfigs() {
defer driverRemoteConnection.Close()
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)
- g.AddV().Iterate()
- count, _ := g.V().Count().Next()
- fmt.Println("Vertex count:", *count)
-}
\ No newline at end of file
+ g.AddV(vertexLabel).Iterate()
+ count, _ := g.V().HasLabel(vertexLabel).Count().Next()
+ fmt.Println("Vertex count:", *count)
+}
diff --git a/gremlin-go/examples/modern_traversals.go
b/gremlin-go/examples/modern_traversals.go
index a1c9ad8320..b722b2812d 100644
--- a/gremlin-go/examples/modern_traversals.go
+++ b/gremlin-go/examples/modern_traversals.go
@@ -21,6 +21,7 @@ package main
import (
"fmt"
+ "os"
"github.com/apache/tinkerpop/gremlin-go/v3/driver"
)
@@ -28,9 +29,20 @@ import (
var __ = gremlingo.T__
var T = gremlingo.T
var P = gremlingo.P
+var serverURL = getEnv("GREMLIN_SERVER_URL", "ws://localhost:8182/gremlin")
+
+func getEnv(key, defaultValue string) string {
+ if value := os.Getenv(key); value != "" {
+ return value
+ }
+ return defaultValue
+}
func main() {
- driverRemoteConnection, err :=
gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin")
+ driverRemoteConnection, err :=
gremlingo.NewDriverRemoteConnection(serverURL,
+ func(settings *gremlingo.DriverRemoteConnectionSettings) {
+ settings.TraversalSource = "gmodern"
+ })
if err != nil {
fmt.Println(err)
return