Search in sources :

Example 1 with SimulatedWaits

use of org.apache.cassandra.simulator.systems.SimulatedWaits in project cassandra by apache.

the class SimulationTestBase method simulate.

public static void simulate(IIsolatedExecutor.SerializableRunnable[] runnables, IIsolatedExecutor.SerializableRunnable check) {
    RandomSource random = new RandomSource.Default();
    SimulatedWaits waits = new SimulatedWaits(random);
    SimulatedTime time = new SimulatedTime(random, 1577836800000L, /*Jan 1st UTC*/
    new LongRange(1, 100, MILLISECONDS, NANOSECONDS), UNIFORM, UNIFORM.period(new LongRange(10L, 60L, SECONDS, NANOSECONDS), random));
    SimulatedExecution execution = new SimulatedExecution();
    InstanceClassLoader classLoader = new InstanceClassLoader(1, 1, AbstractCluster.CURRENT_VERSION.classpath, Thread.currentThread().getContextClassLoader(), AbstractCluster.getSharedClassPredicate(ISOLATE, SHARE, ANY, SIMULATION), new InterceptClasses(() -> 1.0f, () -> 1.0f, NemesisFieldSelectors.get())::apply);
    ThreadGroup tg = new ThreadGroup("test");
    InterceptorOfGlobalMethods interceptorOfGlobalMethods = waits.interceptGlobalMethods(classLoader);
    InterceptingExecutorFactory factory = execution.factory(interceptorOfGlobalMethods, classLoader, tg);
    IsolatedExecutor.transferAdhoc((IIsolatedExecutor.SerializableConsumer<ExecutorFactory>) ExecutorFactory.Global::unsafeSet, classLoader).accept(factory);
    IsolatedExecutor.transferAdhoc((IIsolatedExecutor.SerializableBiConsumer<InterceptorOfGlobalMethods, IntSupplier>) InterceptorOfGlobalMethods.Global::unsafeSet, classLoader).accept(interceptorOfGlobalMethods, () -> {
        if (InterceptibleThread.isDeterministic())
            throw failWithOOM();
        return random.uniform(Integer.MIN_VALUE, Integer.MAX_VALUE);
    });
    SimulatedSystems simulated = new SimulatedSystems(random, time, waits, null, execution, null, null, null, new FutureActionScheduler() {

        @Override
        public Deliver shouldDeliver(int from, int to) {
            return Deliver.DELIVER;
        }

        @Override
        public long messageDeadlineNanos(int from, int to) {
            return 0;
        }

        @Override
        public long messageTimeoutNanos(long expiresAfterNanos) {
            return 0;
        }

        @Override
        public long messageFailureNanos(int from, int to) {
            return 0;
        }

        @Override
        public long schedulerDelayNanos() {
            return 0;
        }
    }, new Debug(), new Failures());
    RunnableActionScheduler runnableScheduler = new RunnableActionScheduler.RandomUniform(random);
    Action entrypoint = new Action("entrypoint", Action.Modifiers.NONE, Action.Modifiers.NONE) {

        protected ActionList performSimple() {
            Action[] actions = new Action[runnables.length];
            for (int i = 0; i < runnables.length; i++) actions[i] = toAction(runnables[i], classLoader, factory, simulated);
            return ActionList.of(actions);
        }
    };
    ActionSchedule testSchedule = new ActionSchedule(simulated.time, simulated.futureScheduler, () -> 0, new Work(UNLIMITED, runnableScheduler, Collections.singletonList(ActionList.of(entrypoint))));
    Iterators.advance(testSchedule, Integer.MAX_VALUE);
    ActionSchedule checkSchedule = new ActionSchedule(simulated.time, simulated.futureScheduler, () -> 0, new Work(UNLIMITED, runnableScheduler, Collections.singletonList(ActionList.of(toAction(check, classLoader, factory, simulated)))));
    Iterators.advance(checkSchedule, Integer.MAX_VALUE);
}
Also used : Action(org.apache.cassandra.simulator.Action) SimulatedTime(org.apache.cassandra.simulator.systems.SimulatedTime) ActionSchedule(org.apache.cassandra.simulator.ActionSchedule) InstanceClassLoader(org.apache.cassandra.distributed.shared.InstanceClassLoader) RunnableActionScheduler(org.apache.cassandra.simulator.RunnableActionScheduler) InterceptClasses(org.apache.cassandra.simulator.asm.InterceptClasses) LongRange(org.apache.cassandra.simulator.utils.LongRange) Work(org.apache.cassandra.simulator.ActionSchedule.Work) InterceptingExecutorFactory(org.apache.cassandra.simulator.systems.InterceptingExecutorFactory) Debug(org.apache.cassandra.simulator.Debug) RandomSource(org.apache.cassandra.simulator.RandomSource) FutureActionScheduler(org.apache.cassandra.simulator.FutureActionScheduler) SimulatedWaits(org.apache.cassandra.simulator.systems.SimulatedWaits) Failures(org.apache.cassandra.simulator.systems.Failures) SimulatedExecution(org.apache.cassandra.simulator.systems.SimulatedExecution) SimulatedSystems(org.apache.cassandra.simulator.systems.SimulatedSystems) InterceptorOfGlobalMethods(org.apache.cassandra.simulator.systems.InterceptorOfGlobalMethods)

Aggregations

InstanceClassLoader (org.apache.cassandra.distributed.shared.InstanceClassLoader)1 Action (org.apache.cassandra.simulator.Action)1 ActionSchedule (org.apache.cassandra.simulator.ActionSchedule)1 Work (org.apache.cassandra.simulator.ActionSchedule.Work)1 Debug (org.apache.cassandra.simulator.Debug)1 FutureActionScheduler (org.apache.cassandra.simulator.FutureActionScheduler)1 RandomSource (org.apache.cassandra.simulator.RandomSource)1 RunnableActionScheduler (org.apache.cassandra.simulator.RunnableActionScheduler)1 InterceptClasses (org.apache.cassandra.simulator.asm.InterceptClasses)1 Failures (org.apache.cassandra.simulator.systems.Failures)1 InterceptingExecutorFactory (org.apache.cassandra.simulator.systems.InterceptingExecutorFactory)1 InterceptorOfGlobalMethods (org.apache.cassandra.simulator.systems.InterceptorOfGlobalMethods)1 SimulatedExecution (org.apache.cassandra.simulator.systems.SimulatedExecution)1 SimulatedSystems (org.apache.cassandra.simulator.systems.SimulatedSystems)1 SimulatedTime (org.apache.cassandra.simulator.systems.SimulatedTime)1 SimulatedWaits (org.apache.cassandra.simulator.systems.SimulatedWaits)1 LongRange (org.apache.cassandra.simulator.utils.LongRange)1