use of com.baidu.hugegraph.computer.core.graph.value.LongValue in project hugegraph-computer by hugegraph.
the class DefaultPropertiesTest method testEquals.
@Test
public void testEquals() {
DefaultProperties props1 = new DefaultProperties(graphFactory());
props1.put("p1", new LongValue(1L));
props1.put("p2", new DoubleValue(2.0D));
DefaultProperties props2 = new DefaultProperties(props1.get(), UnitTestBase.graphFactory());
Assert.assertEquals(props1, props2);
}
use of com.baidu.hugegraph.computer.core.graph.value.LongValue 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());
}
}
use of com.baidu.hugegraph.computer.core.graph.value.LongValue in project hugegraph-computer by hugegraph.
the class StreamGraphOutputInputTest method testWriteReadEdgesWithSinglePerLabelFrequency.
@Test
public void testWriteReadEdgesWithSinglePerLabelFrequency() throws Exception {
UnitTestBase.updateOptions(ComputerOptions.INPUT_EDGE_FREQ, "SINGLE_PER_LABEL");
ComputerContext context = ComputerContext.instance();
GraphFactory graphFactory = context.graphFactory();
Id longId = BytesId.of(100L);
LongValue longValue = new LongValue(999L);
Vertex vertex = graphFactory().createVertex(longId, longValue);
vertex.addEdge(graphFactory.createEdge(BytesId.of(2L)));
vertex.addEdge(graphFactory.createEdge("knows", BytesId.of(3L)));
vertex.addEdge(graphFactory.createEdge("watch", BytesId.of(3L)));
vertex.addEdge(graphFactory.createEdge("watch", "1111", BytesId.of(4L)));
vertex.addEdge(graphFactory.createEdge("watch", "2222", BytesId.of(4L)));
byte[] bytes;
try (BytesOutput bao = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
StreamGraphOutput output = newStreamGraphOutput(bao);
output.writeEdges(vertex);
bytes = bao.toByteArray();
bytes = reweaveBytes(bytes);
}
try (BytesInput bai = IOFactory.createBytesInput(bytes)) {
StreamGraphInput input = newStreamGraphInput(bai);
assertEdgesEqual(vertex, input.readEdges(), EdgeFrequency.SINGLE_PER_LABEL);
}
}
use of com.baidu.hugegraph.computer.core.graph.value.LongValue in project hugegraph-computer by hugegraph.
the class StreamGraphOutputInputTest method testWriteReadEdgesWithMultipleFrequency.
@Test
public void testWriteReadEdgesWithMultipleFrequency() throws Exception {
UnitTestBase.updateOptions(ComputerOptions.INPUT_EDGE_FREQ, "MULTIPLE");
ComputerContext context = ComputerContext.instance();
GraphFactory graphFactory = context.graphFactory();
Id longId = BytesId.of(100L);
LongValue longValue = new LongValue(999L);
Vertex vertex = graphFactory().createVertex(longId, longValue);
vertex.addEdge(graphFactory.createEdge(BytesId.of(2L)));
vertex.addEdge(graphFactory.createEdge("knows", BytesId.of(3L)));
vertex.addEdge(graphFactory.createEdge("watch", BytesId.of(3L)));
vertex.addEdge(graphFactory.createEdge("watch", "1111", BytesId.of(4L)));
vertex.addEdge(graphFactory.createEdge("watch", "2222", BytesId.of(4L)));
byte[] bytes;
try (BytesOutput bao = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
StreamGraphOutput output = newStreamGraphOutput(bao);
output.writeEdges(vertex);
bytes = bao.toByteArray();
bytes = reweaveBytes(bytes);
}
try (BytesInput bai = IOFactory.createBytesInput(bytes)) {
StreamGraphInput input = newStreamGraphInput(bai);
assertEdgesEqual(vertex, input.readEdges(), EdgeFrequency.MULTIPLE);
}
}
use of com.baidu.hugegraph.computer.core.graph.value.LongValue in project hugegraph-computer by hugegraph.
the class ComputeManagerTest method addSingleFreqEdgeBuffer.
private static void addSingleFreqEdgeBuffer(Consumer<ManagedBuffer> consumer) throws IOException {
for (long i = 0L; i < 200L; i++) {
Vertex vertex = graphFactory().createVertex();
vertex.id(BytesId.of(i));
int count = RANDOM.nextInt(20);
if (count == 0) {
continue;
}
Edges edges = graphFactory().createEdges(count);
for (long j = 0; j < count; j++) {
Edge edge = graphFactory().createEdge();
edge.targetId(BytesId.of(RANDOM.nextInt(200)));
Properties properties = graphFactory().createProperties();
properties.put("p1", new LongValue(i));
edge.properties(properties);
edges.add(edge);
}
vertex.edges(edges);
ReceiverUtil.consumeBuffer(writeEdges(vertex, EdgeFrequency.SINGLE), consumer);
}
}
Aggregations