use of com.baidu.hugegraph.computer.core.graph.properties.Properties in project hugegraph-computer by hugegraph.
the class MergeNewPropertiesCombinerTest method testCombineNull.
@Test
public void testCombineNull() {
Properties properties1 = graphFactory().createProperties();
properties1.put("name", BytesId.of("marko"));
properties1.put("city", BytesId.of("Beijing"));
Properties properties2 = graphFactory().createProperties();
properties2.put("name", BytesId.of("josh"));
properties2.put("age", BytesId.of("18"));
PropertiesCombiner combiner = new MergeNewPropertiesCombiner();
Assert.assertThrows(IllegalArgumentException.class, () -> {
combiner.combine(null, properties2, properties2);
}, e -> {
Assert.assertEquals("The combine parameter v1 can't be null", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
combiner.combine(properties1, null, properties2);
}, e -> {
Assert.assertEquals("The combine parameter v2 can't be null", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
combiner.combine(properties1, properties2, null);
}, e -> {
Assert.assertEquals("The combine parameter result can't be null", e.getMessage());
});
}
use of com.baidu.hugegraph.computer.core.graph.properties.Properties in project hugegraph-computer by hugegraph.
the class EdgeMessageRecvPartitionTest method addTenDuplicateEdgeBuffer.
private static void addTenDuplicateEdgeBuffer(Consumer<NetworkBuffer> consumer) throws IOException {
for (long i = 0L; i < 10L; i++) {
Vertex vertex = graphFactory().createVertex();
vertex.id(BytesId.of(i));
Edges edges = graphFactory().createEdges(2);
for (long j = i + 1; j < i + 3; j++) {
Edge edge = graphFactory().createEdge();
edge.targetId(BytesId.of(j));
Properties properties = graphFactory().createProperties();
properties.put("p1", new LongValue(i));
edge.properties(properties);
edges.add(edge);
}
vertex.edges(edges);
ReceiverUtil.consumeBuffer(writeEdges(vertex), consumer);
}
for (long i = 0L; i < 10L; i++) {
Vertex vertex = graphFactory().createVertex();
vertex.id(BytesId.of(i));
Edges edges = graphFactory().createEdges(2);
for (long j = i + 1; j < i + 3; j++) {
Edge edge = graphFactory().createEdge();
edge.targetId(BytesId.of(j));
Properties properties = graphFactory().createProperties();
properties.put("p2", new LongValue(2L * i));
edge.properties(properties);
edges.add(edge);
}
vertex.edges(edges);
ReceiverUtil.consumeBuffer(writeEdges(vertex), consumer);
}
}
use of com.baidu.hugegraph.computer.core.graph.properties.Properties in project hugegraph-computer by hugegraph.
the class EdgeMessageRecvPartitionTest method addTenEdgeBuffer.
public static void addTenEdgeBuffer(Consumer<NetworkBuffer> consumer) throws IOException {
for (long i = 0L; i < 10L; i++) {
Vertex vertex = graphFactory().createVertex();
vertex.id(BytesId.of(i));
Edges edges = graphFactory().createEdges(2);
for (long j = i + 1; j < i + 3; j++) {
Edge edge = graphFactory().createEdge();
edge.targetId(BytesId.of(j));
Properties properties = graphFactory().createProperties();
properties.put("p1", new LongValue(i));
edge.properties(properties);
edges.add(edge);
}
vertex.edges(edges);
ReceiverUtil.consumeBuffer(writeEdges(vertex), consumer);
}
}
use of com.baidu.hugegraph.computer.core.graph.properties.Properties in project hugegraph-computer by hugegraph.
the class VertexMessageRecvPartitionTest method checkTenVertexWithMergedProperties.
private static void checkTenVertexWithMergedProperties(PeekableIterator<KvEntry> it) throws IOException {
for (long i = 0L; i < 10L; i++) {
// Assert key
Assert.assertTrue(it.hasNext());
KvEntry entry = it.next();
Id id = ReceiverUtil.readId(entry.key());
Assert.assertEquals(BytesId.of(i), id);
// Assert value
Pointer value = entry.value();
RandomAccessInput input = value.input();
long position = input.position();
input.seek(value.offset());
String label = StreamGraphInput.readLabel(input);
Assert.assertEquals("", label);
Properties properties = graphFactory().createProperties();
properties.read(input);
input.seek(position);
Assert.assertEquals(2, properties.size());
LongValue v1 = properties.get("p1");
Assert.assertEquals(new LongValue(i), v1);
LongValue v2 = properties.get("p2");
Assert.assertEquals(new LongValue(2L * i), v2);
}
}
use of com.baidu.hugegraph.computer.core.graph.properties.Properties in project hugegraph-computer by hugegraph.
the class HugeConverterTest method testConvertProperties.
@Test
public void testConvertProperties() {
Map<String, Object> rawProperties = new HashMap<>();
rawProperties.put("null-value", null);
rawProperties.put("boolean-value", true);
rawProperties.put("int-value", 1);
rawProperties.put("long-value", 2L);
rawProperties.put("float-value", 0.3F);
rawProperties.put("double-value", 0.4D);
rawProperties.put("list-value", ImmutableList.of(1, 2));
Properties properties = graphFactory().createProperties();
properties.put("null-value", NullValue.get());
properties.put("boolean-value", new BooleanValue(true));
properties.put("int-value", new IntValue(1));
properties.put("long-value", new LongValue(2L));
properties.put("float-value", new FloatValue(0.3F));
properties.put("double-value", new DoubleValue(0.4D));
ListValue<IntValue> listValue = new ListValue<>(ValueType.INT);
listValue.add(new IntValue(1));
listValue.add(new IntValue(2));
properties.put("list-value", listValue);
Assert.assertEquals(properties, HugeConverter.convertProperties(rawProperties));
}
Aggregations