Java源码示例:org.apache.tinkerpop.gremlin.AbstractGremlinTest
示例1
@Test
public void testTail() throws IOException {
Graph graph = this.sqlgGraph;
final GraphReader reader = GryoReader.build()
.mapper(graph.io(GryoIo.build()).mapper().create())
.create();
try (final InputStream stream = AbstractGremlinTest.class.getResourceAsStream("/tinkerpop-modern.kryo")) {
reader.readGraph(stream, graph);
}
assertModernGraph(graph, true, false);
GraphTraversalSource g = graph.traversal();
int tail = 0;
for (int i = 1; i < 72; i++) {
tail = i;
List<Vertex> vertices = g.V().repeat(both()).times(3).tail(tail).toList();
if (tail != vertices.size()) {
System.out.println("expected " + tail + " found " + vertices.size());
}
}
}
示例2
@Test
public void shouldReferenceVertexWhenRemoved() {
final AtomicBoolean triggered = new AtomicBoolean(false);
final Vertex v = this.sqlgGraph.addVertex();
final String label = v.label();
final Object id = v.id();
final MutationListener listener = new AbstractMutationListener() {
@Override
public void vertexRemoved(final Vertex element) {
Assert.assertThat(element, IsInstanceOf.instanceOf(ReferenceVertex.class));
Assert.assertEquals(id, element.id());
Assert.assertEquals(label, element.label());
triggered.set(true);
}
};
final EventStrategy.Builder builder = EventStrategy.build().addListener(listener)
.detach(EventStrategy.Detachment.REFERENCE);
if (this.sqlgGraph.features().graph().supportsTransactions())
builder.eventQueue(new EventStrategy.TransactionalEventQueue(this.sqlgGraph));
final EventStrategy eventStrategy = builder.create();
final GraphTraversalSource gts = this.sqlgGraph.traversal().withStrategies(eventStrategy);
gts.V(v).drop().iterate();
this.sqlgGraph.tx().commit();
AbstractGremlinTest.assertVertexEdgeCounts(this.sqlgGraph, 0, 0);
Assert.assertThat(triggered.get(), CoreMatchers.is(true));
}
示例3
public void g_V_chooseXlabel_eq_person__unionX__out_lang__out_nameX__in_labelX() throws IOException {
Graph graph = this.sqlgGraph;
final GraphReader reader = GryoReader.build()
.mapper(graph.io(GryoIo.build()).mapper().create())
.create();
try (final InputStream stream = AbstractGremlinTest.class.getResourceAsStream("/tinkerpop-modern.kryo")) {
reader.readGraph(stream, graph);
}
assertModernGraph(graph, true, false);
GraphTraversalSource g = graph.traversal();
List<Vertex> traversala2 = g.V().hasId(convertToVertexId("marko")).toList();
Assert.assertEquals(1, traversala2.size());
Assert.assertEquals(convertToVertex(graph, "marko"), traversala2.get(0));
}
示例4
protected void loadModern(SqlgGraph sqlgGraph) {
Io.Builder<GraphSONIo> builder = GraphSONIo.build(GraphSONVersion.V3_0);
final GraphReader reader = sqlgGraph.io(builder).reader().create();
try (final InputStream stream = AbstractGremlinTest.class.getResourceAsStream("/tinkerpop-modern-v3d0.json")) {
reader.readGraph(stream, sqlgGraph);
} catch (IOException e) {
Assert.fail(e.getMessage());
}
}
示例5
protected void loadGratefulDead(SqlgGraph sqlgGraph) {
Io.Builder<GraphSONIo> builder = GraphSONIo.build(GraphSONVersion.V3_0);
final GraphReader reader = sqlgGraph.io(builder).reader().create();
try (final InputStream stream = AbstractGremlinTest.class.getResourceAsStream("/grateful-dead-v3d0.json")) {
reader.readGraph(stream, sqlgGraph);
} catch (IOException e) {
Assert.fail(e.getMessage());
}
}