for(int i=0;i<numThreads;i++) {
executor.execute(new Runnable() {
@Override
public void run() {
Random rand = new Random();
ByteDataBuffer buf = new ByteDataBuffer();
for(int i=0;i<numIterationsPerThread;i++) {
int value = rand.nextInt(numUniqueValues);
VarInt.writeVInt(buf, value);
Integer ordinal = Integer.valueOf(map.getOrAssignOrdinal(buf));
Integer beatMe = controlMap.putIfAbsent(value, ordinal);
if(beatMe != null) {
Assert.assertEquals(ordinal, beatMe);
}
buf.reset();
}
}
});
}
shutdown(executor);
/// serialize then deserialize the map
/*ByteArrayOutputStream os = new ByteArrayOutputStream();
map.serializeTo(os);
ByteArrayOrdinalMap deserializedMap = ByteArrayOrdinalMap.deserializeFrom(new ByteArrayInputStream(os.toByteArray()));*/
ByteDataBuffer buf = new ByteDataBuffer();
for(Map.Entry<Integer, Integer> entry : controlMap.entrySet()) {
Integer value = entry.getKey();
Integer expected = entry.getValue();
buf.reset();
VarInt.writeVLong(buf, value.longValue());
int actual = map.getOrAssignOrdinal(buf);
Assert.assertEquals(actual, expected.intValue());