use of org.apache.cassandra.distributed.shared.InstanceClassLoader in project cassandra by apache.
the class AbstractCluster method uncaughtExceptions.
private void uncaughtExceptions(Thread thread, Throwable error) {
if (!(thread.getContextClassLoader() instanceof InstanceClassLoader)) {
Thread.UncaughtExceptionHandler handler = previousHandler;
if (null != handler)
handler.uncaughtException(thread, error);
return;
}
InstanceClassLoader cl = (InstanceClassLoader) thread.getContextClassLoader();
get(cl.getInstanceId()).uncaughtException(thread, error);
BiPredicate<Integer, Throwable> ignore = ignoreUncaughtThrowable;
I instance = get(cl.getInstanceId());
if ((ignore == null || !ignore.test(cl.getInstanceId(), error)) && instance != null && !instance.isShutdown())
uncaughtExceptions.add(error);
}
use of org.apache.cassandra.distributed.shared.InstanceClassLoader 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);
}
Aggregations