private int generateRandomGraph(int numV) { mgmt.makePropertyKey("uid").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.MULTI).make(); mgmt.makePropertyKey("values").cardinality(Cardinality.LIST).dataType(Integer.class).make(); mgmt.makePropertyKey("numvals").dataType(Integer.class).make(); finishSchema(); int numE = 0; JanusGraphVertex[] vs = new JanusGraphVertex[numV]; for (int i=0;i<numV;i++) { vs[i] = tx.addVertex("uid",i+1); int numberOfValues = random.nextInt(5)+1; vs[i].property(VertexProperty.Cardinality.single, "numvals", numberOfValues); for (int j=0;j<numberOfValues;j++) { vs[i].property("values",random.nextInt(100)); } } for (int i=0;i<numV;i++) { int edges = i+1; JanusGraphVertex v = vs[i]; for (int j=0;j<edges;j++) { JanusGraphVertex u = vs[random.nextInt(numV)]; v.addEdge("knows", u); numE++; } } assertEquals(numV*(numV+1),numE*2); return numE; }
/** * Creates a new edge label with default settings against the provided {@link EdgeLabelMaker}. * * @param factory EdgeLabelMaker through which the edge label is created * @return A new edge label * @throws IllegalArgumentException if the name is already in use or if other configured values are invalid. */ default EdgeLabel makeEdgeLabel(EdgeLabelMaker factory) { return factory.directed().make(); }
if (i % 4 == 1) tm.unidirected(); tm.make();
public EdgeLabel makeLabel(String name) { return mgmt.makeEdgeLabel(name).make(); }
EdgeLabel friend = mgmt.makeEdgeLabel("friend").make(); EdgeLabel link = mgmt.makeEdgeLabel("link").unidirected().multiplicity(Multiplicity.MANY2ONE).make(); EdgeLabel connect = mgmt.makeEdgeLabel("connect").signature(uid).multiplicity(Multiplicity.SIMPLE).make(); EdgeLabel parent = mgmt.makeEdgeLabel("parent").multiplicity(Multiplicity.MANY2ONE).make(); EdgeLabel child = mgmt.makeEdgeLabel("child").multiplicity(Multiplicity.ONE2MANY).make(); EdgeLabel spouse = mgmt.makeEdgeLabel("spouse").multiplicity(Multiplicity.ONE2ONE).make(); mgmt.makeEdgeLabel("link").unidirected().make(); fail(); } catch (SchemaViolationException ignored) { mgmt.makeEdgeLabel("test").signature(someId).make(); fail(); } catch (IllegalArgumentException ignored) { mgmt.makeEdgeLabel("link").unidirected().make(); fail(); } catch (SchemaViolationException ignored) { mgmt.makeEdgeLabel("test").signature(someId).make(); fail(); } catch (IllegalArgumentException ignored) {
@Test public void testShortestDistance() throws Exception { PropertyKey distance = mgmt.makePropertyKey("distance").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); mgmt.makeEdgeLabel("connect").signature(distance).multiplicity(Multiplicity.MULTI).make(); finishSchema();
@Override public EdgeLabel makeEdgeLabel(EdgeLabelMaker factory) { throw new IllegalArgumentException("Edge Label with given name does not exist: " + factory.getName()); }
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(); }
EdgeLabel connect = mgmt.makeEdgeLabel("connect").signature(time).make(); EdgeLabel child = mgmt.makeEdgeLabel("child").multiplicity(Multiplicity.ONE2MANY).make(); EdgeLabel link = mgmt.makeEdgeLabel("link").unidirected().make();
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; } }
management.buildIndex("edges", Edge.class).addKey(reason).addKey(place).buildMixedIndex(mixedIndexName); management.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make(); management.makeEdgeLabel("mother").multiplicity(Multiplicity.MANY2ONE).make(); EdgeLabel battled = management.makeEdgeLabel("battled").signature(time).make(); management.buildEdgeIndex(battled, "battlesByTime", Direction.BOTH, Order.decr, time); management.makeEdgeLabel("lives").signature(reason).make(); management.makeEdgeLabel("pet").make(); management.makeEdgeLabel("brother").make();
tx.makeEdgeLabel("link").unidirected().make(); JanusGraphVertex v3 = tx.addVertex(); v21.addEdge("link", v3);
@Test public void testPageRank() throws ExecutionException, InterruptedException { mgmt.makePropertyKey("distance").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.MULTI).make(); mgmt.makeEdgeLabel("likes").multiplicity(Multiplicity.MULTI).make(); finishSchema(); final int branch = 6;
@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 public void testWithoutIndex() { PropertyKey kid = mgmt.makePropertyKey("kid").dataType(Long.class).make(); mgmt.makePropertyKey("name").dataType(String.class).make(); mgmt.makeEdgeLabel("knows").signature(kid).make(); finishSchema(); Random random = new Random(); int numV = 1000; JanusGraphVertex previous = null; for (int i = 0; i < numV; i++) { JanusGraphVertex v = graph.addVertex( "kid", random.nextInt(numV), "name", "v" + i); if (previous != null) { Edge e = v.addEdge("knows", previous, "kid", random.nextInt(numV / 2)); } previous = v; } verifyElementOrder(graph.query().orderBy("kid", incr).limit(500).vertices(), "kid", Order.ASC, 500); verifyElementOrder(graph.query().orderBy("kid", incr).limit(300).edges(), "kid", Order.ASC, 300); verifyElementOrder(graph.query().orderBy("kid", decr).limit(400).vertices(), "kid", Order.DESC, 400); verifyElementOrder(graph.query().orderBy("kid", decr).limit(200).edges(), "kid", Order.DESC, 200); clopen(); //Copied from above verifyElementOrder(graph.query().orderBy("kid", incr).limit(500).vertices(), "kid", Order.ASC, 500); verifyElementOrder(graph.query().orderBy("kid", incr).limit(300).edges(), "kid", Order.ASC, 300); verifyElementOrder(graph.query().orderBy("kid", decr).limit(400).vertices(), "kid", Order.DESC, 400); verifyElementOrder(graph.query().orderBy("kid", decr).limit(200).edges(), "kid", Order.DESC, 200); }
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())); } }
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(); }