@Override public PageRank process(TitanVertex vertex) { PageRank pr = vertex.<PageRank>getProperty("pageRank"); Double energy = vertex.getProperty("energy"); if (energy==null) energy=0.0; pr.setPr(energy, alpha, numVertices); return pr; } });
@Override public Integer process(TitanVertex vertex) { Integer d = vertex.getProperty("dist"); assertNotNull(d); Integer c = vertex.getProperty("connect"); int result = c==null?d:Math.min(c,d); if (result<d) done.set(false); return result; } });
@Override public Degree process(TitanVertex vertex) { Degree d = vertex.getProperty("all"); if (d==null) d = new Degree(); Degree p = vertex.getProperty(aggregatePropKey); if (checkPropKey!=null) assertNotNull(vertex.getProperty(checkPropKey)); if (p!=null) d.add(p); return d; } });
@Override public PageRank process(TitanVertex vertex) { Long degree = vertex.<Long>getProperty("degree"); return new PageRank(degree==null?0:degree,1.0d/numVertices); } });
@Override public void run() { int reads = 0; while (reads<numReads) { final int pos = random.nextInt(vids.length); long vid = vids[pos]; TitanVertex v = graph.getVertex(vid); assertNotNull(v); boolean postCommit = postcommit[pos].get(); Integer value = v.getProperty(prop); lookups.incrementAndGet(); assertNotNull("On pos [" + pos + "]", value); if (!precommit[pos].get()) assertEquals(0, value.intValue()); else if (postCommit) assertEquals(1, value.intValue()); graph.commit(); try { Thread.sleep(readSleepTime); } catch (InterruptedException e) { return; } reads++; } } });
@Override public void run() { int reads = 0; while (reads<numReads) { final int pos = random.nextInt(vids.length); long vid = vids[pos]; TitanVertex v = graph.getVertex(vid); assertNotNull(v); boolean postCommit = postcommit[pos].get(); Integer value = v.getProperty(prop); lookups.incrementAndGet(); assertNotNull("On pos ["+pos+"]",value); if (!precommit[pos].get()) assertEquals(0,value.intValue()); else if (postCommit) assertEquals(1,value.intValue()); graph.commit(); try { Thread.sleep(readSleepTime); } catch (InterruptedException e) { return; } reads++; } } });
@Override public void run() { TitanTransaction tx = graph.newTransaction(); long ruid = random.nextInt(maxUID) + 1; tx.getVertex("uid", ruid).setProperty("name", fixedName); for (int t = 1; t <= trials; t++) { TitanVertex v = tx.getVertex("uid", random.nextInt(maxUID) + 1); assertEquals(2, Iterables.size(v.getProperties())); int count = 0; for (TitanEdge e : v.getEdges()) { count++; assertTrue(((Number) e.getProperty("time")).longValue() >= 0); } assertTrue(count <= 2); // if (t%(trials/10)==0) System.out.println(t); } assertEquals(fixedName, tx.getVertex("uid", ruid).getProperty("name")); tx.commit(); } });
@Override public void run() { TitanTransaction tx = graph.newTransaction(); long ruid = random.nextInt(maxUID) + 1; getVertex(tx,"uid", ruid).setProperty("name", fixedName); for (int t = 1; t <= trials; t++) { TitanVertex v = getVertex(tx,"uid", random.nextInt(maxUID) + 1); assertEquals(2, Iterables.size(v.getProperties())); int count = 0; for (TitanEdge e : v.getEdges()) { count++; assertTrue(((Number) e.getProperty("time")).longValue() >= 0); } assertTrue(count <= 2); // if (t%(trials/10)==0) System.out.println(t); } assertEquals(fixedName, getVertex(tx,"uid", ruid).getProperty("name")); tx.commit(); } });
@Test public void testPropertyIndexPersistence() { final String propName = "favorite_color"; final String sharedValue = "blue"; makeStringPropertyKey(propName); TitanVertex alice = tx.addVertex(); TitanVertex bob = tx.addVertex(); alice.addProperty(propName, sharedValue); clopen(); alice = tx.getVertex(alice.getID()); bob = tx.getVertex(bob.getID()); assertEquals(sharedValue, alice.getProperty(propName)); assertEquals(null, bob.getProperty(propName)); alice.removeProperty(propName); bob.addProperty(propName, sharedValue); clopen(); }
v = tx.getVertex(v.getLongId()); v.setProperty("foo","band"); assertEquals("band", v.getProperty("foo")); assertEquals(1,Iterables.size(v.getProperties("foo"))); assertEquals(1, Iterables.size(v.getProperties()));
@Test public void testPropertyIndexPersistence() { final String propName = "favorite_color"; final String sharedValue = "blue"; tx.makePropertyKey(propName).dataType(String.class).make(); TitanVertex alice = tx.addVertex(); TitanVertex bob = tx.addVertex(); alice.addProperty(propName, sharedValue); clopen(); alice = tx.getVertex(alice.getLongId()); bob = tx.getVertex(bob.getLongId()); assertEquals(sharedValue, alice.getProperty(propName)); assertEquals(null, bob.getProperty(propName)); alice.removeProperty(propName); bob.addProperty(propName, sharedValue); clopen(); }
assertEquals(getVertex("uid", i).getProperty("name").toString().substring(4), String.valueOf(i % mod));
/** * Very simple graph operation to ensure minimal functionality and cleanup */ @Test public void testBasic() { PropertyKey uid = makeVertexIndexedUniqueKey("name",String.class); finishSchema(); TitanVertex n1 = tx.addVertex(); uid = tx.getPropertyKey("name"); n1.addProperty(uid.getName(), "abcd"); clopen(); long nid = n1.getLongId(); uid = tx.getPropertyKey("name"); assertTrue(tx.containsVertex(nid)); assertTrue(tx.containsVertex(uid.getLongId())); assertFalse(tx.containsVertex(nid + 64)); uid = tx.getPropertyKey(uid.getName()); n1 = tx.getVertex(nid); assertEquals(n1,Iterables.getOnlyElement(tx.getVertices(uid, "abcd"))); assertEquals(1, Iterables.size(n1.query().relations())); assertTrue(n1.getProperty(uid).equals("abcd")); assertEquals(1,Iterables.size(tx.getVertices())); close(); TitanCleanup.clear(graph); open(config); assertTrue(Iterables.isEmpty(tx.getVertices())); }
private void processTx(TitanTransaction tx, int txid, long vid, long uid) { TitanVertex v = tx.getVertex(vid); TitanVertex u = tx.getVertex(uid); assertEquals(5.0,v.<Decimal>getProperty("weight").doubleValue(),0.00001); TitanProperty p = Iterables.getOnlyElement(v.getProperties("weight")); assertEquals(1,p.getProperty("sig"));
assertEquals(445, n3.getProperty("uid")); e = (TitanEdge) Iterables.getOnlyElement(n3.getEdges(OUT, "knows")); assertEquals(111, e.getProperty("uid")); assertEquals(353, n3.getProperty("uid"));
assertEquals(445, n3.getProperty("uid")); e = (TitanEdge) Iterables.getOnlyElement(n3.getEdges(OUT, "knows")); assertEquals(111, e.getProperty("uid")); assertEquals(353, n3.getProperty("uid"));
@Test public void testIndexIteration() { graph.makeKey("objectType").dataType(String.class).indexed(INDEX, Vertex.class).single().make(); graph.makeKey("uid").dataType(Long.class).indexed(INDEX, Vertex.class).single().make(); graph.commit(); Vertex v = graph.addVertex(null); ElementHelper.setProperties(v, "uid", 167774517, "ipv4Addr", "10.0.9.53", "cid", 2, "objectType", "NetworkSensor", "observationDomain", 0); assertNotNull(v.getProperty("uid")); assertNotNull(v.getProperty("objectType")); graph.commit(); assertNotNull(graph.getVertex(v).getProperty("uid")); assertNotNull(graph.getVertex(v).getProperty("objectType")); graph.commit(); for (Vertex u : graph.getVertices()) { assertNotNull(u.getProperty("uid")); assertNotNull(u.getProperty("objectType")); } graph.rollback(); }
@Test public void testBasic() { TitanKey weight = makeWeightPropertyKey("weight"); TitanVertex n1 = tx.addVertex(); n1.addProperty(weight, 10.5); clopen(); long nid = n1.getID(); assertTrue(tx.containsVertex(nid)); assertTrue(tx.containsVertex(weight.getID())); assertFalse(tx.containsVertex(nid + 64)); assertFalse(tx.containsVertex(weight.getID() + 64)); assertTrue(tx.containsType("weight")); weight = tx.getPropertyKey("weight"); assertEquals(weight.getDataType(), Double.class); assertEquals(weight.getName(), "weight"); n1 = tx.getVertex(nid); for (TitanProperty prop : n1.getProperties()) { Object o = prop.getValue(); } n1.query().relations(); assertEquals(10.5, n1.getProperty(weight)); }
assertEquals(6.0,v.<Decimal>getProperty("weight").doubleValue(),0.00001); TitanProperty p = Iterables.getOnlyElement(v.getProperties("weight")); assertEquals(wintx,p.getProperty("sig"));
RelationIdentifier eid = (RelationIdentifier)e.getId(); assertEquals(v.getId(),v.getProperty("id")); assertEquals(eid,e.getProperty("id")); assertEquals("knows",e.getProperty("label")); assertEquals(BaseVertexLabel.DEFAULT_VERTEXLABEL.getName(),v.getProperty("label")); assertEquals(1,v.query().labels("knows").direction(BOTH).has("id",eid).count()); assertEquals(0,v.query().labels("knows").direction(BOTH).has("id",RelationIdentifier.get(new long[]{4,5,6,7})).count());