use of org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy in project sqlg by pietermartin.
the class TestDropStep method shouldReferenceVertexWhenRemoved.
@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(ReferenceFactory.class);
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));
}
use of org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy in project sqlg by pietermartin.
the class TestDropStep method before.
@Before
public void before() throws Exception {
super.before();
configuration.setProperty("implement.foreign.keys", this.fkOn);
this.removedVertices.clear();
if (this.mutatingCallback) {
// Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportReturningDeletedRows());
final MutationListener listener = new AbstractMutationListener() {
@Override
public void vertexRemoved(final Vertex vertex) {
removedVertices.add(vertex);
}
@Override
public void edgeRemoved(final Edge edge) {
removedEdges.add(edge);
}
};
final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
eventStrategy = builder.create();
this.dropTraversal = this.sqlgGraph.traversal();
if (this.mutatingCallback) {
this.dropTraversal = this.dropTraversal.withStrategies(this.eventStrategy);
}
} else {
this.dropTraversal = this.sqlgGraph.traversal();
}
}
use of org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy in project sqlg by pietermartin.
the class TestDropStepBarrier method dropProperty.
@Test
public void dropProperty() {
final AtomicBoolean triggered = new AtomicBoolean(false);
final MutationListener listener = new AbstractMutationListener() {
@Override
public void vertexPropertyRemoved(final VertexProperty element) {
triggered.set(true);
}
};
final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
final EventStrategy eventStrategy = builder.create();
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
this.sqlgGraph.tx().commit();
this.sqlgGraph.traversal().withStrategies(eventStrategy).V().properties().drop().iterate();
this.sqlgGraph.tx().commit();
Assert.assertTrue(triggered.get());
Assert.assertFalse(this.sqlgGraph.traversal().V().hasLabel("A").has("name").hasNext());
}
use of org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy in project sqlg by pietermartin.
the class TestDropStepBarrier method before.
@Before
public void before() throws Exception {
super.before();
configuration.setProperty("implement.foreign.keys", this.fkOn);
configuration.setProperty("implement.foreign.keys", this.fkOn);
this.removedVertices.clear();
if (this.mutatingCallback) {
// Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportReturningDeletedRows());
final MutationListener listener = new AbstractMutationListener() {
@Override
public void vertexRemoved(final Vertex vertex) {
removedVertices.add(vertex);
}
@Override
public void edgeRemoved(final Edge edge) {
removedEdges.add(edge);
}
@Override
public void edgePropertyRemoved(final Edge element, final Property property) {
removedEdgeProperties.add(property);
}
@Override
public void vertexPropertyRemoved(final VertexProperty property) {
removedVertexProperties.add(property);
}
};
final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
eventStrategy = builder.create();
this.dropTraversal = this.sqlgGraph.traversal();
if (this.mutatingCallback) {
this.dropTraversal = this.dropTraversal.withStrategies(this.eventStrategy);
}
} else {
this.dropTraversal = this.sqlgGraph.traversal();
}
}
use of org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy in project sqlg by pietermartin.
the class TestTinkerPopEvent method shouldDetachVertexPropertyWhenRemoved.
@Test
public void shouldDetachVertexPropertyWhenRemoved() {
final AtomicBoolean triggered = new AtomicBoolean(false);
final Vertex v = this.sqlgGraph.addVertex();
final VertexProperty vp = v.property("to-remove", "blah");
final String label = vp.label();
final Object value = vp.value();
final VertexProperty vpToKeep = v.property("to-keep", "dah");
final MutationListener listener = new AbstractMutationListener() {
@Override
public void vertexPropertyRemoved(final VertexProperty element) {
Assert.assertEquals(label, element.label());
Assert.assertEquals(value, element.value());
triggered.set(true);
}
};
final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
if (this.sqlgGraph.features().graph().supportsTransactions())
builder.eventQueue(new EventStrategy.TransactionalEventQueue(this.sqlgGraph));
final EventStrategy eventStrategy = builder.create();
final GraphTraversalSource gts = create(eventStrategy);
gts.V(v).properties("to-remove").drop().iterate();
this.sqlgGraph.tx().commit();
Assert.assertEquals(1, IteratorUtils.count(v.properties()));
Assert.assertEquals(vpToKeep.value(), v.value("to-keep"));
Assert.assertThat(triggered.get(), CoreMatchers.is(true));
}
Aggregations