Search in sources :

Example 51 with Id

use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.

the class BuiltinGraphFactoryTest method testCreateLongId.

@Test
public void testCreateLongId() {
    long value = 1L;
    GraphFactory graphFactory = graphFactory();
    Id id = graphFactory.createId(value);
    Assert.assertEquals(IdType.LONG, id.idType());
    Assert.assertEquals(BytesId.of(value), id);
}
Also used : Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) Test(org.junit.Test)

Example 52 with Id

use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.

the class IdListListTest method testCompare.

@Test
public void testCompare() {
    Id longId1 = BytesId.of(100L);
    Id longId2 = BytesId.of(200L);
    IdList listValue = new IdList();
    listValue.add(longId1);
    listValue.add(longId2);
    IdListList value1 = new IdListList();
    value1.add(listValue);
    IdListList value2 = new IdListList();
    value2.add(listValue);
    IdListList value3 = new IdListList();
    value3.add(listValue);
    value3.add(listValue);
    Assert.assertEquals(0, value1.compareTo(value2));
    Assert.assertLt(0, value1.compareTo(value3));
    Assert.assertGt(0, value3.compareTo(value1));
}
Also used : Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) Test(org.junit.Test)

Example 53 with Id

use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.

the class IdValueListTest method test.

@Test
public void test() {
    Id longId1 = BytesId.of(100L);
    Id longId2 = BytesId.of(200L);
    IdList listValue1 = new IdList();
    IdList listValue2 = new IdList();
    listValue1.add(longId1);
    listValue2.add(longId1);
    Assert.assertEquals(ValueType.ID_LIST, listValue1.valueType());
    Assert.assertEquals(ValueType.ID, listValue1.elemType());
    Assert.assertTrue(ListUtils.isEqualList(Lists.newArrayList(longId1), listValue1.values()));
    Assert.assertEquals(listValue1, listValue2);
    listValue2.add(longId2);
    Assert.assertTrue(ListUtils.isEqualList(Lists.newArrayList(longId1, longId2), listValue2.values()));
    Assert.assertNotEquals(listValue1, listValue2);
    Assert.assertEquals(ListUtils.hashCodeForList(Lists.newArrayList(longId1)), listValue1.hashCode());
}
Also used : Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) Test(org.junit.Test)

Example 54 with Id

use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.

the class JsonStructGraphOutputTest method testWriteReadVertexWithEdges.

@Test
public void testWriteReadVertexWithEdges() throws IOException {
    UnitTestBase.updateOptions(ComputerOptions.OUTPUT_WITH_ADJACENT_EDGES, "true", ComputerOptions.OUTPUT_WITH_VERTEX_PROPERTIES, "false", ComputerOptions.OUTPUT_WITH_EDGE_PROPERTIES, "false", ComputerOptions.OUTPUT_RESULT_NAME, "rank");
    ComputerContext context = context();
    GraphFactory factory = context.graphFactory();
    Id longId = BytesId.of(100L);
    IdList idList = new IdList();
    idList.add(BytesId.of(998L));
    idList.add(BytesId.of(999L));
    Vertex vertex = factory.createVertex(longId, idList);
    vertex.addEdge(factory.createEdge("knows", BytesId.of(200)));
    vertex.addEdge(factory.createEdge("watch", "1111", BytesId.of(300)));
    String fileName = "output.json";
    File file = new File(fileName);
    try {
        BufferedFileOutput dos = new BufferedFileOutput(file);
        StructGraphOutput output = (StructGraphOutput) IOFactory.createGraphOutput(context, OutputFormat.JSON, dos);
        output.writeVertex(vertex);
        dos.close();
        @SuppressWarnings("deprecation") String json = FileUtils.readFileToString(file);
        Assert.assertEquals("{\"id\":100,\"rank\":[998,999]," + "\"adjacent_edges\":[{\"target_id\":200," + "\"label\":\"knows\",\"name\":\"\"}," + "{\"target_id\":300,\"label\":\"watch\"," + "\"name\":\"1111\"}]}" + System.lineSeparator(), json);
    } finally {
        FileUtils.deleteQuietly(file);
    }
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) File(java.io.File) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList) ComputerContext(com.baidu.hugegraph.computer.core.common.ComputerContext) Test(org.junit.Test)

Example 55 with Id

use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.

the class StreamGraphOutputInputTest method testWriteReadVertex.

@Test
public void testWriteReadVertex() throws Exception {
    Id longId = BytesId.of(100L);
    LongValue longValue = new LongValue(999L);
    Vertex vertex = graphFactory().createVertex(longId, longValue);
    Properties properties = graphFactory().createProperties();
    properties.put("age", new LongValue(20L));
    vertex.properties(properties);
    byte[] bytes;
    try (BytesOutput bao = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
        StreamGraphOutput output = newStreamGraphOutput(bao);
        output.writeVertex(vertex);
        bytes = bao.toByteArray();
    }
    try (BytesInput bai = IOFactory.createBytesInput(bytes)) {
        StreamGraphInput input = newStreamGraphInput(bai);
        assertVertexEqualWithoutValue(vertex, input.readVertex());
    }
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) Test(org.junit.Test)

Aggregations

Id (com.baidu.hugegraph.computer.core.graph.id.Id)74 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)51 Test (org.junit.Test)29 IdList (com.baidu.hugegraph.computer.core.graph.value.IdList)18 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)12 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)12 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)12 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)12 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)11 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)10 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)9 ConnectionId (com.baidu.hugegraph.computer.core.network.ConnectionId)8 IdListList (com.baidu.hugegraph.computer.core.graph.value.IdListList)7 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)6 File (java.io.File)6 Value (com.baidu.hugegraph.computer.core.graph.value.Value)5 BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)5 Config (com.baidu.hugegraph.computer.core.config.Config)4 BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)4 FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)4