@Test public void testAllowEnforcedComplexConnections() { createStrictSchemaForComplexConnections(); JanusGraphVertex v1 = tx.addVertex("V1"); JanusGraphVertex v2 = tx.addVertex("V2"); JanusGraphVertex v3 = tx.addVertex("V3"); JanusGraphVertex v4 = tx.addVertex("V4"); v1.addEdge("E1", v2); v3.addEdge("E1", v4); v3.addEdge("E2", v2); v1.addEdge("E2", v4); }
@Test public void testSchemaIsEnforcedForEdgeProperties() { createStrictSchemaForEdgeProperties(); JanusGraphVertex v1 = tx.addVertex("user"); JanusGraphVertex v2 = tx.addVertex("user"); try { v1.addEdge("knows", v2, "test", 10); fail("This should never reached!"); } catch (IllegalArgumentException ignored) { } }
private int growVertex(Vertex vertex, int depth, int maxDepth, int maxBranch) { vertex.property(VertexProperty.Cardinality.single, "distance", depth); int total=1; if (depth>=maxDepth) return total; for (int i=0;i<random.nextInt(maxBranch)+1;i++) { int dist = random.nextInt(3)+1; JanusGraphVertex n = tx.addVertex(); n.addEdge("connect",vertex, "distance",dist); total+=growVertex(n,depth+dist,maxDepth,maxBranch); } return total; }
private void addVertex(int time, String text, double height, String[] phones) { newTx(); final JanusGraphVertex v = tx.addVertex("text", text, "time", time, "height", height); for (final String phone : phones) { v.property("phone", phone); } newTx(); }
@Test public void testEnforcedSchemaAllowsDefinedVertexProperties() { createStrictSchemaForVertexProperties(); JanusGraphVertex v = tx.addVertex("user"); v.property("id", 10); }
@Test public void testAutoSchemaMakerForEdgePropertyConstraints() { clopen(option(SCHEMA_CONSTRAINTS), true); JanusGraphVertex v1 = tx.addVertex("user"); JanusGraphVertex v2 = tx.addVertex("user"); v1.addEdge("knows", v2, "id", 10); clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); v1 = tx.addVertex("user"); v2 = tx.addVertex("user"); v1.addEdge("knows", v2, "id", 10); try { v1.addEdge("knows", v2, "test", 10); fail("This should never reached!"); } catch (IllegalArgumentException ignored) { } }
@Test public void testAutoSchemaMakerForConnectionConstraints() { clopen(option(SCHEMA_CONSTRAINTS), true); JanusGraphVertex v1 = tx.addVertex("user"); JanusGraphVertex v2 = tx.addVertex("user"); v1.addEdge("knows", v2); clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); v1 = tx.addVertex("user"); v2 = tx.addVertex("user"); v1.addEdge("knows", v2); try { v1.addEdge("has", v2); fail("This should never reached!"); } catch (IllegalArgumentException ignored) { } }
@Test public void testAutoSchemaMakerForEdgePropertyDataType(){ JanusGraphVertex v1 = tx.addVertex("user"); JanusGraphVertex v2 = tx.addVertex("user"); v1.addEdge("knows", v2, "id", 10, "created", new Date()); PropertyKey idPropertyKey = tx.getPropertyKey("id"); assertEquals("Data type not identified correctly by auto schema maker", Integer.class, idPropertyKey.dataType()); PropertyKey createdPropertyKey = tx.getPropertyKey("created"); assertEquals("Data type not identified correctly by auto schema maker", Date.class, createdPropertyKey.dataType()); }
@Test public void testSchemaIsEnforcedForConnections() { createStrictSchemaForConnections(); JanusGraphVertex v1 = tx.addVertex("user"); try { v1.addEdge("buys", v1); fail("This should never reached!"); } catch (IllegalArgumentException ignored) { } JanusGraphVertex v2 = tx.addVertex("company"); try { v2.addEdge("knows", v1); fail("This should never reached!"); } catch (IllegalArgumentException ignored) { } }
@Test public void testSchemaIsEnforcedForVertexProperties() { createStrictSchemaForVertexProperties(); JanusGraphVertex v = tx.addVertex("user"); try { v.property("test", 10); fail("This should never reached!"); } catch (IllegalArgumentException ignored) { } }
@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 testAutoSchemaMakerForVertexPropertyConstraints() { clopen(option(SCHEMA_CONSTRAINTS), true); JanusGraphVertex v1 = tx.addVertex("user"); v1.property("test", 10); clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); JanusGraphVertex v2 = tx.addVertex("user"); v2.property("test", 10); try { v2.property("id", 10); fail("This should never reached!"); } catch (IllegalArgumentException ignored) { } }
@Test public void testAutoSchemaMakerForVertexPropertyDataType(){ JanusGraphVertex v1 = tx.addVertex("user"); v1.property("id", 10); v1.property("created", new Date()); PropertyKey idPropertyKey = tx.getPropertyKey("id"); assertEquals("Data type not identified correctly by auto schema maker", Integer.class, idPropertyKey.dataType()); PropertyKey createdPropertyKey = tx.getPropertyKey("created"); assertEquals("Data type not identified properly by auto schema maker", Date.class, createdPropertyKey.dataType()); }
@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 // 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 testAllowDisablingSchemaConstraintForVertexProperty() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), false); mgmt.makeVertexLabel("user").make(); mgmt.makePropertyKey("test").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); finishSchema(); JanusGraphVertex v = tx.addVertex("user"); v.property("test", 10); }
@Test public void testNestedTransactions() { Vertex v1 = graph.addVertex(); newTx(); Vertex v2 = tx.addVertex(); v2.property("name", "foo"); tx.commit(); v1.addEdge("related", graph.traversal().V(v2).next()); graph.tx().commit(); assertCount(1, v1.edges(OUT)); }
@Test public void concurrentIndexTest() { makeVertexIndexedUniqueKey("uid", String.class); makeVertexIndexedKey("value", Object.class); finishSchema(); tx.addVertex("uid", "v"); clopen(); //Concurrent index addition JanusGraphTransaction tx1 = graph.newTransaction(); JanusGraphTransaction tx2 = graph.newTransaction(); getVertex(tx1, "uid", "v").property(VertexProperty.Cardinality.single, "value", 11); getVertex(tx2, "uid", "v").property(VertexProperty.Cardinality.single, "value", 11); tx1.commit(); tx2.commit(); assertEquals("v", Iterators.<String>getOnlyElement(Iterables.getOnlyElement(tx.query().has("value", 11).vertices()).values("uid"))); }