use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.
the class ConfiguredGraphFactoryTest method graphConfigurationShouldBeWhatWeExpectWhenUsingTemplateConfiguration.
@Test
public void graphConfigurationShouldBeWhatWeExpectWhenUsingTemplateConfiguration() throws Exception {
try {
final Map<String, Object> map = new HashMap<>();
map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
ConfiguredGraphFactory.createTemplateConfiguration(new MapConfiguration(map));
final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.create("graph1");
final StandardJanusGraph graph1 = (StandardJanusGraph) ConfiguredGraphFactory.open("graph1");
assertNotNull(graph);
assertEquals(graph, graph1);
assertEquals("graph1", graph.getConfiguration().getConfiguration().get(GRAPH_NAME));
assertEquals("inmemory", graph.getConfiguration().getConfiguration().get(STORAGE_BACKEND));
} finally {
ConfiguredGraphFactory.removeConfiguration("graph1");
ConfiguredGraphFactory.close("graph1");
}
}
use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.
the class ConfiguredGraphFactoryTest method ensureCallingGraphCloseResultsInNewGraphReferenceOnNextCallToOpen.
@Test
public void ensureCallingGraphCloseResultsInNewGraphReferenceOnNextCallToOpen() throws Exception {
try {
final Map<String, Object> map = new HashMap<>();
map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
ConfiguredGraphFactory.createTemplateConfiguration(new MapConfiguration(map));
final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.create("graph1");
assertNotNull(graph);
assertEquals("graph1", graph.getConfiguration().getConfiguration().get(GRAPH_NAME));
graph.close();
assertTrue(graph.isClosed());
final StandardJanusGraph newGraph = (StandardJanusGraph) ConfiguredGraphFactory.open("graph1");
assertFalse(newGraph.isClosed());
} finally {
ConfiguredGraphFactory.removeConfiguration("graph1");
ConfiguredGraphFactory.close("graph1");
}
}
use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.
the class JanusGraphLocalQueryOptimizerStrategy method apply.
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
if (!traversal.getGraph().isPresent())
return;
Graph graph = traversal.getGraph().get();
// If this is a compute graph then we can't apply local traversal optimisation at this stage.
StandardJanusGraph janusGraph = graph instanceof StandardJanusGraphTx ? ((StandardJanusGraphTx) graph).getGraph() : (StandardJanusGraph) graph;
final boolean useMultiQuery = !TraversalHelper.onGraphComputer(traversal) && janusGraph.getConfiguration().useMultiQuery();
/*
====== VERTEX STEP ======
*/
TraversalHelper.getStepsOfClass(VertexStep.class, traversal).forEach(originalStep -> {
JanusGraphVertexStep vertexStep = new JanusGraphVertexStep(originalStep);
TraversalHelper.replaceStep(originalStep, vertexStep, traversal);
if (JanusGraphTraversalUtil.isEdgeReturnStep(vertexStep)) {
HasStepFolder.foldInHasContainer(vertexStep, traversal);
// We cannot fold in orders or ranges since they are not local
}
assert JanusGraphTraversalUtil.isEdgeReturnStep(vertexStep) || JanusGraphTraversalUtil.isVertexReturnStep(vertexStep);
Step nextStep = JanusGraphTraversalUtil.getNextNonIdentityStep(vertexStep);
if (nextStep instanceof RangeGlobalStep) {
int limit = QueryUtil.convertLimit(((RangeGlobalStep) nextStep).getHighRange());
vertexStep.setLimit(QueryUtil.mergeLimits(limit, vertexStep.getLimit()));
}
if (useMultiQuery) {
vertexStep.setUseMultiQuery(true);
}
});
/*
====== PROPERTIES STEP ======
*/
TraversalHelper.getStepsOfClass(PropertiesStep.class, traversal).forEach(originalStep -> {
JanusGraphPropertiesStep propertiesStep = new JanusGraphPropertiesStep(originalStep);
TraversalHelper.replaceStep(originalStep, propertiesStep, traversal);
if (propertiesStep.getReturnType().forProperties()) {
HasStepFolder.foldInHasContainer(propertiesStep, traversal);
// We cannot fold in orders or ranges since they are not local
}
if (useMultiQuery) {
propertiesStep.setUseMultiQuery(true);
}
});
/*
====== EITHER INSIDE LOCAL ======
*/
TraversalHelper.getStepsOfClass(LocalStep.class, traversal).forEach(localStep -> {
Traversal.Admin localTraversal = ((LocalStep<?, ?>) localStep).getLocalChildren().get(0);
Step localStart = localTraversal.getStartStep();
if (localStart instanceof VertexStep) {
JanusGraphVertexStep vertexStep = new JanusGraphVertexStep((VertexStep) localStart);
TraversalHelper.replaceStep(localStart, vertexStep, localTraversal);
if (JanusGraphTraversalUtil.isEdgeReturnStep(vertexStep)) {
HasStepFolder.foldInHasContainer(vertexStep, localTraversal);
HasStepFolder.foldInOrder(vertexStep, localTraversal, traversal, false);
}
HasStepFolder.foldInRange(vertexStep, localTraversal);
unfoldLocalTraversal(traversal, localStep, localTraversal, vertexStep, useMultiQuery);
}
if (localStart instanceof PropertiesStep) {
JanusGraphPropertiesStep propertiesStep = new JanusGraphPropertiesStep((PropertiesStep) localStart);
TraversalHelper.replaceStep(localStart, propertiesStep, localTraversal);
if (propertiesStep.getReturnType().forProperties()) {
HasStepFolder.foldInHasContainer(propertiesStep, localTraversal);
HasStepFolder.foldInOrder(propertiesStep, localTraversal, traversal, false);
}
HasStepFolder.foldInRange(propertiesStep, localTraversal);
unfoldLocalTraversal(traversal, localStep, localTraversal, propertiesStep, useMultiQuery);
}
});
}
use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.
the class JanusGraphTest method testIndexUpdateSyncWithMultipleInstances.
@Tag(TestCategory.BRITTLE_TESTS)
@Test
public void testIndexUpdateSyncWithMultipleInstances() throws InterruptedException {
clopen(option(LOG_SEND_DELAY, MANAGEMENT_LOG), Duration.ofMillis(0), option(KCVSLog.LOG_READ_LAG_TIME, MANAGEMENT_LOG), Duration.ofMillis(50), option(LOG_READ_INTERVAL, MANAGEMENT_LOG), Duration.ofMillis(250));
StandardJanusGraph graph2 = (StandardJanusGraph) JanusGraphFactory.open(config);
JanusGraphTransaction tx2;
mgmt.makePropertyKey("name").dataType(String.class).make();
finishSchema();
tx.addVertex("name", "v1");
newTx();
evaluateQuery(tx.query().has("name", "v1"), ElementCategory.VERTEX, 1, new boolean[] { false, true });
tx2 = graph2.newTransaction();
evaluateQuery(tx2.query().has("name", "v1"), ElementCategory.VERTEX, 1, new boolean[] { false, true });
// Leave tx2 open to delay acknowledgement
mgmt.buildIndex("theIndex", Vertex.class).addKey(mgmt.getPropertyKey("name")).buildCompositeIndex();
mgmt.commit();
JanusGraphTransaction tx3 = graph2.newTransaction();
tx3.addVertex("name", "v2");
tx3.commit();
newTx();
tx.addVertex("name", "v3");
tx.commit();
finishSchema();
try {
mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX);
// Open tx2 should not make this possible
fail();
} catch (IllegalArgumentException ignored) {
}
finishSchema();
// Release transaction and wait a little for registration which should make enabling possible
tx2.commit();
mgmt.rollback();
assertTrue(ManagementSystem.awaitGraphIndexStatus(graph, "theIndex").status(SchemaStatus.REGISTERED).timeout(TestGraphConfigs.getSchemaConvergenceTime(ChronoUnit.SECONDS), ChronoUnit.SECONDS).call().getSucceeded());
finishSchema();
mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX);
finishSchema();
tx2 = graph2.newTransaction();
// Should be added to index but index not yet enabled
tx2.addVertex("name", "v4");
tx2.commit();
newTx();
evaluateQuery(tx.query().has("name", "v1"), ElementCategory.VERTEX, 0, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().has("name", "v2"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().has("name", "v3"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().has("name", "v4"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "theIndex");
tx2 = graph2.newTransaction();
evaluateQuery(tx2.query().has("name", "v1"), ElementCategory.VERTEX, 0, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx2.query().has("name", "v2"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx2.query().has("name", "v3"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx2.query().has("name", "v4"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "theIndex");
tx2.commit();
// Finally test retrieving and closing open instances
Set<String> openInstances = mgmt.getOpenInstances();
assertEquals(2, openInstances.size());
assertTrue(openInstances.contains(graph.getConfiguration().getUniqueGraphId() + "(current)"));
assertTrue(openInstances.contains(graph2.getConfiguration().getUniqueGraphId()));
try {
mgmt.forceCloseInstance(graph.getConfiguration().getUniqueGraphId());
// Cannot close current instance
fail();
} catch (IllegalArgumentException ignored) {
}
mgmt.forceCloseInstance(graph2.getConfiguration().getUniqueGraphId());
graph2.close();
}
use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.
the class AbstractConfiguredGraphFactoryTest method shouldOpenGraphUsingConfiguration.
@Test
public void shouldOpenGraphUsingConfiguration() throws Exception {
final MapConfiguration graphConfig = getGraphConfig();
final String graphName = graphConfig.getString(GRAPH_NAME.toStringWithoutRoot());
try {
ConfiguredGraphFactory.createConfiguration(graphConfig);
final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.open(graphName);
assertNotNull(graph);
} finally {
ConfiguredGraphFactory.removeConfiguration(graphName);
ConfiguredGraphFactory.close(graphName);
}
}
Aggregations