Search in sources :

Example 11 with DoubleValue

use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.

the class WriteBufferTest method testWriteVertex.

@Test
public void testWriteVertex() throws IOException {
    GraphFactory graphFactory = context.graphFactory();
    // NOTE: need ensure the buffer size can hold follow writed bytes
    WriteBuffer buffer = new WriteBuffer(context, 100, 110);
    Vertex vertex = graphFactory.createVertex(BytesId.of(1L), new DoubleValue(0.5d));
    buffer.writeVertex(vertex);
    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);
    buffer.writeVertex(vertex);
    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)));
    buffer.writeEdges(vertex);
    long position3 = buffer.output().position();
    Assert.assertGt(position2, position3);
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue) Test(org.junit.Test)

Example 12 with DoubleValue

use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.

the class WriteBufferTest method testIsEmpty.

@Test
public void testIsEmpty() throws IOException {
    WriteBuffer buffer = new WriteBuffer(context, 10, 20);
    Assert.assertTrue(buffer.isEmpty());
    Vertex vertex = context.graphFactory().createVertex(BytesId.of(1L), new DoubleValue(0.5d));
    buffer.writeVertex(vertex);
    Assert.assertFalse(buffer.isEmpty());
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Test(org.junit.Test)

Example 13 with DoubleValue

use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.

the class DoubleValueSumCombinerTest method testCombineNull.

@Test
public void testCombineNull() {
    DoubleValue value1 = new DoubleValue(0.0D);
    DoubleValue value2 = new DoubleValue(0.0D);
    DoubleValueSumCombiner combiner = new DoubleValueSumCombiner();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        combiner.combine(null, value2, value2);
    }, e -> {
        Assert.assertEquals("The combine parameter v1 can't be null", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        combiner.combine(value1, null, value2);
    }, e -> {
        Assert.assertEquals("The combine parameter v2 can't be null", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        combiner.combine(value1, value2, null);
    }, e -> {
        Assert.assertEquals("The combine parameter result can't be null", e.getMessage());
    });
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Test(org.junit.Test)

Example 14 with DoubleValue

use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.

the class PointerCombinerTest method testMessageCombiner.

@Test
public void testMessageCombiner() throws IOException {
    Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.WORKER_COMBINER_CLASS, DoubleValueSumCombiner.class.getName());
    Combiner<DoubleValue> valueCombiner = config.createObject(ComputerOptions.WORKER_COMBINER_CLASS);
    PointerCombiner combiner = SorterTestUtil.createPointerCombiner(DoubleValue::new, new DoubleValueSumCombiner());
    try (BytesOutput bytesOutput1 = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
        BytesOutput bytesOutput2 = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
        DoubleValue value1 = new DoubleValue(1.0D);
        DoubleValue value2 = new DoubleValue(2.0D);
        value1.write(bytesOutput1);
        value2.write(bytesOutput2);
        Pointer pointer1 = new InlinePointer(bytesOutput1.buffer(), bytesOutput1.position());
        Pointer pointer2 = new InlinePointer(bytesOutput2.buffer(), bytesOutput2.position());
        Pointer pointer = combiner.combine(pointer1, pointer2);
        BytesInput input = IOFactory.createBytesInput(pointer.bytes());
        DoubleValue combinedValue = new DoubleValue();
        combinedValue.read(input);
        Assert.assertEquals(new DoubleValue(3.0D), combinedValue);
    }
}
Also used : BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Config(com.baidu.hugegraph.computer.core.config.Config) InlinePointer(com.baidu.hugegraph.computer.core.store.entry.InlinePointer) Pointer(com.baidu.hugegraph.computer.core.store.entry.Pointer) InlinePointer(com.baidu.hugegraph.computer.core.store.entry.InlinePointer) Test(org.junit.Test)

Example 15 with DoubleValue

use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.

the class DefaultPropertiesTest method testConstructor.

@Test
public void testConstructor() {
    DefaultProperties properties = new DefaultProperties(graphFactory());
    Assert.assertEquals(0, properties.get().size());
    properties.put("p1", new LongValue(1L));
    properties.put("p2", new DoubleValue(2.0D));
    Map<String, Value> props = properties.get();
    Assert.assertEquals(2, props.size());
    Assert.assertEquals(new LongValue(1L), props.get("p1"));
    Assert.assertEquals(new DoubleValue(2.0D), props.get("p2"));
}
Also used : DefaultProperties(com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Value(com.baidu.hugegraph.computer.core.graph.value.Value) Test(org.junit.Test)

Aggregations

DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)49 Test (org.junit.Test)28 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)21 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)14 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)13 FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)12 Id (com.baidu.hugegraph.computer.core.graph.id.Id)10 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)8 DefaultProperties (com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties)7 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)6 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)5 BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)4 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)3 Value (com.baidu.hugegraph.computer.core.graph.value.Value)3 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)2 DefaultEdge (com.baidu.hugegraph.computer.core.graph.edge.DefaultEdge)2 IdList (com.baidu.hugegraph.computer.core.graph.value.IdList)2 IdListList (com.baidu.hugegraph.computer.core.graph.value.IdListList)2 ListValue (com.baidu.hugegraph.computer.core.graph.value.ListValue)2 File (java.io.File)2