Refine search
@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); } } }
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(); assertCount(1, g.V().has("name", "Totoro")); assertCount(1, g.V().has("age", 2)); assertCount(1, g.V().or(__.has("name", "Hiro"),__.has("age", 2))); assertCount(2, g.V().or(__.has("name", "Totoro"),__.has("age", 2))); assertCount(2, g.V().or(__.has("name", "Totoro").has("age", 1),__.has("age", 2)));
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldHidePartitionKeyForPropertyMapWithEmptyKeys() { 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).propertyMap().count().next()); assertEquals("thing", ((List<VertexProperty>) gOverA.V(v).propertyMap().next().get("any")).get(0).value()); }
@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 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(expected = IllegalStateException.class) @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldHidePartitionKeyForPropertyMap() { 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(); gOverA.V(v).propertyMap(partition).next(); }
@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); } } }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldUseActualVertexWhenAdded() { final AtomicBoolean triggered = new AtomicBoolean(false); final AtomicReference<Vertex> eventedVertex = new AtomicReference<>(); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexAdded(final Vertex element) { eventedVertex.set(element); assertEquals("thing", element.label()); assertThat(element.properties("here").hasNext(), is(false)); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener).detach(EventStrategy.Detachment.REFERENCE); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); final Vertex v = gts.addV("thing").property("here", "there").next(); tryCommit(graph); assertVertexEdgeCounts(graph, 1, 0); assertThat(triggered.get(), is(true)); assertEquals(v, eventedVertex.get()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldGenerateDefaultIdOnGraphAddVWithGeneratedDefaultId() throws Exception { final ElementIdStrategy strategy = ElementIdStrategy.build().create(); final GraphTraversalSource sg = create(strategy); final Vertex v = sg.addV().property("name", "stephen").next(); assertEquals("stephen", v.value("name")); final Traversal t1 = graph.traversal().V(v); t1.asAdmin().applyStrategies(); logger.info(t1.toString()); final Traversal t2 = sg.V(v); t2.asAdmin().applyStrategies(); logger.info(t2.toString()); assertNotNull(UUID.fromString(sg.V(v).id().next().toString())); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldDetachVertexWhenAdded() { final AtomicBoolean triggered = new AtomicBoolean(false); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexAdded(final Vertex element) { assertThat(element, instanceOf(DetachedVertex.class)); assertEquals("thing", element.label()); assertEquals("there", element.value("here")); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.addV("thing").property("here", "there").iterate(); tryCommit(graph); assertVertexEdgeCounts(graph, 1, 0); assertThat(triggered.get(), is(true)); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES) public void shouldAppendPartitionToVertexPropertyOverMultiProperty() { final PartitionStrategy partitionStrategy = PartitionStrategy.build() .includeMetaProperties(true) .partitionKey(partition).writePartition("A").readPartitions("A").create(); final Vertex v = g.withStrategies(partitionStrategy).addV().property(VertexProperty.Cardinality.list, "any", "thing") .property(VertexProperty.Cardinality.list, "any", "more").next(); assertNotNull(v); assertThat((List<String>) IteratorUtils.asList(g.V(v).properties("any")).stream().map(p -> ((VertexProperty) p).value()).collect(Collectors.toList()), containsInAnyOrder("thing", "more")); assertEquals("A", v.property(partition).value()); assertThat((List<String>) IteratorUtils.asList(g.V(v).properties("any")).stream().map(p -> ((VertexProperty) p).value(partition)).collect(Collectors.toList()), containsInAnyOrder("A", "A")); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldReferenceVertexWhenAdded() { final AtomicBoolean triggered = new AtomicBoolean(false); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexAdded(final Vertex element) { assertThat(element, instanceOf(ReferenceVertex.class)); assertEquals("thing", element.label()); assertThat(element.properties("here").hasNext(), is(false)); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener).detach(EventStrategy.Detachment.REFERENCE); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.addV("thing").property("here", "there").iterate(); tryCommit(graph); assertVertexEdgeCounts(graph, 1, 0); assertThat(triggered.get(), is(true)); }
@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()); }