Repository navigation
Expand file tree
/
Copy pathPumpComparableValueTest.java
More file actions
119 lines (77 loc) · 3.41 KB
/
Copy pathPumpComparableValueTest.java
File metadata and controls
119 lines (77 loc) · 3.41 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
112
113
114
115
116
117
118
119
package org.mapdb;
import java.util.Iterator;
import org.junit.Test;
import org.mapdb.Fun.Tuple2;
import static org.junit.Assert.assertEquals;
public class PumpComparableValueTest {
/**
* Test mapDB data pump mechanize
*
*/
@Test
public void run(){
DBMaker dbMaker = DBMaker.newMemoryDB()
.transactionDisable();
DB mapDBStore = dbMaker.make();
final int max = 70000;
final int pumpSize = max/10;
// data source returning the same value max times values are NOT comparable
Iterator<Tuple2<String, byte[]>> entriesSourceNonComp = new Iterator<Tuple2<String,byte[]>>() {
int count = 0;
@Override
public void remove() {throw new IllegalArgumentException("NOT SUPPORTED");}
@Override
public Tuple2<String, byte[]> next() {
count++;
String key ="SAME KEY";
byte []value = {1};
Tuple2 <String,byte[]>ret = new Tuple2<String,byte[]>(key,value);
return ret;
}
@Override
public boolean hasNext() {
return count<max;
}
};
BTreeMap<String,String> map2 = mapDBStore.createTreeMap("non comparable values")
.pumpSource(entriesSourceNonComp)
.pumpPresort(pumpSize)
.pumpIgnoreDuplicates()
.counterEnable()
.makeStringMap();
assertEquals(1,map2.size());
}
@Test
public void run2(){
DBMaker dbMaker = DBMaker.newMemoryDB()
.transactionDisable();
DB mapDBStore = dbMaker.make();
final int max = 70000;
final int pumpSize = max/10;
// data source returning the same value max times values are NOT comparable
Iterator<Tuple2<String, byte[]>> entriesSourceNonComp = new Iterator<Tuple2<String,byte[]>>() {
int count = 0;
@Override
public void remove() {throw new IllegalArgumentException("NOT SUPPORTED");}
@Override
public Tuple2<String, byte[]> next() {
count++;
String key = ""+count;
byte []value = {1};
Tuple2 <String,byte[]>ret = new Tuple2<String,byte[]>(key,value);
return ret;
}
@Override
public boolean hasNext() {
return count<max;
}
};
BTreeMap<String,String> map2 = mapDBStore.createTreeMap("non comparable values")
.pumpSource(entriesSourceNonComp)
.pumpPresort(pumpSize)
.pumpIgnoreDuplicates()
.counterEnable()
.makeStringMap();
assertEquals(max,map2.size());
}
}