/** * Creates a new vertex label with the default settings against the provided {@link VertexLabelMaker}. * * @param factory VertexLabelMaker through which the vertex label is created * @return A new vertex label * @throws IllegalArgumentException if the name is already in use or if other configured values are invalid. */ public default VertexLabel makeVertexLabel(VertexLabelMaker factory) { return factory.make(); }
@Test(expected = IllegalArgumentException.class) public void testSettingTTLOnNonStaticVertexLabel() throws Exception { if (!features.hasCellTTL()) { throw new IllegalArgumentException(); } VertexLabel label1 = mgmt.makeVertexLabel("event").make(); mgmt.setTTL(label1, Duration.ofSeconds(42)); }
@Test public void testGettingUndefinedVertexLabelTTL() { if (!features.hasCellTTL()) { return; } // getTTL should return a null duration on an extant type without a TTL mgmt.makeVertexLabel("foo").make(); mgmt.commit(); graph.tx().rollback(); // Check getTTL on vertex label mgmt = graph.openManagement(); assertEquals(Duration.ZERO, mgmt.getTTL(mgmt.getVertexLabel("foo"))); mgmt.rollback(); }
VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make(); mgmt.setTTL(label1, Duration.ofSeconds(ttl1)); assertEquals(Duration.ofSeconds(ttl1), mgmt.getTTL(label1));
private int setupGroupClusters(int[] groupDegrees, CommitMode commitMode) { mgmt.makeVertexLabel("person").make(); mgmt.makeVertexLabel("group").partition().make(); makeVertexIndexedKey("groupid", String.class); makeKey("name", String.class); makeKey("clusterId",String.class); makeLabel("member"); makeLabel("contain"); finishSchema(); int numVertices = 0; TitanVertex[] groups = new TitanVertex[groupDegrees.length]; for (int i = 0; i < groupDegrees.length; i++) { groups[i]=tx.addVertex("group"); groups[i].property("groupid","group"+i); numVertices++; if (commitMode==CommitMode.PER_VERTEX) newTx(); for (int noEdges = 0; noEdges < groupDegrees[i]; noEdges++) { TitanVertex g = vInTx(groups[i],tx); TitanVertex p = tx.addVertex("name","person"+i+":"+noEdges,"clusterId","group"+i); numVertices++; p.addEdge("member",g); g.addEdge("contain", p); if (commitMode==CommitMode.PER_VERTEX) newTx(); } if (commitMode==CommitMode.PER_CLUSTER) newTx(); } newTx(); return numVertices; }
@Test public void testVLabelOnOrderedStorage() { final String label = "pl"; mgmt.makeVertexLabel(label).partition().make(); mgmt.commit(); graph.tx().rollback(); graph.addVertex(label); graph.tx().commit(); mgmt = graph.openManagement(); VertexLabel vl = mgmt.getVertexLabel(label); assertTrue(vl.isPartitioned()); mgmt.rollback(); }
@Test public void testPartitionedVertexScan() throws Exception { tearDown(); clearGraph(getConfiguration()); WriteConfiguration partConf = getConfiguration(); open(partConf); mgmt.makeVertexLabel("part").partition().make(); finishSchema(); TitanVertex supernode = graph.addVertex("part"); for (int i = 0; i < 128; i++) { TitanVertex v = graph.addVertex("part"); v.addEdge("default", supernode); if (0 < i && 0 == i % 4) graph.tx().commit(); } graph.tx().commit(); org.apache.hadoop.conf.Configuration c = new org.apache.hadoop.conf.Configuration(); c.set(ConfigElement.getPath(TitanHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + "storage.cassandra.keyspace", getClass().getSimpleName()); c.set(ConfigElement.getPath(TitanHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + "storage.backend", "cassandrathrift"); c.set("cassandra.input.partitioner.class", "org.apache.cassandra.dht.Murmur3Partitioner"); Job job = getVertexJobWithDefaultMapper(c); // Should throw an exception since filter-partitioned-vertices wasn't enabled assertFalse(job.waitForCompletion(true)); }
@Test public void testPartitionedVertexFilteredScan() throws Exception { tearDown(); clearGraph(getConfiguration()); WriteConfiguration partConf = getConfiguration(); open(partConf); mgmt.makeVertexLabel("part").partition().make(); finishSchema(); TitanVertex supernode = graph.addVertex("part"); for (int i = 0; i < 128; i++) { TitanVertex v = graph.addVertex("part"); v.addEdge("default", supernode); if (0 < i && 0 == i % 4) graph.tx().commit(); } graph.tx().commit(); org.apache.hadoop.conf.Configuration c = new org.apache.hadoop.conf.Configuration(); c.set(ConfigElement.getPath(TitanHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + "storage.cassandra.keyspace", getClass().getSimpleName()); c.set(ConfigElement.getPath(TitanHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + "storage.backend", "cassandrathrift"); c.set(ConfigElement.getPath(TitanHadoopConfiguration.FILTER_PARTITIONED_VERTICES), "true"); c.set("cassandra.input.partitioner.class", "org.apache.cassandra.dht.Murmur3Partitioner"); Job job = getVertexJobWithDefaultMapper(c); // Should succeed assertTrue(job.waitForCompletion(true)); }
@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()); } }
@Test public void testVertexTTLWithCompositeIndex() throws Exception { if (!features.hasCellTTL()) { return; } PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make(); PropertyKey time = mgmt.makePropertyKey("time").dataType(Long.class).make(); TitanGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name).buildCompositeIndex(); TitanGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).addKey(name).addKey(time).buildCompositeIndex(); VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make(); mgmt.setTTL(label1, Duration.ofSeconds(1)); assertEquals(Duration.ZERO, mgmt.getTTL(name)); assertEquals(Duration.ZERO, mgmt.getTTL(time)); assertEquals(Duration.ofSeconds(1), mgmt.getTTL(label1)); mgmt.commit(); TitanVertex v1 = tx.addVertex(T.label, "event", "name", "some event", "time", System.currentTimeMillis()); tx.commit(); Object id = v1.id(); v1 = getV(graph, id); assertNotNull(v1); assertNotEmpty(graph.query().has("name", "some event").vertices()); Thread.sleep(1001); graph.tx().rollback(); v1 = getV(graph, id); assertNull(v1); assertEmpty(graph.query().has("name", "some event").vertices()); }
TitanGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name).buildCompositeIndex(); TitanGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).addKey(name).addKey(place).buildCompositeIndex(); VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make(); mgmt.setTTL(label1, Duration.ofSeconds(2)); assertEquals(Duration.ofSeconds(42), mgmt.getTTL(name));
PropertyKey text = makeKey("text", String.class); VertexLabel event = mgmt.makeVertexLabel("event").setStatic().make(); final int eventTTLSeconds = (int) TestGraphConfigs.getTTL(TimeUnit.SECONDS); mgmt.setTTL(event, Duration.ofSeconds(eventTTLSeconds));
private void createIndices(final TitanGraph g, final LoadGraphWith.GraphData graphData) { TitanManagement mgmt = g.openManagement(); if (graphData.equals(LoadGraphWith.GraphData.GRATEFUL)) { VertexLabel artist = mgmt.makeVertexLabel("artist").make(); VertexLabel song = mgmt.makeVertexLabel("song").make(); VertexLabel person = mgmt.makeVertexLabel("person").make(); VertexLabel software = mgmt.makeVertexLabel("software").make();
mgmt.setTTL(dislikes, Duration.ofSeconds(1)); EdgeLabel indifferentTo = mgmt.makeEdgeLabel("indifferentTo").make(); VertexLabel label1 = mgmt.makeVertexLabel("person").setStatic().make(); mgmt.setTTL(label1, Duration.ofSeconds(2)); assertEquals(Duration.ofSeconds(42), mgmt.getTTL(likes));
tx.makePropertyKey("name").dataType(String.class).make(); tx.makeEdgeLabel("knows").make(); tx.makeVertexLabel("person").make(); tx.commit(); verifyStoreMetrics(EDGESTORE_NAME);
mgmt.buildEdgeIndex(knows, "byTime", Direction.BOTH, time); mgmt.buildIndex("timeIndex", Vertex.class).addKey(time).buildCompositeIndex(); mgmt.makeVertexLabel("people").make(); finishSchema();