Java Code Examples for org.apache.tinkerpop.gremlin.structure.Vertex#id()
The following examples show how to use
org.apache.tinkerpop.gremlin.structure.Vertex#id() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestPropertyValues.java From sqlg with MIT License | 6 votes |
@Test public void testMultipleSelect() { Vertex vA = sqlgGraph.addVertex(T.label, "A", "name", "root"); Vertex vI = sqlgGraph.addVertex(T.label, "I", "name", "item1"); vA.addEdge("likes", vI, "howMuch", 5, "who", "Joe"); this.sqlgGraph.tx().commit(); Object id0 = vI.id(); GraphTraversal<Vertex, Map<String, Object>> gt = sqlgGraph.traversal().V() .hasLabel("A") .has("name", "root") .outE("likes") .as("e") .values("howMuch").as("stars") .select("e") .values("who").as("user") .select("e") .inV() .id().as("item") .select("user", "stars", "item"); printTraversalForm(gt); Assert.assertTrue(gt.hasNext()); Map<String, Object> m = gt.next(); Assert.assertEquals(new Integer(5), m.get("stars")); Assert.assertEquals("Joe", m.get("user")); Assert.assertEquals(id0, m.get("item")); }
Example 2
Source File: ReaderStatusManager.java From atlas with Apache License 2.0 | 6 votes |
private void createAndCommit(Graph rGraph) { Vertex v = rGraph.addVertex(); long longValue = 0L; v.property(Constants.ENTITY_TYPE_PROPERTY_KEY, MIGRATION_STATUS_TYPE_NAME); v.property(CURRENT_COUNTER_PROPERTY, longValue); v.property(CURRENT_INDEX_PROPERTY, longValue); v.property(TOTAL_COUNT_PROPERTY, longValue); v.property(OPERATION_STATUS_PROPERTY, STATUS_NOT_STARTED); v.property(START_TIME_PROPERTY, new Date()); v.property(END_TIME_PROPERTY, new Date()); migrationStatusId = v.id(); if(rGraph.features().graph().supportsTransactions()) { rGraph.tx().commit(); } LOG.info("migrationStatus vertex created! v[{}]", migrationStatusId); }
Example 3
Source File: TestComplex.java From sqlg with MIT License | 6 votes |
@Test public void testProject() { Map<String, Object> aValues = new HashMap<>(); aValues.put("name", "root"); Vertex vA = sqlgGraph.addVertex("A", aValues); Map<String, Object> iValues = new HashMap<>(); iValues.put("name", "item1"); Vertex vI = sqlgGraph.addVertex("I", iValues); vA.addEdge("likes", vI, "howMuch", 5, "who", "Joe"); this.sqlgGraph.tx().commit(); Object id0 = vI.id(); GraphTraversal<Vertex, Map<String, Object>> gt = sqlgGraph.traversal().V() .hasLabel("A") .has("name", "root") .outE("likes") .project("stars", "user", "item") .by("howMuch") .by("who") .by(__.inV().id()) .select("user", "stars", "item"); Assert.assertTrue(gt.hasNext()); Map<String, Object> m = gt.next(); Assert.assertEquals(new Integer(5), m.get("stars")); Assert.assertEquals("Joe", m.get("user")); Assert.assertEquals(id0, m.get("item")); }
Example 4
Source File: TestAllVertices.java From sqlg with MIT License | 6 votes |
@Test public void testVertexIteratorWithIncorrectId() throws Exception { Graph g = this.sqlgGraph; final Vertex v1 = g.addVertex("name", "marko"); final Object oid = v1.id(); g.tx().onClose(Transaction.CLOSE_BEHAVIOR.ROLLBACK); g.close(); try (SqlgGraph graph = SqlgGraph.open(configuration)) { try { graph.vertices(oid).next(); Assert.fail("Vertex should not be found as close behavior was set to rollback"); } catch (Exception ex) { validateException(new NoSuchElementException(), ex); } } }
Example 5
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) public void shouldReferenceEdgeWhenAdded() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final Object id = v.id(); final MutationListener listener = new AbstractMutationListener() { @Override public void edgeAdded(final Edge element) { assertThat(element, instanceOf(ReferenceEdge.class)); assertEquals("self", element.label()); assertEquals(id, element.inVertex().id()); assertEquals(id, element.outVertex().id()); assertThat(element.properties().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.V(v).as("a").addE("self").property("here", "there").from("a").to("a").iterate(); tryCommit(graph); assertVertexEdgeCounts(graph, 1, 1); assertThat(triggered.get(), is(true)); }
Example 6
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) public void shouldReferencePropertyOfEdgeWhenChanged() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final Edge e = v.addEdge("self", v); final String label = e.label(); final Object inId = v.id(); final Object outId = v.id(); e.property("to-change", "no!"); final MutationListener listener = new AbstractMutationListener() { @Override public void edgePropertyChanged(final Edge element, final Property oldValue, final Object setValue) { assertThat(element, instanceOf(ReferenceEdge.class)); assertEquals(label, element.label()); assertEquals(inId, element.inVertex().id()); assertEquals(outId, element.outVertex().id()); assertEquals("no!", oldValue.value()); assertEquals("to-change", oldValue.key()); assertEquals("yay!", setValue); 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.E(e).property("to-change","yay!").iterate(); tryCommit(graph); assertEquals(1, IteratorUtils.count(g.E(e).properties())); assertThat(triggered.get(), is(true)); }
Example 7
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldDetachVertexPropertyWhenNew() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final String label = v.label(); final Object id = v.id(); v.property("old","blah"); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexPropertyChanged(final Vertex element, final VertexProperty oldValue, final Object setValue, final Object... vertexPropertyKeyValues) { assertThat(element, instanceOf(DetachedVertex.class)); assertEquals(label, element.label()); assertEquals(id, element.id()); assertThat(oldValue, instanceOf(KeyedVertexProperty.class)); assertEquals("new", oldValue.key()); assertEquals("dah", setValue); 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.V(v).property(VertexProperty.Cardinality.single, "new", "dah").iterate(); tryCommit(graph); assertEquals(2, IteratorUtils.count(g.V(v).properties())); assertThat(triggered.get(), is(true)); }
Example 8
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) public void shouldDetachEdgeWhenAdded() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final Object id = v.id(); final MutationListener listener = new AbstractMutationListener() { @Override public void edgeAdded(final Edge element) { assertThat(element, instanceOf(DetachedEdge.class)); assertEquals("self", element.label()); assertEquals(id, element.inVertex().id()); assertEquals(id, element.outVertex().id()); 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.V(v).as("a").addE("self").property("here", "there").from("a").to("a").iterate(); tryCommit(graph); assertVertexEdgeCounts(graph, 1, 1); assertThat(triggered.get(), is(true)); }
Example 9
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldDetachVertexPropertyWhenChanged() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final String label = v.label(); final Object id = v.id(); v.property("to-change", "blah"); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexPropertyChanged(final Vertex element, final VertexProperty oldValue, final Object setValue, final Object... vertexPropertyKeyValues) { assertThat(element, instanceOf(DetachedVertex.class)); assertEquals(label, element.label()); assertEquals(id, element.id()); assertEquals("to-change", oldValue.key()); assertEquals("blah", oldValue.value()); assertEquals("dah", setValue); 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.V(v).property(VertexProperty.Cardinality.single, "to-change", "dah").iterate(); tryCommit(graph); assertEquals(1, IteratorUtils.count(g.V(v).properties())); assertThat(triggered.get(), is(true)); }
Example 10
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) public void shouldUseActualPropertyOfEdgeWhenNew() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final Edge e = v.addEdge("self", v); final String label = e.label(); final Object inId = v.id(); final Object outId = v.id(); e.property("to-change", "no!"); final MutationListener listener = new AbstractMutationListener() { @Override public void edgePropertyChanged(final Edge element, final Property oldValue, final Object setValue) { assertEquals(e, element); assertEquals(label, element.label()); assertEquals(inId, element.inVertex().id()); assertEquals(outId, element.outVertex().id()); assertThat(oldValue, instanceOf(KeyedProperty.class)); assertEquals("new", oldValue.key()); assertEquals("yay!", setValue); 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.E(e).property("new","yay!").iterate(); tryCommit(graph); assertEquals(2, IteratorUtils.count(g.E(e).properties())); assertThat(triggered.get(), is(true)); }
Example 11
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldUseActualVertexPropertyWhenChanged() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final String label = v.label(); final Object id = v.id(); v.property("to-change", "blah"); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexPropertyChanged(final Vertex element, final VertexProperty oldValue, final Object setValue, final Object... vertexPropertyKeyValues) { assertEquals(v, element); assertEquals(label, element.label()); assertEquals(id, element.id()); assertEquals("to-change", oldValue.key()); assertEquals("blah", oldValue.value()); assertEquals("dah", setValue); 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.V(v).property(VertexProperty.Cardinality.single, "to-change", "dah").iterate(); tryCommit(graph); assertEquals(1, IteratorUtils.count(g.V(v).properties())); assertThat(triggered.get(), is(true)); }
Example 12
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) public void shouldUseActualEdgeWhenAdded() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final Object id = v.id(); final AtomicReference<Edge> eventedEdge = new AtomicReference<>(); final MutationListener listener = new AbstractMutationListener() { @Override public void edgeAdded(final Edge element) { eventedEdge.set(element); assertEquals("self", element.label()); assertEquals(id, element.inVertex().id()); assertEquals(id, element.outVertex().id()); assertThat(element.properties().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 Edge e = gts.V(v).as("a").addE("self").property("here", "there").from("a").to("a").next(); tryCommit(graph); assertVertexEdgeCounts(graph, 1, 1); assertThat(triggered.get(), is(true)); assertEquals(e, eventedEdge.get()); }
Example 13
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldUseActualVertexPropertyWhenNew() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final String label = v.label(); final Object id = v.id(); v.property("old","blah"); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexPropertyChanged(final Vertex element, final VertexProperty oldValue, final Object setValue, final Object... vertexPropertyKeyValues) { assertEquals(v, element); assertEquals(label, element.label()); assertEquals(id, element.id()); assertThat(oldValue, instanceOf(KeyedVertexProperty.class)); assertEquals("new", oldValue.key()); assertEquals("dah", setValue); 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.V(v).property(VertexProperty.Cardinality.single, "new", "dah").iterate(); tryCommit(graph); assertEquals(2, IteratorUtils.count(g.V(v).properties())); assertThat(triggered.get(), is(true)); }
Example 14
Source File: StarGraph.java From tinkerpop with Apache License 2.0 | 5 votes |
Edge addInEdge(final String label, final Vertex outVertex, final Object... keyValues) { ElementHelper.validateLabel(label); ElementHelper.legalPropertyKeyValueArray(keyValues); if (null == this.inEdges) this.inEdges = new HashMap<>(); List<Edge> inE = this.inEdges.get(label); if (null == inE) { inE = new ArrayList<>(); this.inEdges.put(label, inE); } final StarEdge inEdge = new StarInEdge(ElementHelper.getIdValue(keyValues).orElse(nextId()), label, outVertex.id()); ElementHelper.attachProperties(inEdge, keyValues); inE.add(inEdge); return inEdge; }
Example 15
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldDetachVertexWhenRemoved() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final String label = v.label(); final Object id = v.id(); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexRemoved(final Vertex element) { assertThat(element, instanceOf(DetachedVertex.class)); assertEquals(id, element.id()); assertEquals(label, element.label()); 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.V(v).drop().iterate(); tryCommit(graph); assertVertexEdgeCounts(graph, 0, 0); assertThat(triggered.get(), is(true)); }
Example 16
Source File: TestSimpleVertexEdgeGremlin.java From sqlg with MIT License | 4 votes |
@Test public void testSimpleVertexInsertAndUpdateAndQuery() { this.sqlgGraph.getTopology().ensureVertexLabelExist( "Person", new LinkedHashMap<String, PropertyType>() {{ put("name", PropertyType.varChar(100)); put("surname", PropertyType.varChar(100)); put("country", PropertyType.STRING); }}, ListOrderedSet.listOrderedSet(Arrays.asList("name", "surname")) ); this.sqlgGraph.tx().commit(); List<Vertex> persons = this.sqlgGraph.traversal().V().hasLabel("Person").toList(); Assert.assertTrue(persons.isEmpty()); try { this.sqlgGraph.addVertex(T.label, "Person", "name", "John"); Assert.fail("Primary Key not specified, query suppose to fail!"); } catch (Exception e) { //ignore } this.sqlgGraph.tx().rollback(); this.sqlgGraph.addVertex(T.label, "Person", "name", "John", "surname", "Smith"); this.sqlgGraph.tx().commit(); persons = this.sqlgGraph.traversal().V().hasLabel("Person").toList(); Assert.assertEquals(1, persons.size()); Vertex person = persons.get(0); RecordId recordId = (RecordId) person.id(); Assert.assertNull(recordId.getID().getSequenceId()); Assert.assertEquals(2, recordId.getIdentifiers().size()); Assert.assertEquals("John", recordId.getIdentifiers().get(0)); Assert.assertEquals("Smith", recordId.getIdentifiers().get(1)); Assert.assertEquals("John", person.property("name").value()); Assert.assertEquals("Smith", person.property("surname").value()); Assert.assertFalse(person.property("country").isPresent()); person.property("country", "moon"); this.sqlgGraph.tx().commit(); person = this.sqlgGraph.traversal().V().hasLabel("Person").toList().get(0); Assert.assertTrue(person.property("country").isPresent()); Assert.assertEquals("moon", person.value("country")); }
Example 17
Source File: IoTest.java From tinkerpop with Apache License 2.0 | 4 votes |
/** * This is just a serialization check for JSON. */ @Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = FEATURE_ANY_IDS) public void shouldProperlySerializeCustomIdWithGraphSON() throws Exception { final UUID id = UUID.fromString("AF4B5965-B176-4552-B3C1-FBBE2F52C305"); graph.addVertex(T.id, new CustomId("vertex", id)); final SimpleModule module = new SimpleModule(); module.addSerializer(CustomId.class, new CustomId.CustomIdJacksonSerializerV1d0()); final GraphWriter writer = graph.io(graphson).writer().mapper( graph.io(graphson).mapper().version(GraphSONVersion.V1_0).addCustomModule(module).typeInfo(TypeInfo.PARTIAL_TYPES).create()).create(); try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { writer.writeGraph(baos, graph); final JsonNode jsonGraph = new ObjectMapper().readTree(baos.toByteArray()); final JsonNode idValue = jsonGraph.get(GraphSONTokens.ID); assertTrue(idValue.has("cluster")); assertEquals("vertex", idValue.get("cluster").asText()); assertTrue(idValue.has("elementId")); assertEquals("AF4B5965-B176-4552-B3C1-FBBE2F52C305".toLowerCase(), idValue.get("elementId").get(1).asText()); // reusing the same config used for creation of "g". final Configuration configuration = graphProvider.newGraphConfiguration("g2", this.getClass(), name.getMethodName(), null); graphProvider.clear(configuration); final Graph g2 = graphProvider.openTestGraph(configuration); try (final InputStream is = new ByteArrayInputStream(baos.toByteArray())) { final GraphReader reader = graph.io(graphson).reader() .mapper(graph.io(graphson).mapper().version(GraphSONVersion.V1_0).typeInfo(TypeInfo.PARTIAL_TYPES).addCustomModule(module).create()).create(); reader.readGraph(is, g2); } final Vertex v2 = g2.vertices().next(); final CustomId customId = (CustomId) v2.id(); assertEquals(id, customId.getElementId()); assertEquals("vertex", customId.getCluster()); // need to manually close the "g2" instance graphProvider.clear(g2, configuration); } }
Example 18
Source File: BitsyMemGraphIT.java From bitsy with Apache License 2.0 | 4 votes |
public void testObsolescence() { IGraphStore store = ((BitsyGraph)graph).getStore(); // Create a vertex Vertex v = graph.addVertex(); Object vid = v.id(); v.property("foo", "bar"); // Self edge Edge e = v.addEdge("self", v); Object eid = e.id(); graph.tx().commit(); Record v1MRec = new Record(RecordType.V, "{\"id\":\"" + vid + "\",\"v\":1,\"s\":\"M\"}"); assertFalse(v1MRec.checkObsolete(store, false, 1, null)); assertFalse(v1MRec.checkObsolete(store, true, 1, null)); Record e1MRec = new Record(RecordType.E, "{\"id\":\"" + eid + "\",\"v\":1,\"s\":\"M\",\"o\":\"" + vid + "\",\"l\":\"" + vid + "\",\"i\":\"" + vid + "\"}"); assertFalse(e1MRec.checkObsolete(store, false, 1, null)); assertFalse(e1MRec.checkObsolete(store, true, 1, null)); // Create a vertex v = graph.vertices(vid).next(); v.property("foo", "baz"); e = v.edges(Direction.IN, "self").next(); e.property("foo", "baz"); graph.tx().commit(); Record v2MRec = new Record(RecordType.V, "{\"id\":\"" + vid + "\",\"v\":2,\"s\":\"M\"}"); Record v1DRec = new Record(RecordType.V, "{\"id\":\"" + vid + "\",\"v\":1,\"s\":\"D\"}"); assertTrue(v1MRec.checkObsolete(store, false, 1, null)); assertTrue(v1MRec.checkObsolete(store, true, 1, null)); assertFalse(v1DRec.checkObsolete(store, false, 1, null)); assertTrue(v1DRec.checkObsolete(store, true, 1, null)); assertFalse(v2MRec.checkObsolete(store, false, 1, null)); assertFalse(v2MRec.checkObsolete(store, true, 1, null)); Record e2MRec = new Record(RecordType.E, "{\"id\":\"" + eid + "\",\"v\":2,\"s\":\"M\",\"o\":\"" + vid + "\",\"l\":\"" + vid + "\",\"i\":\"" + vid + "\"}"); Record e1DRec = new Record(RecordType.E, "{\"id\":\"" + eid + "\",\"v\":1,\"s\":\"D\",\"o\":\"" + vid + "\",\"l\":\"" + vid + "\",\"i\":\"" + vid + "\"}"); assertTrue(e1MRec.checkObsolete(store, false, 1, null)); assertTrue(e1MRec.checkObsolete(store, true, 1, null)); assertFalse(e1DRec.checkObsolete(store, false, 1, null)); assertTrue(e1DRec.checkObsolete(store, true, 1, null)); assertFalse(e2MRec.checkObsolete(store, false, 1, null)); assertFalse(e2MRec.checkObsolete(store, true, 1, null)); // Delete vertex v = graph.vertices(vid).next(); v.remove(); // Edge will get deleted automatically! graph.tx().commit(); Record v2DRec = new Record(RecordType.V, "{\"id\":\"" + vid + "\",\"v\":1,\"s\":\"D\"}"); assertFalse(v2DRec.checkObsolete(store, false, 1, null)); assertTrue(v2DRec.checkObsolete(store, true, 1, null)); }
Example 19
Source File: BitsyGraphIT.java From bitsy with Apache License 2.0 | 4 votes |
public void testLargeDegreePerformance() { long ts = System.currentTimeMillis(); Vertex one = graph.addVertex(); one.property("one", "1"); Object oneId = one.id(); int numVertices = 10000; // 1000000; Object[] vids = new Object[numVertices]; for (int i = 0; i < numVertices; i++) { // Change to 1M for perf Vertex many = graph.addVertex(); many.property("many", "2"); addEdge(graph, one, many, "toMany"); vids[i] = many.id(); if (i % 1000 == 0) { System.out.println(i + " 1000 in " + (System.currentTimeMillis() - ts)); ts = System.currentTimeMillis(); graph.tx().commit(); one = graph.vertices(oneId).next(); } } for (int i=0; i < numVertices; i++) { Vertex v = getVertex(graph, vids[i]); Iterator<Edge> iter = v.edges(Direction.BOTH); assertTrue(iter.hasNext()); iter.next(); assertFalse(iter.hasNext()); v.remove(); if (i % 1000 == 0) { System.out.println(i + " 1000 in " + (System.currentTimeMillis() - ts)); if (i % 5000 == 0) { Iterator<Edge> iter2 = getVertex(graph, one.id()).edges(Direction.BOTH); for (int j=0; j < numVertices - i - 1; j++) { assertTrue(iter2.hasNext()); iter2.next(); } assertFalse(iter.hasNext()); } ts = System.currentTimeMillis(); graph.tx().commit(); } } graph.tx().commit(); }
Example 20
Source File: HugeTarget.java From hugegraph with Apache License 2.0 | 4 votes |
public static HugeTarget fromVertex(Vertex vertex) { HugeTarget target = new HugeTarget((Id) vertex.id()); return fromVertex(vertex, target); }