Repository navigation
Expand file tree
/
Copy pathBackupTest.java
More file actions
79 lines (58 loc) · 2.1 KB
/
Copy pathBackupTest.java
File metadata and controls
79 lines (58 loc) · 2.1 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
package org.mapdb;
import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class BackupTest {
@Test
public void full_backup() {
DB db = DBMaker.memoryDB().transactionDisable().make();
Set m = db.hashSet("test");
for (int i = 0; i < 1000; i++) {
m.add(TT.randomString(1000, i));
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
Pump.backupFull(db, out);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
DB db2 = Pump.backupFullRestore(
DBMaker.memoryDB().transactionDisable(),
in);
Set m2 = db2.hashSet("test");
assertEquals(1000, m.size());
assertTrue(m.containsAll(m2));
assertTrue(m2.containsAll(m));
}
@Test
public void incremental_backup() {
DB db = DBMaker.memoryDB().transactionDisable().make();
Map m = db.hashMap("test");
File dir = TT.tempDbDir();
List<byte[]> backups = new ArrayList<byte[]>();
for(int j=0;j<10;j++ ){
for (int i = 0; i < 1000; i++) {
m.put(i, TT.randomString(1000, j*1000+i));
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
Pump.backupIncremental(db,dir);
backups.add(out.toByteArray());
}
InputStream[] in = new InputStream[backups.size()];
for(int i=0;i<in.length;i++){
in[i] = new ByteArrayInputStream(backups.get(i));
}
DB db2 = Pump.backupIncrementalRestore(
DBMaker.memoryDB().transactionDisable(),
dir);
Map m2 = db2.hashMap("test");
assertTrue(m.size() == 1000);
assertTrue(m.entrySet().containsAll(m2.entrySet()));
assertTrue(m2.entrySet().containsAll(m.entrySet()));
}
}