final int BYTES_TO_MOVE = 10000000;
final int ROWS_TO_MOVE = 1000000;
final double FUZZ_FACTOR = .1;
RebalanceStatsChecker checker = new RebalanceStatsChecker(RANGES_TO_MOVE, FUZZ_FACTOR);
BalancePartitionsStatistics bps = new BalancePartitionsStatistics(RANGES_TO_MOVE);
Random r = new Random(2222);
// Random numbers are between zero and the constant, so everything will average out
// to half the time and quantities. Nothing will be exhausted by the test.
final int loopCount = (DURATION_SECONDS * 1000) / (INVOCATION_SLEEP_MILLIS + IDLE_SLEEP_MILLIS);
for (int i = 0; i < loopCount; i++) {
bps.logBalanceStarts();
int invocationTimeMS = r.nextInt(INVOCATION_SLEEP_MILLIS);
Thread.sleep(invocationTimeMS);
checker.totalInvTimeMS += invocationTimeMS;
int ranges = r.nextInt(RANGES_TO_MOVE / loopCount);
int bytes = r.nextInt(BYTES_TO_MOVE / loopCount);
int rows = r.nextInt(ROWS_TO_MOVE / loopCount);
bps.logBalanceEnds(ranges, bytes, TimeUnit.MILLISECONDS.toNanos(invocationTimeMS), TimeUnit.MILLISECONDS.toNanos(invocationTimeMS), rows);
checker.update(ranges, bytes, rows);
checker.check(bps.getLastStatsPoint());
int idleTimeMS = r.nextInt(IDLE_SLEEP_MILLIS);
Thread.sleep(idleTimeMS);
}
// Check the results with fuzzing to avoid rounding errors.
checker.check(bps.getOverallStats());
}