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);
}
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));
}
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());
}
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);
}
}
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());
}
}
Aggregations