This repository has been archived by the owner on May 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
TestZstdWrapper.java
59 lines (51 loc) · 1.87 KB
/
TestZstdWrapper.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.xiaomi.infra.pegasus.tools;
import com.xiaomi.infra.pegasus.client.PException;
import com.xiaomi.infra.pegasus.client.PegasusClientFactory;
import com.xiaomi.infra.pegasus.client.PegasusClientInterface;
import com.xiaomi.infra.pegasus.client.PegasusTableInterface;
import org.junit.Assert;
import org.junit.Test;
public class TestZstdWrapper {
@Test
public void testCompression() throws Exception {
PegasusClientInterface client = PegasusClientFactory.getSingletonClient();
PegasusTableInterface table = client.openTable("temp");
for (int t = 0; t < 4; t++) {
// generate a 10KB value
StringBuilder builder = new StringBuilder();
for (int i = 0; i < 10000; i++) {
builder.append('a' + t);
}
byte[] value = builder.toString().getBytes();
// write the record into pegasus
table.set("h".getBytes(), "s".getBytes(), ZstdWrapper.compress(value), 1000);
// read the record from pegasus
byte[] compressedBuf = table.get("h".getBytes(), "s".getBytes(), 1000);
// decompress the value
Assert.assertArrayEquals(ZstdWrapper.decompress(compressedBuf), value);
}
// ensure empty value won't break the program
{
try {
ZstdWrapper.decompress("".getBytes());
Assert.fail("expecting a IllegalArgumentException");
} catch (Exception e) {
Assert.assertTrue(e instanceof IllegalArgumentException);
}
try {
ZstdWrapper.decompress(null);
Assert.fail("expecting a IllegalArgumentException");
} catch (Exception e) {
Assert.assertTrue(e instanceof IllegalArgumentException);
}
}
{ // decompress invalid data
try {
ZstdWrapper.decompress("abc123".getBytes());
Assert.fail("expecting a PException");
} catch (Exception e) {
Assert.assertTrue(e instanceof PException);
}
}
}
}