Java Code Examples for com.baidu.hugegraph.testutil.Assert#assertArrayEquals()
The following examples show how to use
com.baidu.hugegraph.testutil.Assert#assertArrayEquals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PathSerializerTest.java From hugegraph-client with Apache License 2.0 | 6 votes |
@Test public void testDeserializePathWithListType() { String json = "{" + "\"labels\":[" + "[]," + "[]" + "]," + "\"objects\":[" + "[\"Beijing\", \"Beijing\"]," + "[\"Wuhan\", \"Hongkong\"]" + "]" + "}"; Path path = BaseUnitTest.deserialize(json, Path.class); Assert.assertEquals(2, path.labels().size()); Assert.assertEquals(ImmutableList.of(), path.labels().get(0)); Assert.assertEquals(ImmutableList.of(), path.labels().get(1)); Assert.assertEquals(2, path.objects().size()); Assert.assertArrayEquals(new Object[]{ ImmutableList.of("Beijing", "Beijing"), ImmutableList.of("Wuhan", "Hongkong")}, path.objects().toArray()); }
Example 2
Source File: StringUtilTest.java From hugegraph-common with Apache License 2.0 | 6 votes |
@Test public void testSplitToCharsArray() { Assert.assertArrayEquals(Chars.of("1", "2", "3"), StringUtil.splitToCharsArray("1, 2, 3", ", ")); Assert.assertArrayEquals(Chars.of("1", "1", "1"), StringUtil.splitToCharsArray("1 1 1", " ")); Assert.assertArrayEquals(Chars.of("", "", ""), StringUtil.splitToCharsArray("111", "1")); Assert.assertArrayEquals(new Chars[]{Chars.of("123")}, StringUtil.splitToCharsArray("123", " ")); Assert.assertArrayEquals(Chars.of("1", "", "2", "3"), StringUtil.splitToCharsArray("1::2:3", ":")); Assert.assertArrayEquals(Chars.of("1", "", "2", "", "3"), StringUtil.splitToCharsArray("1::2::3", ":")); Assert.assertThrows(IllegalArgumentException.class, () -> { StringUtil.splitToCharsArray("123", ""); }); }
Example 3
Source File: BytesBufferTest.java From hugegraph with Apache License 2.0 | 6 votes |
@Test public void testStringId() { Id id = IdGenerator.of("abc"); byte[] bytes = new byte[]{(byte) 0x82, 97, 98, 99}; Assert.assertArrayEquals(bytes, BytesBuffer.allocate(4) .writeId(id).bytes()); Assert.assertEquals(id, BytesBuffer.wrap(bytes).readId()); id = IdGenerator.of("abcd"); bytes = new byte[]{(byte) 0x83, 97, 98, 99, 100}; Assert.assertArrayEquals(bytes, BytesBuffer.allocate(5) .writeId(id).bytes()); Assert.assertEquals(id, BytesBuffer.wrap(bytes).readId()); }
Example 4
Source File: RocksDBSessionsTest.java From hugegraph with Apache License 2.0 | 6 votes |
@Test public void testDeleteByRangeWithBytes() throws RocksDBException { Session session = this.rocks.session(); byte[] key11 = new byte[]{1, 1}; byte[] value11 = b("value-1-1"); session.put(TABLE, key11, value11); byte[] key12 = new byte[]{1, 2}; byte[] value12 = b("value-1-2"); session.put(TABLE, key12, value12); byte[] key21 = new byte[]{2, 1}; byte[] value21 = b("value-2-1"); session.put(TABLE, key21, value21); session.delete(TABLE, key11, new byte[]{1, 3}); this.commit(); Assert.assertArrayEquals(null, session.get(TABLE, key11)); Assert.assertArrayEquals(null, session.get(TABLE, key12)); Assert.assertArrayEquals(value21, session.get(TABLE, key21)); }
Example 5
Source File: BytesBufferTest.java From hugegraph with Apache License 2.0 | 6 votes |
@Test public void testAllocate() { Assert.assertEquals(0, BytesBuffer.allocate(0).array().length); Assert.assertEquals(0, BytesBuffer.allocate(0).bytes().length); Assert.assertEquals(4, BytesBuffer.allocate(4).array().length); Assert.assertEquals(0, BytesBuffer.allocate(4).bytes().length); BytesBuffer buf4 = BytesBuffer.allocate(4); Assert.assertArrayEquals(new byte[]{0, 0, 0, 0}, buf4.write(new byte[4]).bytes()); BytesBuffer buf2 = BytesBuffer.allocate(2); Assert.assertArrayEquals(new byte[]{0, 0, 0, 0}, buf2.write(new byte[4]).bytes()); BytesBuffer buf0 = BytesBuffer.allocate(0); Assert.assertArrayEquals(new byte[]{0, 0, 0, 0}, buf0.write(new byte[4]).bytes()); }
Example 6
Source File: IdTest.java From hugegraph with Apache License 2.0 | 5 votes |
@Test public void testStringId() { Id id = IdGenerator.of("test-id"); Assert.assertEquals(IdType.STRING, id.type()); Assert.assertTrue(id.string()); Assert.assertFalse(id.number()); Assert.assertFalse(id.uuid()); Assert.assertEquals(7, id.length()); Assert.assertEquals("test-id", id.asString()); Assert.assertEquals("test-id", id.toString()); Assert.assertEquals("test-id", id.asObject()); Assert.assertArrayEquals(StringEncoding.encode("test-id"), id.asBytes()); Assert.assertEquals("test-id".hashCode(), id.hashCode()); Assert.assertEquals(IdGenerator.of("test-id"), id); Assert.assertNotEquals(IdGenerator.of("test-id2"), id); Assert.assertThrows(IllegalArgumentException.class, () -> { id.asLong(); }); Assert.assertEquals("test-id", IdGenerator.asStoredString(id)); Assert.assertEquals(id, IdGenerator.ofStoredString("test-id", IdType.STRING)); }
Example 7
Source File: StringEncodingTest.java From hugegraph with Apache License 2.0 | 5 votes |
@Test public void testCompress() { Assert.assertArrayEquals(Bytes.fromHex("1f8b080000000000000003" + "000000000000000000"), StringEncoding.compress("")); Assert.assertArrayEquals(Bytes.fromHex("1f8b08000000000000004b" + "4c4a0600c241243503000000"), StringEncoding.compress("abc")); }
Example 8
Source File: LineTest.java From hugegraph-loader with Apache License 2.0 | 5 votes |
@Test public void testRetainAll() { Line line = new Line("1,marko,27", new String[]{"id", "name", "age"}, new Object[]{1, "marko", 27}); line.retainAll(new String[]{"id"}); Assert.assertArrayEquals(new String[]{"id"}, line.names()); Assert.assertArrayEquals(new Object[]{1}, line.values()); }
Example 9
Source File: BytesBufferTest.java From hugegraph with Apache License 2.0 | 5 votes |
@Test public void testStringIdWithBigSize() { Id id = IdGenerator.of(genString(127)); byte[] bytes = genBytes(128); bytes[0] = (byte) 0xfe; Assert.assertArrayEquals(bytes, BytesBuffer.allocate(0) .writeId(id).bytes()); Assert.assertEquals(id, BytesBuffer.wrap(bytes).readId()); id = IdGenerator.of(genString(128)); bytes = genBytes(129); bytes[0] = (byte) 0xff; Assert.assertArrayEquals(bytes, BytesBuffer.allocate(0) .writeId(id).bytes()); Assert.assertEquals(id, BytesBuffer.wrap(bytes).readId()); Assert.assertThrows(IllegalArgumentException.class, () -> { BytesBuffer.allocate(0).writeId(IdGenerator.of(genString(129))); }, e -> { Assert.assertContains("Id max length is 128, but got 129", e.getMessage()); }); Assert.assertThrows(IllegalArgumentException.class, () -> { BytesBuffer.allocate(0).writeId(IdGenerator.of(genString(130))); }, e -> { Assert.assertContains("Id max length is 128, but got 130", e.getMessage()); }); }
Example 10
Source File: StringEncodingTest.java From hugegraph with Apache License 2.0 | 5 votes |
@Test public void testEncode() { Assert.assertArrayEquals(new byte[]{}, StringEncoding.encode("")); Assert.assertArrayEquals(new byte[]{97, 98, 99}, StringEncoding.encode("abc")); }
Example 11
Source File: IdTest.java From hugegraph with Apache License 2.0 | 5 votes |
@Test public void testLongId() { Id id = IdGenerator.of(123L); Assert.assertEquals(IdType.LONG, id.type()); Assert.assertFalse(id.string()); Assert.assertTrue(id.number()); Assert.assertFalse(id.uuid()); Assert.assertEquals(8, id.length()); Assert.assertEquals(123L, id.asLong()); Assert.assertEquals(123L, id.asObject()); Assert.assertEquals("123", id.asString()); Assert.assertEquals("123", id.toString()); Assert.assertArrayEquals(NumericUtil.longToBytes(123L), id.asBytes()); Assert.assertEquals(Long.hashCode(123L), id.hashCode()); Assert.assertEquals(IdGenerator.of(123L), id); Assert.assertEquals(IdGenerator.of(123), id); Assert.assertNotEquals(IdGenerator.of(1233), id); Assert.assertNotEquals(IdGenerator.of("123"), id); Assert.assertEquals("1w", IdGenerator.asStoredString(id)); Assert.assertEquals(id, IdGenerator.ofStoredString("1w", IdType.LONG)); }
Example 12
Source File: PathSerializerTest.java From hugegraph-client with Apache License 2.0 | 5 votes |
@Test public void testDeserializePathWithSimpleType() { String json = "{" + "\"labels\":[" + "[]," + "[]" + "]," + "\"objects\":[" + "\"marko\"," + "\"lop\"" + "]" + "}"; Path path = deserialize(json, Path.class); Assert.assertEquals(2, path.labels().size()); Assert.assertEquals(ImmutableList.of(), path.labels().get(0)); Assert.assertEquals(ImmutableList.of(), path.labels().get(1)); Assert.assertEquals(2, path.objects().size()); Assert.assertArrayEquals(new Object[]{"marko", "lop"}, path.objects().toArray()); json = "{" + "\"labels\":[" + "[]," + "[]" + "]," + "\"objects\":[" + "29," + "32" + "]" + "}"; path = deserialize(json, Path.class); Assert.assertEquals(2, path.objects().size()); Assert.assertArrayEquals(new Object[]{29, 32}, path.objects().toArray()); }
Example 13
Source File: RocksDBSessionsTest.java From hugegraph with Apache License 2.0 | 5 votes |
@Test public void testDeleteByRangeWithSignedBytes() throws RocksDBException { Session session = this.rocks.session(); byte[] key11 = new byte[]{1, 1}; byte[] value11 = b("value-1-1"); session.put(TABLE, key11, value11); byte[] key12 = new byte[]{1, -2}; byte[] value12 = b("value-1-2"); session.put(TABLE, key12, value12); byte[] key21 = new byte[]{2, 1}; byte[] value21 = b("value-2-1"); session.put(TABLE, key21, value21); session.delete(TABLE, new byte[]{1, -3}, new byte[]{1, 3}); this.commit(); Assert.assertArrayEquals(value11, session.get(TABLE, key11)); Assert.assertArrayEquals(value12, session.get(TABLE, key12)); Assert.assertArrayEquals(value21, session.get(TABLE, key21)); session.delete(TABLE, new byte[]{1, 1}, new byte[]{1, -1}); this.commit(); Assert.assertArrayEquals(null, session.get(TABLE, key11)); Assert.assertArrayEquals(null, session.get(TABLE, key12)); Assert.assertArrayEquals(value21, session.get(TABLE, key21)); }
Example 14
Source File: BytesTest.java From hugegraph-common with Apache License 2.0 | 5 votes |
@Test public void testBytesConcat() { Assert.assertArrayEquals(b("12345678"), Bytes.concat(b("1234"), b("5678"))); Assert.assertArrayEquals(b("12345678"), Bytes.concat(b("12345678"), b(""))); Assert.assertArrayEquals(b("12345678"), Bytes.concat(b(""), b("12345678"))); }
Example 15
Source File: StringUtilTest.java From hugegraph-common with Apache License 2.0 | 5 votes |
@Test public void testSplit() { Assert.assertArrayEquals(new String[]{"1", "2", "3"}, StringUtil.split("1, 2, 3", ", ")); Assert.assertArrayEquals(new String[]{"1", "1", "1"}, StringUtil.split("1 1 1", " ")); Assert.assertArrayEquals(new String[]{"", "", ""}, StringUtil.split("111", "1")); Assert.assertEquals(guavaSplit("123", " "), toStringList(StringUtil.split("123", " "))); Assert.assertEquals(guavaSplit("1 2 3", " "), toStringList(StringUtil.split("1 2 3", " "))); Assert.assertEquals(guavaSplit("1:2:3", ":"), toStringList(StringUtil.split("1:2:3", ":"))); Assert.assertEquals(guavaSplit("1::2:3", ":"), toStringList(StringUtil.split("1::2:3", ":"))); Assert.assertEquals(guavaSplit("1::2::3", ":"), toStringList(StringUtil.split("1::2::3", ":"))); Assert.assertEquals(guavaSplit("1::2::3", "::"), toStringList(StringUtil.split("1::2::3", "::"))); Assert.assertEquals(guavaSplit("1:|2|:3", "|"), toStringList(StringUtil.split("1:|2|:3", "|"))); Assert.assertEquals(guavaSplit("1\t2\t3", "\t"), toStringList(StringUtil.split("1\t2\t3", "\t"))); Assert.assertThrows(IllegalArgumentException.class, () -> { StringUtil.split("123", ""); }); }
Example 16
Source File: IdTest.java From hugegraph with Apache License 2.0 | 4 votes |
@Test public void testUuidId() { Id id = IdGenerator.of("835e1153-9281-4957-8691-cf79258e90eb", true); Assert.assertEquals(IdType.UUID, id.type()); Assert.assertFalse(id.string()); Assert.assertFalse(id.number()); Assert.assertTrue(id.uuid()); Assert.assertEquals(16, id.length()); Assert.assertEquals("835e1153-9281-4957-8691-cf79258e90eb", id.asObject().toString()); Assert.assertEquals("835e1153-9281-4957-8691-cf79258e90eb", id.asString()); Assert.assertEquals("835e1153-9281-4957-8691-cf79258e90eb", id.toString()); byte[] h = NumericUtil.longToBytes( Long.parseUnsignedLong("835e115392814957", 16)); byte[] l = NumericUtil.longToBytes( Long.parseUnsignedLong("8691cf79258e90eb", 16)); Assert.assertArrayEquals(Bytes.concat(h, l), id.asBytes()); Id id2 = IdGenerator.of("835e1153928149578691cf79258e90eb", true); Id id3 = IdGenerator.of("835e1153928149578691cf79258e90eb", false); Id id4 = IdGenerator.of("835e1153928149578691cf79258e90ee", true); Assert.assertEquals(id2.hashCode(), id.hashCode()); Assert.assertEquals(id2, id); Assert.assertNotEquals(id3, id); Assert.assertNotEquals(id4, id); Assert.assertThrows(UnsupportedOperationException.class, () -> { id.asLong(); }); Assert.assertEquals("g14RU5KBSVeGkc95JY6Q6w==", IdGenerator.asStoredString(id)); Assert.assertEquals(id, IdGenerator.ofStoredString( "g14RU5KBSVeGkc95JY6Q6w==", IdType.UUID)); }
Example 17
Source File: RocksDBSessionsTest.java From hugegraph with Apache License 2.0 | 4 votes |
@Test public void testDeleteByRangeWithMinMaxByteValue() throws RocksDBException { Session session = this.rocks.session(); byte[] key11 = new byte[]{1, 0}; byte[] value11 = b("value-1-1"); session.put(TABLE, key11, value11); byte[] key12 = new byte[]{1, 127}; byte[] value12 = b("value-1-2"); session.put(TABLE, key12, value12); byte[] key13 = new byte[]{1, (byte) 0x80}; // 128 byte[] value13 = b("value-1-3"); session.put(TABLE, key13, value13); byte[] key14 = new byte[]{1, (byte) 0xff}; // 255 byte[] value14 = b("value-1-4"); session.put(TABLE, key14, value14); byte[] key20 = new byte[]{2, 0}; byte[] value20 = b("value-2-0"); session.put(TABLE, key20, value20); session.delete(TABLE, new byte[]{1, 0}, new byte[]{1, (byte) 0xff}); this.commit(); Assert.assertArrayEquals(null, session.get(TABLE, key11)); Assert.assertArrayEquals(null, session.get(TABLE, key12)); Assert.assertArrayEquals(null, session.get(TABLE, key13)); Assert.assertArrayEquals(value14, session.get(TABLE, key14)); Assert.assertArrayEquals(value20, session.get(TABLE, key20)); session.delete(TABLE, new byte[]{1, (byte) 0xff}, new byte[]{2, 0}); this.commit(); Assert.assertArrayEquals(null, session.get(TABLE, key11)); Assert.assertArrayEquals(null, session.get(TABLE, key12)); Assert.assertArrayEquals(null, session.get(TABLE, key13)); Assert.assertArrayEquals(null, session.get(TABLE, key14)); Assert.assertArrayEquals(value20, session.get(TABLE, key20)); }
Example 18
Source File: RocksDBSessionsTest.java From hugegraph with Apache License 2.0 | 4 votes |
@Test public void testScanByRangeWithSignedBytes() throws RocksDBException { Session session = this.rocks.session(); byte[] key11 = new byte[]{1, 1}; byte[] value11 = b("value-1-1"); session.put(TABLE, key11, value11); byte[] key12 = new byte[]{1, 2}; byte[] value12 = b("value-1-2"); session.put(TABLE, key12, value12); byte[] key13 = new byte[]{1, -3}; byte[] value13 = b("value-1-3"); session.put(TABLE, key13, value13); byte[] key21 = new byte[]{2, 1}; byte[] value21 = b("value-2-1"); session.put(TABLE, key21, value21); this.commit(); Iterator<BackendColumn> iter; iter = session.scan(TABLE, new byte[]{1, -1}, new byte[]{1, 3}); Assert.assertFalse(iter.hasNext()); iter = session.scan(TABLE, new byte[]{1, 1}, new byte[]{1, -1}); Map<ByteBuffer, byte[]> results = new HashMap<>(); while (iter.hasNext()) { BackendColumn col = iter.next(); results.put(ByteBuffer.wrap(col.name), col.value); } Assert.assertEquals(3, results.size()); Assert.assertArrayEquals(value11, results.get(ByteBuffer.wrap(key11))); Assert.assertArrayEquals(value12, results.get(ByteBuffer.wrap(key12))); Assert.assertArrayEquals(value13, results.get(ByteBuffer.wrap(key13))); Assert.assertArrayEquals(value21, session.get(TABLE, key21)); }
Example 19
Source File: RocksDBSessionsTest.java From hugegraph with Apache License 2.0 | 4 votes |
@Test public void testScanByRangeWithBytes() throws RocksDBException { Session session = this.rocks.session(); byte[] key11 = new byte[]{1, 1}; byte[] value11 = b("value-1-1"); session.put(TABLE, key11, value11); byte[] key12 = new byte[]{1, 2}; byte[] value12 = b("value-1-2"); session.put(TABLE, key12, value12); byte[] key21 = new byte[]{2, 1}; byte[] value21 = b("value-2-1"); session.put(TABLE, key21, value21); byte[] key22 = new byte[]{2, 2}; byte[] value22 = b("value-2-2"); session.put(TABLE, key22, value22); byte[] key23 = new byte[]{2, 3}; byte[] value23 = b("value-2-3"); session.put(TABLE, key23, value23); this.commit(); Map<ByteBuffer, byte[]> results = new HashMap<>(); Iterator<BackendColumn> iter = session.scan(TABLE, new byte[]{1, 0}, new byte[]{2, 3}); while (iter.hasNext()) { BackendColumn col = iter.next(); results.put(ByteBuffer.wrap(col.name), col.value); } Assert.assertEquals(4, results.size()); Assert.assertArrayEquals(value11, results.get(ByteBuffer.wrap(key11))); Assert.assertArrayEquals(value12, results.get(ByteBuffer.wrap(key12))); Assert.assertArrayEquals(value21, results.get(ByteBuffer.wrap(key21))); Assert.assertArrayEquals(value22, results.get(ByteBuffer.wrap(key22))); Assert.assertArrayEquals(value23, session.get(TABLE, key23)); }
Example 20
Source File: BytesBufferTest.java From hugegraph with Apache License 2.0 | 4 votes |
@Test public void testString() { BytesBuffer buf = BytesBuffer.allocate(0); buf.writeStringRaw("any"); byte[] bytes = genBytes("616e79"); Assert.assertArrayEquals(bytes, buf.bytes()); buf.forReadWritten(); Assert.assertEquals("any", buf.readStringFromRemaining()); bytes = genBytes("61626364"); buf = BytesBuffer.allocate(0); Assert.assertArrayEquals(bytes, buf.writeStringToRemaining("abcd").bytes()); Assert.assertEquals("abcd", BytesBuffer.wrap(bytes).readStringFromRemaining()); bytes = genBytes("0461626364"); buf = BytesBuffer.allocate(0); Assert.assertArrayEquals(bytes, buf.writeString("abcd").bytes()); Assert.assertEquals("abcd", BytesBuffer.wrap(bytes).readString()); bytes = genBytes("61626364ff"); buf = BytesBuffer.allocate(0); Assert.assertArrayEquals(bytes, buf.writeStringWithEnding("abcd").bytes()); Assert.assertEquals("abcd", BytesBuffer.wrap(bytes).readStringWithEnding()); bytes = genBytes("616200ff"); buf = BytesBuffer.allocate(0); Assert.assertArrayEquals(bytes, buf.writeStringWithEnding("ab\u0000").bytes()); Assert.assertEquals("ab\u0000", BytesBuffer.wrap(bytes).readStringWithEnding()); bytes = genBytes("616201ff"); buf = BytesBuffer.allocate(0); Assert.assertArrayEquals(bytes, buf.writeStringWithEnding("ab\u0001").bytes()); Assert.assertEquals("ab\u0001", BytesBuffer.wrap(bytes).readStringWithEnding()); }