当前位置: 首页>>代码示例>>Java>>正文


Java TitanVertex.addEdge方法代码示例

本文整理汇总了Java中com.thinkaurelius.titan.core.TitanVertex.addEdge方法的典型用法代码示例。如果您正苦于以下问题:Java TitanVertex.addEdge方法的具体用法?Java TitanVertex.addEdge怎么用?Java TitanVertex.addEdge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.thinkaurelius.titan.core.TitanVertex的用法示例。


在下文中一共展示了TitanVertex.addEdge方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSelfLoop

import com.thinkaurelius.titan.core.TitanVertex; //导入方法依赖的package包/类
/**
 * Tests that self-loop edges are handled and counted correctly
 */
@Test
public void testSelfLoop() {
    TitanVertex v = tx.addVertex();
    v.addEdge("self", v);
    assertCount(1, v.query().direction(Direction.OUT).labels("self").edges());
    assertCount(1, v.query().direction(Direction.IN).labels("self").edges());
    assertCount(2, v.query().direction(Direction.BOTH).labels("self").edges());
    clopen();
    v = getV(tx, v);
    assertNotNull(v);
    assertCount(1, v.query().direction(Direction.IN).labels("self").edges());
    assertCount(1, v.query().direction(Direction.OUT).labels("self").edges());
    assertCount(1, v.query().direction(Direction.IN).labels("self").edges());
    assertCount(2, v.query().direction(Direction.BOTH).labels("self").edges());
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:19,代码来源:TitanGraphTest.java

示例2: testEdgesExceedCacheSize

import com.thinkaurelius.titan.core.TitanVertex; //导入方法依赖的package包/类
@Test
public void testEdgesExceedCacheSize() {
    // Add a vertex with as many edges as the tx-cache-size. (20000 by default)
    int numEdges = graph.getConfiguration().getTxVertexCacheSize();
    TitanVertex parentVertex = graph.addVertex();
    for (int i = 0; i < numEdges; i++) {
        TitanVertex childVertex = graph.addVertex();
        parentVertex.addEdge("friend", childVertex);
    }
    graph.tx().commit();
    assertCount(numEdges, parentVertex.query().direction(Direction.OUT).edges());

    // Remove an edge.
    parentVertex.query().direction(OUT).edges().iterator().next().remove();

    // Check that getEdges returns one fewer.
    assertCount(numEdges - 1, parentVertex.query().direction(Direction.OUT).edges());

    // Run the same check one more time.
    // This fails! (Expected: 19999. Actual: 20000.)
    assertCount(numEdges - 1, parentVertex.query().direction(Direction.OUT).edges());
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:23,代码来源:TitanGraphTest.java

示例3: testVertexRemoval

import com.thinkaurelius.titan.core.TitanVertex; //导入方法依赖的package包/类
/**
 * Adding a removing a vertex with index
 */
@Test
public void testVertexRemoval() {
    final String namen = "name";
    makeVertexIndexedUniqueKey(namen, String.class);
    finishSchema();

    TitanVertex v1 = graph.addVertex(namen, "v1");
    TitanVertex v2 = graph.addVertex(namen, "v2");
    v1.addEdge("knows", v2);
    assertCount(2, graph.query().vertices());
    assertCount(1, graph.query().has(namen, "v2").vertices());

    clopen();

    v1 = getV(graph, v1);
    v2 = getV(graph, v2);
    assertCount(1, v1.query().direction(BOTH).edges());
    assertCount(1, v2.query().direction(Direction.BOTH).edges());
    v2.remove();
    assertCount(0, v1.query().direction(Direction.BOTH).edges());
    try {
        assertCount(0, v2.query().direction(Direction.BOTH).edges());
        fail();
    } catch (IllegalStateException ex) {
    }
    assertCount(1, graph.query().vertices());
    assertCount(1, graph.query().has(namen, "v1").vertices());
    assertCount(0, graph.query().has(namen, "v2").vertices());
    graph.tx().commit();

    assertMissing(graph, v2);
    assertCount(1, graph.query().vertices());
    assertCount(1, graph.query().has(namen, "v1").vertices());
    assertCount(0, graph.query().has(namen, "v2").vertices());
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:39,代码来源:TitanGraphTest.java

示例4: testWithoutIndex

import com.thinkaurelius.titan.core.TitanVertex; //导入方法依赖的package包/类
@Test
public void testWithoutIndex() {
    PropertyKey kid = mgmt.makePropertyKey("kid").dataType(Long.class).make();
    mgmt.makePropertyKey("name").dataType(String.class).make();
    mgmt.makeEdgeLabel("knows").signature(kid).make();
    finishSchema();

    Random random = new Random();
    int numV = 1000;
    TitanVertex previous = null;
    for (int i = 0; i < numV; i++) {
        TitanVertex v = graph.addVertex(
                "kid", random.nextInt(numV), "name", "v" + i);
        if (previous != null) {
            Edge e = v.addEdge("knows", previous, "kid", random.nextInt(numV / 2));
        }
        previous = v;
    }

    verifyElementOrder(graph.query().orderBy("kid", incr).limit(500).vertices(), "kid", Order.ASC, 500);
    verifyElementOrder(graph.query().orderBy("kid", incr).limit(300).edges(), "kid", Order.ASC, 300);
    verifyElementOrder(graph.query().orderBy("kid", decr).limit(400).vertices(), "kid", Order.DESC, 400);
    verifyElementOrder(graph.query().orderBy("kid", decr).limit(200).edges(), "kid", Order.DESC, 200);

    clopen();

    //Copied from above
    verifyElementOrder(graph.query().orderBy("kid", incr).limit(500).vertices(), "kid", Order.ASC, 500);
    verifyElementOrder(graph.query().orderBy("kid", incr).limit(300).edges(), "kid", Order.ASC, 300);
    verifyElementOrder(graph.query().orderBy("kid", decr).limit(400).vertices(), "kid", Order.DESC, 400);
    verifyElementOrder(graph.query().orderBy("kid", decr).limit(200).edges(), "kid", Order.DESC, 200);
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:33,代码来源:TitanGraphTest.java

示例5: setupChainGraph

import com.thinkaurelius.titan.core.TitanVertex; //导入方法依赖的package包/类
private void setupChainGraph(int numV, String[] strs, boolean sameNameMapping) {
    clopen(option(INDEX_NAME_MAPPING, INDEX), sameNameMapping);
    TitanGraphIndex vindex = getExternalIndex(Vertex.class, INDEX);
    TitanGraphIndex eindex = getExternalIndex(Edge.class, INDEX);
    TitanGraphIndex pindex = getExternalIndex(TitanVertexProperty.class, INDEX);
    PropertyKey name = makeKey("name", String.class);

    mgmt.addIndexKey(vindex, name, getStringMapping());
    mgmt.addIndexKey(eindex, name, getStringMapping());
    mgmt.addIndexKey(pindex, name, getStringMapping(), Parameter.of("mapped-name", "xstr"));
    PropertyKey text = makeKey("text", String.class);
    mgmt.addIndexKey(vindex, text, getTextMapping(), Parameter.of("mapped-name", "xtext"));
    mgmt.addIndexKey(eindex, text, getTextMapping());
    mgmt.addIndexKey(pindex, text, getTextMapping());
    mgmt.makeEdgeLabel("knows").signature(name).make();
    mgmt.makePropertyKey("uid").dataType(String.class).signature(text).make();
    finishSchema();
    TitanVertex previous = null;
    for (int i = 0; i < numV; i++) {
        TitanVertex v = graph.addVertex("name", strs[i % strs.length], "text", strs[i % strs.length]);
        Edge e = v.addEdge("knows", previous == null ? v : previous,
                "name", strs[i % strs.length], "text", strs[i % strs.length]);
        VertexProperty p = v.property("uid", "v" + i,
                "name", strs[i % strs.length], "text", strs[i % strs.length]);
        previous = v;
    }
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:28,代码来源:TitanIndexTest.java

示例6: testPartitionedVertexScan

import com.thinkaurelius.titan.core.TitanVertex; //导入方法依赖的package包/类
@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));
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:28,代码来源:CassandraScanJobIT.java

示例7: testPartitionedVertexFilteredScan

import com.thinkaurelius.titan.core.TitanVertex; //导入方法依赖的package包/类
@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));
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:29,代码来源:CassandraScanJobIT.java

示例8: testGlobalIteration

import com.thinkaurelius.titan.core.TitanVertex; //导入方法依赖的package包/类
/**
 * Iterating over all vertices and edges in a graph
 */
@Test
public void testGlobalIteration() {
    int numV = 50;
    int deleteV = 5;

    TitanVertex previous = tx.addVertex("count", 0);
    for (int i = 1; i < numV; i++) {
        TitanVertex next = tx.addVertex("count", i);
        previous.addEdge("next", next);
        previous = next;
    }
    int numE = numV - 1;
    assertCount(numV, tx.query().vertices());
    assertCount(numV, tx.query().vertices());
    assertCount(numE, tx.query().edges());
    assertCount(numE, tx.query().edges());

    clopen();

    assertCount(numV, tx.query().vertices());
    assertCount(numV, tx.query().vertices());
    assertCount(numE, tx.query().edges());
    assertCount(numE, tx.query().edges());

    //tx.V().range(0,deleteV).remove();
    for (TitanVertex v : tx.query().limit(deleteV).vertices()) {
        v.remove();
    }

    for (int i = 0; i < 10; i++) { //Repeated vertex counts
        assertCount(numV - deleteV, tx.query().vertices());
        assertCount(numV - deleteV, tx.query().has("count", Cmp.GREATER_THAN_EQUAL, 0).vertices());
    }

    clopen();
    for (int i = 0; i < 10; i++) { //Repeated vertex counts
        assertCount(numV - deleteV, tx.query().vertices());
        assertCount(numV - deleteV, tx.query().has("count", Cmp.GREATER_THAN_EQUAL, 0).vertices());
    }
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:44,代码来源:TitanGraphTest.java

示例9: testSchemaNameChange

import com.thinkaurelius.titan.core.TitanVertex; //导入方法依赖的package包/类
@Test
public void testSchemaNameChange() {
    PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).cardinality(Cardinality.SINGLE).make();
    EdgeLabel knows = mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.MULTI).make();
    mgmt.buildEdgeIndex(knows, "byTime", Direction.BOTH, time);
    mgmt.buildIndex("timeIndex", Vertex.class).addKey(time).buildCompositeIndex();
    mgmt.makeVertexLabel("people").make();
    finishSchema();

    //CREATE SMALL GRAPH
    TitanVertex v = tx.addVertex("people");
    v.property(VertexProperty.Cardinality.single, "time", 5);
    v.addEdge("knows", v, "time", 11);

    newTx();
    v = getOnlyElement(tx.query().has("time", 5).vertices());
    assertNotNull(v);
    assertEquals("people", v.label());
    assertEquals(5, v.<Integer>value("time").intValue());
    assertCount(1, v.query().direction(Direction.IN).labels("knows").edges());
    assertCount(1, v.query().direction(Direction.OUT).labels("knows").has("time", 11).edges());
    newTx();

    //UPDATE SCHEMA NAMES

    assertTrue(mgmt.containsRelationType("knows"));
    knows = mgmt.getEdgeLabel("knows");
    mgmt.changeName(knows, "know");
    assertEquals("know", knows.name());

    assertTrue(mgmt.containsRelationIndex(knows, "byTime"));
    RelationTypeIndex rindex = mgmt.getRelationIndex(knows, "byTime");
    assertEquals("byTime", rindex.name());
    mgmt.changeName(rindex, "overTime");
    assertEquals("overTime", rindex.name());

    assertTrue(mgmt.containsVertexLabel("people"));
    VertexLabel vl = mgmt.getVertexLabel("people");
    mgmt.changeName(vl, "person");
    assertEquals("person", vl.name());

    assertTrue(mgmt.containsGraphIndex("timeIndex"));
    TitanGraphIndex gindex = mgmt.getGraphIndex("timeIndex");
    mgmt.changeName(gindex, "byTime");
    assertEquals("byTime", gindex.name());

    finishSchema();

    //VERIFY UPDATES IN MGMT SYSTEM

    assertTrue(mgmt.containsRelationType("know"));
    assertFalse(mgmt.containsRelationType("knows"));
    knows = mgmt.getEdgeLabel("know");

    assertTrue(mgmt.containsRelationIndex(knows, "overTime"));
    assertFalse(mgmt.containsRelationIndex(knows, "byTime"));

    assertTrue(mgmt.containsVertexLabel("person"));
    assertFalse(mgmt.containsVertexLabel("people"));

    assertTrue(mgmt.containsGraphIndex("byTime"));
    assertFalse(mgmt.containsGraphIndex("timeIndex"));

    //VERIFY UPDATES IN TRANSACTION
    newTx();
    v = getOnlyElement(tx.query().has("time", 5).vertices());
    assertNotNull(v);
    assertEquals("person", v.label());
    assertEquals(5, v.<Integer>value("time").intValue());
    assertCount(1, v.query().direction(Direction.IN).labels("know").edges());
    assertCount(0, v.query().direction(Direction.IN).labels("knows").edges());
    assertCount(1, v.query().direction(Direction.OUT).labels("know").has("time", 11).edges());
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:74,代码来源:TitanGraphTest.java

示例10: testUnsettingTTL

import com.thinkaurelius.titan.core.TitanVertex; //导入方法依赖的package包/类
@Test
public void testUnsettingTTL() throws InterruptedException {
    if (!features.hasCellTTL()) {
        return;
    }

    int initialTTLMillis = 2000;

    // Define schema: one edge label with a short ttl
    EdgeLabel likes = mgmt.makeEdgeLabel("likes").make();
    mgmt.setTTL(likes, Duration.ofMillis(initialTTLMillis));
    mgmt.commit();
    graph.tx().rollback();

    // Insert two vertices with a TTLed edge
    TitanVertex v1 = graph.addVertex();
    TitanVertex v2 = graph.addVertex();
    v1.addEdge("likes", v2);
    graph.tx().commit();

    // Let the edge die
    Thread.sleep((long) Math.ceil(initialTTLMillis * 1.25));

    // Edge should be gone
    assertEquals(2, Iterators.size(graph.vertices()));
    assertEquals(0, Iterators.size(graph.edges()));
    graph.tx().rollback();

    // Remove the TTL on the edge label
    mgmt = graph.openManagement();
    mgmt.setTTL(mgmt.getEdgeLabel("likes"), Duration.ZERO);
    mgmt.commit();

    Thread.sleep(1L);

    // Check that the edge is still gone, add a new edge
    assertEquals(2, Iterators.size(graph.vertices()));
    assertEquals(0, Iterators.size(graph.edges()));
    v1 = graph.addVertex();
    v2 = graph.addVertex();
    v1.addEdge("likes", v2);
    graph.tx().commit();

    // Sleep past when it would have expired under the original config
    Thread.sleep((long) Math.ceil(initialTTLMillis * 1.25));

    // Edge must not be dead
    assertEquals(4, Iterators.size(graph.vertices()));
    assertEquals(1, Iterators.size(graph.edges()));
    graph.tx().rollback();
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:52,代码来源:TitanGraphTest.java


注:本文中的com.thinkaurelius.titan.core.TitanVertex.addEdge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。