move TimeStampDeltaDecoder to BSFile
Now the encoding and decoding code is in the same class.
This commit is contained in:
@@ -8,6 +8,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
@@ -131,4 +132,58 @@ public class BSFileTest {
|
||||
}
|
||||
}
|
||||
|
||||
public void testBlockStorageTimeValue() throws Exception {
|
||||
final Path file = dataDirectory.resolve("data.int.db");
|
||||
final Random random = ThreadLocalRandom.current();
|
||||
final int numTimeValuePairs = 1000;
|
||||
long blockNumber = -1;
|
||||
final LongList expectedLongs = new LongList();
|
||||
|
||||
long start = System.nanoTime();
|
||||
long lastEpochMilli = 0;
|
||||
//
|
||||
try (final DiskStorage ds = new DiskStorage(file)) {
|
||||
|
||||
try (final BSFile bsFile = BSFile.newFile(ds)) {
|
||||
|
||||
blockNumber = bsFile.getRootBlockNumber();
|
||||
|
||||
for (long i = 0; i < numTimeValuePairs / 2; i++) {
|
||||
|
||||
final long epochMilli = lastEpochMilli + random.nextInt(1000);
|
||||
final long value = random.nextInt(10000);
|
||||
|
||||
lastEpochMilli = epochMilli;
|
||||
|
||||
bsFile.appendTimeValue(epochMilli, value);
|
||||
expectedLongs.add(epochMilli);
|
||||
expectedLongs.add(value);
|
||||
}
|
||||
}
|
||||
try (final BSFile bsFile = BSFile.existingFile(blockNumber, ds)) {
|
||||
|
||||
for (long i = numTimeValuePairs / 2; i < numTimeValuePairs; i++) {
|
||||
final long epochMilli = lastEpochMilli + random.nextInt(100);
|
||||
final long value = random.nextInt(10000);
|
||||
|
||||
lastEpochMilli = epochMilli;
|
||||
|
||||
bsFile.appendTimeValue(epochMilli, value);
|
||||
expectedLongs.add(epochMilli);
|
||||
expectedLongs.add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("duration write: " + (System.nanoTime() - start) / 1_000_000.0 + "ms");
|
||||
|
||||
start = System.nanoTime();
|
||||
try (final DiskStorage ds = new DiskStorage(file)) {
|
||||
final BSFile bsFile = BSFile.existingFile(blockNumber, ds);
|
||||
final LongList actualLongs = bsFile.asTimeValueLongList();
|
||||
|
||||
Assert.assertEquals(actualLongs, expectedLongs);
|
||||
}
|
||||
System.out.println("duration read: " + (System.nanoTime() - start) / 1_000_000.0 + "ms");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user