use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.
the class WriteBuffersTest method testReachThreshold.
@Test
public void testReachThreshold() throws IOException {
WriteBuffers buffers = new WriteBuffers(context(), 20, 50);
Assert.assertFalse(buffers.reachThreshold());
Vertex vertex = context().graphFactory().createVertex(BytesId.of(1L), new DoubleValue(0.5d));
// After write, the position is 11
buffers.writeVertex(vertex);
Assert.assertFalse(buffers.reachThreshold());
// After write, the position is 22
buffers.writeVertex(vertex);
Assert.assertTrue(buffers.reachThreshold());
// After write, the position is 33
buffers.writeVertex(vertex);
Assert.assertTrue(buffers.reachThreshold());
}
use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.
the class WriteBuffersTest method testWriteVertex.
@Test
public void testWriteVertex() throws IOException {
GraphFactory graphFactory = context().graphFactory();
// NOTE: need ensure the buffer size can hold follow writed bytes
WriteBuffers buffers = new WriteBuffers(context(), 100, 110);
Vertex vertex = graphFactory.createVertex(BytesId.of(1L), new DoubleValue(0.5d));
buffers.writeVertex(vertex);
WriteBuffer buffer = Whitebox.getInternalState(buffers, "writingBuffer");
long position1 = buffer.output().position();
Assert.assertGt(0L, position1);
vertex = graphFactory.createVertex(BytesId.of(1L), new DoubleValue(0.5d));
Properties properties = graphFactory.createProperties();
properties.put("name", BytesId.of("marko"));
properties.put("age", new IntValue(18));
properties.put("city", new ListValue<>(ValueType.ID, ImmutableList.of(BytesId.of("wuhan"), BytesId.of("xian"))));
vertex.properties(properties);
buffers.writeVertex(vertex);
buffer = Whitebox.getInternalState(buffers, "writingBuffer");
long position2 = buffer.output().position();
Assert.assertGt(position1, position2);
vertex = graphFactory.createVertex(BytesId.of(1L), new DoubleValue(0.5d));
vertex.addEdge(graphFactory.createEdge(BytesId.of(2L)));
vertex.addEdge(graphFactory.createEdge("knows", BytesId.of(3L)));
vertex.addEdge(graphFactory.createEdge("watch", "1111", BytesId.of(4L)));
buffers.writeEdges(vertex);
buffer = Whitebox.getInternalState(buffers, "writingBuffer");
long position3 = buffer.output().position();
Assert.assertGt(position2, position3);
}
use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.
the class WriteBuffersTest method wrapForRead.
@Test
public void wrapForRead() throws IOException {
GraphFactory graphFactory = context().graphFactory();
WriteBuffers buffers = new WriteBuffers(context(), 10, 20);
Vertex vertex = graphFactory.createVertex(BytesId.of(1L), new DoubleValue(0.5d));
buffers.writeVertex(vertex);
buffers.prepareSorting();
try (RandomAccessInput input = buffers.wrapForRead()) {
EntryInput entryInput = new EntryInputImpl(input);
StreamGraphInput graphInput = new StreamGraphInput(context(), entryInput);
vertex.value(null);
Assert.assertEquals(vertex, graphInput.readVertex());
}
}
use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.
the class WriteBuffersTest method testIsEmpty.
@Test
public void testIsEmpty() throws IOException {
WriteBuffers buffers = new WriteBuffers(context(), 10, 20);
Assert.assertTrue(buffers.isEmpty());
Vertex vertex = context().graphFactory().createVertex(BytesId.of(1L), new DoubleValue(0.5d));
buffers.writeVertex(vertex);
Assert.assertFalse(buffers.isEmpty());
}
use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.
the class ComputeMessageRecvPartitionTest method addTwentyCombineMessageBuffer.
public static void addTwentyCombineMessageBuffer(Consumer<NetworkBuffer> consumer) throws IOException {
for (long i = 0L; i < 10L; i++) {
for (int j = 0; j < 2; j++) {
Id id = BytesId.of(i);
DoubleValue message = new DoubleValue(i);
ReceiverUtil.consumeBuffer(ReceiverUtil.writeMessage(id, message), consumer);
}
}
}
Aggregations