Repository navigation
Expand file tree
/
Copy pathCompressTest.java
More file actions
65 lines (47 loc) · 1.69 KB
/
Copy pathCompressTest.java
File metadata and controls
65 lines (47 loc) · 1.69 KB
Edit and raw actions
OlderNewer
1
package org.mapdb;
2
3
import org.junit.Before;
4
import org.junit.Test;
5
6
import java.io.IOException;
7
8
import static org.junit.Assert.*;
9
10
public class CompressTest{
11
12
DB db;
13
14
@Before public void init(){
15
db = DBMaker
16
.newMemoryDB()
17
.cacheDisable()
18
.compressionEnable()
19
.make();
20
}
21
22
23
@Test
24
public void check_instance() throws Exception {
25
Store s = Store.forDB(db);
26
assertTrue(s.compress);
27
}
28
29
30
@Test
31
public void put_get_update() throws Exception {
32
long recid = db.engine.put("aaaa", Serializer.STRING_NOSIZE);
33
assertEquals("aaaa",db.engine.get(recid, Serializer.STRING_NOSIZE));
34
db.engine.update(recid, "bbbb", Serializer.STRING_NOSIZE);
35
assertEquals("bbbb",db.engine.get(recid, Serializer.STRING_NOSIZE));
36
db.engine.delete(recid,Serializer.STRING_NOSIZE);
37
assertEquals(null,db.engine.get(recid, Serializer.STRING_NOSIZE));
38
39
}
40
41
42
@Test
43
public void short_compression() throws Exception {
44
byte[] b = new byte[]{1,2,3,4,5,33,3};
45
byte[] b2 = UtilsTest.clone(b, new Serializer.CompressionWrapper<byte[]>(Serializer.BYTE_ARRAY));
46
assertArrayEquals(b,b2);
47
}
48
49
@Test public void large_compression() throws IOException {
50
byte[] b = new byte[1024];
51
b[0] = 1;
52
b[4] = 5;
53
b[1000] = 1;
54
55
Serializer<byte[]> ser = new Serializer.CompressionWrapper<byte[]>(Serializer.BYTE_ARRAY);
56
assertArrayEquals(b, UtilsTest.clone(b, ser));
57
58
//check compressed size is actually smaller
59
DataOutput2 out = new DataOutput2();
60
ser.serialize(out,b);
61
assertTrue(out.pos<100);
62
}
63
64
65
}