From 81d6dc0daf6f2328e6f67429507076f27c13f980 Mon Sep 17 00:00:00 2001 From: Kirill Stepanishin Date: Thu, 22 Jan 2026 15:19:25 -0800 Subject: [PATCH 1/2] Integrate Java driver examples into CI testing - Move examples from gremlin-driver to gremlin-server test sources - Add DriverExamplesIntegrateTest to run examples against test server - Change examples to use System.getProperty for test compatibility - Update ModernTraversals to use gmodern traversal source - Remove compiler exclusion for examples in gremlin-driver pom --- gremlin-driver/pom.xml | 5 - gremlin-driver/src/main/java/examples/pom.xml | 91 ------------------- .../src/test}/java/examples/BasicGremlin.java | 6 +- .../src/test}/java/examples/Connections.java | 6 +- .../test}/java/examples/ModernTraversals.java | 6 +- .../driver/DriverExamplesIntegrateTest.java | 77 ++++++++++++++++ 6 files changed, 86 insertions(+), 105 deletions(-) delete mode 100644 gremlin-driver/src/main/java/examples/pom.xml rename {gremlin-driver/src/main => gremlin-server/src/test}/java/examples/BasicGremlin.java (89%) rename {gremlin-driver/src/main => gremlin-server/src/test}/java/examples/Connections.java (93%) rename {gremlin-driver/src/main => gremlin-server/src/test}/java/examples/ModernTraversals.java (93%) create mode 100644 gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/DriverExamplesIntegrateTest.java diff --git a/gremlin-driver/pom.xml b/gremlin-driver/pom.xml index 49fc17b25e0..f61ec74fead 100644 --- a/gremlin-driver/pom.xml +++ b/gremlin-driver/pom.xml @@ -268,11 +268,6 @@ limitations under the License. org.apache.maven.plugins maven-compiler-plugin - - - examples/** - - diff --git a/gremlin-driver/src/main/java/examples/pom.xml b/gremlin-driver/src/main/java/examples/pom.xml deleted file mode 100644 index 85417eff1dc..00000000000 --- a/gremlin-driver/src/main/java/examples/pom.xml +++ /dev/null @@ -1,91 +0,0 @@ - - - 4.0.0 - - org.apache.tinkerpop - run-examples - 3.7.1 - - - UTF-8 - ${project.version} - - - - - org.apache.tinkerpop - gremlin-core - ${project.version} - - - org.apache.tinkerpop - gremlin-driver - ${project.version} - - - org.apache.tinkerpop - tinkergraph-gremlin - ${project.version} - - - - - . - - - org.apache.maven.plugins - maven-compiler-plugin - - - org.apache.maven.plugins - maven-shade-plugin - 3.4.1 - - - package - - shade - - - run-examples-shaded - false - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - - - - - - - \ No newline at end of file diff --git a/gremlin-driver/src/main/java/examples/BasicGremlin.java b/gremlin-server/src/test/java/examples/BasicGremlin.java similarity index 89% rename from gremlin-driver/src/main/java/examples/BasicGremlin.java rename to gremlin-server/src/test/java/examples/BasicGremlin.java index 13bc53b7ed0..ffee2dabaea 100644 --- a/gremlin-driver/src/main/java/examples/BasicGremlin.java +++ b/gremlin-server/src/test/java/examples/BasicGremlin.java @@ -29,9 +29,9 @@ Licensed to the Apache Software Foundation (ASF) under one import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal; public class BasicGremlin { - static final String SERVER_HOST = System.getenv().getOrDefault("GREMLIN_SERVER_HOST", "localhost"); - static final int SERVER_PORT = Integer.parseInt(System.getenv().getOrDefault("GREMLIN_SERVER_PORT", "8182")); - static final String VERTEX_LABEL = System.getenv().getOrDefault("VERTEX_LABEL", "person"); + static final String SERVER_HOST = System.getProperty("GREMLIN_SERVER_HOST", "localhost"); + static final int SERVER_PORT = Integer.parseInt(System.getProperty("GREMLIN_SERVER_PORT", "8182")); + static final String VERTEX_LABEL = System.getProperty("VERTEX_LABEL", "person"); public static void main(String[] args) throws Exception { Cluster cluster = Cluster.build(SERVER_HOST).port(SERVER_PORT).create(); diff --git a/gremlin-driver/src/main/java/examples/Connections.java b/gremlin-server/src/test/java/examples/Connections.java similarity index 93% rename from gremlin-driver/src/main/java/examples/Connections.java rename to gremlin-server/src/test/java/examples/Connections.java index 549c8c7bb95..f48b1b811b2 100644 --- a/gremlin-driver/src/main/java/examples/Connections.java +++ b/gremlin-server/src/test/java/examples/Connections.java @@ -35,9 +35,9 @@ Licensed to the Apache Software Foundation (ASF) under one import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal; public class Connections { - static final String SERVER_HOST = System.getenv().getOrDefault("GREMLIN_SERVER_HOST", "localhost"); - static final int SERVER_PORT = Integer.parseInt(System.getenv().getOrDefault("GREMLIN_SERVER_PORT", "8182")); - static final String VERTEX_LABEL = System.getenv().getOrDefault("VERTEX_LABEL", "connection"); + static final String SERVER_HOST = System.getProperty("GREMLIN_SERVER_HOST", "localhost"); + static final int SERVER_PORT = Integer.parseInt(System.getProperty("GREMLIN_SERVER_PORT", "8182")); + static final String VERTEX_LABEL = System.getProperty("VERTEX_LABEL", "connection"); public static void main(String[] args) throws Exception { withEmbedded(); diff --git a/gremlin-driver/src/main/java/examples/ModernTraversals.java b/gremlin-server/src/test/java/examples/ModernTraversals.java similarity index 93% rename from gremlin-driver/src/main/java/examples/ModernTraversals.java rename to gremlin-server/src/test/java/examples/ModernTraversals.java index 375d17c6972..4ba5415b991 100644 --- a/gremlin-driver/src/main/java/examples/ModernTraversals.java +++ b/gremlin-server/src/test/java/examples/ModernTraversals.java @@ -33,13 +33,13 @@ Licensed to the Apache Software Foundation (ASF) under one import static org.apache.tinkerpop.gremlin.structure.T.id; public class ModernTraversals { - static final String SERVER_HOST = System.getenv().getOrDefault("GREMLIN_SERVER_HOST", "localhost"); - static final int SERVER_PORT = Integer.parseInt(System.getenv().getOrDefault("GREMLIN_SERVER_PORT", "8182")); + static final String SERVER_HOST = System.getProperty("GREMLIN_SERVER_HOST", "localhost"); + static final int SERVER_PORT = Integer.parseInt(System.getProperty("GREMLIN_SERVER_PORT", "8182")); public static void main(String[] args) throws Exception { // Performs basic traversals on the Modern toy graph loaded on the server Cluster cluster = Cluster.build(SERVER_HOST).port(SERVER_PORT).create(); - GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using(cluster, "g")); + GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using(cluster, "gmodern")); List e1 = g.V(1).bothE().toList(); // (1) List e2 = g.V(1).bothE().where(otherV().hasId(2)).toList(); // (2) diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/DriverExamplesIntegrateTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/DriverExamplesIntegrateTest.java new file mode 100644 index 00000000000..f83966c3712 --- /dev/null +++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/DriverExamplesIntegrateTest.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tinkerpop.gremlin.driver; + +import examples.BasicGremlin; +import examples.Connections; +import examples.ModernTraversals; +import org.apache.tinkerpop.gremlin.server.AbstractGremlinServerIntegrationTest; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.fail; + +/** + * Integration tests for driver examples to ensure they work with the current driver. + * These tests catch breaking changes that would affect example code. + */ +public class DriverExamplesIntegrateTest extends AbstractGremlinServerIntegrationTest { + + @BeforeClass + public static void setUpEnvironment() { + // Set environment variables for examples to connect to test server + System.setProperty("GREMLIN_SERVER_HOST", "localhost"); + System.setProperty("GREMLIN_SERVER_PORT", "45940"); + } + + @AfterClass + public static void tearDownAfterClass() { + // Clean up system properties + System.clearProperty("GREMLIN_SERVER_HOST"); + System.clearProperty("GREMLIN_SERVER_PORT"); + } + + @Test + public void shouldRunBasicGremlinExample() throws Exception { + try { + BasicGremlin.main(new String[]{}); + } catch (Exception e) { + fail("BasicGremlin example failed: " + e.getMessage()); + } + } + + @Test + public void shouldRunModernTraversalsExample() throws Exception { + try { + ModernTraversals.main(new String[]{}); + } catch (Exception e) { + fail("ModernTraversals example failed: " + e.getMessage()); + } + } + + @Test + public void shouldRunConnectionsExample() throws Exception { + try { + Connections.main(new String[]{}); + } catch (Exception e) { + fail("Connections example failed: " + e.getMessage()); + } + } +} From d2d568aa5ede8246c033b32aafbdfb4abdab1345 Mon Sep 17 00:00:00 2001 From: Kirill Stepanishin Date: Tue, 27 Jan 2026 09:43:23 -0800 Subject: [PATCH 2/2] Rename tearDownAfterClass() --- .../tinkerpop/gremlin/driver/DriverExamplesIntegrateTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/DriverExamplesIntegrateTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/DriverExamplesIntegrateTest.java index f83966c3712..742468ae611 100644 --- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/DriverExamplesIntegrateTest.java +++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/DriverExamplesIntegrateTest.java @@ -42,7 +42,7 @@ public static void setUpEnvironment() { } @AfterClass - public static void tearDownAfterClass() { + public static void tearDownEnvironment() { // Clean up system properties System.clearProperty("GREMLIN_SERVER_HOST"); System.clearProperty("GREMLIN_SERVER_PORT");