@Test public void testReservedNamesRejectedForVertexLabels() { for (String s : ILLEGAL_USER_DEFINED_NAMES) { JanusGraphManagement tm = graph.openManagement(); try { tm.makeVertexLabel(s); Assert.fail("Vertex label \"" + s + "\" must be rejected"); } catch (IllegalArgumentException e) { log.debug("Caught expected exception", e); } finally { tm.commit(); } } } }
@Test public void testReservedNamesRejectedForPropertyKeys() { for (String s : ILLEGAL_USER_DEFINED_NAMES) { JanusGraphManagement tm = graph.openManagement(); try { tm.makePropertyKey(s); Assert.fail("Property key \"" + s + "\" must be rejected"); } catch (IllegalArgumentException e) { log.debug("Caught expected exception", e); } finally { tm.commit(); } } }
@Test public void testReservedNamesRejectedForEdgeLabels() { for (String s : ILLEGAL_USER_DEFINED_NAMES) { JanusGraphManagement tm = graph.openManagement(); try { tm.makeEdgeLabel(s); Assert.fail("Edge label \"" + s + "\" must be rejected"); } catch (IllegalArgumentException e) { log.debug("Caught expected exception", e); } finally { tm.commit(); } } }
private <A> void setIllegalGraphOption(ConfigOption<A> opt, ConfigOption.Type requiredType, A attemptedValue) { // Sanity check: make sure the Type of the configuration option is what we expect final ConfigOption.Type type = opt.getType(); Preconditions.checkState(type.equals(requiredType)); Preconditions.checkArgument(requiredType.equals(ConfigOption.Type.LOCAL) || requiredType.equals(ConfigOption.Type.FIXED)); // Get full string path of config option final String path = ConfigElement.getPath(opt); // Try to read the option try { mgmt.get(path); } catch (Throwable t) { log.debug("Caught expected exception", t); } // Try to modify the option try { mgmt.set(path, attemptedValue); mgmt.commit(); fail("Option " + path + " with type " + type + " should not be modifiable in the persistent graph config"); } catch (Throwable t) { log.debug("Caught expected exception", t); } }
public void finishSchema() { if (mgmt!=null && mgmt.isOpen()) mgmt.commit(); mgmt=graph.openManagement(); newTx(); graph.tx().commit(); }
@Before public void setup() { GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true); JanusGraphManagement management = graph.openManagement(); management.makePropertyKey("shape").dataType(Geoshape.class).make(); management.commit(); }
@Test public void testIndexQueryWithScore() throws InterruptedException { final PropertyKey textKey = mgmt.makePropertyKey("text").dataType(String.class).make(); mgmt.buildIndex("store1", Vertex.class).addKey(textKey).buildMixedIndex(INDEX); mgmt.commit(); final JanusGraphVertex v1 = tx.addVertex(); final JanusGraphVertex v2 = tx.addVertex(); final JanusGraphVertex v3 = tx.addVertex(); v1.property("text", "Hello Hello Hello Hello Hello Hello Hello Hello world"); v2.property("text", "Hello abab abab fsdfsd sfdfsd sdffs fsdsdf fdf fsdfsd aera fsad abab abab fsdfsd sfdf"); v3.property("text", "Hello Hello world world"); tx.commit(); final Set<Double> scores = graph.indexQuery("store1", "v.text:(Hello)").vertexStream() .map(JanusGraphIndexQuery.Result::getScore) .collect(Collectors.toSet()); Assert.assertEquals(3, scores.size()); }
@Override public void loadGraphData(final Graph g, final LoadGraphWith loadGraphWith, final Class testClass, final String testName) { if (loadGraphWith != null) { this.createIndices((JanusGraph) g, loadGraphWith.value()); } else { if (TransactionTest.class.equals(testClass) && testName.equalsIgnoreCase("shouldExecuteWithCompetingThreads")) { JanusGraphManagement management = ((JanusGraph) g).openManagement(); management.makePropertyKey("blah").dataType(Double.class).make(); management.makePropertyKey("bloop").dataType(Integer.class).make(); management.makePropertyKey("test").dataType(Object.class).make(); management.makeEdgeLabel("friend").make(); management.commit(); } } super.loadGraphData(g, loadGraphWith, testClass, testName); }
@Test // this tests a case when there as AND with a single CONTAINS condition inside AND(name:(was here)) // which (in case of Solr) spans multiple conditions such as AND(AND(name:was, name:here)) // so we need to make sure that we don't apply AND twice. public void testContainsWithMultipleValues() throws Exception { final PropertyKey name = makeKey("name", String.class); mgmt.buildIndex("store1", Vertex.class).addKey(name).buildMixedIndex(INDEX); mgmt.commit(); final JanusGraphVertex v1 = tx.addVertex(); v1.property("name", "hercules was here"); tx.commit(); final JanusGraphVertex r = Iterables.get(graph.query().has("name", Text.CONTAINS, "hercules here").vertices(), 0); Assert.assertEquals(r.property("name").value(), "hercules was here"); }
@Test public void testGettingUndefinedEdgeLabelTTL() { if (!features.hasCellTTL()) { return; } // getTTL should return a null duration on an extant type without a TTL mgmt.makeEdgeLabel("likes").make(); mgmt.commit(); graph.tx().rollback(); // Check getTTL on edge label mgmt = graph.openManagement(); assertEquals(Duration.ZERO, mgmt.getTTL(mgmt.getEdgeLabel("likes"))); mgmt.rollback(); }
@Test public void testGettingUndefinedVertexLabelTTL() { if (!features.hasCellTTL()) { return; } // getTTL should return a null duration on an extant type without a TTL mgmt.makeVertexLabel("foo").make(); mgmt.commit(); graph.tx().rollback(); // Check getTTL on vertex label mgmt = graph.openManagement(); assertEquals(Duration.ZERO, mgmt.getTTL(mgmt.getVertexLabel("foo"))); mgmt.rollback(); }
private GraphTraversalSource prepareGraphForDirectCommitTests() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); GraphTraversalSource g = graph.traversal(); VertexLabel user = mgmt.makeVertexLabel("user").make(); EdgeLabel edge = mgmt.makeEdgeLabel("knows").make(); PropertyKey id = mgmt.makePropertyKey("id").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); mgmt.addProperties(edge, id); mgmt.addConnection(edge, user, user); mgmt.commit(); return g; }
@Test public void testSupportDirectCommitOfSchemaChangesForVertexProperties() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); GraphTraversalSource g = graph.traversal(); VertexLabel label = mgmt.makeVertexLabel("user").make(); PropertyKey prop = mgmt.makePropertyKey("id").dataType(Integer.class).make(); mgmt.addProperties(label, prop); mgmt.commit(); g.addV("user").property("id", 10).iterate(); }
@Test public void testVLabelOnOrderedStorage() { final String label = "pl"; mgmt.makeVertexLabel(label).partition().make(); mgmt.commit(); graph.tx().rollback(); graph.addVertex(label); graph.tx().commit(); mgmt = graph.openManagement(); VertexLabel vl = mgmt.getVertexLabel(label); assertTrue(vl.isPartitioned()); mgmt.rollback(); }
@Test public void testSupportChangeNameOfEdgeAndUpdateConnections() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); VertexLabel user = mgmt.makeVertexLabel("V1").make(); VertexLabel company = mgmt.makeVertexLabel("V2").make(); EdgeLabel edge = mgmt.makeEdgeLabel("E1").make(); mgmt.addConnection(edge, user, company); finishSchema(); JanusGraphVertex v1 = tx.addVertex("V1"); JanusGraphVertex v2 = tx.addVertex("V2"); v1.addEdge("E1", v2); newTx(); edge = mgmt.getEdgeLabel("E1"); mgmt.changeName(edge, "E2"); mgmt.commit(); JanusGraphVertex v3 = tx.addVertex("V1"); JanusGraphVertex v4 = tx.addVertex("V2"); v3.addEdge("E2", v4); }
@Test public void shouldAwaitMultipleStatuses() throws InterruptedException, ExecutionException { final PropertyKey key1 = makeKey("key1", String.class); final JanusGraphIndex index = mgmt.buildIndex("randomMixedIndex", Vertex.class).addKey(key1).buildMixedIndex(INDEX); if (index.getIndexStatus(key1) == SchemaStatus.INSTALLED) { mgmt.updateIndex(mgmt.getGraphIndex("randomMixedIndex"), SchemaAction.REGISTER_INDEX).get(); mgmt.updateIndex(mgmt.getGraphIndex("randomMixedIndex"), SchemaAction.ENABLE_INDEX).get(); } else if (index.getIndexStatus(key1) == SchemaStatus.REGISTERED) { mgmt.updateIndex(mgmt.getGraphIndex("randomMixedIndex"), SchemaAction.ENABLE_INDEX).get(); } final PropertyKey key2 = makeKey("key2", String.class); mgmt.addIndexKey(index, key2); mgmt.commit(); //key1 now has status ENABLED, let's ensure we can watch for REGISTERED and ENABLED try { ManagementSystem.awaitGraphIndexStatus(graph, "randomMixedIndex").status(SchemaStatus.REGISTERED, SchemaStatus.ENABLED).call(); } catch (final Exception e) { Assert.fail("Failed to awaitGraphIndexStatus on multiple statuses."); } }
@Test public void testOrForceIndexUniqueMixedIndex() throws Exception { JanusGraph customGraph = null; try { customGraph = this.getForceIndexGraph(); final JanusGraphManagement management = customGraph.openManagement(); final PropertyKey nameProperty = management.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make(); final PropertyKey ageProperty = management.makePropertyKey("age").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); final PropertyKey lengthProperty = management.makePropertyKey("length").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); management.buildIndex("oridx", Vertex.class).addKey(nameProperty, getStringMapping()).addKey(ageProperty).addKey(lengthProperty).buildMixedIndex(INDEX); management.commit(); customGraph.tx().commit(); testOr(customGraph); } finally { if (customGraph != null) { JanusGraphFactory.close(customGraph); } } }
@Test public void testOrForceIndexPartialIndex() throws Exception { JanusGraph customGraph = null; try { customGraph = this.getForceIndexGraph(); final JanusGraphManagement management = customGraph.openManagement(); final PropertyKey stringProperty = management.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make(); management.makePropertyKey("age").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); management.buildIndex("oridx", Vertex.class).addKey(stringProperty, getStringMapping()).buildMixedIndex(INDEX); management.commit(); customGraph.tx().commit(); final GraphTraversalSource g = customGraph.traversal(); g.addV().property("name", "Hiro").property("age", 2).next(); g.addV().property("name", "Totoro").property("age", 1).next(); customGraph.tx().commit(); g.V().or(__.has("name", "Totoro"),__.has("age", 2)).hasNext(); fail("should fail"); } catch (final JanusGraphException e){ assertTrue(e.getMessage().contains("Could not find a suitable index to answer graph query and graph scans are disabled")); } finally { if (customGraph != null) { JanusGraphFactory.close(customGraph); } } }
@Test public void testOrForceIndexMixedAndCompositeIndex() throws Exception { JanusGraph customGraph = null; try { customGraph = this.getForceIndexGraph(); final JanusGraphManagement management = customGraph.openManagement(); final PropertyKey nameProperty = management.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make(); final PropertyKey ageProperty = management.makePropertyKey("age").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); final PropertyKey lengthProperty = management.makePropertyKey("length").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); management.buildIndex("nameidx", Vertex.class).addKey(nameProperty, getStringMapping()).buildMixedIndex(INDEX); management.buildIndex("ageridx", Vertex.class).addKey(ageProperty).buildCompositeIndex(); management.buildIndex("lengthidx", Vertex.class).addKey(lengthProperty).buildMixedIndex(INDEX); management.commit(); customGraph.tx().commit(); testOr(customGraph); } finally { if (customGraph != null) { JanusGraphFactory.close(customGraph); } } }
@Test public void testAndForceIndex() throws Exception { JanusGraph customGraph = null; try { customGraph = this.getForceIndexGraph(); final JanusGraphManagement management = customGraph.openManagement(); final PropertyKey nameProperty = management.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make(); final PropertyKey ageProperty = management.makePropertyKey("age").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); management.buildIndex("oridx", Vertex.class).addKey(nameProperty, getStringMapping()).addKey(ageProperty).buildMixedIndex(INDEX); management.commit(); customGraph.tx().commit(); final GraphTraversalSource g = customGraph.traversal(); g.addV().property("name", "Hiro").property("age", 2).next(); g.addV().property("name", "Totoro").property("age", 1).next(); customGraph.tx().commit(); assertCount(1, g.V().has("name", "Totoro")); assertCount(1, g.V().has("age", 2)); assertCount(1, g.V().and(__.has("name", "Hiro"),__.has("age", 2))); assertCount(0, g.V().and(__.has("name", "Totoro"),__.has("age", 2))); } finally { if (customGraph != null) { JanusGraphFactory.close(customGraph); } } }