Repository navigation
Expand file tree
/
Copy pathSerialization2Test.java
More file actions
111 lines (67 loc) · 2.71 KB
/
Copy pathSerialization2Test.java
File metadata and controls
111 lines (67 loc) · 2.71 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package org.mapdb;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class Serialization2Test extends TestFile {
@Test public void test2() throws IOException {
DB db = DBMaker.newFileDB(index).cacheDisable().transactionDisable().make();
Serialization2Bean processView = new Serialization2Bean();
Map<Object, Object> map = db.getHashMap("test2");
map.put("abc", processView);
db.commit();
Serialization2Bean retProcessView = (Serialization2Bean)map.get("abc");
assertEquals(processView, retProcessView);
db.close();
}
@Test public void test2_engine() throws IOException {
DB db = DBMaker.newFileDB(index).cacheDisable().make();
Serialization2Bean processView = new Serialization2Bean();
long recid = db.engine.put(processView, (Serializer<Object>) db.getDefaultSerializer());
db.commit();
Serialization2Bean retProcessView = (Serialization2Bean) db.engine.get(recid, db.getDefaultSerializer());
assertEquals(processView, retProcessView);
db.close();
}
@Test public void test3() throws IOException {
Serialized2DerivedBean att = new Serialized2DerivedBean();
DB db = DBMaker.newFileDB(index).cacheDisable().make();
Map<Object, Object> map = db.getHashMap("test");
map.put("att", att);
db.commit();
db.close();
db = DBMaker.newFileDB(index).cacheDisable().make();
map = db.getHashMap("test");
Serialized2DerivedBean retAtt = (Serialized2DerivedBean) map.get("att");
assertEquals(att, retAtt);
}
static class AAA implements Serializable {
private static final long serialVersionUID = 632633199013551846L;
String test = "aa";
}
@Test public void testReopenWithDefrag(){
File f = UtilsTest.tempDbFile();
DB db = DBMaker.newFileDB(f)
.transactionDisable()
.cacheDisable()
.checksumEnable()
.make();
Map<Integer,AAA> map = db.getTreeMap("test");
map.put(1,new AAA());
db.compact();
System.out.println(db.getEngine().get(Engine.CLASS_INFO_RECID, SerializerPojo.serializer));
db.close();
db = DBMaker.newFileDB(f)
.transactionDisable()
.cacheDisable()
.checksumEnable()
.make();
map = db.getTreeMap("test");
assertNotNull(map.get(1));
assertEquals(map.get(1).test, "aa");
db.close();
}
}