Skip to content

Commit 81d6dc0

Browse files
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
1 parent e8446d2 commit 81d6dc0

6 files changed

Lines changed: 86 additions & 105 deletions

File tree

gremlin-driver/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,6 @@ limitations under the License.
268268
<plugin>
269269
<groupId>org.apache.maven.plugins</groupId>
270270
<artifactId>maven-compiler-plugin</artifactId>
271-
<configuration>
272-
<excludes>
273-
<exclude>examples/**</exclude>
274-
</excludes>
275-
</configuration>
276271
</plugin>
277272
</plugins>
278273
</build>

gremlin-driver/src/main/java/examples/pom.xml

Lines changed: 0 additions & 91 deletions
This file was deleted.

gremlin-driver/src/main/java/examples/BasicGremlin.java renamed to gremlin-server/src/test/java/examples/BasicGremlin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ Licensed to the Apache Software Foundation (ASF) under one
2929
import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
3030

3131
public class BasicGremlin {
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");
32+
static final String SERVER_HOST = System.getProperty("GREMLIN_SERVER_HOST", "localhost");
33+
static final int SERVER_PORT = Integer.parseInt(System.getProperty("GREMLIN_SERVER_PORT", "8182"));
34+
static final String VERTEX_LABEL = System.getProperty("VERTEX_LABEL", "person");
3535

3636
public static void main(String[] args) throws Exception {
3737
Cluster cluster = Cluster.build(SERVER_HOST).port(SERVER_PORT).create();

gremlin-driver/src/main/java/examples/Connections.java renamed to gremlin-server/src/test/java/examples/Connections.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ 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");
38+
static final String SERVER_HOST = System.getProperty("GREMLIN_SERVER_HOST", "localhost");
39+
static final int SERVER_PORT = Integer.parseInt(System.getProperty("GREMLIN_SERVER_PORT", "8182"));
40+
static final String VERTEX_LABEL = System.getProperty("VERTEX_LABEL", "connection");
4141

4242
public static void main(String[] args) throws Exception {
4343
withEmbedded();

gremlin-driver/src/main/java/examples/ModernTraversals.java renamed to gremlin-server/src/test/java/examples/ModernTraversals.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +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-
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"));
36+
static final String SERVER_HOST = System.getProperty("GREMLIN_SERVER_HOST", "localhost");
37+
static final int SERVER_PORT = Integer.parseInt(System.getProperty("GREMLIN_SERVER_PORT", "8182"));
3838

3939
public static void main(String[] args) throws Exception {
4040
// Performs basic traversals on the Modern toy graph loaded on the server
4141
Cluster cluster = Cluster.build(SERVER_HOST).port(SERVER_PORT).create();
42-
GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using(cluster, "g"));
42+
GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using(cluster, "gmodern"));
4343

4444
List<Edge> e1 = g.V(1).bothE().toList(); // (1)
4545
List<Edge> e2 = g.V(1).bothE().where(otherV().hasId(2)).toList(); // (2)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.tinkerpop.gremlin.driver;
20+
21+
import examples.BasicGremlin;
22+
import examples.Connections;
23+
import examples.ModernTraversals;
24+
import org.apache.tinkerpop.gremlin.server.AbstractGremlinServerIntegrationTest;
25+
import org.junit.AfterClass;
26+
import org.junit.BeforeClass;
27+
import org.junit.Test;
28+
29+
import static org.junit.Assert.fail;
30+
31+
/**
32+
* Integration tests for driver examples to ensure they work with the current driver.
33+
* These tests catch breaking changes that would affect example code.
34+
*/
35+
public class DriverExamplesIntegrateTest extends AbstractGremlinServerIntegrationTest {
36+
37+
@BeforeClass
38+
public static void setUpEnvironment() {
39+
// Set environment variables for examples to connect to test server
40+
System.setProperty("GREMLIN_SERVER_HOST", "localhost");
41+
System.setProperty("GREMLIN_SERVER_PORT", "45940");
42+
}
43+
44+
@AfterClass
45+
public static void tearDownAfterClass() {
46+
// Clean up system properties
47+
System.clearProperty("GREMLIN_SERVER_HOST");
48+
System.clearProperty("GREMLIN_SERVER_PORT");
49+
}
50+
51+
@Test
52+
public void shouldRunBasicGremlinExample() throws Exception {
53+
try {
54+
BasicGremlin.main(new String[]{});
55+
} catch (Exception e) {
56+
fail("BasicGremlin example failed: " + e.getMessage());
57+
}
58+
}
59+
60+
@Test
61+
public void shouldRunModernTraversalsExample() throws Exception {
62+
try {
63+
ModernTraversals.main(new String[]{});
64+
} catch (Exception e) {
65+
fail("ModernTraversals example failed: " + e.getMessage());
66+
}
67+
}
68+
69+
@Test
70+
public void shouldRunConnectionsExample() throws Exception {
71+
try {
72+
Connections.main(new String[]{});
73+
} catch (Exception e) {
74+
fail("Connections example failed: " + e.getMessage());
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)