Repository navigation
Expand file tree
/
Copy pathCompressTest.java
More file actions
62 lines (45 loc) · 1.7 KB
/
Copy pathCompressTest.java
File metadata and controls
62 lines (45 loc) · 1.7 KB
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
60
61
62
package org.mapdb;
import org.junit.Test;
import java.io.IOException;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class CompressTest{
DB db = DBMaker
.newMemoryDB()
.cacheDisable()
.compressionEnable()
.make();
@Test
public void check_instance() throws Exception {
Store s = Store.forDB(db);
assertTrue(s.compress);
}
@Test
public void put_get_update() throws Exception {
long recid = db.engine.put("aaaa", Serializer.STRING_NOSIZE);
assertEquals("aaaa",db.engine.get(recid, Serializer.STRING_NOSIZE));
db.engine.update(recid, "bbbb", Serializer.STRING_NOSIZE);
assertEquals("bbbb",db.engine.get(recid, Serializer.STRING_NOSIZE));
db.engine.delete(recid,Serializer.STRING_NOSIZE);
assertEquals(null,db.engine.get(recid, Serializer.STRING_NOSIZE));
}
@Test
public void short_compression() throws Exception {
byte[] b = new byte[]{1,2,3,4,5,33,3};
byte[] b2 = UtilsTest.clone(b, new Serializer.CompressionWrapper<byte[]>(Serializer.BYTE_ARRAY));
assertArrayEquals(b,b2);
}
@Test public void large_compression() throws IOException {
byte[] b = new byte[1024];
b[0] = 1;
b[4] = 5;
b[1000] = 1;
Serializer<byte[]> ser = new Serializer.CompressionWrapper<byte[]>(Serializer.BYTE_ARRAY);
assertArrayEquals(b, UtilsTest.clone(b, ser));
//check compressed size is actually smaller
DataOutput2 out = new DataOutput2();
ser.serialize(out,b);
assertTrue(out.pos<100);
}
}