Created
July 2, 2021 16:13
-
-
Save mad/3027855063bed41bae0a2aa7d2051352 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import org.apache.commons.compress.utils.Lists; | |
import org.apache.tinkerpop.gremlin.process.traversal.P; | |
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy; | |
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; | |
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__; | |
import org.apache.tinkerpop.gremlin.structure.Column; | |
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; | |
import org.junit.jupiter.api.Test; | |
public class TraversalFailIT { | |
public static final String LINK1 = "LINK1"; | |
public static final String LINK2 = "LINK2"; | |
public static final String LINK3 = "LINK3"; | |
public static final String LINK4 = "LINK4"; | |
public static final String LINK5 = "LINK5"; | |
public static final String LINK6 = "LINK6"; | |
public static final String PROPERTY1 = "prop1"; | |
public static final String PERSON = "Лицо"; | |
public static final String PHONE = "Телефон"; | |
public static final String PLACE = "Место"; | |
@Test | |
void name() { | |
// JanusGraph graph = JanusGraphFactory.open("inmemory"); | |
TinkerGraph graph = TinkerGraph.open(); // not reproduced | |
String lastOrder = null; | |
for (int i = 0; i < 1000; i++) { | |
populate(graph.traversal()); | |
if (graph.features().graph().supportsTransactions()) { | |
graph.tx().commit(); | |
} | |
// Re add all strategies for invoke issue | |
List<TraversalStrategy<?>> strategies = Lists.newArrayList(graph.traversal().getStrategies().iterator()); | |
GraphTraversalSource traversal = graph.traversal(); | |
for (TraversalStrategy<?> strategy : strategies) { | |
traversal.getStrategies().removeStrategies(strategy.getClass()); | |
} | |
Collections.shuffle(strategies); | |
System.out.println(i); | |
for (TraversalStrategy<?> strategy : strategies) { | |
traversal.getStrategies().addStrategies(strategy); | |
} | |
// Re add to fix issues fir random exception | |
// traversal.getStrategies().addStrategies(PathRetractionStrategy.instance()); | |
// traversal.getStrategies().addStrategies(InlineFilterStrategy.instance()); | |
System.out.println(traversal.getStrategies()); | |
traversal | |
.V().as("org1").id().as("id1").select("org1") | |
.filter( | |
__.hasLabel("Organization")) | |
.both().as("node") | |
.both().as("org2").id().as("id2").select("org2") | |
.filter(__.hasLabel("Organization").has("activeOrganization", true)) | |
.filter(__.where("id1", P.lt("id2"))) | |
.flatMap(__.project("id1", "id2", "weight") | |
.by(__.select("org1").id()) | |
.by(__.select("node").id()) | |
.by(__.select("org2").label().map(it -> it.get() != null ? 1 : 0)) | |
) | |
.toList(); | |
} | |
} | |
@SuppressWarnings("VariableDeclarationUsageDistance") | |
private void populate(GraphTraversalSource traversal) { | |
traversal | |
.addV("Organization").property("activeOrganization", true).as("org0") | |
.addV("Organization").property("activeOrganization", true).as("org1") | |
.addV("Organization").property("activeOrganization", true).as("org2") | |
.addV("Organization").property("activeOrganization", true).as("org3") | |
.addV("Organization").property("activeOrganization", true).as("org4") | |
.addV("Organization").property("activeOrganization", true).as("org5") | |
.addV("Organization").property("activeOrganization", true).as("org6") | |
.addV("Organization").property("activeOrganization", true).as("org7") | |
.addV("Organization").property("activeOrganization", true).as("org8") | |
.addV("Organization").property("activeOrganization", true).as("org9") | |
.addV("Organization").property("activeOrganization", true).as("org10") | |
.addV("Organization").as("org11") | |
.addV(PERSON).as("person") | |
.addV(PHONE).as("phone") | |
.addV(PLACE).as("place") | |
.addE(LINK1).property(PROPERTY1, true).from("org0").to("org1") | |
.addE(LINK2).property(PROPERTY1, true).from("org1").to("org2") | |
.addE(LINK3).property(PROPERTY1, true).from("org2").to("org3") | |
.addE(LINK4).property("share", 55.0).from("org2").to("org3") | |
.addE(LINK5).from("org2").to("phone") | |
.addE(LINK5).from("phone").to("org3") | |
.addE(LINK5).from("org2").to("place") | |
.addE(LINK5).from("place").to("org3") | |
.addE(LINK4).property(PROPERTY1, true).property("share", 20.0).from("org3").to("org4") | |
.addE(LINK3).property(PROPERTY1, true).from("org4").to("org5") | |
.addE(LINK4).property("share", 10.0).from("person").to("org6") | |
.addE(LINK4).property(PROPERTY1, true).property("share", 70.0).from("person").to("org7") | |
.addE(LINK6).property(PROPERTY1, true).from("person").to("org8") | |
.addE(LINK4).property(PROPERTY1, true).property("share", 1.0).from("org8").to("org9") | |
.addE(LINK1).property(PROPERTY1, true).from("org8").to("org10") | |
.addE(LINK4).property(PROPERTY1, true).property("share", 80.0).from("org10").to("org11") | |
.project("group1", "group2") | |
.by(org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.__.select("org0", "org1", "org2", "org3", "org4").by( | |
org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.__.id()).select(Column.values)) | |
.by(org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.__.select("org7", "org8", "org10").by( | |
org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.__.id()).select(Column.values)) | |
.select(Column.values) | |
.unfold() | |
.toList(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment