public EdgeLabel makeLabel(String name) { return mgmt.makeEdgeLabel(name).make(); }
@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 void createStrictSchemaForConnections() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); VertexLabel user = mgmt.makeVertexLabel("user").make(); VertexLabel company = mgmt.makeVertexLabel("company").make(); EdgeLabel edge = mgmt.makeEdgeLabel("knows").make(); mgmt.makeEdgeLabel("buys").make(); mgmt.addConnection(edge, user, company); finishSchema(); }
@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); }
private void createStrictSchemaForComplexConnections() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); VertexLabel v1 = mgmt.makeVertexLabel("V1").make(); VertexLabel v2 = mgmt.makeVertexLabel("V2").make(); VertexLabel v3 = mgmt.makeVertexLabel("V3").make(); VertexLabel v4 = mgmt.makeVertexLabel("V4").make(); EdgeLabel e1 = mgmt.makeEdgeLabel("E1").make(); EdgeLabel e2 = mgmt.makeEdgeLabel("E2").make(); mgmt.addConnection(e1, v1, v2); mgmt.addConnection(e1, v3, v4); mgmt.addConnection(e2, v1, v4); mgmt.addConnection(e2, v3, v2); finishSchema(); }
@Test public void testAllowDisablingSchemaConstraintForConnection() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), false); mgmt.makeVertexLabel("user").make(); mgmt.makeEdgeLabel("knows").make(); finishSchema(); JanusGraphVertex v1 = tx.addVertex("user"); JanusGraphVertex v2 = tx.addVertex("user"); v1.addEdge("knows", v2); }
@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 testBanListCardinalityForEdgeProperties() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); EdgeLabel edge = mgmt.makeEdgeLabel("knows").make(); try { PropertyKey id = mgmt.makePropertyKey("id").cardinality(Cardinality.LIST).dataType(Integer.class).make(); mgmt.addProperties(edge, id); fail("This should never reached!"); } catch (IllegalArgumentException ignored) { } finishSchema(); }
@Test public void testBanSetCardinalityForEdgeProperties() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); EdgeLabel edge = mgmt.makeEdgeLabel("knows").make(); try { PropertyKey id = mgmt.makePropertyKey("id").cardinality(Cardinality.SET).dataType(Integer.class).make(); mgmt.addProperties(edge, id); fail("This should never reached!"); } catch (IllegalArgumentException ignored) { } finishSchema(); }
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; }
public void testBatchLoadingLocking(boolean batchLoading) { PropertyKey uid = makeKey("uid",Long.class); JanusGraphIndex uidIndex = mgmt.buildIndex("uid",Vertex.class).unique().addKey(uid).buildCompositeIndex(); mgmt.setConsistency(uid, ConsistencyModifier.LOCK); mgmt.setConsistency(uidIndex,ConsistencyModifier.LOCK); EdgeLabel knows = mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.ONE2ONE).make(); mgmt.setConsistency(knows,ConsistencyModifier.LOCK); finishSchema(); TestLockerManager.ERROR_ON_LOCKING=true; clopen(option(GraphDatabaseConfiguration.STORAGE_BATCH),batchLoading, option(GraphDatabaseConfiguration.LOCK_BACKEND),"test"); int numV = 10000; for (int i=0;i<numV;i++) { JanusGraphVertex v = tx.addVertex("uid",i+1); v.addEdge("knows",v); } clopen(); for (int i=0;i<Math.min(numV,300);i++) { assertEquals(1, Iterables.size(graph.query().has("uid", i + 1).vertices())); JanusGraphVertex v = Iterables.getOnlyElement(graph.query().has("uid", i + 1).vertices()); assertEquals(1, Iterables.size(v.query().direction(OUT).labels("knows").edges())); } }
@Test public void testAllowDisablingSchemaConstraintForEdgeProperty() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), false); mgmt.makeVertexLabel("user").make(); mgmt.makeEdgeLabel("knows").make(); mgmt.makePropertyKey("test").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); finishSchema(); JanusGraphVertex v1 = tx.addVertex("user"); JanusGraphVertex v2 = tx.addVertex("user"); v1.addEdge("knows", v2, "test", 10); }
@Test public void testAllowSingleCardinalityForEdgeProperties() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); EdgeLabel edge = mgmt.makeEdgeLabel("knows").make(); PropertyKey propertyKey1 = mgmt.makePropertyKey("propertyKey1").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); mgmt.addProperties(edge, propertyKey1); PropertyKey propertyKey2 = mgmt.makePropertyKey("propertyKey2").dataType(Integer.class).make(); mgmt.addProperties(edge, propertyKey2); finishSchema(); }
@Test public void testIndexShouldBeEnabledForExistingPropertyKeyAndConstrainedToNewEdgeLabel() { mgmt.makePropertyKey("alreadyExistingProperty").dataType(String.class).cardinality(Cardinality.SINGLE).make(); finishSchema(); PropertyKey existingPropertyKey = mgmt.getPropertyKey("alreadyExistingProperty"); EdgeLabel newLabel = mgmt.makeEdgeLabel("newLabel").make(); mgmt.buildIndex("newIndex", Edge.class).addKey(existingPropertyKey).indexOnly(newLabel).buildCompositeIndex(); finishSchema(); assertEquals(SchemaStatus.ENABLED, mgmt.getGraphIndex("newIndex").getIndexStatus(existingPropertyKey)); }
@Test public void testVertexCentricIndexOrderingOnEdgePropertyWithCardinalityList() { 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) ); PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).cardinality(Cardinality.LIST).make(); EdgeLabel friend = mgmt.makeEdgeLabel("friend").multiplicity(Multiplicity.MULTI).make(); mgmt.buildEdgeIndex(friend, "byTime", Direction.OUT, decr, time); finishSchema(); JanusGraphVertex v = tx.addVertex(); for (int i = 200; i < 210; i++) { JanusGraphVertex o = tx.addVertex(); v.addEdge("friend", o, "time", i); } assertEquals(SchemaStatus.ENABLED, mgmt.getRelationIndex(mgmt.getRelationType("friend"), "byTime").getIndexStatus()); evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 201, 205).orderBy("time", decr), EDGE, 4, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC); tx.commit(); finishSchema(); }
@Test public void testVertexCentricEdgeIndexOnSimpleMultiplicityShouldWork() { 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) ); PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); EdgeLabel friend = mgmt.makeEdgeLabel("friend").multiplicity(Multiplicity.SIMPLE).make(); mgmt.buildEdgeIndex(friend, "byTime", Direction.OUT, decr, time); finishSchema(); assertEquals(SchemaStatus.ENABLED, mgmt.getRelationIndex(mgmt.getRelationType("friend"), "byTime").getIndexStatus()); JanusGraphVertex v = tx.addVertex(); v = getV(tx, v); for (int i = 200; i < 210; i++) { JanusGraphVertex o = tx.addVertex(); v.addEdge("friend", o, "time", i); } evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 199, 210).orderBy("time", decr), EDGE, 10, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC); tx.commit(); finishSchema(); }
private void createStrictSchemaForEdgeProperties() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); 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.makePropertyKey("test").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); mgmt.addProperties(edge, id); mgmt.addConnection(edge, user, user); finishSchema(); }
@Test public void testIndexShouldNotBeEnabledForExistingPropertyKeyAndConstrainedToExistingEdgeLabel() { mgmt.makePropertyKey("alreadyExistingProperty").dataType(String.class).cardinality(Cardinality.SINGLE).make(); mgmt.makeEdgeLabel("alreadyExistingLabel").make(); finishSchema(); PropertyKey existingPropertyKey = mgmt.getPropertyKey("alreadyExistingProperty"); EdgeLabel existingLabel = mgmt.getEdgeLabel("alreadyExistingLabel"); mgmt.buildIndex("newIndex", Edge.class).addKey(existingPropertyKey).indexOnly(existingLabel).buildCompositeIndex(); finishSchema(); assertNotEquals(SchemaStatus.ENABLED, mgmt.getGraphIndex("newIndex").getIndexStatus(existingPropertyKey)); }
@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); }
private void setupChainGraph(int numV, String[] strings, boolean sameNameMapping) { clopen(option(INDEX_NAME_MAPPING, INDEX), sameNameMapping); final JanusGraphIndex vindex = getExternalIndex(Vertex.class, INDEX); final JanusGraphIndex eindex = getExternalIndex(Edge.class, INDEX); final JanusGraphIndex pindex = getExternalIndex(JanusGraphVertexProperty.class, INDEX); final PropertyKey name = makeKey("name", String.class); mgmt.addIndexKey(vindex, name, getStringMapping()); mgmt.addIndexKey(eindex, name, getStringMapping()); mgmt.addIndexKey(pindex, name, getStringMapping(), Parameter.of("mapped-name", "xstr")); final PropertyKey text = makeKey("text", String.class); mgmt.addIndexKey(vindex, text, getTextMapping(), Parameter.of("mapped-name", "xtext")); mgmt.addIndexKey(eindex, text, getTextMapping()); mgmt.addIndexKey(pindex, text, getTextMapping()); mgmt.makeEdgeLabel("knows").signature(name).make(); mgmt.makePropertyKey("uid").dataType(String.class).signature(text).make(); finishSchema(); JanusGraphVertex previous = null; for (int i = 0; i < numV; i++) { final JanusGraphVertex v = graph.addVertex("name", strings[i % strings.length], "text", strings[i % strings.length]); v.addEdge("knows", previous == null ? v : previous, "name", strings[i % strings.length], "text", strings[i % strings.length]); v.property("uid", "v" + i, "name", strings[i % strings.length], "text", strings[i % strings.length]); previous = v; } }