Repository navigation
Expand file tree
/
Copy pathTxEngineTest.java
More file actions
105 lines (87 loc) · 3.48 KB
/
Copy pathTxEngineTest.java
File metadata and controls
105 lines (87 loc) · 3.48 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
package org.mapdb;
import org.junit.Test;
import java.util.Map;
import static org.junit.Assert.*;
public class TxEngineTest {
TxEngine e = new TxEngine(new StoreWAL(Volume.memoryFactory(false, 0L, false)),false);
@Test public void update(){
long recid = e.put(111, Serializer.INTEGER);
e.commit();
Engine snapshot = e.snapshot();
e.update(recid, 222, Serializer.INTEGER);
assertEquals(Integer.valueOf(111), snapshot.get(recid, Serializer.INTEGER));
}
@Test public void compareAndSwap(){
long recid = e.put(111, Serializer.INTEGER);
e.commit();
Engine snapshot = e.snapshot();
e.compareAndSwap(recid, 111, 222, Serializer.INTEGER);
assertEquals(Integer.valueOf(111), snapshot.get(recid, Serializer.INTEGER));
}
@Test public void delete(){
long recid = e.put(111, Serializer.INTEGER);
e.commit();
Engine snapshot = e.snapshot();
e.delete(recid, Serializer.INTEGER);
assertEquals(Integer.valueOf(111), snapshot.get(recid, Serializer.INTEGER));
}
@Test public void notExist(){
Engine snapshot = e.snapshot();
long recid = e.put(111, Serializer.INTEGER);
assertNull(snapshot.get(recid, Serializer.INTEGER));
}
@Test public void create_snapshot(){
Engine e = DBMaker.newMemoryDB().snapshotEnable().makeEngine();
Engine snapshot = TxEngine.createSnapshotFor(e);
assertNotNull(snapshot);
}
@Test public void DB_snapshot(){
DB db = DBMaker.newMemoryDB().snapshotEnable().asyncWriteFlushDelay(100).transactionDisable().make();
long recid = db.getEngine().put("aa", Serializer.STRING_NOSIZE);
DB db2 = db.snapshot();
assertEquals("aa", db2.getEngine().get(recid,Serializer.STRING_NOSIZE));
db.getEngine().update(recid, "bb",Serializer.STRING_NOSIZE);
assertEquals("aa", db2.getEngine().get(recid, Serializer.STRING_NOSIZE));
}
@Test public void DB_snapshot2(){
DB db = DBMaker.newMemoryDB().transactionDisable().snapshotEnable().make();
long recid = db.getEngine().put("aa",Serializer.STRING_NOSIZE);
DB db2 = db.snapshot();
assertEquals("aa", db2.getEngine().get(recid,Serializer.STRING_NOSIZE));
db.getEngine().update(recid, "bb",Serializer.STRING_NOSIZE);
assertEquals("aa", db2.getEngine().get(recid,Serializer.STRING_NOSIZE));
}
@Test public void BTreeMap_snapshot(){
BTreeMap map =
DBMaker.newMemoryDB().transactionDisable().snapshotEnable()
.make().getTreeMap("aaa");
map.put("aa","aa");
Map map2 = map.snapshot();
map.put("aa","bb");
assertEquals("aa",map2.get("aa"));
}
@Test public void HTreeMap_snapshot(){
HTreeMap map =
DBMaker.newMemoryDB().transactionDisable().snapshotEnable()
.make().getHashMap("aaa");
map.put("aa","aa");
Map map2 = map.snapshot();
map.put("aa", "bb");
assertEquals("aa",map2.get("aa"));
}
// @Test public void test_stress(){
// ExecutorService ex = Executors.newCachedThreadPool();
//
// TxMaker tx = DBMaker.newMemoryDB().transactionDisable().makeTxMaker();
//
// DB db = tx.makeTx();
// final long recid =
//
// final int threadNum = 32;
// for(int i=0;i<threadNum;i++){
// ex.execute(new Runnable() { @Override public void run() {
//
// }});
// }
// }
}