Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
orisgarno committed Feb 6, 2025
1 parent 2de4407 commit 59645e9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.github.luben.zstd.Zstd;
import com.github.luben.zstd.ZstdException;

public class ZstdMetaCompressor implements MetaCompressor{
public class ZstdMetaCompressor implements MetaCompressor {

@Override
public byte[] compress(byte[] data, int offset, int size) {
Expand All @@ -34,8 +34,12 @@ public byte[] compress(byte[] data, int offset, int size) {

byte[] compressedData = new byte[(int) maxCompressedSize];
Zstd.compressByteArray(
compressedData, 0, (int)maxCompressedSize,
data, offset, size,
compressedData,
0,
(int) maxCompressedSize,
data,
offset,
size,
Zstd.defaultCompressionLevel());

return compressedData;
Expand All @@ -61,5 +65,4 @@ public boolean equals(Object o) {
}
return o != null && getClass() == o.getClass();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ public void testBasicClassDef() throws Exception {
Assert.assertEquals(classDef.getFieldsInfo(), fieldsInfo);
}

@Test
public void testBasicClassDef_zstdMetaCompressor() throws Exception {
Fury fury =
Fury.builder().withMetaShare(true).withMetaCompressor(new ZstdMetaCompressor()).build();
Class<ClassDefTest.TestFieldsOrderClass1> type = ClassDefTest.TestFieldsOrderClass1.class;
List<ClassDef.FieldInfo> fieldsInfo = buildFieldsInfo(fury.getClassResolver(), type);
MemoryBuffer buffer =
ClassDefEncoder.encodeClassDef(
fury.getClassResolver(), type, getClassFields(type, fieldsInfo), true);
ClassDef classDef = ClassDef.readClassDef(fury.getClassResolver(), buffer);
Assert.assertEquals(classDef.getClassName(), type.getName());
Assert.assertEquals(classDef.getFieldsInfo().size(), type.getDeclaredFields().length);
Assert.assertEquals(classDef.getFieldsInfo(), fieldsInfo);
}

@Test
public void testBigMetaEncoding() {
for (Class<?> type :
Expand Down

0 comments on commit 59645e9

Please sign in to comment.