@Test public void testSupportDirectCommitOfSchemaChangesForConnection() { GraphTraversalSource g = prepareGraphForDirectCommitTests(); g.addV("user").as("p1").addV("user").addE("knows").from("p1").iterate(); }
@Test public void testSupportDirectCommitOfSchemaChangesForEdgeProperties() { GraphTraversalSource g = prepareGraphForDirectCommitTests(); g.addV("user").as("p1").addV("user").addE("knows").from("p1").property("id", 10).iterate(); }
@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 testOrForceIndexComposite() throws Exception { JanusGraph customGraph = null; try { customGraph = this.getForceIndexGraph(); final JanusGraphManagement management = customGraph.openManagement(); 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("ageridx", Vertex.class).addKey(ageProperty).buildCompositeIndex(); 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().has("age", P.gte(4).or(P.lt(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 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 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); } } }
private void testOr(final Graph aGraph) { final GraphTraversalSource g = aGraph.traversal(); final Vertex hiro = g.addV().property("name", "Hiro").property("age", 2).property("length", 90).next(); final Vertex totoro = g.addV().property("name", "Totoro").property("age", 1).next(); final Vertex john = g.addV().property("name", "John").property("age", 3).property("length", 110).next(); final Vertex mike = g.addV().property("name", "Mike").property("age", 4).property("length", 130).next(); aGraph.tx().commit();
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldHidePartitionKeyForValueMapWithEmptyKeys() { final GraphTraversalSource gOverA = g.withStrategies(PartitionStrategy.build() .includeMetaProperties(true) .partitionKey(partition).writePartition("A").readPartitions("A").create()); final Vertex v = gOverA.addV().property("any", "thing").next(); assertEquals(1L, (long) gOverA.V(v).valueMap().count().next()); assertEquals("thing", ((List) gOverA.V(v).valueMap().next().get("any")).get(0)); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldSetIdOnAddVWithIdPropertyKeySpecifiedAndNameSuppliedAsProperty() throws Exception { final ElementIdStrategy strategy = ElementIdStrategy.build().idPropertyKey("name").create(); final GraphTraversalSource sg = create(strategy); final Vertex v = sg.addV().property("name", "stephen").next(); assertEquals("stephen", v.value("name")); assertEquals("stephen", sg.V(v).id().next()); assertEquals("stephen", sg.V("stephen").id().next()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldSetIdOnAddVWithIdPropertyKeySpecifiedAndIdSuppliedAsProperty() throws Exception { final ElementIdStrategy strategy = ElementIdStrategy.build().idPropertyKey("name").create(); final GraphTraversalSource sg = create(strategy); final Vertex v = sg.addV().property(T.id, "stephen").next(); assertEquals("stephen", v.value("name")); assertEquals("stephen", sg.V(v).id().next()); assertEquals("stephen", sg.V("stephen").id().next()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldGenerateDefaultIdOnGraphAddVWithSpecifiedId() throws Exception { final ElementIdStrategy strategy = ElementIdStrategy.build().create(); final GraphTraversalSource sg = create(strategy); final Vertex v = sg.addV().property(T.id, "STEPHEN").property("name", "stephen").next(); assertEquals("stephen", v.value("name")); assertEquals("STEPHEN", sg.V(v).id().next()); assertEquals("STEPHEN", sg.V("STEPHEN").id().next()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldGenerateDefaultIdOnGraphAddVWithGeneratedCustomId() throws Exception { final ElementIdStrategy strategy = ElementIdStrategy.build().idMaker(new ConstantSupplier<>("xxx")).create(); final GraphTraversalSource sg = create(strategy); final Vertex v = sg.addV().property("name", "stephen").next(); assertEquals("stephen", v.value("name")); assertEquals("xxx", sg.V(v).id().next()); assertEquals("xxx", sg.V("xxx").id().next()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldHidePartitionKeyForValuesWithEmptyKeys() { final GraphTraversalSource gOverA = g.withStrategies(PartitionStrategy.build() .includeMetaProperties(true) .partitionKey(partition).writePartition("A").readPartitions("A").create()); final Vertex v = gOverA.addV().property("any", "thing").next(); assertEquals(1L, (long) gOverA.V(v).values().count().next()); assertEquals("thing", gOverA.V(v).values().next()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldAppendPartitionToVertexProperty() { final PartitionStrategy partitionStrategy = PartitionStrategy.build() .includeMetaProperties(true) .partitionKey(partition).writePartition("A").readPartitions("A").create(); final Vertex v = g.withStrategies(partitionStrategy).addV().property("any", "thing").next(); assertNotNull(v); assertEquals("thing", g.V(v).values("any").next()); assertEquals("A", g.V(v).values(partition).next()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldHidePartitionKeyForPropertiesWithEmptyKeys() { final GraphTraversalSource gOverA = g.withStrategies(PartitionStrategy.build() .includeMetaProperties(true) .partitionKey(partition).writePartition("A").readPartitions("A").create()); final Vertex v = gOverA.addV().property("any", "thing").next(); assertEquals(1L, (long) gOverA.V(v).properties().count().next()); assertEquals("thing", gOverA.V(v).properties().value().next()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) public void shouldGenerateDefaultIdOnAddEWithSpecifiedId() throws Exception { final ElementIdStrategy strategy = ElementIdStrategy.build().create(); final GraphTraversalSource sg = create(strategy); final Vertex v = sg.addV().next(); final Edge e = sg.withSideEffect("v", v).V(v).addE("self").to("v").property("test", "value").property(T.id, "some-id").next(); assertEquals("value", e.value("test")); assertEquals("some-id", sg.E(e).id().next()); assertEquals("some-id", sg.E("some-id").id().next()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldGenerateDefaultIdOnAddVWithSpecifiedId() throws Exception { final ElementIdStrategy strategy = ElementIdStrategy.build().create(); final GraphTraversalSource sg = create(strategy); sg.addV().next(); assertEquals(1, IteratorUtils.count(sg.V())); final Vertex v = sg.V().addV().property(T.id, "STEPHEN").property("name", "stephen").next(); assertEquals("stephen", v.value("name")); assertEquals("STEPHEN", sg.V(v).id().next()); assertEquals("STEPHEN", sg.V("STEPHEN").id().next()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) public void shouldSetIdOnAddEWithIdPropertyKeySpecifiedAndNameSuppliedAsProperty() throws Exception { final ElementIdStrategy strategy = ElementIdStrategy.build().idPropertyKey("name").create(); final GraphTraversalSource sg = create(strategy); final Vertex v = sg.addV().next(); final Edge e = sg.withSideEffect("v", v).V(v).addE("self").to("v").property("test", "value").property(T.id, "some-id").next(); assertEquals("value", e.value("test")); assertEquals("some-id", e.value("name")); assertEquals("some-id", sg.E(e).id().next()); assertEquals("some-id", sg.E("some-id").id().next()); }