@Override public <V> TitanVertexProperty<V> property(final VertexProperty.Cardinality cardinality, final String key, final V value, final Object... keyValues);
@Override public void run(TitanTransaction tx) { TitanVertex v1 = tx.addVertex("person"); v1.property(VertexProperty.Cardinality.single, "time", 1); } });
@Override public void run(TitanTransaction tx) { TitanVertex u = getV(tx, vids[0]); u.property(VertexProperty.Cardinality.single, "name", "v" + random.nextInt(10)); } });
@Override public void run(TitanTransaction tx) { TitanVertex u = getV(tx, vids[pos++]); u.property(VertexProperty.Cardinality.single, "uid", 5); } });
/** * This is essentially an adjusted copy&paste from TinkerPop's ElementHelper class. * The reason for copying it is so that we can determine the cardinality of a property key based on * Titan's schema which is tied to this particular transaction and not the graph. * * @param vertex * @param propertyKeyValues */ public static void attachProperties(final TitanVertex vertex, final Object... propertyKeyValues) { if (null == vertex) throw Graph.Exceptions.argumentCanNotBeNull("vertex"); for (int i = 0; i < propertyKeyValues.length; i = i + 2) { if (!propertyKeyValues[i].equals(T.id) && !propertyKeyValues[i].equals(T.label)) vertex.property((String) propertyKeyValues[i], propertyKeyValues[i + 1]); } }
@Override public void run() { for (int i=0;i<numV;i++) { try { TitanVertex v = getV(graph,vids[i]); v.property(VertexProperty.Cardinality.single, prop, 1); precommit[i].set(true); graph.tx().commit(); postcommit[i].set(true); Thread.sleep(updateSleepTime); } catch (InterruptedException e) { throw new RuntimeException("Unexpected interruption",e); } } } });
@Override public void run() { for (int r = 0; r < rounds; r++) { TitanTransaction tx = graph.newTransaction(); TitanVertex previous = null; for (int c = 0; c < commitSize; c++) { TitanVertex v = tx.addVertex(); long uid = uidCounter.incrementAndGet(); v.property(VertexProperty.Cardinality.single, "uid", uid); v.property(VertexProperty.Cardinality.single, "name", "user" + uid); if (previous != null) { v.addEdge("friend", previous, "time", Math.abs(random.nextInt())); } previous = v; } tx.commit(); } } });
@Override public void run() { while (run.get()) { TitanTransaction tx = graph.newTransaction(); try { for (int i = 0; i < batchV; i++) { TitanVertex v = tx.addVertex(); v.property("k", random.nextInt(maxK)); v.property("q", random.nextInt(maxQ)); } tx.commit(); } catch (Throwable e) { e.printStackTrace(); } finally { if (tx.isOpen()) tx.rollback(); } } } });
@Override public void run() { TitanTransaction tx = graph.newTransaction(); TitanVertex[] vs = new TitanVertex[verticesPerTask]; for (int j=0;j<verticesPerTask;j++) { vs[j]=tx.addVertex(); vs[j].property(VertexProperty.Cardinality.single, "w", random.nextInt(maxWeight)); } for (int j=0;j<verticesPerTask*10;j++) { TitanEdge e = vs[random.nextInt(verticesPerTask)].addEdge("l",vs[random.nextInt(verticesPerTask)]); e.property("t",random.nextInt(maxTime)); } System.out.print("."); tx.commit(); } });
private void addVertex(int time, String text, double height, String[] phones) { newTx(); TitanVertex v = tx.addVertex("text", text, "time", time, "height", height); for (String phone : phones) { v.property("phone", phone); } newTx(); }
@Override public void run() { while (true) { // Set propType to a random value on a random node TitanVertex n = getOnlyVertex(tx.query().has(idKey, RandomGenerator.randomInt(0, nodeCount))); String propVal = RandomGenerator.randomString(); n.property(randomKey, propVal); if (Thread.interrupted()) break; // Is creating the same property twice an error? } } }
@Test public void testIndexQueryWithScore() throws InterruptedException { PropertyKey textKey = mgmt.makePropertyKey("text").dataType(String.class).make(); mgmt.buildIndex("store1", Vertex.class).addKey(textKey).buildMixedIndex(INDEX); mgmt.commit(); TitanVertex v1 = tx.addVertex(); TitanVertex v2 = tx.addVertex(); TitanVertex v3 = tx.addVertex(); v1.property("text", "Hello Hello Hello Hello Hello Hello Hello Hello"); v2.property("text", "Hello abab abab fsdfsd sfdfsd sdffs fsdsdf fdf fsdfsd aera fsad abab abab fsdfsd sfdf"); v3.property("text", "Hello"); tx.commit(); Thread.sleep(5000); Set<Double> scores = new HashSet<Double>(); for (TitanIndexQuery.Result<TitanVertex> r : graph.indexQuery("store1", "v.text:(Hello)").vertices()) { scores.add(r.getScore()); } Assert.assertEquals(3, scores.size()); }
@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"); }
/** * Tests indexing using _all virtual field */ @Test public void testWidcardQuery() { if (supportsWildcardQuery()) { PropertyKey p1 = makeKey("p1", String.class); PropertyKey p2 = makeKey("p2", String.class); mgmt.buildIndex("mixedIndex", Vertex.class).addKey(p1).addKey(p2).buildMixedIndex(INDEX); finishSchema(); clopen(); TitanVertex v1 = graph.addVertex(); v1.property("p1", "test1"); v1.property("p2", "test2"); clopen();//Flush the index assertEquals(v1, graph.indexQuery("mixedIndex", "v.*:\"test1\"").vertices().iterator().next().getElement()); assertEquals(v1, graph.indexQuery("mixedIndex", "v.*:\"test2\"").vertices().iterator().next().getElement()); } }
@Test public void testArrayEqualityUsingImplicitKey() { TitanVertex v = graph.addVertex(); byte singleDimension[] = new byte[]{127, 0, 0, 1}; byte singleDimensionCopy[] = new byte[]{127, 0, 0, 1}; final String singlePropName = "single"; v.property(singlePropName, singleDimension); assertEquals(1, Iterables.size(graph.query().has(singlePropName, singleDimension).vertices())); assertEquals(1, Iterables.size(graph.query().has(singlePropName, singleDimensionCopy).vertices())); graph.tx().commit(); assertEquals(1, Iterables.size(graph.query().has(singlePropName, singleDimension).vertices())); assertEquals(1, Iterables.size(graph.query().has(singlePropName, singleDimensionCopy).vertices())); }
@Test public void concurrentIndexTest() { makeVertexIndexedUniqueKey("uid", String.class); makeVertexIndexedKey("value", Object.class); finishSchema(); TitanVertex v = tx.addVertex("uid", "v"); clopen(); //Concurrent index addition TitanTransaction tx1 = graph.newTransaction(); TitanTransaction tx2 = graph.newTransaction(); getVertex(tx1, "uid", "v").property(VertexProperty.Cardinality.single, "value", 11); getVertex(tx2, "uid", "v").property(VertexProperty.Cardinality.single, "value", 11); tx1.commit(); tx2.commit(); assertEquals("v", Iterators.<String>getOnlyElement(Iterables.<TitanVertex>getOnlyElement(tx.query().has("value", 11).vertices()).values("uid"))); }
@Override public void run() { TitanTransaction tx = graph.newTransaction(); long ruid = random.nextInt(maxUID) + 1; getVertex(tx,"uid", ruid).property(VertexProperty.Cardinality.single, "name", fixedName); for (int t = 1; t <= trials; t++) { TitanVertex v = getVertex(tx,"uid", random.nextInt(maxUID) + 1); assertCount(2, v.properties()); int count = 0; for (TitanEdge e : v.query().direction(Direction.BOTH).edges()) { count++; assertTrue(e.<Integer>value("time") >= 0); } assertTrue(count <= 2); // if (t%(trials/10)==0) System.out.println(t); } assertEquals(fixedName, getVertex(tx,"uid", ruid).value("name")); tx.commit(); } });
@Test public void testIndexQueryWithLabelsAndContainsIN() { // This test is based on the steps to reproduce #882 String labelName = "labelName"; VertexLabel label = mgmt.makeVertexLabel(labelName).make(); PropertyKey uid = mgmt.makePropertyKey("uid").dataType(String.class).make(); TitanGraphIndex uidCompositeIndex = mgmt.buildIndex("uidIndex", Vertex.class).indexOnly(label).addKey(uid).unique().buildCompositeIndex(); mgmt.setConsistency(uidCompositeIndex, ConsistencyModifier.LOCK); finishSchema(); TitanVertex foo = graph.addVertex(labelName); TitanVertex bar = graph.addVertex(labelName); foo.property("uid", "foo"); bar.property("uid", "bar"); graph.tx().commit(); Iterable<TitanVertex> vertexes = graph.query() .has("uid", Contain.IN, ImmutableList.of("foo", "bar")) .has(LABEL_NAME, labelName) .vertices(); assertEquals(2, Iterables.size(vertexes)); for (TitanVertex v : vertexes) { assertEquals(labelName, v.vertexLabel().name()); } }
@Override public void process(TitanVertex vertex, ScanMetrics metrics) { long outDegree = vertex.query().labels("knows").direction(Direction.OUT).edgeCount(); assertEquals(0, vertex.query().labels("knows").direction(Direction.IN).edgeCount()); assertEquals(1, vertex.query().labels("uid").propertyCount()); assertTrue(vertex.<Integer>property("uid").orElse(0) > 0); metrics.incrementCustom(DEGREE_COUNT,outDegree); metrics.incrementCustom(VERTEX_COUNT); }