public void run() {
NativeMap nm = new NativeMap();
Random r = new Random();
OpTimer opTimer = new OpTimer(log, Level.INFO);
opTimer.start("Creating map of size " + mapSizePerThread);
for (int i = 0; i < mapSizePerThread; i++) {
String row = String.format("r%08d", i);
String val = row + "v";
put(nm, row, val, i);
}
opTimer.stop("Created map of size " + nm.size() + " in %DURATION%");
opTimer.start("Doing " + getsPerThread + " gets()");
for (int i = 0; i < getsPerThread; i++) {
String row = String.format("r%08d", r.nextInt(mapSizePerThread));
String val = row + "v";
Value value = nm.get(new Key(new Text(row)));
if (value == null || !value.toString().equals(val)) {
log.error("nm.get(" + row + ") failed");
}
}
opTimer.stop("Finished " + getsPerThread + " gets in %DURATION%");
int scanned = 0;
opTimer.start("Doing " + getsPerThread + " random iterations");
for (int i = 0; i < getsPerThread; i++) {
int startRow = r.nextInt(mapSizePerThread);
String row = String.format("r%08d", startRow);
Iterator<Entry<Key,Value>> iter = nm.iterator(new Key(new Text(row)));
int count = 0;
while (iter.hasNext() && count < 10) {
String row2 = String.format("r%08d", startRow + count);
String val2 = row2 + "v";
Entry<Key,Value> entry = iter.next();
if (!entry.getValue().toString().equals(val2) || !entry.getKey().equals(new Key(new Text(row2)))) {
log.error("nm.iter(" + row2 + ") failed row = " + row + " count = " + count + " row2 = " + row + " val2 = " + val2);
}
count++;
}
scanned += count;
}
opTimer.stop("Finished " + getsPerThread + " random iterations (scanned = " + scanned + ") in %DURATION%");
nm.delete();
}
};