From f1e4478020579c0b815e74bdadf402ab697d9d35 Mon Sep 17 00:00:00 2001 From: Nicole00 Date: Tue, 25 Jan 2022 13:41:06 +0800 Subject: [PATCH] add vertexKey without tag& add test --- .../vesoft/nebula/encoder/NebulaCodec.java | 4 + .../nebula/encoder/NebulaCodecImpl.java | 100 +++++++---- .../vesoft/nebula/encoder/TestEncoder.java | 165 ++++++++++-------- 3 files changed, 158 insertions(+), 111 deletions(-) diff --git a/client/src/main/java/com/vesoft/nebula/encoder/NebulaCodec.java b/client/src/main/java/com/vesoft/nebula/encoder/NebulaCodec.java index e5c53de3a..acdc15749 100644 --- a/client/src/main/java/com/vesoft/nebula/encoder/NebulaCodec.java +++ b/client/src/main/java/com/vesoft/nebula/encoder/NebulaCodec.java @@ -15,6 +15,10 @@ byte[] vertexKey(int vidLen, byte[] vertexId, int tagId); + byte[] orphanVertexKey(int vidLen, + int partitionId, + byte[] vertexId); + byte[] edgeKey(int vidLen, int partitionId, byte[] srcId, diff --git a/client/src/main/java/com/vesoft/nebula/encoder/NebulaCodecImpl.java b/client/src/main/java/com/vesoft/nebula/encoder/NebulaCodecImpl.java index 8e9e0345c..6db29f615 100644 --- a/client/src/main/java/com/vesoft/nebula/encoder/NebulaCodecImpl.java +++ b/client/src/main/java/com/vesoft/nebula/encoder/NebulaCodecImpl.java @@ -17,9 +17,9 @@ import java.util.List; /** - * NebulaCodecImpl is an encoder to generate the given data. - * If the schema with default value, and the filed without given data, it will throw error. - * TODO: Support default value + * NebulaCodecImpl is an encoder to generate the given data. + * If the schema with default value, and the filed without given data, it will throw error. + * TODO: Support default value */ public class NebulaCodecImpl implements NebulaCodec { private static final int PARTITION_ID_SIZE = 4; @@ -29,10 +29,11 @@ public class NebulaCodecImpl implements NebulaCodec { private static final int EDGE_VER_PLACE_HOLDER_SIZE = 1; private static final int VERTEX_SIZE = PARTITION_ID_SIZE + TAG_ID_SIZE; private static final int EDGE_SIZE = PARTITION_ID_SIZE + EDGE_TYPE_SIZE - + EDGE_RANKING_SIZE + EDGE_VER_PLACE_HOLDER_SIZE; + + EDGE_RANKING_SIZE + EDGE_VER_PLACE_HOLDER_SIZE; private static final int VERTEX_KEY_TYPE = 0x00000001; private static final int EDGE_KEY_TYPE = 0x00000002; + private static final int ORPHAN_VERTEX_KEY_TYPE = 0x00000007; private static final int SEEK = 0xc70f6907; private final ByteOrder byteOrder; @@ -41,10 +42,10 @@ public NebulaCodecImpl() { } /** - * @param vidLen the vidLen from the space description + * @param vidLen the vidLen from the space description * @param partitionId the partitionId - * @param vertexId the vertex id - * @param tagId the tag id + * @param vertexId the vertex id + * @param tagId the tag id * @return */ @Override @@ -60,7 +61,7 @@ public byte[] vertexKey(int vidLen, buffer.order(this.byteOrder); partitionId = (partitionId << 8) | VERTEX_KEY_TYPE; buffer.putInt(partitionId) - .put(vertexId); + .put(vertexId); if (vertexId.length < vidLen) { ByteBuffer complementVid = ByteBuffer.allocate(vidLen - vertexId.length); Arrays.fill(complementVid.array(), (byte) '\0'); @@ -71,12 +72,39 @@ public byte[] vertexKey(int vidLen, } /** - * @param vidLen the vidLen from the space description + * @param vidLen the vidLen from the space description * @param partitionId the partitionId - * @param srcId the src id - * @param edgeType the edge type - * @param edgeRank the ranking - * @param dstId the dstId + * @param vertexId the vertex id + * @return + */ + @Override + public byte[] orphanVertexKey(int vidLen, + int partitionId, + byte[] vertexId) { + if (vertexId.length > vidLen) { + throw new RuntimeException( + "The length of vid size is out of the range, expected vidLen less then " + vidLen); + } + ByteBuffer buffer = ByteBuffer.allocate(PARTITION_ID_SIZE + vidLen); + buffer.order(this.byteOrder); + partitionId = (partitionId << 8) | ORPHAN_VERTEX_KEY_TYPE; + buffer.putInt(partitionId) + .put(vertexId); + if (vertexId.length < vidLen) { + ByteBuffer complementVid = ByteBuffer.allocate(vidLen - vertexId.length); + Arrays.fill(complementVid.array(), (byte) '\0'); + buffer.put(complementVid); + } + return buffer.array(); + } + + /** + * @param vidLen the vidLen from the space description + * @param partitionId the partitionId + * @param srcId the src id + * @param edgeType the edge type + * @param edgeRank the ranking + * @param dstId the dstId * @return byte[] */ @Override @@ -86,16 +114,16 @@ public byte[] edgeKeyByDefaultVer(int vidLen, int edgeType, long edgeRank, byte[] dstId) { - return edgeKey(vidLen, partitionId, srcId, edgeType, edgeRank, dstId, (byte)1); + return edgeKey(vidLen, partitionId, srcId, edgeType, edgeRank, dstId, (byte) 1); } /** - * @param vidLen the vidLen from the space description - * @param partitionId the partitionId - * @param srcId the src id - * @param edgeType the edge type - * @param edgeRank the ranking - * @param dstId the dstId + * @param vidLen the vidLen from the space description + * @param partitionId the partitionId + * @param srcId the src id + * @param edgeType the edge type + * @param edgeRank the ranking + * @param dstId the dstId * @param edgeVerHolder the edgeVerHolder * @return byte[] */ @@ -134,8 +162,8 @@ public byte[] edgeKey(int vidLen, } /** - * @param tag the TagItem - * @param names the property names + * @param tag the TagItem + * @param names the property names * @param values the property values * @return the encode byte[] * @throws RuntimeException expection @@ -143,7 +171,7 @@ public byte[] edgeKey(int vidLen, @Override public byte[] encodeTag(TagItem tag, List names, - List values) throws RuntimeException { + List values) throws RuntimeException { if (tag == null) { throw new RuntimeException("TagItem is null"); } @@ -152,8 +180,8 @@ public byte[] encodeTag(TagItem tag, } /** - * @param edge the EdgeItem - * @param names the property names + * @param edge the EdgeItem + * @param names the property names * @param values the property values * @return the encode byte[] * @throws RuntimeException expection @@ -161,7 +189,7 @@ public byte[] encodeTag(TagItem tag, @Override public byte[] encodeEdge(EdgeItem edge, List names, - List values) throws RuntimeException { + List values) throws RuntimeException { if (edge == null) { throw new RuntimeException("EdgeItem is null"); } @@ -171,8 +199,8 @@ public byte[] encodeEdge(EdgeItem edge, /** * @param schema the schema - * @param ver the version of tag or edge - * @param names the property names + * @param ver the version of tag or edge + * @param names the property names * @param values the property values * @return the encode byte[] * @throws RuntimeException expection @@ -181,11 +209,11 @@ private byte[] encode(Schema schema, long ver, List names, List values) - throws RuntimeException { + throws RuntimeException { if (names.size() != values.size()) { throw new RuntimeException( - String.format("The names' size no equal with values' size, [%d] != [%d]", - names.size(), values.size())); + String.format("The names' size no equal with values' size, [%d] != [%d]", + names.size(), values.size())); } RowWriterImpl writer = new RowWriterImpl(genSchemaProvider(ver, schema), this.byteOrder); for (int i = 0; i < names.size(); i++) { @@ -204,11 +232,11 @@ private SchemaProviderImpl genSchemaProvider(long ver, Schema schema) { int len = type.isSetType_length() ? type.getType_length() : 0; GeoShape geoShape = type.isSetGeo_shape() ? type.getGeo_shape() : GeoShape.ANY; schemaProvider.addField(new String(col.getName()), - type.type.getValue(), - len, - nullable, - hasDefault ? col.getDefault_value() : null, - geoShape.getValue()); + type.type.getValue(), + len, + nullable, + hasDefault ? col.getDefault_value() : null, + geoShape.getValue()); } return schemaProvider; } diff --git a/client/src/test/java/com/vesoft/nebula/encoder/TestEncoder.java b/client/src/test/java/com/vesoft/nebula/encoder/TestEncoder.java index 7a0012781..e11e0998a 100644 --- a/client/src/test/java/com/vesoft/nebula/encoder/TestEncoder.java +++ b/client/src/test/java/com/vesoft/nebula/encoder/TestEncoder.java @@ -37,27 +37,27 @@ public class TestEncoder { private final NebulaCodecImpl codec = new NebulaCodecImpl(); final String allTypeValueExpectResult = "090ce001081000200000004000000000000000" - + "db0f49406957148b0abf05407d0000000c0000004e6562756c61204772617068bb334e5e" - + "00000000e40702140a1e2d00000000e40702140a1e2d0000000000000000000000000000" - + "000089000000150000009e00000039000000d70000009100000000000000000000004865" - + "6c6c6f20776f726c6421010100000000000000006066409a999999997956400102000000" - + "030000000000000000000000000000000000f03f000000000000f03f0000000000000040" - + "00000000000008400000000000001c4001030000000200000004000000cdcccccccc2c5b" - + "c0000000000080414000000000000059c00000000000404740cdccccccccac56c0333333" - + "3333734140cdcccccccc2c5bc000000000008041400400000066666666660659c0333333" - + "3333b344409a99999999b959c0cdcccccccccc424033333333333358c00000000000c042" - + "4066666666660659c03333333333b34440"; + + "db0f49406957148b0abf05407d0000000c0000004e6562756c61204772617068bb334e5e" + + "00000000e40702140a1e2d00000000e40702140a1e2d0000000000000000000000000000" + + "000089000000150000009e00000039000000d70000009100000000000000000000004865" + + "6c6c6f20776f726c6421010100000000000000006066409a999999997956400102000000" + + "030000000000000000000000000000000000f03f000000000000f03f0000000000000040" + + "00000000000008400000000000001c4001030000000200000004000000cdcccccccc2c5b" + + "c0000000000080414000000000000059c00000000000404740cdccccccccac56c0333333" + + "3333734140cdcccccccc2c5bc000000000008041400400000066666666660659c0333333" + + "3333b344409a99999999b959c0cdcccccccccc424033333333333358c00000000000c042" + + "4066666666660659c03333333333b34440"; private List getCols() { - return Arrays.asList("Col01","Col02", "Col03", "Col04", "Col05", "Col06", - "Col07","Col08", "Col09", "Col10", "Col11", "Col12", "Col13", "Col14", - // Purposely skip the col15 - "Col16", "Col17", "Col18", "Col19"); + return Arrays.asList("Col01", "Col02", "Col03", "Col04", "Col05", "Col06", + "Col07", "Col08", "Col09", "Col10", "Col11", "Col12", "Col13", "Col14", + // Purposely skip the col15 + "Col16", "Col17", "Col18", "Col19"); } private List getValues() { final double e = 2.71828182845904523536028747135266249775724709369995; - final float pi = (float)3.14159265358979; + final float pi = (float) 3.14159265358979; final Value strVal = new Value(); strVal.setSVal("Hello world!".getBytes()); final Value fixVal = new Value(); @@ -67,12 +67,12 @@ private List getValues() { final Value intVal = new Value(); intVal.setIVal(64); final Value timeVal = new Value(); - timeVal.setTVal(new Time((byte)10, (byte)30, (byte)45, 0)); + timeVal.setTVal(new Time((byte) 10, (byte) 30, (byte) 45, 0)); final Value datetimeValue = new Value(); - datetimeValue.setDtVal(new DateTime((short)2020, (byte)2, (byte)20, - (byte)10, (byte)30, (byte)45, 0)); + datetimeValue.setDtVal(new DateTime((short) 2020, (byte) 2, (byte) 20, + (byte) 10, (byte) 30, (byte) 45, 0)); final Value dateValue = new Value(); - dateValue.setDVal(new Date((short)2020, (byte)2, (byte)20)); + dateValue.setDVal(new Date((short) 2020, (byte) 2, (byte) 20)); final Value nullVal = new Value(); nullVal.setNVal(NullType.__NULL__); // geograph point @@ -106,8 +106,8 @@ private List getValues() { rings.add(hole); geogPolygonVal.setGgVal(Geography.pgVal(new Polygon(rings))); return Arrays.asList(true, 8, 16, 32, intVal, pi, e, strVal, fixVal, - timestampVal, dateValue, timeVal, datetimeValue, nullVal, - geogPointVal, geogLineStringVal, geogPolygonVal, nullVal); + timestampVal, dateValue, timeVal, datetimeValue, nullVal, + geogPointVal, geogLineStringVal, geogPolygonVal, nullVal); } public int getSpaceVidLen(String spaceName) throws RuntimeException { @@ -138,7 +138,12 @@ public int getPartId(int partNum, String vertexId) { private byte[] getVertexKey(String spaceName, String vid, String tagName) { int tagId = cacheImplTest.getTag(spaceName, tagName).tag_id; return codec.vertexKey(getSpaceVidLen(spaceName), - getPartId(getPartSize(spaceName), vid), vid.getBytes(), tagId); + getPartId(getPartSize(spaceName), vid), vid.getBytes(), tagId); + } + + private byte[] getOrphanVertexKey(String spaceName, String vid, String tagName) { + return codec.orphanVertexKey(getSpaceVidLen(spaceName), + getPartId(getPartSize(spaceName), vid), vid.getBytes()); } private byte[] getInBoundEdgeKey(String spaceName, @@ -148,11 +153,11 @@ private byte[] getInBoundEdgeKey(String spaceName, Long ranking) { int edgeType = cacheImplTest.getEdge(spaceName, edgeName).edge_type; return codec.edgeKeyByDefaultVer(getSpaceVidLen(spaceName), - getPartId(getPartSize(spaceName), srcId), - srcId.getBytes(), - edgeType, - ranking, - dstId.getBytes()); + getPartId(getPartSize(spaceName), srcId), + srcId.getBytes(), + edgeType, + ranking, + dstId.getBytes()); } private byte[] getOutBoundEdgeKey(String spaceName, @@ -162,46 +167,52 @@ private byte[] getOutBoundEdgeKey(String spaceName, Long ranking) { int edgeType = cacheImplTest.getEdge(spaceName, edgeName).edge_type; return codec.edgeKeyByDefaultVer(getSpaceVidLen(spaceName), - getPartId(getPartSize(spaceName), dstId), - dstId.getBytes(), - -edgeType, - ranking, - srcId.getBytes()); + getPartId(getPartSize(spaceName), dstId), + dstId.getBytes(), + -edgeType, + ranking, + srcId.getBytes()); } @Test() public void testVertexKey() { // test vertexKey - byte[] vertexKey = getVertexKey("test_space","Tom", "person"); + byte[] vertexKey = getVertexKey("test_space", "Tom", "person"); String hexStr = Hex.encodeHexString(vertexKey); String expectResult = "01d80100546f6d00000000000000000000000000" - + "0000000002000000"; + + "0000000002000000"; + Assert.assertArrayEquals(expectResult.getBytes(), hexStr.getBytes()); + + // test orphanVertexKey + byte[] orphanVertexKey = getOrphanVertexKey("test_space", "Tom", "person"); + hexStr = Hex.encodeHexString(orphanVertexKey); + expectResult = "07d80100546f6d0000000000000000000000000000000000"; Assert.assertArrayEquals(expectResult.getBytes(), hexStr.getBytes()); // less than vidLen String vid = "0123456789"; - vertexKey = codec.vertexKey(10,123, vid.getBytes(), 2020); + vertexKey = codec.vertexKey(10, 123, vid.getBytes(), 2020); hexStr = Hex.encodeHexString(vertexKey); expectResult = "017b000030313233343536373839e4070000"; Assert.assertArrayEquals(expectResult.getBytes(), hexStr.getBytes()); // large than vidLen - vertexKey = codec.vertexKey(100,123, vid.getBytes(), 2020); + vertexKey = codec.vertexKey(100, 123, vid.getBytes(), 2020); hexStr = Hex.encodeHexString(vertexKey); expectResult = "017b00003031323334353637383900000000000000000000000000000000000" - + "00000000000000000000000000000000000000000000000000000000000000000000000000" - + "00000000000000000000000000000000000000000000000000000000000000000000000e407" - + "0000"; + + "00000000000000000000000000000000000000000000000000000000000000000000000000" + + "00000000000000000000000000000000000000000000000000000000000000000000000e407" + + "0000"; Assert.assertArrayEquals(expectResult.getBytes(), hexStr.getBytes()); } @Test() public void testEdgeKey() { // test edgeKey - byte[] edgeKey = getInBoundEdgeKey("test_space", "friend", "Kate","Lily", 0L); + byte[] edgeKey = getInBoundEdgeKey("test_space", "friend", "Kate", "Lily", 0L); String hexStr = Hex.encodeHexString(edgeKey); String expectResult = "02ef00004b617465000000000000000000000000000000000300000080000" - + "000000000004c696c790000000000000000000000000000000001"; + + "000000000004c696c790000000000000000000000000000000001"; Assert.assertArrayEquals(expectResult.getBytes(), hexStr.getBytes()); String srcVid = "0123456789"; @@ -209,41 +220,45 @@ public void testEdgeKey() { // less than vidLen edgeKey = codec.edgeKeyByDefaultVer( - 10,123, srcVid.getBytes(), 1010, 10L, dstVid.getBytes()); + 10, 123, srcVid.getBytes(), 1010, 10L, dstVid.getBytes()); hexStr = Hex.encodeHexString(edgeKey); expectResult = "027b000030313233343536373839f2030000800000000000000a3938373635343332313001"; Assert.assertArrayEquals(expectResult.getBytes(), hexStr.getBytes()); // large than vidLen edgeKey = codec.edgeKeyByDefaultVer( - 100,123, srcVid.getBytes(), 1010, 10L, dstVid.getBytes()); + 100, 123, srcVid.getBytes(), 1010, 10L, dstVid.getBytes()); hexStr = Hex.encodeHexString(edgeKey); expectResult = "027b0000303132333435363738390000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000f20300008000000000" - + "00000a3938373635343332313000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000000000000000000" - + "00000000000000000000000000000000000000000000000001"; + + "0000000000000000000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000f20300008000000000" + + "00000a3938373635343332313000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000000000000000000" + + "00000000000000000000000000000000000000000000000001"; Assert.assertArrayEquals(expectResult.getBytes(), hexStr.getBytes()); // less than vidLen with negative edgeType edgeKey = codec.edgeKeyByDefaultVer( - 10,123, srcVid.getBytes(), -1010, 10L, dstVid.getBytes()); + 10, 123, srcVid.getBytes(), -1010, 10L, dstVid.getBytes()); hexStr = Hex.encodeHexString(edgeKey); expectResult = "027b0000303132333435363738390efcffff800000000000000a39" - + "38373635343332313001"; + + "38373635343332313001"; Assert.assertArrayEquals(expectResult.getBytes(), hexStr.getBytes()); // large than vidLen with negative edgeType edgeKey = codec.edgeKeyByDefaultVer( - 100,123, srcVid.getBytes(), -1010, 10L, dstVid.getBytes()); + 100, 123, srcVid.getBytes(), -1010, 10L, dstVid.getBytes()); hexStr = Hex.encodeHexString(edgeKey); expectResult = "027b0000303132333435363738390000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000000000000000000000" - + "00000000000000000000000000000000000000000000000000000000efcffff800000000000000a393" - + "8373635343332313000000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000000000000000000000" - + "00000000000000000000000000000000001"; + + + "0000000000000000000000000000000000000000000000000000000000000000000000000000000000" + + + "00000000000000000000000000000000000000000000000000000000efcffff800000000000000a393" + + + "8373635343332313000000000000000000000000000000000000000000000000000000000000000000" + + + "0000000000000000000000000000000000000000000000000000000000000000000000000000000000" + + "00000000000000000000000000000000001"; Assert.assertArrayEquals(expectResult.getBytes(), hexStr.getBytes()); } @@ -251,7 +266,7 @@ public void testEdgeKey() { public void testEncodeVertexValue() { // encode failed, loss filed value List colNames = Arrays.asList("Col01", "Col02", "Col03", "Col04", "Col05"); - List colVals = Arrays.asList(true, 8, 16, 32, (long)100); + List colVals = Arrays.asList(true, 8, 16, 32, (long) 100); TagItem tagItem1 = cacheImplTest.getTag("test", "tag_no_default"); TagItem tagItem2 = cacheImplTest.getTag("test", "tag_with_empty_string"); TagItem tagItem3 = cacheImplTest.getTag("test", "tag_with_default"); @@ -273,7 +288,7 @@ public void testEncodeVertexValue() { // FileOutputStream fileOutputStream = new FileOutputStream(file); // fileOutputStream.write(encodeStr); Assert.assertArrayEquals(allTypeValueExpectResult.getBytes(), - hexStr.substring(0, hexStr.length() - 16).getBytes()); + hexStr.substring(0, hexStr.length() - 16).getBytes()); } catch (Exception exception) { exception.printStackTrace(); Assert.fail(exception.getMessage()); @@ -282,11 +297,11 @@ public void testEncodeVertexValue() { // encode empty string succeeded try { byte[] encodeStr = codec.encodeTag(tagItem2, - Collections.singletonList("Col01"), Collections.singletonList("")); + Collections.singletonList("Col01"), Collections.singletonList("")); String hexStr = Hex.encodeHexString(encodeStr); String expectResult = "080900000000000000"; Assert.assertArrayEquals(expectResult.getBytes(), - hexStr.substring(0, hexStr.length() - 16).getBytes()); + hexStr.substring(0, hexStr.length() - 16).getBytes()); } catch (Exception exception) { exception.printStackTrace(); Assert.fail(exception.getMessage()); @@ -297,18 +312,18 @@ public void testEncodeVertexValue() { codec.encodeTag(tagItem3, Arrays.asList("Col01", "Col02"), Arrays.asList(true, 8)); } catch (RuntimeException e) { Assert.assertArrayEquals(e.getMessage().getBytes(), - "Unsupported default value yet".getBytes()); + "Unsupported default value yet".getBytes()); assert (true); } // test without string type try { byte[] encodeStr = codec.encodeTag( - tagItem4, Arrays.asList("Col01"), Arrays.asList(1024)); + tagItem4, Arrays.asList("Col01"), Arrays.asList(1024)); String hexStr = Hex.encodeHexString(encodeStr); String expectResult = "09070004000000000000"; Assert.assertArrayEquals(expectResult.getBytes(), - hexStr.substring(0, hexStr.length() - 16).getBytes()); + hexStr.substring(0, hexStr.length() - 16).getBytes()); } catch (Exception exception) { exception.printStackTrace(); Assert.fail(exception.getMessage()); @@ -320,7 +335,7 @@ public void testEncodeVertexValue() { String hexStr = Hex.encodeHexString(encodeStr); String expectResult = "0907"; Assert.assertArrayEquals(expectResult.getBytes(), - hexStr.substring(0, hexStr.length() - 16).getBytes()); + hexStr.substring(0, hexStr.length() - 16).getBytes()); } catch (Exception exception) { exception.printStackTrace(); Assert.fail(exception.getMessage()); @@ -329,12 +344,12 @@ public void testEncodeVertexValue() { // test with chinese value try { byte[] encodeStr = codec.encodeTag(tagItem2, - Collections.singletonList("Col01"), - Collections.singletonList("中国")); + Collections.singletonList("Col01"), + Collections.singletonList("中国")); String hexStr = Hex.encodeHexString(encodeStr); String expectResult = "080900000006000000e4b8ade59bbd"; Assert.assertArrayEquals(expectResult.getBytes(), - hexStr.substring(0, hexStr.length() - 16).getBytes()); + hexStr.substring(0, hexStr.length() - 16).getBytes()); } catch (Exception exception) { exception.printStackTrace(); Assert.fail(exception.getMessage()); @@ -345,7 +360,7 @@ public void testEncodeVertexValue() { public void testEncodeEdge() { // encode failed, loss filed value List colNames = Arrays.asList("Col01", "Col02", "Col03", "Col04", "Col05"); - List colVals = Arrays.asList(true, 8, 16, 32, (long)100); + List colVals = Arrays.asList(true, 8, 16, 32, (long) 100); EdgeItem edgeItem1 = cacheImplTest.getEdge("test", "edge_no_default"); EdgeItem edgeItem2 = cacheImplTest.getEdge("test", "edge_with_empty_string"); EdgeItem edgeItem3 = cacheImplTest.getEdge("test", "edge_without_property"); @@ -361,8 +376,8 @@ public void testEncodeEdge() { byte[] encodeStr = codec.encodeEdge(edgeItem1, getCols(), getValues()); String hexStr = Hex.encodeHexString(encodeStr); Assert.assertArrayEquals( - allTypeValueExpectResult.getBytes(), - hexStr.substring(0, hexStr.length() - 16).getBytes()); + allTypeValueExpectResult.getBytes(), + hexStr.substring(0, hexStr.length() - 16).getBytes()); } catch (Exception exception) { exception.printStackTrace(); Assert.fail(exception.getMessage()); @@ -370,11 +385,11 @@ public void testEncodeEdge() { // encode empty string succeeded try { byte[] encodeStr = codec.encodeEdge(edgeItem2, - Collections.singletonList("Col01"), Collections.singletonList("")); + Collections.singletonList("Col01"), Collections.singletonList("")); String hexStr = Hex.encodeHexString(encodeStr); String expectResult = "080900000000000000"; Assert.assertArrayEquals(expectResult.getBytes(), - hexStr.substring(0, hexStr.length() - 16).getBytes()); + hexStr.substring(0, hexStr.length() - 16).getBytes()); } catch (Exception exception) { exception.printStackTrace(); Assert.fail(exception.getMessage()); @@ -386,7 +401,7 @@ public void testEncodeEdge() { String hexStr = Hex.encodeHexString(encodeStr); String expectResult = "0907"; Assert.assertArrayEquals(expectResult.getBytes(), - hexStr.substring(0, hexStr.length() - 16).getBytes()); + hexStr.substring(0, hexStr.length() - 16).getBytes()); } catch (Exception exception) { exception.printStackTrace(); Assert.fail(exception.getMessage()); @@ -402,7 +417,7 @@ public void testEncodeWithNotExistedSchema() { Assert.fail(); } catch (RuntimeException e) { Assert.assertArrayEquals(e.getMessage().getBytes(), - "TagItem is null".getBytes()); + "TagItem is null".getBytes()); assert (true); } @@ -411,7 +426,7 @@ public void testEncodeWithNotExistedSchema() { Assert.fail(); } catch (RuntimeException e) { Assert.assertArrayEquals(e.getMessage().getBytes(), - "EdgeItem is null".getBytes()); + "EdgeItem is null".getBytes()); assert (true); } }