private void updateVertexWithProperties(String propertyKey, Object propertyValue, Map<Object, Object> map) { if (graph.traversal().V().has(propertyKey, propertyValue).hasNext()) { final Vertex v = graph.traversal().V().has(propertyKey, propertyValue).next(); map.forEach((key, value) -> v.property((String) key, value)); graph.tx().commit(); } }
@Test public void testTransactionalScopeOfSchemaTypes() { makeVertexIndexedUniqueKey("domain", String.class); v1 = tx.addVertex(); try { v1.property(VertexProperty.Cardinality.single, "domain", "unique1"); } catch (SchemaViolationException e) { v1.property("domain", "unique1"); try { v2 = tx.addVertex(); v2.property("domain", "unique1"); fail(); } catch (SchemaViolationException e) { v1.property("domain", "unique1"); assertCount(1, tx.query().has("domain", "unique1").vertices()); try { v2 = tx.addVertex(); v2.property("domain", "unique1"); fail(); } catch (SchemaViolationException e) {
@Category({BrittleTests.class}) @Test public void testIndexReplay() throws Exception { final TimestampProvider times = graph.getConfiguration().getTimestampProvider(); vs[2].remove(); vs[3] = getV(tx, vs[3]); vs[3].property(VertexProperty.Cardinality.single, "name", "Bad Boy Badsy"); vs[3].property("age").remove(); newTx(); vs[0] = getV(tx, vs[0]); vs[0].property(VertexProperty.Cardinality.single, "age", 66); newTx(); assertEquals(1, recoveryStats[0]); //schema transaction was successful assertEquals(4, recoveryStats[1]); //all 4 index transaction had provoked errors in the indexing backend
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) public void shouldNotBeEqualsPropertiesAsIdIsDifferent() { final Vertex v = graph.addVertex(); final VertexProperty vp1 = v.property(VertexProperty.Cardinality.single, "test", "this"); final ReferenceVertexProperty mp1 = ReferenceFactory.detach(vp1); final VertexProperty vp2 = v.property(VertexProperty.Cardinality.single, "testing", "this"); final ReferenceVertexProperty mp2 = ReferenceFactory.detach(vp2); assertFalse(mp1.equals(mp2)); }
@Test public void testUpdateVertexPropertyOfRemovingVertexWithDrop() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); graph.tx().commit(); graph.traversal().V(vertex.id()).drop().iterate(); // Update on dirty vertex Assert.assertThrows(IllegalArgumentException.class, () -> { vertex.property("lived").remove(); }); Assert.assertThrows(IllegalArgumentException.class, () -> { vertex.property("lived", "Shanghai"); }); }
v1.property(property, value1); assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices())); v1.property(property, value2); assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices())); assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices())); assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices())); v1.property(property, value1); assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices())); assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices())); v1.property(property, value1); v1.property(property, value1); v1.property(property, value2); assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));
@Override public void setVreImage(String vreName, byte[] uploadedBytes, MediaType mediaType) { final GraphTraversal<Vertex, Vertex> vreT = getVreTraversal(vreName); if (vreT.hasNext()) { final Vertex vreVertex = vreT.next(); final Integer imageRev = vreVertex.property(Vre.IMAGE_REV_PROPERTY_NAME).isPresent() ? vreVertex.<Integer>value(Vre.IMAGE_REV_PROPERTY_NAME) + 1 : 1; vreVertex.property(Vre.IMAGE_REV_PROPERTY_NAME, imageRev); vreVertex.property(Vre.IMAGE_BLOB_PROPERTY_NAME, uploadedBytes); vreVertex.property(Vre.IMAGE_MEDIA_TYPE_PROPERTY_NAME, mediaType.toString()); } }
@Category({BrittleTests.class}) @Test public void testIndexReplay() throws Exception { final TimestampProvider times = graph.getConfiguration().getTimestampProvider(); vs[2].remove(); vs[3] = getV(tx, vs[3]); vs[3].property(VertexProperty.Cardinality.single, "name", "Bad Boy Badsy"); vs[3].property("age").remove(); newTx(); vs[0] = getV(tx, vs[0]); vs[0].property(VertexProperty.Cardinality.single, "age", 66); newTx(); assertEquals(1, recoveryStats[0]); //schema transaction was successful assertEquals(4, recoveryStats[1]); //all 4 index transaction had provoked errors in the indexing backend
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) public void shouldNotBeEqualsPropertiesAsIdIsDifferent() { final Vertex v = graph.addVertex(); final VertexProperty vp1 = v.property(VertexProperty.Cardinality.single, "test", "this"); final DetachedVertexProperty mp1 = DetachedFactory.detach(vp1, true); final VertexProperty vp2 = v.property(VertexProperty.Cardinality.single, "testing", "this"); final DetachedVertexProperty mp2 = DetachedFactory.detach(vp2, true); assertFalse(mp1.equals(mp2)); }
@Test public void testQueryByIntPropUsingInsideWithOneResult() { Assume.assumeTrue("Not support range condition query", storeFeatures().supportsQueryWithRangeCondition()); HugeGraph graph = graph(); initPersonIndex(false); init5Persons(); // 3 < age && age < 20 (that's age == 19) List<Vertex> vertexes = graph.traversal().V() .hasLabel("person").has("age", P.inside(3, 20)) .toList(); Assert.assertEquals(1, vertexes.size()); Assert.assertEquals(19, vertexes.get(0).property("age").value()); }
@Test public void testTransactionalScopeOfSchemaTypes() { makeVertexIndexedUniqueKey("domain", String.class); v1 = tx.addVertex(); try { v1.property(VertexProperty.Cardinality.single, "domain", "unique1"); } catch (SchemaViolationException ignored) { v1.property("domain", "unique1"); try { v2 = tx.addVertex(); v2.property("domain", "unique1"); fail(); } catch (SchemaViolationException ignored) { v1.property("domain", "unique1"); assertCount(1, tx.query().has("domain", "unique1").vertices()); try { v2 = tx.addVertex(); v2.property("domain", "unique1"); fail(); } catch (SchemaViolationException ignored) {
@Override public void map(final Vertex vertex, final MapEmitter emitter) { assertFalse(vertex.property("v1").isPresent()); assertFalse(vertex.property("v2").isPresent()); assertTrue(vertex.property("v3").isPresent()); assertTrue(vertex.property("name").isPresent()); assertEquals(3, IteratorUtils.count(vertex.properties())); assertEquals(3, IteratorUtils.count(vertex.values())); }
@Test public void testTinkerPopCardinality() { PropertyKey id = mgmt.makePropertyKey("id").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); PropertyKey name = mgmt.makePropertyKey("name").cardinality(Cardinality.SINGLE).dataType(String.class).make(); PropertyKey names = mgmt.makePropertyKey("names").cardinality(Cardinality.LIST).dataType(String.class).make(); mgmt.buildIndex("byId", Vertex.class).addKey(id).buildCompositeIndex(); finishSchema(); GraphTraversalSource gts; Vertex v; v = graph.addVertex("id", 1); v.property(single, "name", "t1"); graph.addVertex("id", 2, "names", "n1", "names", "n2"); graph.tx().commit(); gts = graph.traversal(); v = gts.V().has("id", 1).next(); v.property(single, "name", "t2"); v = gts.V().has("id", 1).next(); v.property(single, "name", "t3"); assertCount(1, gts.V(v).properties("name")); assertCount(2, gts.V().has("id", 2).properties("names")); assertCount(2, gts.V().hasLabel("vertex")); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeVertexProperty() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper(); final VertexProperty vp = graph.vertices(convertToVertexId("marko")).next().property("name"); final String json = mapper.writeValueAsString(vp); final Map<String, Object> m = mapper.readValue(json, mapTypeReference); assertEquals(vp.label(), m.get(GraphSONTokens.LABEL)); assertNotNull(m.get(GraphSONTokens.ID)); assertEquals(vp.value(), m.get(GraphSONTokens.VALUE)); }
@Test(expected = IllegalStateException.class) @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) public void shouldNotSupportRemove() { final Vertex v = graph.addVertex(); final VertexProperty vp = v.property(VertexProperty.Cardinality.single, "test", "this"); DetachedFactory.detach(vp, true).remove(); }