Refine search
@Override public void write(NullWritable key, VertexWritable value) throws IOException, InterruptedException { // TODO tolerate possibility that concurrent OLTP activity has deleted the vertex? maybe configurable... Object vertexID = value.get().id(); Vertex vertex = tx.vertices(vertexID).next(); Iterator<VertexProperty<Object>> vpIter = value.get().properties(); while (vpIter.hasNext()) { VertexProperty<Object> vp = vpIter.next(); if (!persistableKeys.isEmpty() && !persistableKeys.contains(vp.key())) { log.debug("[vid {}] skipping key {}", vertexID, vp.key()); continue; } vertex.property(vp.key(), vp.value()); log.debug("[vid {}] set {}={}", vertexID, vp.key(), vp.value()); } }
@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 { PropertyKey name = makeKey("name", String.class); mgmt.buildIndex("store1", Vertex.class).addKey(name).buildMixedIndex(INDEX); mgmt.commit(); TitanVertex v1 = tx.addVertex(); v1.property("name", "hercules was here"); tx.commit(); Thread.sleep(2000); TitanVertex r = Iterables.<TitanVertex>get(graph.query().has("name", Text.CONTAINS, "hercules here").vertices(), 0); Assert.assertEquals(r.property("name").value(), "hercules was here"); }
txNo = 1; assertEquals(1, Iterables.size(changes.getVertices(Change.ADDED))); assertEquals(0, Iterables.size(changes.getVertices(Change.REMOVED))); assertEquals(1, Iterables.size(changes.getVertices(Change.ANY))); assertEquals(2, Iterables.size(changes.getRelations(Change.ADDED))); assertEquals(v1id, getId(v)); VertexProperty<Float> p = Iterables.getOnlyElement(changes.getProperties(v, Change.ADDED, "weight")); assertEquals(111.1, p.value().doubleValue(), 0.01); assertEquals(1, Iterables.size(changes.getEdges(v, Change.ADDED, OUT))); assertEquals(1, Iterables.size(changes.getEdges(v, Change.ADDED, BOTH))); assertEquals(v2id, getId(v)); VertexProperty<Float> p = Iterables.getOnlyElement(changes.getProperties(v, Change.ADDED, "weight")); assertEquals(222.2, p.value().doubleValue(), 0.01); assertEquals(1, Iterables.size(changes.getEdges(v, Change.ADDED, OUT))); assertEquals(1, Iterables.size(changes.getEdges(v, Change.ADDED, BOTH))); assertEquals(v2id, getId(v)); VertexProperty<Float> p = Iterables.getOnlyElement(changes.getProperties(v, Change.REMOVED, "weight")); assertEquals(222.2, p.value().doubleValue(), 0.01); assertEquals(1, Iterables.size(changes.getEdges(v, Change.REMOVED, OUT))); assertEquals(0, Iterables.size(changes.getEdges(v, Change.ADDED, BOTH)));
@Test @LoadGraphWith(MODERN) public void g_V_hasXageX_propertiesXnameX() { final VertexProperty<String> vertexProperty = traversal.next(); keys.add(vertexProperty.key()); values.add(vertexProperty.value()); ids.add(vertexProperty.id()); Object id = vertexProperty.id(); id = id instanceof Number ? ((Number) id).longValue() : id; Object otherId = convertToVertex(graph, vertexProperty.value()).property("name").id(); otherId = otherId instanceof Number ? ((Number) otherId).longValue() : otherId; assertEquals(otherId, id); assertEquals("name", vertexProperty.key()); assertEquals(convertToVertex(graph, vertexProperty.value()).values("name").next(), vertexProperty.value()); assertEquals(convertToVertex(graph, vertexProperty.value()).value("name"), vertexProperty.value()); assertEquals(4, counter);
@Test public void testAppendAndAppendDifferentVertexProperty() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); vertex.property("name", "Tomcat"); vertex.property("lived", "Shanghai"); graph.tx().commit(); vertex = vertex("author", "id", 1); Assert.assertEquals("Tomcat", vertex.property("name").value()); Assert.assertEquals("Shanghai", vertex.property("lived").value()); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.CREW) public void shouldSerializeVertexPropertyWithProperties() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper(); final VertexProperty vp = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next(); 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)); assertEquals(vp.values("startTime").next(), ((Map) m.get(GraphSONTokens.PROPERTIES)).get("startTime")); assertEquals(vp.values("endTime").next(), ((Map) m.get(GraphSONTokens.PROPERTIES)).get("endTime")); }
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())); if (p.value().equals(value1)) { p.remove(); v1.property(property, value1); assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices())); assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));
@Test @LoadGraphWith(MODERN) public void shouldSupportMultipleScopesWithEdgeFunction() throws ExecutionException, InterruptedException { final ComputerResult result = graphProvider.getGraphComputer(graph).program(new MultiScopeVertexWithEdgeFunctionProgram()).submit().get(); assertEquals(result.graph().traversal().V().has("name", "josh").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 0L); assertEquals(result.graph().traversal().V().has("name", "lop").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 4L); assertEquals(result.graph().traversal().V().has("name", "ripple").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 10L); assertEquals(result.graph().traversal().V().has("name", "marko").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 20L); }
@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 testAddVertexProperty() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom"); graph.tx().commit(); // Add properties vertex.property("name", "Tom2"); vertex.property("age", 10); vertex.property("lived", "USA"); graph.tx().commit(); vertex = vertex("author", "id", 1); Assert.assertEquals("Tom2", vertex.property("name").value()); Assert.assertEquals(10, vertex.property("age").value()); Assert.assertEquals("USA", vertex.property("lived").value()); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.CREW) public void shouldSerializeVertexPropertyWithProperties() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper(); final VertexProperty vp = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next(); final String json = mapper.writeValueAsString(vp); final VertexProperty<?> detached = mapper.readValue(json, VertexProperty.class); assertNotNull(detached); assertEquals(vp.label(), detached.label()); assertEquals(vp.id(), detached.id()); assertEquals(vp.value(), detached.value()); assertEquals(vp.values("startTime").next(), detached.values("startTime").next()); assertEquals(((Property) vp.properties("startTime").next()).key(), ((Property) detached.properties("startTime").next()).key()); assertEquals(vp.values("endTime").next(), detached.values("endTime").next()); assertEquals(((Property) vp.properties("endTime").next()).key(), ((Property) detached.properties("endTime").next()).key()); }
public void checkFastProperty(boolean fastProperty) { makeKey("uid",String.class); makeKey("name", String.class); makeKey("age", String.class); finishSchema(); clopen(option(GraphDatabaseConfiguration.PROPERTY_PREFETCHING), fastProperty); metricsPrefix = "checkFastProperty"+fastProperty; TitanTransaction tx = graph.buildTransaction().groupName(metricsPrefix).start(); TitanVertex v = tx.addVertex("uid", "v1", "age", 25, "name", "john"); tx.commit(); verifyStoreMetrics(EDGESTORE_NAME); verifyStoreMetrics(INDEXSTORE_NAME); verifyStoreMetrics(METRICS_STOREMANAGER_NAME, ImmutableMap.of(M_MUTATE, 1l)); tx = graph.buildTransaction().groupName(metricsPrefix).start(); v = getV(tx, v); assertEquals("v1",v.property("uid").value()); assertEquals("25",v.property("age").value()); assertEquals("john",v.property("name").value()); tx.commit(); if (fastProperty) verifyStoreMetrics(EDGESTORE_NAME, ImmutableMap.of(M_GET_SLICE, 2l)); else verifyStoreMetrics(EDGESTORE_NAME, ImmutableMap.of(M_GET_SLICE, 4l)); verifyStoreMetrics(INDEXSTORE_NAME); verifyStoreMetrics(METRICS_STOREMANAGER_NAME, ImmutableMap.of(M_MUTATE, 1l)); }
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())); if (p.value().equals(value1)) { p.remove(); v1.property(property, value1); assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices())); assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));
@Override public void execute(final Vertex vertex, Messenger<Long> messenger, final Memory memory) { if (memory.isInitialIteration()) { if (vertex.id().equals(Long.valueOf(seed).longValue())) { // The seed sends a single message to start the computation log.debug("Sent initial message from {}", vertex.id()); // The seed's distance to itself is zero vertex.property(VertexProperty.Cardinality.single, DISTANCE, 0L); messenger.sendMessage(incidentMessageScope, 0L); } } else { Iterator<Long> distances = messenger.receiveMessages(); // Find minimum distance among all incoming messages, or null if no messages came in Long shortestDistanceSeenOnThisIteration = IteratorUtils.stream(distances).reduce((a, b) -> Math.min(a, b)).orElse(null); if (null == shortestDistanceSeenOnThisIteration) return; // no messages to process or forward on this superstep VertexProperty<Long> currentShortestVP = vertex.property(DISTANCE); if (!currentShortestVP.isPresent() || currentShortestVP.value() > shortestDistanceSeenOnThisIteration) { // First/shortest distance seen by this vertex: store it and forward to neighbors vertex.property(VertexProperty.Cardinality.single, DISTANCE, shortestDistanceSeenOnThisIteration); messenger.sendMessage(incidentMessageScope, shortestDistanceSeenOnThisIteration); } // else: no new winner, ergo no reason to send message to neighbors } }
@Test @LoadGraphWith(MODERN) public void shouldSupportMultipleScopes() throws ExecutionException, InterruptedException { final ComputerResult result = graphProvider.getGraphComputer(graph).program(new MultiScopeVertexProgram()).submit().get(); assertEquals(result.graph().traversal().V().has("name", "josh").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 0L); assertEquals(result.graph().traversal().V().has("name", "lop").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 1L); assertEquals(result.graph().traversal().V().has("name", "ripple").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 1L); assertEquals(result.graph().traversal().V().has("name", "marko").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 2L); }
@Test public void checkPropertyLockingAndIndex() { PropertyKey uid = makeKey("uid",String.class); TitanGraphIndex index = mgmt.buildIndex("uid",Vertex.class).unique().addKey(uid).buildCompositeIndex(); mgmt.setConsistency(index, ConsistencyModifier.LOCK); mgmt.makePropertyKey("name").dataType(String.class).make(); mgmt.makePropertyKey("age").dataType(Integer.class).make(); finishSchema(); metricsPrefix = "checkPropertyLockingAndIndex"; TitanTransaction tx = graph.buildTransaction().groupName(metricsPrefix).start(); TitanVertex v = tx.addVertex("uid", "v1", "age", 25, "name", "john"); assertEquals(25,v.property("age").value()); tx.commit(); verifyStoreMetrics(EDGESTORE_NAME); verifyLockingOverwrite(INDEXSTORE_NAME, 1); verifyStoreMetrics(METRICS_STOREMANAGER_NAME, ImmutableMap.of(M_MUTATE, 1l)); resetMetrics(); tx = graph.buildTransaction().groupName(metricsPrefix).start(); v = Iterables.getOnlyElement(tx.query().has("uid", Cmp.EQUAL, "v1").vertices()); assertEquals(25,v.property("age").value()); tx.commit(); verifyStoreMetrics(EDGESTORE_NAME, ImmutableMap.of(M_GET_SLICE,1l)); verifyStoreMetrics(INDEXSTORE_NAME, ImmutableMap.of(M_GET_SLICE,1l)); verifyStoreMetrics(METRICS_STOREMANAGER_NAME); }
@Test public void testAppendAndAppendSameVertexProperty() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); vertex.property("lived", "Wuhan"); vertex.property("lived", "Shanghai"); graph.tx().commit(); vertex = vertex("author", "id", 1); Assert.assertEquals("Shanghai", vertex.property("lived").value()); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.CREW) public void shouldSerializeVertexPropertyWithProperties() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper(); final VertexProperty vp = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next(); final String json = mapper.writeValueAsString(vp); final VertexProperty<?> detached = mapper.readValue(json, VertexProperty.class); assertNotNull(detached); assertEquals(vp.label(), detached.label()); assertEquals(vp.id(), detached.id()); assertEquals(vp.value(), detached.value()); assertEquals(vp.values("startTime").next(), detached.values("startTime").next()); assertEquals(((Property) vp.properties("startTime").next()).key(), ((Property) detached.properties("startTime").next()).key()); assertEquals(vp.values("endTime").next(), detached.values("endTime").next()); assertEquals(((Property) vp.properties("endTime").next()).key(), ((Property) detached.properties("endTime").next()).key()); }
private void processTx(TitanTransaction tx, int txid, long vid, long uid) { TitanVertex v = getV(tx,vid); TitanVertex u = getV(tx,uid); assertEquals(5.0,v.<Double>value("weight").doubleValue(),0.00001); VertexProperty p = getOnlyElement(v.properties("weight")); assertEquals(1,p.<Integer>value("sig").intValue()); sign(v.property("weight",6.0),txid); p = getOnlyElement(v.properties("name")); assertEquals(1,p.<Integer>value("sig").intValue()); assertEquals("John",p.value()); p.remove(); sign(v.property("name","Bob"),txid); for (String pkey : new String[]{"value","valuef"}) { p = getOnlyElement(v.properties(pkey)); assertEquals(1,p.<Integer>value("sig").intValue()); assertEquals(2,p.value()); sign((TitanVertexProperty)p,txid);
@Override public void execute(final Vertex vertex, Messenger<Long> messenger, final Memory memory) { if (memory.isInitialIteration()) { if (vertex.id().equals(seed)) { // The seed sends a single message to start the computation log.debug("Sent initial message from {}", vertex.id()); // The seed's distance to itself is zero vertex.property(VertexProperty.Cardinality.single, DISTANCE, 0L); messenger.sendMessage(incidentMessageScope, 0L); } } else { Iterator<Long> distances = messenger.receiveMessages(); // Find minimum distance among all incoming messages, or null if no messages came in Long shortestDistanceSeenOnThisIteration = IteratorUtils.stream(distances).reduce(Math::min).orElse(null); if (null == shortestDistanceSeenOnThisIteration) return; // no messages to process or forward on this superstep VertexProperty<Long> currentShortestVP = vertex.property(DISTANCE); if (!currentShortestVP.isPresent() || currentShortestVP.value() > shortestDistanceSeenOnThisIteration) { // First/shortest distance seen by this vertex: store it and forward to neighbors vertex.property(VertexProperty.Cardinality.single, DISTANCE, shortestDistanceSeenOnThisIteration); messenger.sendMessage(incidentMessageScope, shortestDistanceSeenOnThisIteration); } // else: no new winner, ergo no reason to send message to neighbors } }