/** * Insert an extremely simple graph and start * TASK_COUNT simultaneous readers in an executor with * THREAD_COUNT threads. * * @throws Exception */ @Test public void concurrentReadsOnSingleTransaction() throws Exception { initializeGraph(); PropertyKey id = tx.getPropertyKey("uid"); // Tail many concurrent readers on a single transaction CountDownLatch startLatch = new CountDownLatch(TASK_COUNT); CountDownLatch stopLatch = new CountDownLatch(TASK_COUNT); for (int i = 0; i < TASK_COUNT; i++) { int vertexid = RandomGenerator.randomInt(0, VERTEX_COUNT); EdgeLabel elabel = tx.getEdgeLabel("rel" + RandomGenerator.randomInt(0, REL_COUNT)); executor.execute(new SimpleReader(tx, startLatch, stopLatch, vertexid, elabel.name(), EDGE_COUNT * 2, id.name())); startLatch.countDown(); } stopLatch.await(); }
public static boolean validTitanOrder(OrderGlobalStep ostep, Traversal rootTraversal, boolean isVertexOrder) { for (Comparator comp : (List<Comparator>) ostep.getComparators()) { if (!(comp instanceof ElementValueComparator)) return false; ElementValueComparator evc = (ElementValueComparator) comp; if (!(evc.getValueComparator() instanceof Order)) return false; TitanTransaction tx = TitanTraversalUtil.getTx(rootTraversal.asAdmin()); String key = evc.getPropertyKey(); PropertyKey pkey = tx.getPropertyKey(key); if (pkey == null || !(Comparable.class.isAssignableFrom(pkey.dataType()))) return false; if (isVertexOrder && pkey.cardinality() != Cardinality.SINGLE) return false; } return true; }
finishSchema(); PropertyKey id = tx.getPropertyKey("uid"); Runnable propMaker = new RandomPropertyMaker(tx, VERTEX_COUNT, id.name(), "dummyProperty"); Runnable relMaker = new FixedRelationshipMaker(tx, id.name(), "dummyRelationship");
assertTrue(tx.containsRelationType("weight")); EdgeLabel knows = tx.getEdgeLabel("knows"); PropertyKey weight = tx.getPropertyKey("weight");
/** * 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.property(uid.name(), "abcd"); clopen(); long nid = n1.longId(); uid = tx.getPropertyKey("name"); assertTrue(getV(tx, nid) != null); assertTrue(getV(tx, uid.longId()) != null); assertMissing(tx, nid + 64); uid = tx.getPropertyKey(uid.name()); n1 = getV(tx, nid); assertEquals(n1, getOnlyVertex(tx.query().has(uid.name(), "abcd"))); assertEquals(1, Iterables.size(n1.query().relations())); //TODO: how to expose relations? assertEquals("abcd", n1.value(uid.name())); assertCount(1, tx.query().vertices()); close(); TitanCleanup.clear(graph); open(config); assertEmpty(tx.query().vertices()); }
clopen(); boolval = tx.getPropertyKey("boolval"); num = tx.getPropertyKey("num"); barr = tx.getPropertyKey("barr"); birthday = tx.getPropertyKey("birthday"); geo = tx.getPropertyKey("geo"); precise = tx.getPropertyKey("precise"); any = tx.getPropertyKey("any");
ElementCategory.VERTEX, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC, "index1"); evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "event"), ElementCategory.VERTEX, 1, new boolean[]{true, true}, "index2"); ElementCategory.VERTEX, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC, "index1"); evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "event"), ElementCategory.VERTEX, 1, new boolean[]{true, true}, "index2"); ElementCategory.VERTEX, 0, new boolean[]{true, true}, "index2"); evaluateQuery(tx.query().has("name", "first event").orderBy("time", decr), ElementCategory.VERTEX, 0, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC, "index1");
assertTrue(tx.containsRelationType("knows")); assertTrue(tx.containsVertexLabel("person")); PropertyKey name = tx.getPropertyKey("name"); EdgeLabel knows = tx.getEdgeLabel("knows"); VertexLabel person = tx.getVertexLabel("person"); PropertyKey uid = tx.getPropertyKey("uid");
PROPERTY, 4, 1, new boolean[]{false, false}, tx.getPropertyKey("time"), Order.DESC); evaluateQuery(v.query().keys("sensor").interval("time", 101, 105).orderBy("time", decr), PROPERTY, 0, 1, new boolean[]{false, false}, tx.getPropertyKey("time"), Order.DESC); evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 1, 5).orderBy("time", decr), EDGE, 4, 1, new boolean[]{false, false}, tx.getPropertyKey("time"), Order.DESC); evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 101, 105).orderBy("time", decr), EDGE, 0, 1, new boolean[]{false, false}, tx.getPropertyKey("time"), Order.DESC); evaluateQuery(tx.query().has("name", "v5"), ElementCategory.VERTEX, 1, new boolean[]{false, true}); PROPERTY, 4, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC); evaluateQuery(v.query().keys("sensor").interval("time", 101, 105).orderBy("time", decr), PROPERTY, 4, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC); evaluateQuery(v.query().keys("sensor").interval("time", 201, 205).orderBy("time", decr), PROPERTY, 4, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC); evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 1, 5).orderBy("time", decr), EDGE, 0, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC); evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 101, 105).orderBy("time", decr), EDGE, 4, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC); evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 201, 205).orderBy("time", decr), EDGE, 4, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC); evaluateQuery(tx.query().has("name", "v5"), ElementCategory.VERTEX, 1, new boolean[]{true, true}, "bySensorReading"); EDGE, 4, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC); evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 101, 105).orderBy("time", decr), EDGE, 4, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC); evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 201, 205).orderBy("time", decr), EDGE, 4, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC);
ElementCategory.EDGE, 1, new boolean[]{true, true}, "index2"); evaluateQuery(tx.query().has("name", "v2 likes v3").orderBy("time", decr), ElementCategory.EDGE, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC, "index1"); v1 = getV(tx, v1.id()); v2 = getV(tx, v2.id()); ElementCategory.EDGE, 0, new boolean[]{true, true}, "index2"); evaluateQuery(tx.query().has("name", "v2 likes v3").orderBy("time", decr), ElementCategory.EDGE, 0, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC, "index1");
assertFalse(tx.containsVertexLabel("person")); assertFalse(tx.containsRelationType("value")); assertNull(tx.getPropertyKey("value")); PropertyKey value = tx.getOrCreatePropertyKey("value"); assertNotNull(value);
finishSchema(); name = tx.getPropertyKey("name"); connect = tx.getEdgeLabel("connect"); related = tx.getEdgeLabel("related");
weight = tx.getPropertyKey("weight"); weight = tx.getPropertyKey("weight");
weight = tx.getPropertyKey("weight"); time = tx.getPropertyKey("time"); weight = tx.getPropertyKey("weight"); time = tx.getPropertyKey("time"); weight = tx.getPropertyKey("weight"); time = tx.getPropertyKey("time");
TitanTransaction tt = TitanGraph.newTransaction(); PropertyKey userNameKey = tt.getPropertyKey("userName"); TitanVertex v = tt.getVertex(someUserVertexId); String userName = v.valueOrNull(userNameKey);
/** * Insert an extremely simple graph and start * TASK_COUNT simultaneous readers in an executor with * THREAD_COUNT threads. * * @throws Exception */ @Test public void concurrentReadsOnSingleTransaction() throws Exception { TitanKey id = tx.getPropertyKey("uid"); // Tail many concurrent readers on a single transaction CountDownLatch startLatch = new CountDownLatch(TASK_COUNT); CountDownLatch stopLatch = new CountDownLatch(TASK_COUNT); for (int i = 0; i < TASK_COUNT; i++) { int nodeid = RandomGenerator.randomInt(0, NODE_COUNT); TitanLabel rel = tx.getEdgeLabel("rel" + RandomGenerator.randomInt(0, REL_COUNT)); executor.execute(new SimpleReader(tx, startLatch, stopLatch, nodeid, rel, EDGE_COUNT * 2, id)); startLatch.countDown(); } stopLatch.await(); }
/** * Insert an extremely simple graph and start * TASK_COUNT simultaneous readers in an executor with * THREAD_COUNT threads. * * @throws Exception */ @Test public void concurrentReadsOnSingleTransaction() throws Exception { initializeGraph(); PropertyKey id = tx.getPropertyKey("uid"); // Tail many concurrent readers on a single transaction CountDownLatch startLatch = new CountDownLatch(TASK_COUNT); CountDownLatch stopLatch = new CountDownLatch(TASK_COUNT); for (int i = 0; i < TASK_COUNT; i++) { int nodeid = RandomGenerator.randomInt(0, NODE_COUNT); EdgeLabel rel = tx.getEdgeLabel("rel" + RandomGenerator.randomInt(0, REL_COUNT)); executor.execute(new SimpleReader(tx, startLatch, stopLatch, nodeid, rel, EDGE_COUNT * 2, id)); startLatch.countDown(); } stopLatch.await(); }
public static boolean validTitanOrder(OrderGlobalStep ostep, Traversal rootTraversal, boolean isVertexOrder) { for (Comparator comp : (List<Comparator>) ostep.getComparators()) { if (!(comp instanceof ElementValueComparator)) return false; ElementValueComparator evc = (ElementValueComparator) comp; if (!(evc.getValueComparator() instanceof Order)) return false; TitanTransaction tx = TitanTraversalUtil.getTx(rootTraversal.asAdmin()); String key = evc.getPropertyKey(); PropertyKey pkey = tx.getPropertyKey(key); if (pkey == null || !(Comparable.class.isAssignableFrom(pkey.dataType()))) return false; if (isVertexOrder && pkey.cardinality() != Cardinality.SINGLE) return false; } return true; }
public void makeTypes(TitanGraph g) { Preconditions.checkArgument(edgeLabels <= edgePropKeys); TitanTransaction tx = g.newTransaction(); for (int i = 0; i < vertexPropKeys; i++) { tx.makeKey(getVertexPropertyName(i)).dataType(Integer.class).indexed(Vertex.class).single().make(); } for (int i = 0; i < edgePropKeys; i++) { tx.makeKey(getEdgePropertyName(i)).dataType(Integer.class).indexed(Edge.class).single().make(); } for (int i = 0; i < edgeLabels; i++) { String labelName = getEdgeLabelName(i); String pkName = getSortKeyForLabel(labelName); TitanKey pk = tx.getPropertyKey(pkName); tx.makeLabel(getEdgeLabelName(i)).sortKey(pk).make(); } tx.makeKey(UID_PROP).dataType(Long.class).indexed(Vertex.class).single().unique().make(); tx.commit(); }
@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)); }