use of com.baidu.hugegraph.backend.serializer.BytesBuffer in project incubator-hugegraph by apache.
the class BytesBufferTest method testPropertyWithSet.
@Test
public void testPropertyWithSet() {
BytesBuffer buf = BytesBuffer.allocate(0);
PropertyKey pkey = genSetPkey(DataType.BOOLEAN);
Object value = ImmutableSet.of(true, false);
byte[] bytes = genBytes("020100");
Assert.assertArrayEquals(bytes, buf.writeProperty(pkey, value).bytes());
Assert.assertEquals(value, BytesBuffer.wrap(bytes).readProperty(pkey));
pkey = genSetPkey(DataType.BYTE);
value = ImmutableSet.of();
bytes = genBytes("00");
buf.forReadWritten();
Assert.assertArrayEquals(bytes, buf.writeProperty(pkey, value).bytes());
Assert.assertEquals(value, BytesBuffer.wrap(bytes).readProperty(pkey));
pkey = genSetPkey(DataType.BYTE);
value = ImmutableSet.of((byte) 127, (byte) 128);
bytes = genBytes("027f8fffffff00");
buf.forReadWritten();
Assert.assertArrayEquals(bytes, buf.writeProperty(pkey, value).bytes());
Assert.assertEquals(value, BytesBuffer.wrap(bytes).readProperty(pkey));
pkey = genSetPkey(DataType.INT);
value = ImmutableSet.of(127, 128);
bytes = genBytes("027f8100");
buf.forReadWritten();
Assert.assertArrayEquals(bytes, buf.writeProperty(pkey, value).bytes());
Assert.assertEquals(value, BytesBuffer.wrap(bytes).readProperty(pkey));
pkey = genSetPkey(DataType.FLOAT);
value = ImmutableSet.of(1.0f, 3.14f);
bytes = genBytes("023f8000004048f5c3");
buf.forReadWritten();
Assert.assertArrayEquals(bytes, buf.writeProperty(pkey, value).bytes());
Assert.assertEquals(value, BytesBuffer.wrap(bytes).readProperty(pkey));
pkey = genSetPkey(DataType.LONG);
value = ImmutableSet.of(127L, 128L);
bytes = genBytes("027f8100");
buf.forReadWritten();
Assert.assertArrayEquals(bytes, buf.writeProperty(pkey, value).bytes());
Assert.assertEquals(value, BytesBuffer.wrap(bytes).readProperty(pkey));
pkey = genSetPkey(DataType.DOUBLE);
value = ImmutableSet.of(1.0d, 3.14d);
bytes = genBytes("023ff000000000000040091eb851eb851f");
buf.forReadWritten();
Assert.assertArrayEquals(bytes, buf.writeProperty(pkey, value).bytes());
Assert.assertEquals(value, BytesBuffer.wrap(bytes).readProperty(pkey));
pkey = genSetPkey(DataType.DATE);
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("Beijing"));
c.setTimeInMillis(1565851529514L);
value = ImmutableSet.of(c.getTime(), c.getTime());
bytes = genBytes("01adc9a098e22a");
buf.forReadWritten();
Assert.assertArrayEquals(bytes, buf.writeProperty(pkey, value).bytes());
Assert.assertEquals(value, BytesBuffer.wrap(bytes).readProperty(pkey));
pkey = genSetPkey(DataType.TEXT);
value = ImmutableSet.of("abc", "123");
bytes = genBytes("020361626303313233");
buf.forReadWritten();
Assert.assertArrayEquals(bytes, buf.writeProperty(pkey, value).bytes());
Assert.assertEquals(value, BytesBuffer.wrap(bytes).readProperty(pkey));
pkey = genSetPkey(DataType.BLOB);
value = ImmutableSet.of(genBytes("001199aabbcc"), genBytes("5566"));
bytes = genBytes("0206001199aabbcc025566");
buf.forReadWritten();
Assert.assertArrayEquals(bytes, buf.writeProperty(pkey, value).bytes());
Set<?> set = (Set<?>) BytesBuffer.wrap(bytes).readProperty(pkey);
Iterator<?> iterator = set.iterator();
Assert.assertEquals(Blob.wrap(genBytes("001199aabbcc")), iterator.next());
Assert.assertEquals(Blob.wrap(genBytes("5566")), iterator.next());
pkey = genSetPkey(DataType.UUID);
UUID uuid = UUID.fromString("3cfcafc8-7906-4ab7-a207-4ded056f58de");
value = ImmutableSet.of(uuid, uuid);
bytes = genBytes("013cfcafc879064ab7a2074ded056f58de");
buf.forReadWritten();
Assert.assertArrayEquals(bytes, buf.writeProperty(pkey, value).bytes());
Assert.assertEquals(value, BytesBuffer.wrap(bytes).readProperty(pkey));
pkey = genSetPkey(DataType.OBJECT);
value = ImmutableSet.of(new Point(3, 8), new Point(3, 9));
bytes = genBytes("021301006a6176612e6177742e506f696ef4010610" + "1301006a6176612e6177742e506f696ef4010612");
buf.forReadWritten();
Assert.assertArrayEquals(bytes, buf.writeProperty(pkey, value).bytes());
Assert.assertEquals(value, BytesBuffer.wrap(bytes).readProperty(pkey));
pkey = genSetPkey(DataType.OBJECT);
value = ImmutableSet.of(new int[] { 1, 3 }, new int[] { 2, 5 });
bytes = genBytes("020801005bc9010302060801005bc90103040a");
buf.forReadWritten();
Assert.assertArrayEquals(bytes, buf.writeProperty(pkey, value).bytes());
set = (Set<?>) BytesBuffer.wrap(bytes).readProperty(pkey);
iterator = set.iterator();
Assert.assertArrayEquals(new int[] { 1, 3 }, (int[]) iterator.next());
Assert.assertArrayEquals(new int[] { 2, 5 }, (int[]) iterator.next());
}
Aggregations