use of io.datarouter.filesystem.snapshot.reader.SnapshotKeyReader in project datarouter by hotpads.
the class BaseSnapshotTests method testOperationInternal.
private void testOperationInternal(BlockLoader threadSafeBlockLoader, boolean random, boolean multiThreaded, Operation operation) {
List<Input> searchKeys = random ? randomInputs : sortedInputs;
int batchSize = 10_000;
var parallelScannerContext = new ParallelScannerContext(exec, getNumThreads(), true, multiThreaded);
var count = new AtomicLong();
Scanner.of(searchKeys).batch(batchSize).parallel(parallelScannerContext).forEach(batch -> {
var idReader = new SnapshotIdReader(snapshotKey, threadSafeBlockLoader);
var keyReader = new SnapshotKeyReader(snapshotKey, threadSafeBlockLoader);
for (int i = 0; i < batch.size(); ++i) {
Input input = batch.get(i);
long id = input.id;
byte[] key = input.entry.key();
byte[] value = input.entry.value();
if (Operation.GET_LEAF_RECORD == operation) {
SnapshotLeafRecord leafRecord = idReader.leafRecord(id);
if (!Arrays.equals(key, leafRecord.key)) {
String message = String.format("%s, expected=%s, actual=%s", id, utf8(key), utf8(leafRecord.key));
throw new RuntimeException(message);
}
if (!Arrays.equals(value, leafRecord.value)) {
String message = String.format("%s, expected=%s, actual=%s", id, utf8(value), utf8(leafRecord.value));
throw new RuntimeException(message);
}
} else if (Operation.GET_RECORD == operation) {
SnapshotRecord result = idReader.getRecord(id);
if (id != result.id) {
String message = String.format("%s, expected=%s, actual=%s", id, id, result.id);
throw new RuntimeException(message);
}
if (!Arrays.equals(key, result.key)) {
String message = String.format("%s, expected=%s, actual=%s", id, utf8(key), utf8(result.key));
throw new RuntimeException(message);
}
if (!SnapshotEntry.equal(input.entry, result.entry())) {
String message = String.format("%s, expected=%s, actual=%s", i, // TODO print more than column 0
utf8(input.entry.columnValues[0]), utf8(result.columnValues[0]));
throw new RuntimeException(message);
}
} else if (Operation.FIND_ID == operation) {
if (keyReader.findRecordId(key).isEmpty()) {
String message = String.format("%s, %s not found", i, utf8(key));
throw new RuntimeException(message);
}
if (id != keyReader.findRecordId(key).get().longValue()) {
String message = String.format("%s, %s not found", i, utf8(key));
throw new RuntimeException(message);
}
} else if (Operation.FIND_RECORD == operation) {
Optional<SnapshotRecord> output = keyReader.findRecord(key);
if (output.isEmpty()) {
String message = String.format("%s, %s not found", i, utf8(key));
throw new RuntimeException(message);
}
if (!SnapshotEntry.equal(input.entry, output.get().entry())) {
String message = String.format("%s, expected=%s, actual=%s", i, // TODO print more than column 0
utf8(batch.get(i).entry.columnValues[0]), utf8(output.get().columnValues[0]));
throw new RuntimeException(message);
}
}
}
count.addAndGet(batch.size());
logger.warn("{}, {}, {} for {}/{} {}", random ? "random" : "sorted", multiThreaded ? "multi" : "single", operation.toString().toLowerCase(), NumberFormatter.addCommas(count.get()), NumberFormatter.addCommas(searchKeys.size()), utf8(ListTool.getLast(batch).entry.key()));
});
}
Aggregations