Repository navigation
Expand file tree
/
Copy pathIssue77Test.java
More file actions
67 lines (56 loc) · 1.63 KB
/
Copy pathIssue77Test.java
File metadata and controls
67 lines (56 loc) · 1.63 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
package org.mapdb;
import org.junit.After;
import org.junit.Test;
import java.io.File;
import java.util.Random;
import java.util.concurrent.ConcurrentNavigableMap;
public class Issue77Test {
private Random random = new Random(1);
private File dir = new File(UtilsTest.tempDbFile()+"aaa");
@Test
public void run(){
create();
read(); // UnsupportedOperationException
read(); // InternalError
}
DB open(boolean readOnly) {
// This works:
// DBMaker maker = DBMaker.newFileDB(new File(dir + "/test"));
// This is faster, but fails if read() is called for the second time:
DBMaker maker = DBMaker.newAppendFileDB(new File(dir + "/test"));
if (readOnly) {
maker.readOnly();
}
// maker.randomAccessFileEnableIfNeeded();
maker.closeOnJvmShutdown();
DB db = maker.make(); // InternalError, UnsupportedOperationException
return db;
}
void create() {
dir.mkdirs();
DB db = open(false);
ConcurrentNavigableMap<Integer, byte[]> map = db.getTreeMap("bytes");
int n = 10;
int m = 10;
for (int i = 0; i < n; i++) {
map.put(i, getRandomData(m));
}
db.commit();
db.close();
}
void read() {
DB db = open(true); // InternalError, UnsupportedOperationException
db.close();
}
byte[] getRandomData(int n) {
byte[] c = new byte[n];
random.nextBytes(c);
return c;
}
@After
public void cleanup(){
for (File f : dir.listFiles()) {
f.delete();
}
}
}