use of org.apache.cassandra.simulator.ClusterSimulation in project cassandra by apache.
the class SimulationTestBase method simulate.
public static void simulate(Function<DTestClusterSimulation, ActionList> init, Function<DTestClusterSimulation, ActionList> test, Consumer<ClusterSimulation.Builder<DTestClusterSimulation>> configure) throws IOException {
SimulationRunner.beforeAll();
long seed = System.currentTimeMillis();
RandomSource random = new RandomSource.Default();
random.reset(seed);
class Factory extends ClusterSimulation.Builder<DTestClusterSimulation> {
public ClusterSimulation<DTestClusterSimulation> create(long seed) throws IOException {
return new ClusterSimulation<>(random, seed, 1, this, (c) -> {
}, (simulated, scheduler, cluster, options) -> new DTestClusterSimulation(simulated, scheduler, cluster) {
protected ActionList initialize() {
return init.apply(this);
}
protected ActionList execute() {
return test.apply(this);
}
});
}
}
Factory factory = new Factory();
configure.accept(factory);
try (ClusterSimulation<?> cluster = factory.create(seed)) {
try {
cluster.simulation.run();
} catch (Throwable t) {
throw new AssertionError(String.format("Failed on seed %s", Long.toHexString(seed)), t);
}
}
}
Aggregations