Asynchronous unit test and benchmark library
For asynchronous programming, it's not easy to do the unit test. Particularly, it's hard to do the benchmark for asynchronous program.
Runidle-Testing is designed to help for the unit tests and benchmark on asynchronous programming.
public class RxJavaUnit extends BaseUnitSpec {
@Test
public void testRxJava() {
Blocker blocker = new Blocker();
Observable.just(1)
.map(integer -> 1000)
.observeOn(Schedulers.computation())
.subscribe(integer -> {
assertEquals(integer.intValue(), 1000);
blocker.end();
});
blocker.awaitEnd();
}
}
blocker: need to use blocker object to control the test workflow of asynchronous program
Benchmark.benchmark()
.threads(1)
.concurrency(20000)
.iterations(500)
.rounds(10)
.warmupConcurrency(10000)
.warmupIterations(1000)
.warmupRounds(1)
.reportIntervalSeconds(3)
.benchmarkTask((index, runnerContext) -> {
Observable.just(index)
.subscribe(integer -> {
runnerContext.done(index);
}, throwable -> {
runnerContext.done(index);
});
}).start();
threads: how many threads to start the benchmark.For asynchronous program, maybe need more threads to start iterations
concurrency: how many actors on asynchronous benchmark. For asynchronous program, the number of actors decides the concurrency, which is not decided by the threads.
iterations: how many iterations for each actors. This is not the total iterations. TotalIterations = concurrency*iterations Don't make the totalIteration too large.
rounds: how many benchmark rounds
warmupConcurrency: how many actors for warmup.
warmupIterations: how many iterations for warmup.
warmupRounds: how many rounds for warmup.
reportIntervalSeconds: benchmark report interval. The default value is 2 seconds. In some case, the value should larger.