Search in sources :

Example 1 with ClusterSimulation

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);
        }
    }
}
Also used : ClusterSimulation(org.apache.cassandra.simulator.ClusterSimulation) RandomSource(org.apache.cassandra.simulator.RandomSource) ExecutorFactory(org.apache.cassandra.concurrent.ExecutorFactory) InterceptingExecutorFactory(org.apache.cassandra.simulator.systems.InterceptingExecutorFactory) ActionList(org.apache.cassandra.simulator.ActionList)

Aggregations

ExecutorFactory (org.apache.cassandra.concurrent.ExecutorFactory)1 ActionList (org.apache.cassandra.simulator.ActionList)1 ClusterSimulation (org.apache.cassandra.simulator.ClusterSimulation)1 RandomSource (org.apache.cassandra.simulator.RandomSource)1 InterceptingExecutorFactory (org.apache.cassandra.simulator.systems.InterceptingExecutorFactory)1