Remove TaskExecutor and TaskScheduler

- As all execution and scheduling is now in reactor,
  remove all traces of these spring interfaces.
- Fixes #800
This commit is contained in:
Janne Valkealahti
2019-08-03 14:40:37 +01:00
parent f1bf35e688
commit da9c68f4e6
63 changed files with 172 additions and 1428 deletions

View File

@@ -36,10 +36,6 @@ public class TimerSmokeTests {
private StateMachine<String, String> buildMachine() throws Exception {
StateMachineBuilder.Builder<String, String> builder = StateMachineBuilder.builder();
builder.configureConfiguration()
.withConfiguration()
.taskExecutor(taskExecutor);
builder.configureStates()
.withStates()
.initial("initial")
@@ -61,10 +57,6 @@ public class TimerSmokeTests {
private StateMachine<String, String> buildMachine2() throws Exception {
StateMachineBuilder.Builder<String, String> builder = StateMachineBuilder.builder();
builder.configureConfiguration()
.withConfiguration()
.taskExecutor(taskExecutor);
builder.configureStates()
.withStates()
.initial("initial").end("end").and()

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,8 +34,4 @@ public abstract class StateMachineSystemConstants {
/** State machine id key for headers and variables */
public static final String STATEMACHINE_IDENTIFIER = "_sm_id_";
/** Bean name for task executor */
public static final String TASK_EXECUTOR_BEAN_NAME = "stateMachineTaskExecutor";
}

View File

@@ -34,9 +34,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.SmartLifecycle;
import org.springframework.core.task.TaskExecutor;
import org.springframework.messaging.Message;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.statemachine.ExtendedState;
import org.springframework.statemachine.StateContext;
import org.springframework.statemachine.StateMachine;
@@ -229,9 +227,9 @@ public abstract class AbstractStateMachineFactory<S, E> extends LifecycleObjectS
String mId = machineId != null ? machineId : stateMachineModel.getConfigurationData().getMachineId();
mId = mId + "#" + (rId != null ? rId.toString() : "");
machine = buildMachine(machineMap, stateMap, holderList, regionStateDatas, transitionsData, resolveBeanFactory(stateMachineModel),
contextEvents, defaultExtendedState, stateMachineModel.getTransitionsData(), resolveTaskExecutor(stateMachineModel),
resolveTaskScheduler(stateMachineModel), mId, null, stateMachineModel);
machine = buildMachine(machineMap, stateMap, holderList, regionStateDatas, transitionsData,
resolveBeanFactory(stateMachineModel), contextEvents, defaultExtendedState,
stateMachineModel.getTransitionsData(), mId, null, stateMachineModel);
regionStack.push(new MachineStackItem<S, E>(machine));
machines.add(machine);
}
@@ -255,17 +253,16 @@ public abstract class AbstractStateMachineFactory<S, E> extends LifecycleObjectS
states.add(rstate);
Transition<S, E> initialTransition = new InitialTransition<S, E>(rstate);
StateMachine<S, E> m = buildStateMachineInternal(states, new ArrayList<Transition<S, E>>(), rstate, initialTransition,
null, defaultExtendedState, null, contextEvents, resolveBeanFactory(stateMachineModel), resolveTaskExecutor(stateMachineModel),
resolveTaskScheduler(stateMachineModel), beanName,
null, defaultExtendedState, null, contextEvents, resolveBeanFactory(stateMachineModel), beanName,
machineId != null ? machineId : stateMachineModel.getConfigurationData().getMachineId(),
uuid, stateMachineModel);
machine = m;
machines.add(m);
}
} else {
machine = buildMachine(machineMap, stateMap, holderList, stateDatas, transitionsData, resolveBeanFactory(stateMachineModel), contextEvents,
defaultExtendedState, stateMachineModel.getTransitionsData(), resolveTaskExecutor(stateMachineModel), resolveTaskScheduler(stateMachineModel),
machineId, uuid, stateMachineModel);
machine = buildMachine(machineMap, stateMap, holderList, stateDatas, transitionsData,
resolveBeanFactory(stateMachineModel), contextEvents, defaultExtendedState,
stateMachineModel.getTransitionsData(), machineId, uuid, stateMachineModel);
machines.add(machine);
if (peek.isInitial() || (!peek.isInitial() && !machineMap.containsKey(peek.getParent()))) {
machineMap.put(peek.getParent(), machine);
@@ -473,22 +470,6 @@ public abstract class AbstractStateMachineFactory<S, E> extends LifecycleObjectS
}
}
protected TaskExecutor resolveTaskExecutor(StateMachineModel<S, E> stateMachineModel) {
if (stateMachineModel.getConfigurationData().getTaskExecutor() != null) {
return stateMachineModel.getConfigurationData().getTaskExecutor();
} else {
return getTaskExecutor();
}
}
protected TaskScheduler resolveTaskScheduler(StateMachineModel<S, E> stateMachineModel) {
if (stateMachineModel.getConfigurationData().getTaskScheduler() != null) {
return stateMachineModel.getConfigurationData().getTaskScheduler();
} else {
return getTaskScheduler();
}
}
protected StateMachineModel<S, E> resolveStateMachineModel(String machineId) {
if (stateMachineModelFactory == null) {
return defaultStateMachineModel;
@@ -590,9 +571,9 @@ public abstract class AbstractStateMachineFactory<S, E> extends LifecycleObjectS
@SuppressWarnings("unchecked")
private StateMachine<S, E> buildMachine(Map<Object, StateMachine<S, E>> machineMap, Map<S, State<S, E>> stateMap,
List<HolderListItem<S, E>> holderList, Collection<StateData<S, E>> stateDatas, Collection<TransitionData<S, E>> transitionsData,
BeanFactory beanFactory, Boolean contextEvents, DefaultExtendedState defaultExtendedState,
TransitionsData<S, E> stateMachineTransitions, TaskExecutor taskExecutor, TaskScheduler taskScheduler, String machineId,
List<HolderListItem<S, E>> holderList, Collection<StateData<S, E>> stateDatas,
Collection<TransitionData<S, E>> transitionsData, BeanFactory beanFactory, Boolean contextEvents,
DefaultExtendedState defaultExtendedState, TransitionsData<S, E> stateMachineTransitions, String machineId,
UUID uuid, StateMachineModel<S, E> stateMachineModel) {
State<S, E> state = null;
State<S, E> initialState = null;
@@ -861,12 +842,6 @@ public abstract class AbstractStateMachineFactory<S, E> extends LifecycleObjectS
if (beanFactory != null) {
t.setBeanFactory(beanFactory);
}
if (taskExecutor != null) {
t.setTaskExecutor(taskExecutor);
}
if (taskScheduler != null) {
t.setTaskScheduler(taskScheduler);
}
trigger = t;
((AbstractState<S, E>)stateMap.get(source)).getTriggers().add(trigger);
}
@@ -917,15 +892,15 @@ public abstract class AbstractStateMachineFactory<S, E> extends LifecycleObjectS
Transition<S, E> initialTransition = new InitialTransition<S, E>(initialState, Actions.from(initialAction));
StateMachine<S, E> machine = buildStateMachineInternal(states, transitions, initialState, initialTransition,
null, defaultExtendedState, historyState, contextEvents, beanFactory, taskExecutor, taskScheduler,
null, defaultExtendedState, historyState, contextEvents, beanFactory,
beanName, machineId != null ? machineId : stateMachineModel.getConfigurationData().getMachineId(), uuid, stateMachineModel);
return machine;
}
protected abstract StateMachine<S, E> buildStateMachineInternal(Collection<State<S, E>> states,
Collection<Transition<S, E>> transitions, State<S, E> initialState, Transition<S, E> initialTransition, Message<E> initialEvent,
ExtendedState extendedState, PseudoState<S, E> historyState, Boolean contextEventsEnabled, BeanFactory beanFactory,
TaskExecutor taskExecutor, TaskScheduler taskScheduler, String beanName, String machineId, UUID uuid,
Collection<Transition<S, E>> transitions, State<S, E> initialState, Transition<S, E> initialTransition,
Message<E> initialEvent, ExtendedState extendedState, PseudoState<S, E> historyState,
Boolean contextEventsEnabled, BeanFactory beanFactory, String beanName, String machineId, UUID uuid,
StateMachineModel<S, E> stateMachineModel);
protected abstract State<S, E> buildStateInternal(S id, Collection<E> deferred,

View File

@@ -21,9 +21,7 @@ import java.util.function.Function;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.core.task.TaskExecutor;
import org.springframework.messaging.Message;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.statemachine.ExtendedState;
import org.springframework.statemachine.ObjectStateMachine;
import org.springframework.statemachine.StateContext;
@@ -71,10 +69,11 @@ public class ObjectStateMachineFactory<S, E> extends AbstractStateMachineFactory
}
@Override
protected StateMachine<S, E> buildStateMachineInternal(Collection<State<S, E>> states, Collection<Transition<S, E>> transitions,
State<S, E> initialState, Transition<S, E> initialTransition, Message<E> initialEvent, ExtendedState extendedState,
PseudoState<S, E> historyState, Boolean contextEventsEnabled, BeanFactory beanFactory, TaskExecutor taskExecutor,
TaskScheduler taskScheduler, String beanName, String machineId, UUID uuid, StateMachineModel<S, E> stateMachineModel) {
protected StateMachine<S, E> buildStateMachineInternal(Collection<State<S, E>> states,
Collection<Transition<S, E>> transitions, State<S, E> initialState, Transition<S, E> initialTransition,
Message<E> initialEvent, ExtendedState extendedState, PseudoState<S, E> historyState,
Boolean contextEventsEnabled, BeanFactory beanFactory, String beanName, String machineId, UUID uuid,
StateMachineModel<S, E> stateMachineModel) {
ObjectStateMachine<S, E> machine = new ObjectStateMachine<S, E>(states, transitions, initialState, initialTransition, initialEvent,
extendedState, uuid);
machine.setId(machineId);
@@ -86,12 +85,6 @@ public class ObjectStateMachineFactory<S, E> extends AbstractStateMachineFactory
if (beanFactory != null) {
machine.setBeanFactory(beanFactory);
}
if (taskExecutor != null) {
machine.setTaskExecutor(taskExecutor);
}
if (taskScheduler != null) {
machine.setTaskScheduler(taskScheduler);
}
if (machine instanceof BeanNameAware) {
((BeanNameAware)machine).setBeanName(beanName);
}
@@ -109,14 +102,6 @@ public class ObjectStateMachineFactory<S, E> extends AbstractStateMachineFactory
if (beanFactory != null) {
objectState.setBeanFactory(beanFactory);
}
TaskExecutor taskExecutor = resolveTaskExecutor(stateMachineModel);
if (taskExecutor != null) {
objectState.setTaskExecutor(taskExecutor);
}
TaskScheduler taskScheduler = resolveTaskScheduler(stateMachineModel);
if (taskScheduler != null) {
objectState.setTaskScheduler(taskScheduler);
}
objectState.setStateDoActionPolicy(stateMachineModel.getConfigurationData().getStateDoActionPolicy());
objectState.setStateDoActionPolicyTimeout(stateMachineModel.getConfigurationData().getStateDoActionPolicyTimeout());
return objectState;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,8 +15,6 @@
*/
package org.springframework.statemachine.config;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
import org.springframework.statemachine.StateMachine;
import org.springframework.statemachine.StateMachineException;
import org.springframework.statemachine.config.builders.StateMachineConfigBuilder;
@@ -142,16 +140,6 @@ public class StateMachineBuilder {
if (stateMachineConfigurationConfig.getBeanFactory() != null) {
stateMachineFactory.setBeanFactory(stateMachineConfigurationConfig.getBeanFactory());
}
if (stateMachineConfigurationConfig.getTaskExecutor() != null) {
stateMachineFactory.setTaskExecutor(stateMachineConfigurationConfig.getTaskExecutor());
} else {
stateMachineFactory.setTaskExecutor(new SyncTaskExecutor());
}
if (stateMachineConfigurationConfig.getTaskScheduler() != null) {
stateMachineFactory.setTaskScheduler(stateMachineConfigurationConfig.getTaskScheduler());
} else {
stateMachineFactory.setTaskScheduler(new ConcurrentTaskScheduler());
}
return stateMachineFactory.getStateMachine();
} catch (Exception e) {
throw new StateMachineException("Error building state machine", e);

View File

@@ -19,8 +19,6 @@ import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.security.access.AccessDecisionManager;
import org.springframework.statemachine.action.StateDoActionPolicy;
import org.springframework.statemachine.config.common.annotation.AbstractConfiguredAnnotationBuilder;
@@ -64,8 +62,6 @@ public class StateMachineConfigurationBuilder<S, E>
private String machineId;
private BeanFactory beanFactory;
private TaskExecutor taskExecutor;
private TaskScheduler taskScheculer;
private boolean autoStart = false;
private TransitionConflictPolicy transitionConflictPolicy;
private StateDoActionPolicy stateDoActionPolicy;
@@ -150,11 +146,10 @@ public class StateMachineConfigurationBuilder<S, E>
interceptorsCopy.add(interceptor);
}
}
return new ConfigurationData<S, E>(beanFactory, taskExecutor, taskScheculer, autoStart, ensemble, listeners,
securityEnabled, transitionSecurityAccessDecisionManager, eventSecurityAccessDecisionManager,
eventSecurityRule, transitionSecurityRule, verifierEnabled, verifier, machineId, stateMachineMonitor,
interceptorsCopy, transitionConflictPolicy, stateDoActionPolicy, stateDoActionPolicyTimeout,
regionExecutionPolicy);
return new ConfigurationData<S, E>(beanFactory, autoStart, ensemble, listeners, securityEnabled,
transitionSecurityAccessDecisionManager, eventSecurityAccessDecisionManager, eventSecurityRule,
transitionSecurityRule, verifierEnabled, verifier, machineId, stateMachineMonitor, interceptorsCopy,
transitionConflictPolicy, stateDoActionPolicy, stateDoActionPolicyTimeout, regionExecutionPolicy);
}
/**
@@ -175,24 +170,6 @@ public class StateMachineConfigurationBuilder<S, E>
this.beanFactory = beanFactory;
}
/**
* Sets the task executor.
*
* @param taskExecutor the new task executor
*/
public void setTaskExecutor(TaskExecutor taskExecutor) {
this.taskExecutor = taskExecutor;
}
/**
* Sets the task scheculer.
*
* @param taskScheculer the new task scheculer
*/
public void setTaskScheculer(TaskScheduler taskScheculer) {
this.taskScheculer = taskScheculer;
}
/**
* Sets the state machine ensemble.
*

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,11 +17,6 @@ package org.springframework.statemachine.config.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
import org.springframework.statemachine.StateMachineSystemConstants;
/**
* Common configuration for statemachine.
@@ -32,16 +27,6 @@ import org.springframework.statemachine.StateMachineSystemConstants;
@Configuration
public class StateMachineCommonConfiguration {
@Bean(name = StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME)
public TaskExecutor taskExecutor() {
return new SyncTaskExecutor();
}
@Bean
public TaskScheduler taskScheduler() {
return new ConcurrentTaskScheduler();
}
@Bean(name = StateMachineHandlerApplicationListener.BEAN_NAME)
public StateMachineHandlerApplicationListener stateMachineHandlerApplicationListener() {
return new StateMachineHandlerApplicationListener();

View File

@@ -18,8 +18,6 @@ package org.springframework.statemachine.config.configurers;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.statemachine.StateMachine;
import org.springframework.statemachine.action.StateDoActionPolicy;
import org.springframework.statemachine.config.builders.StateMachineConfigurationConfigurer;
@@ -56,22 +54,6 @@ public interface ConfigurationConfigurer<S, E> extends
*/
ConfigurationConfigurer<S, E> beanFactory(BeanFactory beanFactory);
/**
* Specify a {@link TaskExecutor}.
*
* @param taskExecutor the task executor
* @return configurer for chaining
*/
ConfigurationConfigurer<S, E> taskExecutor(TaskExecutor taskExecutor);
/**
* Specify a {@link TaskScheduler}.
*
* @param taskScheduler the task scheduler
* @return configurer for chaining
*/
ConfigurationConfigurer<S, E> taskScheduler(TaskScheduler taskScheduler);
/**
* Specify if state machine should be started automatically.
* On default state machine is not started automatically.

View File

@@ -20,8 +20,6 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.statemachine.action.StateDoActionPolicy;
import org.springframework.statemachine.config.builders.StateMachineConfigurationBuilder;
import org.springframework.statemachine.config.builders.StateMachineConfigurationConfigurer;
@@ -45,8 +43,6 @@ public class DefaultConfigurationConfigurer<S, E>
private String machineId;
private BeanFactory beanFactory;
private TaskExecutor taskExecutor;
private TaskScheduler taskScheculer;
private boolean autoStart = false;
private TransitionConflictPolicy transitionConflightPolicy;
private StateDoActionPolicy stateDoActionPolicy;
@@ -58,8 +54,6 @@ public class DefaultConfigurationConfigurer<S, E>
public void configure(StateMachineConfigurationBuilder<S, E> builder) throws Exception {
builder.setMachineId(machineId);
builder.setBeanFactory(beanFactory);
builder.setTaskExecutor(taskExecutor);
builder.setTaskScheculer(taskScheculer);
builder.setAutoStart(autoStart);
builder.setStateMachineListeners(listeners);
builder.setTransitionConflictPolicy(transitionConflightPolicy);
@@ -79,18 +73,6 @@ public class DefaultConfigurationConfigurer<S, E>
return this;
}
@Override
public ConfigurationConfigurer<S, E> taskExecutor(TaskExecutor taskExecutor) {
this.taskExecutor = taskExecutor;
return this;
}
@Override
public ConfigurationConfigurer<S, E> taskScheduler(TaskScheduler taskScheduler) {
this.taskScheculer = taskScheduler;
return this;
}
@Override
public ConfigurationConfigurer<S, E> autoStartup(boolean autoStart) {
this.autoStart = autoStart;

View File

@@ -19,10 +19,6 @@ import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
import org.springframework.security.access.AccessDecisionManager;
import org.springframework.statemachine.action.StateDoActionPolicy;
import org.springframework.statemachine.config.builders.StateMachineConfigurationBuilder;
@@ -48,8 +44,6 @@ public class ConfigurationData<S, E> {
private final String machineId;
private final BeanFactory beanFactory;
private final TaskExecutor taskExecutor;
private final TaskScheduler taskScheduler;
private final boolean autoStart;
private final TransitionConflictPolicy transitionConflictPolicy;
private final StateDoActionPolicy stateDoActionPolicy;
@@ -71,16 +65,14 @@ public class ConfigurationData<S, E> {
* Instantiates a new state machine configuration config data.
*/
public ConfigurationData() {
this(null, new SyncTaskExecutor(), new ConcurrentTaskScheduler(), false, null, new ArrayList<StateMachineListener<S, E>>(), false,
null, null, null, null, true, new DefaultStateMachineModelVerifier<S, E>(), null, null, null);
this(null, false, null, new ArrayList<StateMachineListener<S, E>>(), false, null, null, null, null, true,
new DefaultStateMachineModelVerifier<S, E>(), null, null, null);
}
/**
* Instantiates a new state machine configuration config data.
*
* @param beanFactory the bean factory
* @param taskExecutor the task executor
* @param taskScheduler the task scheduler
* @param autoStart the autostart flag
* @param ensemble the state machine ensemble
* @param listeners the state machine listeners
@@ -95,24 +87,22 @@ public class ConfigurationData<S, E> {
* @param stateMachineMonitor the state machine monitor
* @param interceptors the state machine interceptors.
*/
public ConfigurationData(BeanFactory beanFactory, TaskExecutor taskExecutor,
TaskScheduler taskScheduler, boolean autoStart, StateMachineEnsemble<S, E> ensemble,
public ConfigurationData(BeanFactory beanFactory, boolean autoStart, StateMachineEnsemble<S, E> ensemble,
List<StateMachineListener<S, E>> listeners, boolean securityEnabled,
AccessDecisionManager transitionSecurityAccessDecisionManager, AccessDecisionManager eventSecurityAccessDecisionManager,
SecurityRule eventSecurityRule, SecurityRule transitionSecurityRule, boolean verifierEnabled,
StateMachineModelVerifier<S, E> verifier, String machineId, StateMachineMonitor<S, E> stateMachineMonitor,
AccessDecisionManager transitionSecurityAccessDecisionManager,
AccessDecisionManager eventSecurityAccessDecisionManager, SecurityRule eventSecurityRule,
SecurityRule transitionSecurityRule, boolean verifierEnabled, StateMachineModelVerifier<S, E> verifier,
String machineId, StateMachineMonitor<S, E> stateMachineMonitor,
List<StateMachineInterceptor<S, E>> interceptors) {
this(beanFactory, taskExecutor, taskScheduler, autoStart, ensemble, listeners, securityEnabled,
transitionSecurityAccessDecisionManager, eventSecurityAccessDecisionManager, eventSecurityRule, transitionSecurityRule,
verifierEnabled, verifier, machineId, stateMachineMonitor, interceptors, null, null, null, null);
this(beanFactory, autoStart, ensemble, listeners, securityEnabled, transitionSecurityAccessDecisionManager,
eventSecurityAccessDecisionManager, eventSecurityRule, transitionSecurityRule, verifierEnabled,
verifier, machineId, stateMachineMonitor, interceptors, null, null, null, null);
}
/**
* Instantiates a new state machine configuration config data.
*
* @param beanFactory the bean factory
* @param taskExecutor the task executor
* @param taskScheduler the task scheduler
* @param autoStart the autostart flag
* @param ensemble the state machine ensemble
* @param listeners the state machine listeners
@@ -131,17 +121,16 @@ public class ConfigurationData<S, E> {
* @param stateDoActionPolicyTimeout the state do action policy timeout
* @param regionExecutionPolicy the region execution policy
*/
public ConfigurationData(BeanFactory beanFactory, TaskExecutor taskExecutor,
TaskScheduler taskScheduler, boolean autoStart, StateMachineEnsemble<S, E> ensemble,
public ConfigurationData(BeanFactory beanFactory, boolean autoStart, StateMachineEnsemble<S, E> ensemble,
List<StateMachineListener<S, E>> listeners, boolean securityEnabled,
AccessDecisionManager transitionSecurityAccessDecisionManager, AccessDecisionManager eventSecurityAccessDecisionManager,
SecurityRule eventSecurityRule, SecurityRule transitionSecurityRule, boolean verifierEnabled,
StateMachineModelVerifier<S, E> verifier, String machineId, StateMachineMonitor<S, E> stateMachineMonitor,
AccessDecisionManager transitionSecurityAccessDecisionManager,
AccessDecisionManager eventSecurityAccessDecisionManager, SecurityRule eventSecurityRule,
SecurityRule transitionSecurityRule, boolean verifierEnabled, StateMachineModelVerifier<S, E> verifier,
String machineId, StateMachineMonitor<S, E> stateMachineMonitor,
List<StateMachineInterceptor<S, E>> interceptors, TransitionConflictPolicy transitionConflightPolicy,
StateDoActionPolicy stateDoActionPolicy, Long stateDoActionPolicyTimeout, RegionExecutionPolicy regionExecutionPolicy) {
StateDoActionPolicy stateDoActionPolicy, Long stateDoActionPolicyTimeout,
RegionExecutionPolicy regionExecutionPolicy) {
this.beanFactory = beanFactory;
this.taskExecutor = taskExecutor;
this.taskScheduler = taskScheduler;
this.autoStart = autoStart;
this.ensemble = ensemble;
this.listeners = listeners;
@@ -174,24 +163,6 @@ public class ConfigurationData<S, E> {
return beanFactory;
}
/**
* Gets the task executor.
*
* @return the task executor
*/
public TaskExecutor getTaskExecutor() {
return taskExecutor;
}
/**
* Gets the task scheduler.
*
* @return the task scheduler
*/
public TaskScheduler getTaskScheduler() {
return taskScheduler;
}
/**
* Gets the state machine ensemble.
*

View File

@@ -31,7 +31,6 @@ import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.context.Lifecycle;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
@@ -308,16 +307,6 @@ public abstract class AbstractStateMachine<S, E> extends StateMachineObjectSuppo
if (getBeanFactory() != null) {
executor.setBeanFactory(getBeanFactory());
}
if (getTaskExecutor() != null){
// parent machine is set when we're on substates(not regions)
// so then force sync executor which makes things a bit more reliable
// as state execution should anyway get synched with plain substates.
if(parentMachine != null) {
executor.setTaskExecutor(new SyncTaskExecutor());
} else {
executor.setTaskExecutor(getTaskExecutor());
}
}
executor.afterPropertiesSet();
executor.setStateMachineExecutorTransit(new StateMachineExecutorTransit<S, E>() {

View File

@@ -26,8 +26,6 @@ import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.SmartLifecycle;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.util.Assert;
import reactor.core.publisher.Mono;
@@ -49,10 +47,6 @@ public abstract class LifecycleObjectSupport
private volatile boolean autoStartup = false;
private volatile int phase = 0;
// common task handling
private TaskScheduler taskScheduler;
private TaskExecutor taskExecutor;
// to access bean factory
private volatile BeanFactory beanFactory;
@@ -168,56 +162,6 @@ public abstract class LifecycleObjectSupport
return beanFactory;
}
/**
* Sets the used {@link TaskScheduler}.
*
* @param taskScheduler the task scheduler
*/
public void setTaskScheduler(TaskScheduler taskScheduler) {
Assert.notNull(taskScheduler, "taskScheduler must not be null");
this.taskScheduler = taskScheduler;
}
/**
* Gets the defined {@link TaskScheduler}.
*
* @return the defined task scheduler
*/
protected TaskScheduler getTaskScheduler() {
if(taskScheduler == null && getBeanFactory() != null) {
if(log.isTraceEnabled()) {
log.trace("getting taskScheduler service from bean factory " + getBeanFactory());
}
taskScheduler = StateMachineContextUtils.getTaskScheduler(getBeanFactory());
}
return taskScheduler;
}
/**
* Sets the used {@link TaskExecutor}.
*
* @param taskExecutor the task executor
*/
public void setTaskExecutor(TaskExecutor taskExecutor) {
Assert.notNull(taskExecutor, "taskExecutor must not be null");
this.taskExecutor = taskExecutor;
}
/**
* Gets the defined {@link TaskExecutor}.
*
* @return the defined task executor
*/
protected TaskExecutor getTaskExecutor() {
if(taskExecutor == null && getBeanFactory() != null) {
if(log.isTraceEnabled()) {
log.trace("getting taskExecutor service from bean factory " + getBeanFactory());
}
taskExecutor = StateMachineContextUtils.getTaskExecutor(getBeanFactory());
}
return taskExecutor;
}
/**
* Subclasses may implement this for initialization logic. Called during the
* {@link InitializingBean} phase.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,9 +17,7 @@ package org.springframework.statemachine.support;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.task.TaskExecutor;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.statemachine.StateMachineSystemConstants;
import org.springframework.statemachine.event.StateMachineEventPublisher;
import org.springframework.util.Assert;
@@ -32,40 +30,12 @@ import org.springframework.util.Assert;
*/
public class StateMachineContextUtils {
/* Default task scheduler bean name */
public static final String TASK_SCHEDULER_BEAN_NAME = "taskScheduler";
/* Default task executor bean name */
public static final String TASK_EXECUTOR_BEAN_NAME = StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME;
/* Default conversion service bean name */
public static final String CONVERSION_SERVICE_BEAN_NAME = "cloudClusterConversionService";
/* Default evaluation context bean name */
public static final String EVALUATION_CONTEXT_BEAN_NAME = "cloudClusterEvaluationContext";
/**
* Return the {@link TaskScheduler} bean whose name is "taskScheduler" if
* available.
*
* @param beanFactory BeanFactory for lookup, must not be null.
* @return task scheduler
*/
public static TaskScheduler getTaskScheduler(BeanFactory beanFactory) {
return getBeanOfType(beanFactory, TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class);
}
/**
* Return the {@link TaskScheduler} bean whose name is "taskExecutor" if
* available.
*
* @param beanFactory BeanFactory for lookup, must not be null.
* @return task executor
*/
public static TaskExecutor getTaskExecutor(BeanFactory beanFactory) {
return getBeanOfType(beanFactory, TASK_EXECUTOR_BEAN_NAME, TaskExecutor.class);
}
/**
* Return the {@link ConversionService} bean whose name is
* "yarnConversionService" if available.

View File

@@ -25,13 +25,6 @@ import org.apache.commons.logging.LogFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.statemachine.action.Action;
import org.springframework.statemachine.guard.Guard;
import org.springframework.statemachine.listener.StateMachineListenerAdapter;
@@ -98,38 +91,6 @@ public abstract class AbstractStateMachineTests {
PLAY, STOP, PAUSE, EJECT, LOAD
}
@Configuration
public static class BaseConfig {
@Bean(name = StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME)
public TaskExecutor taskExecutor() {
return new SyncTaskExecutor();
}
@Bean
public TaskScheduler taskScheduler() {
return new ConcurrentTaskScheduler();
}
}
@Configuration
public static class BaseConfig2 {
@Bean(name = StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME)
public TaskExecutor taskExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
return taskExecutor;
}
@Bean
public TaskScheduler taskScheduler() {
return new ConcurrentTaskScheduler();
}
}
public static class TestEntryAction extends AbstractTestAction {
public TestEntryAction() {

View File

@@ -27,7 +27,6 @@ import org.apache.commons.logging.LogFactory;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.statemachine.action.Action;
import org.springframework.statemachine.action.Actions;
@@ -80,10 +79,8 @@ public class EnumStateMachineTests extends AbstractStateMachineTests {
transitions.add(transitionFromS1ToS2);
transitions.add(transitionFromS2ToS3);
SyncTaskExecutor taskExecutor = new SyncTaskExecutor();
BeanFactory beanFactory = new DefaultListableBeanFactory();
ObjectStateMachine<TestStates, TestEvents> machine = new ObjectStateMachine<TestStates, TestEvents>(states, transitions, stateSI);
machine.setTaskExecutor(taskExecutor);
machine.setBeanFactory(beanFactory);
machine.afterPropertiesSet();
machine.start();
@@ -155,10 +152,8 @@ public class EnumStateMachineTests extends AbstractStateMachineTests {
transitions.add(transitionFromS2ToS3);
// create machine
SyncTaskExecutor taskExecutor = new SyncTaskExecutor();
BeanFactory beanFactory = new DefaultListableBeanFactory();
ObjectStateMachine<TestStates, TestEvents> machine = new ObjectStateMachine<TestStates, TestEvents>(states, transitions, stateSI);
machine.setTaskExecutor(taskExecutor);
machine.setBeanFactory(beanFactory);
machine.afterPropertiesSet();
machine.start();
@@ -198,10 +193,8 @@ public class EnumStateMachineTests extends AbstractStateMachineTests {
Collection<Transition<TestStates,TestEvents>> transitions = new ArrayList<Transition<TestStates,TestEvents>>();
transitions.add(transitionInternalSI);
SyncTaskExecutor taskExecutor = new SyncTaskExecutor();
BeanFactory beanFactory = new DefaultListableBeanFactory();
ObjectStateMachine<TestStates, TestEvents> machine = new ObjectStateMachine<TestStates, TestEvents>(states, transitions, stateSI);
machine.setTaskExecutor(taskExecutor);
machine.setBeanFactory(beanFactory);
machine.afterPropertiesSet();
machine.start();

View File

@@ -32,10 +32,7 @@ import java.util.concurrent.atomic.AtomicReference;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.statemachine.config.EnableStateMachine;
import org.springframework.statemachine.config.StateMachineConfigurerAdapter;
import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
@@ -67,30 +64,6 @@ public class EventDeferTests extends AbstractStateMachineTests {
assertThat(readField.size(), is(2));
}
@Test
public void testDeferWithFlatThreadExecutor() throws Exception {
context.register(Config2.class, ExecutorConfig.class);
context.refresh();
StateMachine<String, String> machine = resolveMachine(context);
TestListener listener = new TestListener();
machine.addStateListener(listener);
doStartAndAssert(machine);
assertThat(listener.stateMachineStartedLatch.await(3, TimeUnit.SECONDS), is(true));
assertThat(listener.stateChangedLatch.await(3, TimeUnit.SECONDS), is(true));
listener.reset(1, 0, 0, 0);
doSendEventAndConsumeAll(machine, "E3");
assertThat(listener.stateChangedLatch.await(3, TimeUnit.SECONDS), is(true));
doSendEventAndConsumeAll(machine, "E1");
doSendEventAndConsumeAll(machine, "E1");
Object executor = TestUtils.readField("stateMachineExecutor", machine);
Collection<?> readField = TestUtils.readField("deferList", executor);
assertThat(readField.size(), is(2));
doSendEventAndConsumeAll(machine, "E2");
assertThat(readField.size(), is(3));
}
@Test
public void testDeferSmokeExecutorConcurrentModification() throws Exception {
context.register(Config5.class);
@@ -169,71 +142,6 @@ public class EventDeferTests extends AbstractStateMachineTests {
assertThat(machine.getState().getIds(), contains("READY"));
}
@Test
public void testDeferWithSubsThreadExecutor() throws Exception {
context.register(Config1.class, ExecutorConfig2.class);
context.refresh();
StateMachine<String, String> machine = resolveMachine(context);
TestListener listener = new TestListener();
machine.addStateListener(listener);
doStartAndAssert(machine);
assertThat(listener.stateMachineStartedLatch.await(3, TimeUnit.SECONDS), is(true));
assertThat(listener.stateChangedLatch.await(3, TimeUnit.SECONDS), is(true));
listener.reset(0, 0, 0, 1);
doSendEventAndConsumeAll(machine, "E3");
assertThat(listener.sub3readyStateEnteredLatch.await(3, TimeUnit.SECONDS), is(true));
assertThat(listener.sub3readyStateEnteredCount, is(1));
listener.reset(0, 0, 2, 0);
doSendEventAndConsumeAll(machine, "E1");
doSendEventAndConsumeAll(machine, "E1");
Object executor = TestUtils.readField("stateMachineExecutor", machine);
Collection<?> readField = TestUtils.readField("deferList", executor);
assertThat(readField.size(), is(2));
listener.reset(0, 0, 3, 0);
doSendEventAndConsumeAll(machine, "E4");
assertThat(listener.readyStateEnteredLatch.await(3, TimeUnit.SECONDS), is(true));
assertThat(listener.readyStateEnteredCount, is(3));
assertThat(machine.getState().getIds(), contains("READY"));
}
@Test
public void testDeferWithSubs2ThreadExecutor() throws Exception {
context.register(Config1.class, ExecutorConfig.class);
context.refresh();
StateMachine<String, String> machine = resolveMachine(context);
TestListener listener = new TestListener();
machine.addStateListener(listener);
doStartAndAssert(machine);
assertThat(listener.stateMachineStartedLatch.await(3, TimeUnit.SECONDS), is(true));
assertThat(listener.stateChangedLatch.await(3, TimeUnit.SECONDS), is(true));
listener.reset(0, 0, 2, 0);
doSendEventAndConsumeAll(machine, "E2");
doSendEventAndConsumeAll(machine, "E2");
assertThat(listener.readyStateEnteredLatch.await(3, TimeUnit.SECONDS), is(true));
assertThat(listener.readyStateEnteredCount, is(2));
assertThat(machine.getState().getIds(), contains("READY"));
}
@Test
public void testDeferWithSubs2ThreadExecutorSmoke() throws Exception {
// smoke above test to see threading issues
for (int i = 0; i < 500; i++) {
setup();
testDeferWithSubs2ThreadExecutor();
clean();
}
}
@Test
public void testSubNotDeferOverrideSuperTransition() throws Exception {
context.register(Config3.class);
@@ -636,32 +544,6 @@ public class EventDeferTests extends AbstractStateMachineTests {
}
}
@Configuration
static class ExecutorConfig {
@Bean(name=StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME)
public TaskExecutor taskExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(1);
taskExecutor.setMaxPoolSize(1);
return taskExecutor;
}
}
@Configuration
static class ExecutorConfig2 {
@Bean(name=StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME)
public TaskExecutor taskExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(1);
taskExecutor.setMaxPoolSize(4);
return taskExecutor;
}
}
static class TestListener extends StateMachineListenerAdapter<String, String> {
volatile CountDownLatch stateChangedLatch = new CountDownLatch(1);

View File

@@ -29,9 +29,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.statemachine.action.Action;
import org.springframework.statemachine.config.EnableStateMachine;
import org.springframework.statemachine.config.StateMachineConfigurerAdapter;
@@ -505,13 +503,6 @@ public class EventHeaderTests extends AbstractStateMachineTests {
public HeaderTestAction headerTestAction112() {
return new HeaderTestAction();
}
@Bean(name = StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME)
public TaskExecutor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(1);
return executor;
}
}
@Configuration
@@ -606,13 +597,6 @@ public class EventHeaderTests extends AbstractStateMachineTests {
public HeaderTestAction headerTestAction3() {
return new HeaderTestAction();
}
@Bean(name = StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME)
public TaskExecutor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(3);
return executor;
}
}
private static class HeaderTestAction implements Action<String, String> {

View File

@@ -140,7 +140,7 @@ public class ReactiveTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testJoin() throws Exception {
context.register(BaseConfig.class, Config2.class);
context.register(Config2.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);

View File

@@ -35,7 +35,6 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.statemachine.action.Actions;
import org.springframework.statemachine.config.EnableStateMachine;
import org.springframework.statemachine.config.EnumStateMachineConfigurerAdapter;
@@ -108,11 +107,9 @@ public class RegionMachineTests extends AbstractStateMachineTests {
transitions.add(transitionFromS1ToS2);
transitions.add(transitionFromS2ToS3);
SyncTaskExecutor taskExecutor = new SyncTaskExecutor();
BeanFactory beanFactory = new DefaultListableBeanFactory();
Transition<TestStates,TestEvents> initialTransition = new InitialTransition<TestStates,TestEvents>(stateSI);
ObjectStateMachine<TestStates, TestEvents> machine = new ObjectStateMachine<TestStates, TestEvents>(states, transitions, stateSI, initialTransition, null, null, null);
machine.setTaskExecutor(taskExecutor);
machine.setBeanFactory(beanFactory);
machine.afterPropertiesSet();
machine.start();
@@ -139,7 +136,6 @@ public class RegionMachineTests extends AbstractStateMachineTests {
@Test
public void testMultiRegionBuildRaw() throws Exception {
SyncTaskExecutor taskExecutor = new SyncTaskExecutor();
BeanFactory beanFactory = new DefaultListableBeanFactory();
PseudoState<TestStates,TestEvents> pseudoState = new DefaultPseudoState<TestStates,TestEvents>(PseudoStateKind.INITIAL);
State<TestStates,TestEvents> stateSI = new EnumState<TestStates,TestEvents>(TestStates.SI, pseudoState);
@@ -178,7 +174,6 @@ public class RegionMachineTests extends AbstractStateMachineTests {
transitions11.add(transitionFromS111ToS112);
Transition<TestStates,TestEvents> initialTransition11 = new InitialTransition<TestStates,TestEvents>(stateS111);
ObjectStateMachine<TestStates, TestEvents> machine11 = new ObjectStateMachine<TestStates, TestEvents>(states11, transitions11, stateS111, initialTransition11, null, null, null);
machine11.setTaskExecutor(taskExecutor);
machine11.setBeanFactory(beanFactory);
machine11.afterPropertiesSet();
@@ -191,7 +186,6 @@ public class RegionMachineTests extends AbstractStateMachineTests {
transitions12.add(transitionFromSIToS121);
Transition<TestStates,TestEvents> initialTransition12 = new InitialTransition<TestStates,TestEvents>(stateS121);
ObjectStateMachine<TestStates, TestEvents> machine12 = new ObjectStateMachine<TestStates, TestEvents>(states12, transitions12, stateS121, initialTransition12, null, null, null);
machine12.setTaskExecutor(taskExecutor);
machine12.setBeanFactory(beanFactory);
machine12.afterPropertiesSet();
@@ -209,7 +203,6 @@ public class RegionMachineTests extends AbstractStateMachineTests {
Transition<TestStates,TestEvents> initialTransition = new InitialTransition<TestStates,TestEvents>(stateR);
ObjectStateMachine<TestStates, TestEvents> machine = new ObjectStateMachine<TestStates, TestEvents>(states, transitions, stateR, initialTransition, null, null, null);
machine.setTaskExecutor(taskExecutor);
machine.setBeanFactory(beanFactory);
machine.afterPropertiesSet();
machine.start();
@@ -291,7 +284,7 @@ public class RegionMachineTests extends AbstractStateMachineTests {
@Test
public void testParallelRegionExecution() throws Exception {
context.register(Config3.class, BaseConfig2.class);
context.register(Config3.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
@SuppressWarnings("unchecked")
@@ -331,7 +324,7 @@ public class RegionMachineTests extends AbstractStateMachineTests {
@Test
public void testParallelRegionExecutionInInitialState() throws Exception {
context.register(Config4.class, BaseConfig2.class);
context.register(Config4.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
@SuppressWarnings("unchecked")

View File

@@ -29,11 +29,7 @@ import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
import org.springframework.context.SmartLifecycle;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.statemachine.config.EnableStateMachineFactory;
import org.springframework.statemachine.config.EnumStateMachineConfigurerAdapter;
import org.springframework.statemachine.config.StateMachineFactory;
@@ -155,12 +151,6 @@ public class StateMachineFactoryTests extends AbstractStateMachineTests {
.target(TestStates.S2)
.event(TestEvents.E1);
}
@Bean
public TaskExecutor taskExecutor() {
return new SyncTaskExecutor();
}
}
@Configuration
@@ -279,8 +269,7 @@ public class StateMachineFactoryTests extends AbstractStateMachineTests {
public void configure(StateMachineConfigurationConfigurer<TestStates, TestEvents> config) throws Exception {
config
.withConfiguration()
.autoStartup(true)
.taskExecutor(new SimpleAsyncTaskExecutor());
.autoStartup(true);
}
@Override

View File

@@ -37,8 +37,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.statemachine.action.Action;
import org.springframework.statemachine.config.EnableStateMachine;
@@ -72,7 +70,7 @@ public class StateMachineTests extends AbstractStateMachineTests {
@Test
public void testTimerTransition() throws Exception {
context.register(BaseConfig.class, Config2.class);
context.register(Config2.class);
context.refresh();
TestAction testAction1 = context.getBean("testAction1", TestAction.class);
@@ -120,7 +118,7 @@ public class StateMachineTests extends AbstractStateMachineTests {
@Test
public void testForkJoin() throws Exception {
context.register(BaseConfig.class, Config3.class);
context.register(Config3.class);
context.refresh();
StateMachine<TestStates, TestEvents> machine = resolveMachine(context);
TestListener listener = new TestListener();
@@ -174,7 +172,7 @@ public class StateMachineTests extends AbstractStateMachineTests {
@Test
public void testBackToItself() {
context.register(BaseConfig.class, Config5.class);
context.register(Config5.class);
context.refresh();
StateMachine<TestStates, TestEvents> machine = resolveMachine(context);
assertThat(machine, notNullValue());
@@ -254,12 +252,6 @@ public class StateMachineTests extends AbstractStateMachineTests {
public LoggingAction loggingAction() {
return new LoggingAction("as bean");
}
@Bean
public TaskExecutor taskExecutor() {
return new SyncTaskExecutor();
}
}
@Configuration

View File

@@ -33,7 +33,6 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.statemachine.action.Action;
import org.springframework.statemachine.action.Actions;
import org.springframework.statemachine.config.EnableStateMachine;
@@ -134,15 +133,11 @@ public class SubStateMachineTests extends AbstractStateMachineTests {
ObjectStateMachine<TestStates, TestEvents> machine = new ObjectStateMachine<TestStates, TestEvents>(states, transitions, stateS1);
SyncTaskExecutor taskExecutor = new SyncTaskExecutor();
BeanFactory beanFactory = new DefaultListableBeanFactory();
machine.setTaskExecutor(taskExecutor);
machine.setBeanFactory(beanFactory);
machine.afterPropertiesSet();
submachine1.setTaskExecutor(taskExecutor);
submachine1.setBeanFactory(beanFactory);
submachine1.afterPropertiesSet();
submachine11.setTaskExecutor(taskExecutor);
submachine11.setBeanFactory(beanFactory);
submachine11.afterPropertiesSet();
machine.start();
@@ -231,12 +226,9 @@ public class SubStateMachineTests extends AbstractStateMachineTests {
ObjectStateMachine<TestStates, TestEvents> machine = new ObjectStateMachine<TestStates, TestEvents>(states, transitions, stateS1);
SyncTaskExecutor taskExecutor = new SyncTaskExecutor();
BeanFactory beanFactory = new DefaultListableBeanFactory();
machine.setTaskExecutor(taskExecutor);
machine.setBeanFactory(beanFactory);
machine.afterPropertiesSet();
submachine11.setTaskExecutor(taskExecutor);
submachine11.setBeanFactory(beanFactory);
submachine11.afterPropertiesSet();
machine.start();
@@ -332,15 +324,11 @@ public class SubStateMachineTests extends AbstractStateMachineTests {
ObjectStateMachine<TestStates, TestEvents> machine = new ObjectStateMachine<TestStates, TestEvents>(states, transitions, stateS1);
SyncTaskExecutor taskExecutor = new SyncTaskExecutor();
BeanFactory beanFactory = new DefaultListableBeanFactory();
machine.setTaskExecutor(taskExecutor);
machine.setBeanFactory(beanFactory);
machine.afterPropertiesSet();
submachine1.setTaskExecutor(taskExecutor);
submachine1.setBeanFactory(beanFactory);
submachine1.afterPropertiesSet();
submachine11.setTaskExecutor(taskExecutor);
submachine11.setBeanFactory(beanFactory);
submachine11.afterPropertiesSet();
machine.start();
@@ -364,7 +352,7 @@ public class SubStateMachineTests extends AbstractStateMachineTests {
@Test
public void testExternalTransition3() throws Exception {
context.register(BaseConfig.class, Config1.class);
context.register(Config1.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
@SuppressWarnings("unchecked")
@@ -400,7 +388,7 @@ public class SubStateMachineTests extends AbstractStateMachineTests {
@Test
public void testMixedStates() throws Exception {
context.register(BaseConfig.class, Config2.class);
context.register(Config2.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
@SuppressWarnings("unchecked")
@@ -414,7 +402,7 @@ public class SubStateMachineTests extends AbstractStateMachineTests {
@Test
public void testStateChangeWithinMachine() {
context.register(BaseConfig.class, Config3.class);
context.register(Config3.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
@SuppressWarnings("unchecked")

View File

@@ -30,8 +30,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.statemachine.AbstractStateMachineTests;
import org.springframework.statemachine.StateContext;
import org.springframework.statemachine.StateMachine;
@@ -73,35 +71,6 @@ public class ActionAndTimerTests extends AbstractStateMachineTests {
assertThat(testExitAction.e, nullValue());
}
@Test
public void testExitActionWithTimerOnceThreadPoolTaskScheduler() throws Exception {
context.register(Config2.class);
context.refresh();
StateMachine<TestStates, TestEvents> machine = resolveMachine(context);
TestTimerAction testTimerAction = context.getBean(TestTimerAction.class);
TestExitAction testExitAction = context.getBean(TestExitAction.class);
TestListener testListener = new TestListener();
machine.addStateListener(testListener);
doStartAndAssert(machine);
assertThat(machine.getState().getIds(), containsInAnyOrder(TestStates.S1));
doSendEventAndConsumeAll(machine, TestEvents.E1);
assertThat(machine.getState().getIds(), containsInAnyOrder(TestStates.S2));
assertThat(testTimerAction.latch.await(4, TimeUnit.SECONDS), is(true));
assertThat(testTimerAction.e, nullValue());
// need to sleep for TimerTrigger not causing
// next event to get handled with threads, thus
// causing interrupt
Thread.sleep(1000);
doSendEventAndConsumeAll(machine, TestEvents.E2);
assertThat(testListener.s3EnteredLatch.await(2, TimeUnit.SECONDS), is(true));
assertThat(machine.getState().getIds(), containsInAnyOrder(TestStates.S3));
assertThat(testExitAction.latch.await(2, TimeUnit.SECONDS), is(true));
assertThat(testExitAction.e, nullValue());
}
@Configuration
@EnableStateMachine
static class Config1 extends EnumStateMachineConfigurerAdapter<TestStates, TestEvents> {
@@ -177,12 +146,6 @@ public class ActionAndTimerTests extends AbstractStateMachineTests {
.timerOnce(1000);
}
@Bean
public TaskScheduler taskScheduler() {
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
return taskScheduler;
}
@Bean
public TestExitAction testExitAction() {
return new TestExitAction();

View File

@@ -30,8 +30,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.statemachine.AbstractStateMachineTests;
import org.springframework.statemachine.StateContext;
import org.springframework.statemachine.StateMachine;
@@ -208,11 +206,6 @@ public class ActionTests extends AbstractStateMachineTests {
public TestCountAction testAction3() {
return new TestCountAction();
}
@Bean
public TaskExecutor taskExecutor() {
return new SyncTaskExecutor();
}
}
@Configuration
@@ -253,12 +246,6 @@ public class ActionTests extends AbstractStateMachineTests {
public TestCountAction testErrorAction() {
return new TestCountAction();
}
@Bean
public TaskExecutor taskExecutor() {
return new SyncTaskExecutor();
}
}
@Configuration

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,7 +43,7 @@ public class ClassAnnotationTests extends AbstractStateMachineTests {
@SuppressWarnings("unchecked")
public void testClassAnnotations() throws Exception {
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext(BaseConfig.class, BeanConfig1.class, FooConfig.class, BarConfig.class);
new AnnotationConfigApplicationContext(BeanConfig1.class, FooConfig.class, BarConfig.class);
ObjectStateMachine<TestStates,TestEvents> fooMachine =
context.getBean("fooMachine", ObjectStateMachine.class);
@@ -82,7 +82,7 @@ public class ClassAnnotationTests extends AbstractStateMachineTests {
@SuppressWarnings("unchecked")
public void testClassAnnotationsWithMeta() throws Exception {
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext(BaseConfig.class, BeanConfig2.class, JeeConfig.class, FooConfig.class);
new AnnotationConfigApplicationContext(BeanConfig2.class, JeeConfig.class, FooConfig.class);
ObjectStateMachine<TestStates,TestEvents> jeeMachine =
context.getBean("jeeMachine", ObjectStateMachine.class);

View File

@@ -55,7 +55,7 @@ public class MethodAnnotationTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testOnTransition() throws Exception {
context.register(BaseConfig.class, BeanConfig1.class, Config1.class);
context.register(BeanConfig1.class, Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
@@ -84,7 +84,7 @@ public class MethodAnnotationTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testOnStateChanged() throws Exception {
context.register(BaseConfig.class, BeanConfig1.class, Config1.class);
context.register(BeanConfig1.class, Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
@@ -113,7 +113,7 @@ public class MethodAnnotationTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testOnStateMachineStartStop() throws Exception {
context.register(BaseConfig.class, BeanConfig1.class, Config1.class);
context.register(BeanConfig1.class, Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -139,7 +139,7 @@ public class MethodAnnotationTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testOnExtendedStateChanged() throws Exception {
context.register(BaseConfig.class, BeanConfig5.class, Config1.class);
context.register(BeanConfig5.class, Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
@@ -166,7 +166,7 @@ public class MethodAnnotationTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testMethodAnnotations2() throws Exception {
context.register(BaseConfig.class, BeanConfig2.class, Config1.class);
context.register(BeanConfig2.class, Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
@@ -203,7 +203,7 @@ public class MethodAnnotationTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testMethodAnnotations3() throws Exception {
context.register(BaseConfig.class, BeanConfig3.class, Config1.class);
context.register(BeanConfig3.class, Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
@@ -222,7 +222,7 @@ public class MethodAnnotationTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testMethodAnnotations4() throws Exception {
context.register(BaseConfig.class, BeanConfig4.class, Config1.class);
context.register(BeanConfig4.class, Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
@@ -249,7 +249,7 @@ public class MethodAnnotationTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testMethodAnnotations5() throws Exception {
context.register(BaseConfig.class, BeanConfig6.class, Config1.class);
context.register(BeanConfig6.class, Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
@@ -270,7 +270,7 @@ public class MethodAnnotationTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testMethodAnnotations6() throws Exception {
context.register(BaseConfig.class, BeanConfig7.class, Config1.class);
context.register(BeanConfig7.class, Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
@@ -290,7 +290,7 @@ public class MethodAnnotationTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testMethodAnnotations7() throws Exception {
context.register(BaseConfig.class, BeanConfig8.class, Config1.class);
context.register(BeanConfig8.class, Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
@@ -307,7 +307,7 @@ public class MethodAnnotationTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testMethodAnnotations8() throws Exception {
context.register(BaseConfig.class, BeanConfig9.class, Config2.class);
context.register(BeanConfig9.class, Config2.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
@@ -328,7 +328,7 @@ public class MethodAnnotationTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testMethodAnnotations9() throws Exception {
context.register(BaseConfig.class, BeanConfig10.class, Config3.class);
context.register(BeanConfig10.class, Config3.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2017 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package org.springframework.statemachine.config;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.sameInstance;
@@ -38,9 +37,6 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.statemachine.AbstractStateMachineTests;
import org.springframework.statemachine.ObjectStateMachine;
import org.springframework.statemachine.StateMachine;
@@ -176,66 +172,6 @@ public class ConfigurationTests extends AbstractStateMachineTests {
});
}
@Test
public void testTaskExecutor1() throws Exception {
// set in builder, no bf or taskExecutor bean registered
context.register(Config14.class);
context.refresh();
@SuppressWarnings("unchecked")
StateMachine<String, String> stateMachine = context.getBean(StateMachine.class);
Object executorFromMachine = TestUtils.readField("taskExecutor", stateMachine);
Object stateMachineExecutor = TestUtils.readField("stateMachineExecutor", stateMachine);
Object executorFromExecutor = TestUtils.readField("taskExecutor", stateMachineExecutor);
assertThat(executorFromMachine, sameInstance(Config14.taskExecutor));
assertThat(executorFromExecutor, sameInstance(Config14.taskExecutor));
assertThat(executorFromMachine, notNullValue());
assertThat(executorFromExecutor, notNullValue());
assertThat(executorFromMachine, sameInstance(executorFromExecutor));
}
@Test
public void testTaskExecutor2() throws Exception {
// set as bean, should get from bf
context.register(BaseConfig.class, Config15.class);
context.refresh();
@SuppressWarnings("unchecked")
StateMachine<String, String> stateMachine = context.getBean(StateMachine.class);
assertThat(context.containsBean(StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME), is(true));
Object stateMachineExecutor = TestUtils.readField("stateMachineExecutor", stateMachine);
Object executorFromMachine = TestUtils.callMethod("getTaskExecutor", stateMachine);
Object executorFromExecutor = TestUtils.callMethod("getTaskExecutor", stateMachineExecutor);
assertThat(executorFromMachine, notNullValue());
assertThat(executorFromExecutor, notNullValue());
assertThat(executorFromMachine, sameInstance(executorFromExecutor));
}
@Test
public void testTaskExecutor3() throws Exception {
// override task execution via configurer
context.register(Config19.class);
context.refresh();
@SuppressWarnings("unchecked")
StateMachine<String, String> stateMachine = context.getBean(StateMachine.class);
assertThat(context.containsBean(StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME), is(true));
Object stateMachineExecutor = TestUtils.readField("stateMachineExecutor", stateMachine);
Object executorFromMachine = TestUtils.callMethod("getTaskExecutor", stateMachine);
Object executorFromExecutor = TestUtils.callMethod("getTaskExecutor", stateMachineExecutor);
assertThat(executorFromMachine, notNullValue());
assertThat(executorFromExecutor, notNullValue());
assertThat(executorFromMachine, sameInstance(executorFromExecutor));
assertThat(executorFromMachine, instanceOf(ThreadPoolTaskExecutor.class));
}
@Test
public void testBeanFactory1() throws Exception {
// should come from context
@@ -318,7 +254,7 @@ public class ConfigurationTests extends AbstractStateMachineTests {
}
}
}
@Test
public void testMachinesWithDependenciesAndConstructorInjection() {
context.register(Config21.class);
@@ -329,8 +265,8 @@ public class ConfigurationTests extends AbstractStateMachineTests {
StateMachine<String,String> stateMachine22 = stateMachineFactory22.getStateMachine();
assertThat(stateMachine22, notNullValue());
}
@Configuration
@EnableStateMachine
@@ -367,12 +303,6 @@ public class ConfigurationTests extends AbstractStateMachineTests {
public TestGuard testGuard() {
return new TestGuard();
}
@Bean
public TaskExecutor taskExecutor() {
return new SyncTaskExecutor();
}
}
@Configuration
@@ -745,16 +675,12 @@ public class ConfigurationTests extends AbstractStateMachineTests {
@Configuration
public static class Config14 {
public static TaskExecutor taskExecutor = new SyncTaskExecutor();
@Bean
StateMachine<String, String> stateMachine() throws Exception {
Builder<String, String> builder = StateMachineBuilder.builder();
builder.configureConfiguration()
.withConfiguration()
.autoStartup(false)
.taskExecutor(taskExecutor);
.autoStartup(false);
builder.configureStates()
.withStates()
.initial("S1").state("S2");
@@ -887,7 +813,6 @@ public class ConfigurationTests extends AbstractStateMachineTests {
public void configure(StateMachineConfigurationConfigurer<String, String> config) throws Exception {
config
.withConfiguration()
.taskExecutor(taskExecutor())
.autoStartup(true);
}
@@ -907,11 +832,6 @@ public class ConfigurationTests extends AbstractStateMachineTests {
.target("S2")
.event("E1");
}
@Bean(name = "fakeBeanName")
public TaskExecutor taskExecutor() {
return new ThreadPoolTaskExecutor();
}
}
@Configuration
@@ -936,7 +856,7 @@ public class ConfigurationTests extends AbstractStateMachineTests {
.event("E1");
}
}
@Configuration
@EnableStateMachineFactory(name="stateMachineConfig21")
public static class Config21 extends StateMachineConfigurerAdapter<String, String> {

View File

@@ -1,160 +0,0 @@
/*
* Copyright 2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.statemachine.config;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.statemachine.AbstractStateMachineTests;
import org.springframework.statemachine.ObjectStateMachine;
import org.springframework.statemachine.StateMachineSystemConstants;
import org.springframework.statemachine.TestUtils;
import org.springframework.statemachine.config.builders.StateMachineConfigurationConfigurer;
import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;
public class ContextTests extends AbstractStateMachineTests {
@Override
protected AnnotationConfigApplicationContext buildContext() {
return new AnnotationConfigApplicationContext();
}
@SuppressWarnings("unchecked")
@Test
public void testTaskExecutor() throws Exception {
context.register(Config2.class);
context.refresh();
ObjectStateMachine<String, String> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
assertThat(TestUtils.readField("taskExecutor", machine), instanceOf(SyncTaskExecutor.class));
}
@SuppressWarnings("unchecked")
@Test
public void testTaskExecutorWithScheduling() throws Exception {
context.register(Config1.class, Config2.class);
context.refresh();
ObjectStateMachine<String, String> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
assertThat(TestUtils.readField("taskExecutor", machine), instanceOf(SyncTaskExecutor.class));
}
@SuppressWarnings("unchecked")
@Test
public void testTaskExecutorOverrideFromBean() throws Exception {
context.register(Config2.class, Config3.class);
context.refresh();
ObjectStateMachine<String, String> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
assertThat(TestUtils.readField("taskExecutor", machine), instanceOf(ThreadPoolTaskExecutor.class));
}
@SuppressWarnings("unchecked")
@Test
public void testTaskExecutorOverrideFromConfig() throws Exception {
context.register(Config4.class);
context.refresh();
ObjectStateMachine<String, String> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
assertThat(TestUtils.readField("taskExecutor", machine), instanceOf(ThreadPoolTaskExecutor.class));
}
@Configuration
@EnableScheduling
static class Config1 {
@Scheduled(fixedRate=500)
public void scheduledMethod() {
}
}
@Configuration
@EnableStateMachine
static class Config2 extends StateMachineConfigurerAdapter<String, String> {
@Override
public void configure(StateMachineStateConfigurer<String, String> states) throws Exception {
states
.withStates()
.initial("SI")
.state("S1")
.state("S2");
}
@Override
public void configure(StateMachineTransitionConfigurer<String, String> transitions) throws Exception {
transitions
.withExternal()
.source("SI")
.target("S1")
.event("E1");
}
}
@Configuration
static class Config3 {
@Bean(name = StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME)
public TaskExecutor myTaskExecutor() {
return new ThreadPoolTaskExecutor();
}
}
@Configuration
@EnableStateMachine
static class Config4 extends StateMachineConfigurerAdapter<String, String> {
@Override
public void configure(StateMachineConfigurationConfigurer<String, String> config) throws Exception {
config
.withConfiguration()
.taskExecutor(new ThreadPoolTaskExecutor());
}
@Override
public void configure(StateMachineStateConfigurer<String, String> states) throws Exception {
states
.withStates()
.initial("SI")
.state("S1")
.state("S2");
}
@Override
public void configure(StateMachineTransitionConfigurer<String, String> transitions) throws Exception {
transitions
.withExternal()
.source("SI")
.target("S1")
.event("E1");
}
}
}

View File

@@ -29,7 +29,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.statemachine.AbstractStateMachineTests;
import org.springframework.statemachine.StateMachine;
import org.springframework.statemachine.config.StateMachineBuilder.Builder;
@@ -83,8 +82,7 @@ public class ManualBuilderContextTests extends AbstractStateMachineTests {
builder.configureConfiguration()
.withConfiguration()
.autoStartup(true)
.listener(testListener())
.taskExecutor(new SyncTaskExecutor());
.listener(testListener());
builder.configureStates()
.withStates()
.initial("S1").state("S2");
@@ -114,8 +112,7 @@ public class ManualBuilderContextTests extends AbstractStateMachineTests {
builder.configureConfiguration()
.withConfiguration()
.autoStartup(false)
.listener(testListener())
.taskExecutor(new SyncTaskExecutor());
.listener(testListener());
builder.configureStates()
.withStates()
.initial("S1").state("S2");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,11 +28,7 @@ import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.support.StaticListableBeanFactory;
import org.springframework.context.SmartLifecycle;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
import org.springframework.statemachine.StateMachine;
import org.springframework.statemachine.StateMachineSystemConstants;
import org.springframework.statemachine.TestUtils;
import org.springframework.statemachine.config.StateMachineBuilder.Builder;
import org.springframework.statemachine.config.builders.StateMachineConfigBuilder;
import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
@@ -60,8 +56,6 @@ public class ManualBuilderTests {
new DefaultStateMachineModel<String, String>(stateMachineConfigurationConfig, stateMachineStates, stateMachineTransitions));
StaticListableBeanFactory beanFactory = new StaticListableBeanFactory();
beanFactory.addBean(StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME, new SyncTaskExecutor());
beanFactory.addBean("taskScheduler", new ConcurrentTaskScheduler());
stateMachineFactory.setBeanFactory(beanFactory);
TestListener listener = new TestListener();
@@ -80,8 +74,6 @@ public class ManualBuilderTests {
Builder<String, String> builder = StateMachineBuilder.builder();
StaticListableBeanFactory beanFactory = new StaticListableBeanFactory();
beanFactory.addBean(StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME, new SyncTaskExecutor());
beanFactory.addBean("taskScheduler", new ConcurrentTaskScheduler());
builder.configureConfiguration()
.withConfiguration()
@@ -115,8 +107,6 @@ public class ManualBuilderTests {
Builder<MyStates, MyEvents> builder = StateMachineBuilder.builder();
StaticListableBeanFactory beanFactory = new StaticListableBeanFactory();
beanFactory.addBean(StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME, new SyncTaskExecutor());
beanFactory.addBean("taskScheduler", new ConcurrentTaskScheduler());
builder.configureConfiguration()
.withConfiguration()
@@ -152,76 +142,13 @@ public class ManualBuilderTests {
assertThat(stateMachine.getState().getIds(), containsInAnyOrder(MyStates.S2));
}
@Test
public void testManualBuildExplicitTaskExecutorAndScheduler() throws Exception {
Builder<String, String> builder = StateMachineBuilder.builder();
builder.configureConfiguration()
.withConfiguration()
.taskExecutor(new SyncTaskExecutor())
.taskScheduler(new ConcurrentTaskScheduler());
builder.configureStates()
.withStates()
.initial("S1").state("S2");
builder.configureTransitions()
.withExternal()
.source("S1").target("S2").event("E1")
.and()
.withExternal()
.source("S2").target("S1").event("E2");
StateMachine<String, String> stateMachine = builder.build();
assertThat(stateMachine, notNullValue());
TestListener listener = new TestListener();
stateMachine.addStateListener(listener);
doStartAndAssert(stateMachine);
assertThat(listener.stateChangedLatch.await(2, TimeUnit.SECONDS), is(true));
assertThat(listener.stateChangedCount, is(1));
assertThat(stateMachine, notNullValue());
assertThat(stateMachine.getState().getIds(), containsInAnyOrder("S1"));
listener.reset(1);
doSendEventAndConsumeAll(stateMachine, "E1");
assertThat(listener.stateChangedLatch.await(2, TimeUnit.SECONDS), is(true));
assertThat(listener.stateChangedCount, is(1));
assertThat(stateMachine, notNullValue());
assertThat(stateMachine.getState().getIds(), containsInAnyOrder("S2"));
}
@Test
public void testManualBuildDefaultTaskExecutor() throws Exception {
Builder<String, String> builder = StateMachineBuilder.builder();
builder.configureStates()
.withStates()
.initial("S1").state("S2");
builder.configureTransitions()
.withExternal()
.source("S1").target("S2").event("E1")
.and()
.withExternal()
.source("S2").target("S1").event("E2");
StateMachine<String, String> stateMachine = builder.build();
assertThat(stateMachine, notNullValue());
assertThat(TestUtils.readField("taskExecutor", stateMachine), notNullValue());
assertThat(TestUtils.readField("taskScheduler", stateMachine), notNullValue());
}
@Test
public void testAutoStartFlagOn() throws Exception {
Builder<String, String> builder = StateMachineBuilder.builder();
builder.configureConfiguration()
.withConfiguration()
.autoStartup(true)
.taskExecutor(new SyncTaskExecutor())
.taskScheduler(new ConcurrentTaskScheduler());
.autoStartup(true);
builder.configureStates()
.withStates()
@@ -279,12 +206,6 @@ public class ManualBuilderTests {
stateChangedCount++;
stateChangedLatch.countDown();
}
public void reset(int a1) {
stateChangedCount = 0;
stateChangedLatch = new CountDownLatch(a1);
}
}
private static class TestListener2 extends StateMachineListenerAdapter<MyStates, MyEvents> {

View File

@@ -31,7 +31,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -137,8 +136,7 @@ public class SessionScopedManualTests {
Builder<String, String> builder = StateMachineBuilder.builder();
builder.configureConfiguration()
.withConfiguration()
.autoStartup(true)
.taskExecutor(new SyncTaskExecutor());
.autoStartup(true);
builder.configureStates()
.withStates()
.initial("S1").state("S2");

View File

@@ -29,9 +29,6 @@ import java.util.Map;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.security.access.AccessDecisionManager;
import org.springframework.statemachine.StateMachine;
import org.springframework.statemachine.config.ObjectStateMachineFactory;
@@ -47,8 +44,6 @@ public class StateMachineModelTests {
@Test
public void testMachineManuallyViaModel() {
BeanFactory beanFactory = null;
TaskExecutor taskExecutor = new SyncTaskExecutor();
TaskScheduler taskScheduler = null;
boolean autoStart = false;
StateMachineEnsemble<String, String> ensemble = null;
List<StateMachineListener<String, String>> listeners = new ArrayList<>();
@@ -60,8 +55,8 @@ public class StateMachineModelTests {
boolean verifierEnabled = true;
StateMachineModelVerifier<String, String> verifier = new DefaultStateMachineModelVerifier<>();
ConfigurationData<String, String> configurationData = new ConfigurationData<>(beanFactory, taskExecutor, taskScheduler, autoStart,
ensemble, listeners, securityEnabled, transitionSecurityAccessDecisionManager, eventSecurityAccessDecisionManager,
ConfigurationData<String, String> configurationData = new ConfigurationData<>(beanFactory, autoStart, ensemble,
listeners, securityEnabled, transitionSecurityAccessDecisionManager, eventSecurityAccessDecisionManager,
eventSecurityRule, transitionSecurityRule, verifierEnabled, verifier, null, null, null);
Collection<StateData<String, String>> stateData = new ArrayList<>();

View File

@@ -24,13 +24,11 @@ import org.springframework.beans.factory.support.StaticListableBeanFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
import org.springframework.statemachine.AbstractStateMachineTests;
import org.springframework.statemachine.StateContext;
import org.springframework.statemachine.StateMachine;
@@ -437,8 +435,6 @@ public class DocsConfigurationSampleTests extends AbstractStateMachineTests {
.withConfiguration()
.autoStartup(false)
.beanFactory(null)
.taskExecutor(null)
.taskScheduler(null)
.listener(null);
return builder.build();
}
@@ -1193,8 +1189,6 @@ public class DocsConfigurationSampleTests extends AbstractStateMachineTests {
.autoStartup(true)
.machineId("myMachineId")
.beanFactory(new StaticListableBeanFactory())
.taskExecutor(new SyncTaskExecutor())
.taskScheduler(new ConcurrentTaskScheduler())
.listener(new StateMachineListenerAdapter<States, Events>())
.transitionConflictPolicy(TransitionConflictPolicy.CHILD);
}

View File

@@ -31,17 +31,13 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.statemachine.AbstractStateMachineTests;
import org.springframework.statemachine.StateContext;
import org.springframework.statemachine.StateMachine;
import org.springframework.statemachine.StateMachineSystemConstants;
import org.springframework.statemachine.action.Action;
import org.springframework.statemachine.config.EnableStateMachine;
import org.springframework.statemachine.config.StateMachineBuilder;
@@ -128,8 +124,7 @@ public class DocsConfigurationSampleTests2 extends AbstractStateMachineTests {
Builder<String, String> builder = StateMachineBuilder.builder();
builder.configureConfiguration()
.withConfiguration()
.autoStartup(true)
.taskExecutor(new SyncTaskExecutor());
.autoStartup(true);
builder.configureStates()
.withStates()
.initial("S1")
@@ -205,7 +200,7 @@ public class DocsConfigurationSampleTests2 extends AbstractStateMachineTests {
@Test
public void testConfig51() throws Exception {
context.register(Config5.class, ExecutorConfig.class);
context.register(Config5.class);
context.refresh();
StateMachine<String, String> machine = resolveMachine(context);
TestListener listener = new TestListener();
@@ -241,7 +236,7 @@ public class DocsConfigurationSampleTests2 extends AbstractStateMachineTests {
@Test
public void testConfig61() throws Exception {
context.register(Config6.class, ExecutorConfig.class);
context.register(Config6.class);
context.refresh();
StateMachine<String, String> machine = resolveMachine(context);
TestListener listener = new TestListener();
@@ -275,17 +270,6 @@ public class DocsConfigurationSampleTests2 extends AbstractStateMachineTests {
assertThat(listener.readyStateEnteredCount, is(2));
}
@Configuration
static class ExecutorConfig {
@Bean(name=StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME)
public TaskExecutor taskExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(1);
return taskExecutor;
}
}
// tag::snippetE[]
@Configuration
@EnableStateMachine

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -54,7 +54,7 @@ public class ContextEventTests extends AbstractStateMachineTests {
@SuppressWarnings("unchecked")
@Test
public void contextEventsEnabled() throws Exception {
context.register(BaseConfig.class, Config.class, Config1.class);
context.register(Config.class, Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -68,7 +68,7 @@ public class ContextEventTests extends AbstractStateMachineTests {
@SuppressWarnings("unchecked")
@Test
public void contextEventsDisabled() throws Exception {
context.register(BaseConfig.class, Config.class, Config2.class);
context.register(Config.class, Config2.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -82,7 +82,7 @@ public class ContextEventTests extends AbstractStateMachineTests {
@SuppressWarnings("unchecked")
@Test
public void contextEventsWithManualBuilder() throws Exception {
context.register(BaseConfig.class, Config.class, Config3.class);
context.register(Config.class, Config3.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -96,7 +96,7 @@ public class ContextEventTests extends AbstractStateMachineTests {
@SuppressWarnings("unchecked")
@Test
public void contextEventsWithManualBuilderExternalConfigClass() throws Exception {
context.register(BaseConfig.class, Config.class, ExternalConfig.class);
context.register(Config.class, ExternalConfig.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);

View File

@@ -57,7 +57,7 @@ public class StateMachineEventTests extends AbstractStateMachineTests {
@Test
public void testContextEvents() throws Exception {
context.register(BaseConfig.class, Config1.class);
context.register(Config1.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
TestEventListener listener = context.getBean(TestEventListener.class);
@@ -80,7 +80,7 @@ public class StateMachineEventTests extends AbstractStateMachineTests {
@Test
public void testEventNotAccepted() throws Exception {
context.register(BaseConfig.class, Config1.class);
context.register(Config1.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
TestEventListener eventListener = context.getBean(TestEventListener.class);
@@ -110,7 +110,7 @@ public class StateMachineEventTests extends AbstractStateMachineTests {
@Test
public void testSubmachineHandlesEvent() throws Exception {
context.register(BaseConfig.class, Config2.class);
context.register(Config2.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
@SuppressWarnings("unchecked")
@@ -126,7 +126,7 @@ public class StateMachineEventTests extends AbstractStateMachineTests {
@Test
public void testEventNotAcceptedS1() throws Exception {
context.register(BaseConfig.class, Config3.class);
context.register(Config3.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
@SuppressWarnings("unchecked")
@@ -148,7 +148,7 @@ public class StateMachineEventTests extends AbstractStateMachineTests {
@Test
public void testEventAcceptedS1() throws Exception {
context.register(BaseConfig.class, Config3.class);
context.register(Config3.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
@SuppressWarnings("unchecked")
@@ -170,7 +170,7 @@ public class StateMachineEventTests extends AbstractStateMachineTests {
@Test
public void testEventAcceptedS1NoS1Transition() throws Exception {
context.register(BaseConfig.class, Config4.class);
context.register(Config4.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
@SuppressWarnings("unchecked")
@@ -192,7 +192,7 @@ public class StateMachineEventTests extends AbstractStateMachineTests {
@Test
public void testEventAcceptedS1GuardAllow() throws Exception {
context.register(BaseConfig.class, Config3.class);
context.register(Config3.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
@SuppressWarnings("unchecked")
@@ -215,7 +215,7 @@ public class StateMachineEventTests extends AbstractStateMachineTests {
@Test
public void testEventAcceptedS11GuardAllow() throws Exception {
context.register(BaseConfig.class, Config3.class);
context.register(Config3.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
@SuppressWarnings("unchecked")
@@ -238,7 +238,7 @@ public class StateMachineEventTests extends AbstractStateMachineTests {
@Test
public void testEventAcceptedS111GuardAllow() throws Exception {
context.register(BaseConfig.class, Config3.class);
context.register(Config3.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
@SuppressWarnings("unchecked")

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,8 +26,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.statemachine.AbstractStateMachineTests.TestAction;
import org.springframework.statemachine.AbstractStateMachineTests.TestEvents;
import org.springframework.statemachine.AbstractStateMachineTests.TestGuard;
@@ -139,12 +137,6 @@ public class GuardTests {
public TestGuard testGuard() {
return new TestGuard(true);
}
@Bean
public TaskExecutor taskExecutor() {
return new SyncTaskExecutor();
}
}
@Configuration
@@ -180,12 +172,6 @@ public class GuardTests {
public TestAction testAction() {
return new TestAction();
}
@Bean
public TaskExecutor taskExecutor() {
return new SyncTaskExecutor();
}
}
@Configuration

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -67,7 +67,7 @@ public class SpelExpressionGuardTests extends AbstractStateMachineTests {
@SuppressWarnings({ "unchecked" })
@Test
public void testGuardDenyStateChange() throws Exception {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(BaseConfig.class, Config1.class);
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config1.class);
assertTrue(ctx.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
ObjectStateMachine<TestStates,TestEvents> machine =
ctx.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,8 +31,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.statemachine.AbstractStateMachineTests;
@@ -273,12 +271,6 @@ public class ListenerTests extends AbstractStateMachineTests {
public LoggingAction loggingAction() {
return new LoggingAction("as bean");
}
@Bean
public TaskExecutor taskExecutor() {
return new SyncTaskExecutor();
}
}
@Configuration
@@ -309,12 +301,5 @@ public class ListenerTests extends AbstractStateMachineTests {
.target(TestStates.S3)
.event(TestEvents.E2);
}
@Bean
public TaskExecutor taskExecutor() {
return new SyncTaskExecutor();
}
}
}

View File

@@ -23,7 +23,6 @@ import static org.springframework.statemachine.TestUtils.doSendEventAndConsumeAl
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.statemachine.AbstractStateMachineTests;
import org.springframework.statemachine.StateMachine;
import org.springframework.statemachine.config.StateMachineBuilder;
@@ -98,8 +97,7 @@ public abstract class AbstractSecurityTests extends AbstractStateMachineTests {
StateMachineConfigurationConfigurer<States, Events> configureConfiguration = builder.configureConfiguration();
configureConfiguration.withConfiguration()
.listener(listener)
.autoStartup(true)
.taskExecutor(new SyncTaskExecutor());
.autoStartup(true);
SecurityConfigurer<States, Events> withSecurity = configureConfiguration.withSecurity();
withSecurity.enabled(true);

View File

@@ -26,7 +26,6 @@ import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.statemachine.AbstractStateMachineTests;
import org.springframework.statemachine.StateMachine;
@@ -128,7 +127,6 @@ public class TransitionSecurityExpressionTests extends AbstractStateMachineTests
.withConfiguration()
.listener(listener)
.autoStartup(true)
.taskExecutor(new SyncTaskExecutor())
.and()
.withSecurity()
.enabled(true);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,10 +23,7 @@ import java.util.Map;
import org.junit.jupiter.api.Test;
import org.springframework.context.Lifecycle;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.statemachine.AbstractStateMachineTests;
import org.springframework.statemachine.StateMachine;
import org.springframework.statemachine.StateMachineSystemConstants;
@@ -34,7 +31,6 @@ import org.springframework.statemachine.TestUtils;
import org.springframework.statemachine.config.EnableStateMachineFactory;
import org.springframework.statemachine.config.EnumStateMachineConfigurerAdapter;
import org.springframework.statemachine.config.StateMachineFactory;
import org.springframework.statemachine.config.builders.StateMachineConfigurationConfigurer;
import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;
@@ -104,58 +100,6 @@ public class DefaultStateMachineServiceTests extends AbstractStateMachineTests {
assertThat(((Lifecycle)machine1).isRunning(), is(true));
}
@Test
public void testAcquireNotStartedThreading() {
context.register(Config2.class);
context.refresh();
StateMachineFactory<TestStates, TestEvents> stateMachineFactory =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINEFACTORY, StateMachineFactory.class);
DefaultStateMachineService<TestStates, TestEvents> service = new DefaultStateMachineService<>(stateMachineFactory);
StateMachine<TestStates,TestEvents> machine1 = service.acquireStateMachine("m1", false);
assertThat(((Lifecycle)machine1).isRunning(), is(false));
}
@Test
public void testAcquireStartedThreading() {
context.register(Config2.class);
context.refresh();
StateMachineFactory<TestStates, TestEvents> stateMachineFactory =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINEFACTORY, StateMachineFactory.class);
DefaultStateMachineService<TestStates, TestEvents> service = new DefaultStateMachineService<>(stateMachineFactory);
StateMachine<TestStates,TestEvents> machine1 = service.acquireStateMachine("m1", true);
assertThat(((Lifecycle)machine1).isRunning(), is(true));
}
@Test
public void testReleaseStopsMachineThreading() {
context.register(Config2.class);
context.refresh();
StateMachineFactory<TestStates, TestEvents> stateMachineFactory =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINEFACTORY, StateMachineFactory.class);
DefaultStateMachineService<TestStates, TestEvents> service = new DefaultStateMachineService<>(stateMachineFactory);
StateMachine<TestStates,TestEvents> machine1 = service.acquireStateMachine("m1", true);
assertThat(((Lifecycle)machine1).isRunning(), is(true));
service.releaseStateMachine("m1");
assertThat(((Lifecycle)machine1).isRunning(), is(false));
}
@Test
public void testReleaseDoesNotStopMachineThreading() {
context.register(Config2.class);
context.refresh();
StateMachineFactory<TestStates, TestEvents> stateMachineFactory =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINEFACTORY, StateMachineFactory.class);
DefaultStateMachineService<TestStates, TestEvents> service = new DefaultStateMachineService<>(stateMachineFactory);
StateMachine<TestStates,TestEvents> machine1 = service.acquireStateMachine("m1", true);
assertThat(((Lifecycle)machine1).isRunning(), is(true));
service.releaseStateMachine("m1", false);
assertThat(((Lifecycle)machine1).isRunning(), is(true));
}
@Test
public void testServiceStop() throws Exception {
context.register(Config1.class);
@@ -196,42 +140,4 @@ public class DefaultStateMachineServiceTests extends AbstractStateMachineTests {
.event(TestEvents.E1);
}
}
@Configuration
@EnableStateMachineFactory
static class Config2 extends EnumStateMachineConfigurerAdapter<TestStates, TestEvents> {
@Override
public void configure(StateMachineConfigurationConfigurer<TestStates, TestEvents> config) throws Exception {
config
.withConfiguration()
.taskExecutor(stateMachineTaskExecutor());
}
@Override
public void configure(StateMachineStateConfigurer<TestStates, TestEvents> states) throws Exception {
states
.withStates()
.initial(TestStates.S1)
.state(TestStates.S1)
.state(TestStates.S2);
}
@Override
public void configure(StateMachineTransitionConfigurer<TestStates, TestEvents> transitions) throws Exception {
transitions
.withExternal()
.source(TestStates.S1)
.target(TestStates.S2)
.event(TestEvents.E1);
}
@Bean
public TaskExecutor stateMachineTaskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(4);
return executor;
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2017 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -54,7 +54,7 @@ public class ChoiceStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testFirst() {
context.register(BaseConfig.class, Config1.class);
context.register(Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -68,7 +68,7 @@ public class ChoiceStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testThen1() {
context.register(BaseConfig.class, Config1.class);
context.register(Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -82,7 +82,7 @@ public class ChoiceStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testThen2() {
context.register(BaseConfig.class, Config1.class);
context.register(Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -96,7 +96,7 @@ public class ChoiceStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testLast() {
context.register(BaseConfig.class, Config1.class);
context.register(Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -110,7 +110,7 @@ public class ChoiceStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testOnlyLast() {
context.register(BaseConfig.class, Config2.class);
context.register(Config2.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -124,7 +124,7 @@ public class ChoiceStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testSubsequentChoiceStates() {
context.register(BaseConfig.class, Config3.class);
context.register(Config3.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -138,7 +138,7 @@ public class ChoiceStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testBackToItself() {
context.register(BaseConfig.class, Config4.class);
context.register(Config4.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);

View File

@@ -63,24 +63,6 @@ public class CompletionEventTests extends AbstractStateMachineTests {
assertThat(machine.getState().getId(), is("S3"));
}
@Test
public void testSimpleStateWithStateActionCompletesThreading() throws Exception {
context.register(Config1.class, BaseConfig2.class);
context.refresh();
StateMachine<String,String> machine = resolveMachine(context);
TestCountAction testAction2 = context.getBean("testAction2", TestCountAction.class);
doStartAndAssert(machine);
Thread.sleep(1000);
doSendEventAndConsumeAll(machine, "E1");
assertThat(testAction2.latch.await(2, TimeUnit.SECONDS), is(true));
assertThat(testAction2.count, is(1));
Thread.sleep(1000);
assertThat(machine.getState().getId(), is("S3"));
}
@Test
public void testSimpleStateWithoutStateActionCompletes() throws Exception {
context.register(Config2.class);
@@ -123,24 +105,6 @@ public class CompletionEventTests extends AbstractStateMachineTests {
assertThat(machine.getState().getId(), is("S3"));
}
@Test
public void testSubmachineWithoutStateActionCompletesThreading() throws Exception {
context.register(Config3.class, BaseConfig2.class);
context.refresh();
StateMachine<String,String> machine = resolveMachine(context);
doStartAndAssert(machine);
Thread.sleep(200);
assertThat(machine.getState().getId(), is("S1"));
doSendEventAndConsumeAll(machine, "E1");
Thread.sleep(200);
assertThat(machine.getState().getId(), is("S3"));
}
public void testRegionWithStateActionCompletes() throws Exception {
}
@Test
public void testRegionWithoutStateActionCompletes() throws Exception {
context.register(Config4.class);

View File

@@ -27,10 +27,7 @@ import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.statemachine.AbstractStateMachineTests;
import org.springframework.statemachine.ObjectStateMachine;
import org.springframework.statemachine.StateMachineSystemConstants;
@@ -169,7 +166,7 @@ public class EndStateTests extends AbstractStateMachineTests {
@Test
public void testEndStatesWithRegionsCompletionCompletes() throws InterruptedException {
context.register(Config8.class, BaseConfig2.class);
context.register(Config8.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
@SuppressWarnings("unchecked")
@@ -186,7 +183,7 @@ public class EndStateTests extends AbstractStateMachineTests {
@Test
public void testEndStatesWithSubmachineCompletionCompletes() throws InterruptedException {
context.register(Config9.class, BaseConfig2.class);
context.register(Config9.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
@SuppressWarnings("unchecked")
@@ -204,7 +201,7 @@ public class EndStateTests extends AbstractStateMachineTests {
@Test
public void testEndStatesWithRegionsCompletionCompletes2() throws InterruptedException {
context.register(Config10.class, BaseConfig2.class);
context.register(Config10.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
@SuppressWarnings("unchecked")
@@ -276,12 +273,6 @@ public class EndStateTests extends AbstractStateMachineTests {
.target(TestStates.SF)
.event(TestEvents.EF);
}
@Bean
public TaskExecutor taskExecutor() {
return new SyncTaskExecutor();
}
}
@Configuration
@@ -456,11 +447,6 @@ public class EndStateTests extends AbstractStateMachineTests {
.target(TestStates.SF)
.event(TestEvents.E3);
}
@Bean
public TaskExecutor taskExecutor() {
return new SyncTaskExecutor();
}
}
@Configuration

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,7 +48,7 @@ public class ForkStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testForkEventPassed() throws Exception {
context.register(BaseConfig.class, Config1.class);
context.register(Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -80,7 +80,7 @@ public class ForkStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testForkToSuperEventNotPassed() throws Exception {
context.register(BaseConfig.class, Config2.class);
context.register(Config2.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -112,7 +112,7 @@ public class ForkStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testForkToSuperAndSubEventPassed() throws Exception {
context.register(BaseConfig.class, Config3.class);
context.register(Config3.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,7 +41,7 @@ public class HistoryStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testShallowInSubmachine() {
context.register(BaseConfig.class, Config1.class);
context.register(Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -58,7 +58,7 @@ public class HistoryStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testShallowNoHistoryDefaultsNormalEntry() {
context.register(BaseConfig.class, Config1.class);
context.register(Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -72,7 +72,7 @@ public class HistoryStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testDeep() {
context.register(BaseConfig.class, Config2.class);
context.register(Config2.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -88,7 +88,7 @@ public class HistoryStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testShallow() {
context.register(BaseConfig.class, Config3.class);
context.register(Config3.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -105,7 +105,7 @@ public class HistoryStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testDefaultNotEntered() {
context.register(BaseConfig.class, Config4.class);
context.register(Config4.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -119,7 +119,7 @@ public class HistoryStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testDefaultHistoryIsFinal() {
context.register(BaseConfig.class, Config4.class);
context.register(Config4.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@ public class InitialStateTests extends AbstractStateMachineTests {
@SuppressWarnings({ "unchecked" })
@Test
public void testInitialStateTransition() throws Exception {
context.register(BaseConfig.class, Config1.class);
context.register(Config1.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
ObjectStateMachine<TestStates,TestEvents> machine =
@@ -56,7 +56,7 @@ public class InitialStateTests extends AbstractStateMachineTests {
@Test
public void testInitialStateMissingFailure() throws Exception {
assertThrows(Exception.class, () -> {
context.register(BaseConfig.class, Config2.class);
context.register(Config2.class);
context.refresh();
});
@@ -65,7 +65,7 @@ public class InitialStateTests extends AbstractStateMachineTests {
@SuppressWarnings({ "unchecked" })
@Test
public void testInitialNoNeedAsState() throws Exception {
context.register(BaseConfig.class, Config3.class);
context.register(Config3.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
ObjectStateMachine<TestStates,TestEvents> machine =
@@ -151,7 +151,7 @@ public class InitialStateTests extends AbstractStateMachineTests {
}
}
@Override
protected AnnotationConfigApplicationContext buildContext() {
return new AnnotationConfigApplicationContext();

View File

@@ -53,7 +53,7 @@ public class JoinStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testJoin() throws Exception {
context.register(BaseConfig.class, Config1.class);
context.register(Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -86,7 +86,7 @@ public class JoinStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testJoinLoopTwice() throws Exception {
context.register(BaseConfig.class, Config1.class);
context.register(Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -128,7 +128,7 @@ public class JoinStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testJoinSuper() throws Exception {
context.register(BaseConfig.class, Config2.class);
context.register(Config2.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -161,7 +161,7 @@ public class JoinStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testJoinSuperLoopTwice() throws Exception {
context.register(BaseConfig.class, Config2.class);
context.register(Config2.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -202,7 +202,7 @@ public class JoinStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testMultiJoin1() throws Exception {
context.register(BaseConfig.class, Config3.class);
context.register(Config3.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -235,7 +235,7 @@ public class JoinStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testMultiJoin2() throws Exception {
context.register(BaseConfig.class, Config3.class);
context.register(Config3.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -269,7 +269,7 @@ public class JoinStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testInterceptorPostStateChangeTransitionNotNull() throws Exception {
context.register(BaseConfig.class, Config1.class);
context.register(Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -316,7 +316,7 @@ public class JoinStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testJoinSuperMultipleEnds1() throws Exception {
context.register(BaseConfig.class, Config4.class);
context.register(Config4.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -349,7 +349,7 @@ public class JoinStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testJoinSuperMultipleEnds2() throws Exception {
context.register(BaseConfig.class, Config4.class);
context.register(Config4.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,7 +51,7 @@ public class JunctionStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testFirst() {
context.register(BaseConfig.class, Config1.class);
context.register(Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -65,7 +65,7 @@ public class JunctionStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testThen1() {
context.register(BaseConfig.class, Config1.class);
context.register(Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -79,7 +79,7 @@ public class JunctionStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testThen2() {
context.register(BaseConfig.class, Config1.class);
context.register(Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -93,7 +93,7 @@ public class JunctionStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testLast() {
context.register(BaseConfig.class, Config1.class);
context.register(Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -107,7 +107,7 @@ public class JunctionStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testOnlyLast() {
context.register(BaseConfig.class, Config2.class);
context.register(Config2.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -121,7 +121,7 @@ public class JunctionStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testSubsequentJunctionStates() {
context.register(BaseConfig.class, Config3.class);
context.register(Config3.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +25,6 @@ import java.util.Collection;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.statemachine.AbstractStateMachineTests;
import org.springframework.statemachine.ObjectStateMachine;
import org.springframework.statemachine.region.Region;
@@ -70,10 +69,8 @@ public class RegionStateTests extends AbstractStateMachineTests {
transitions.add(transitionFromS1ToS2);
transitions.add(transitionFromS2ToS3);
SyncTaskExecutor taskExecutor = new SyncTaskExecutor();
BeanFactory beanFactory = new DefaultListableBeanFactory();
ObjectStateMachine<TestStates, TestEvents> machine = new ObjectStateMachine<TestStates, TestEvents>(states, transitions, stateSI);
machine.setTaskExecutor(taskExecutor);
machine.setBeanFactory(beanFactory);
machine.afterPropertiesSet();
machine.start();

View File

@@ -28,8 +28,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.statemachine.AbstractStateMachineTests;
import org.springframework.statemachine.ObjectStateMachine;
import org.springframework.statemachine.StateMachineSystemConstants;
@@ -120,12 +118,6 @@ public class StateActionTests extends AbstractStateMachineTests {
public Action<TestStates, TestEvents> testExitAction() {
return new TestExitAction();
}
@Bean
public TaskExecutor taskExecutor() {
return new SyncTaskExecutor();
}
}
@Configuration

View File

@@ -28,7 +28,6 @@ import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.statemachine.AbstractStateMachineTests;
import org.springframework.statemachine.ObjectStateMachine;
import org.springframework.statemachine.StateMachine;
@@ -83,10 +82,8 @@ public class SubmachineStateTests extends AbstractStateMachineTests {
transitions.add(transitionFromS1ToS2);
transitions.add(transitionFromS2ToS3);
SyncTaskExecutor taskExecutor = new SyncTaskExecutor();
BeanFactory beanFactory = new DefaultListableBeanFactory();
ObjectStateMachine<TestStates, TestEvents> machine = new ObjectStateMachine<TestStates, TestEvents>(states, transitions, stateSI);
machine.setTaskExecutor(taskExecutor);
machine.setBeanFactory(beanFactory);
machine.afterPropertiesSet();
machine.start();
@@ -104,7 +101,7 @@ public class SubmachineStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testFromSimpleToOtherSubstate() {
context.register(BaseConfig.class, Config1.class);
context.register(Config1.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -121,7 +118,7 @@ public class SubmachineStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testAllSubmachinesRunningInitialsTakesToDeep() throws Exception {
context.register(BaseConfig.class, Config2.class);
context.register(Config2.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -147,7 +144,7 @@ public class SubmachineStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testAllSubmachinesRunningInitialsNotTakeToDeep() throws Exception {
context.register(BaseConfig.class, Config3.class);
context.register(Config3.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
@@ -173,7 +170,7 @@ public class SubmachineStateTests extends AbstractStateMachineTests {
@Test
@SuppressWarnings("unchecked")
public void testAllSubmachinesStopped() throws Exception {
context.register(BaseConfig.class, Config3.class);
context.register(Config3.class);
context.refresh();
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);

View File

@@ -28,9 +28,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.statemachine.AbstractStateMachineTests;
import org.springframework.statemachine.ObjectStateMachine;
import org.springframework.statemachine.StateContext;
@@ -39,7 +37,6 @@ import org.springframework.statemachine.StateMachineSystemConstants;
import org.springframework.statemachine.action.Action;
import org.springframework.statemachine.config.EnableStateMachine;
import org.springframework.statemachine.config.EnumStateMachineConfigurerAdapter;
import org.springframework.statemachine.config.builders.StateMachineConfigurationConfigurer;
import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;
import org.springframework.statemachine.guard.Guard;
@@ -386,11 +383,6 @@ public class TransitionEventHeaderTests extends AbstractStateMachineTests {
@EnableStateMachine
public static class Config5 extends EnumStateMachineConfigurerAdapter<TestStates, TestEvents> {
@Override
public void configure(StateMachineConfigurationConfigurer<TestStates, TestEvents> config) throws Exception {
config.withConfiguration().taskExecutor(customTaskExecutor());
}
@Override
public void configure(StateMachineStateConfigurer<TestStates, TestEvents> states) throws Exception {
states
@@ -443,14 +435,6 @@ public class TransitionEventHeaderTests extends AbstractStateMachineTests {
public EventCheckGuard eventCheckGuard() {
return new EventCheckGuard(true);
}
@Bean(name = StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME)
public TaskExecutor customTaskExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(1);
return taskExecutor;
}
}
private static class EventCheckGuard implements Guard<TestStates, TestEvents> {

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.statemachine.transition;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.springframework.statemachine.TestUtils.doSendEventAndConsumeAll;
@@ -24,17 +23,12 @@ import static org.springframework.statemachine.TestUtils.resolveMachine;
import java.util.ArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.statemachine.AbstractStateMachineTests;
import org.springframework.statemachine.StateMachine;
import org.springframework.statemachine.StateMachineSystemConstants;
import org.springframework.statemachine.config.EnableStateMachine;
import org.springframework.statemachine.config.EnumStateMachineConfigurerAdapter;
import org.springframework.statemachine.config.builders.StateMachineConfigurationConfigurer;
@@ -179,24 +173,6 @@ public class TransitionOrderTests extends AbstractStateMachineTests {
contains(TestStates.S1, TestStates.S10, TestStates.S1011, TestStates.S1));
}
@Test
public void testAnonymousTransitionInConfigUseParent3Threading() throws InterruptedException {
TestListener listener = new TestListener();
context.register(Config4.class, StateMachineExecutorConfiguration.class);
context.refresh();
StateMachine<TestStates, TestEvents> machine = resolveMachine(context);
machine.addStateListener(listener);
doStartAndAssert(machine);
assertThat(listener.statesEnteredLatch.await(1, TimeUnit.SECONDS), is(true));
assertThat(machine.getState().getIds(), contains(TestStates.S1));
listener.reset(1, 3);
doSendEventAndConsumeAll(machine, TestEvents.E1);
assertThat(listener.statesEnteredLatch.await(1, TimeUnit.SECONDS), is(true));
assertThat(listener.statesEntered, contains(TestStates.S10, TestStates.S1011, TestStates.S1));
}
@Configuration
@EnableStateMachine
public static class Config1 extends EnumStateMachineConfigurerAdapter<TestStates, TestEvents> {
@@ -558,18 +534,6 @@ public class TransitionOrderTests extends AbstractStateMachineTests {
}
}
@Configuration
public static class StateMachineExecutorConfiguration {
@Bean(name = StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME)
public TaskExecutor stateMachineTaskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(4);
return executor;
}
}
static class TestListener extends StateMachineListenerAdapter<TestStates, TestEvents> {
volatile CountDownLatch stateChangedLatch = new CountDownLatch(1);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2018 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,9 +34,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.statemachine.AbstractStateMachineTests;
import org.springframework.statemachine.ObjectStateMachine;
import org.springframework.statemachine.StateContext;
@@ -68,7 +66,7 @@ public class TransitionTests extends AbstractStateMachineTests {
@SuppressWarnings({ "unchecked" })
@Test
public void testTriggerlessTransition() throws Exception {
context.register(BaseConfig.class, Config1.class);
context.register(Config1.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
@@ -91,7 +89,7 @@ public class TransitionTests extends AbstractStateMachineTests {
@SuppressWarnings({ "unchecked" })
@Test
public void testTriggerlessTransitionFromInitial() throws Exception {
context.register(BaseConfig.class, Config3.class);
context.register(Config3.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
ObjectStateMachine<TestStates,TestEvents> machine =
@@ -103,7 +101,7 @@ public class TransitionTests extends AbstractStateMachineTests {
@SuppressWarnings({ "unchecked" })
@Test
public void testTriggerlessTransitionFromInitialToEnd() throws Exception {
context.register(BaseConfig.class, Config4.class);
context.register(Config4.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
@@ -120,7 +118,7 @@ public class TransitionTests extends AbstractStateMachineTests {
@SuppressWarnings({ "unchecked" })
@Test
public void testTriggerlessTransitionInRegionsDefinedInSubStates() throws Exception {
context.register(BaseConfig.class, Config5.class);
context.register(Config5.class);
context.refresh();
TestAction testAction1 = context.getBean("testAction1", TestAction.class);
@@ -147,7 +145,7 @@ public class TransitionTests extends AbstractStateMachineTests {
@SuppressWarnings({ "unchecked" })
@Test
public void testTriggerlessTransitionInRegions() throws Exception {
context.register(BaseConfig.class, Config6.class);
context.register(Config6.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
ObjectStateMachine<TestStates,TestEvents> machine =
@@ -161,7 +159,7 @@ public class TransitionTests extends AbstractStateMachineTests {
@SuppressWarnings({ "unchecked" })
@Test
public void testInternalTransition() throws Exception {
context.register(BaseConfig.class, Config2.class);
context.register(Config2.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
ObjectStateMachine<TestStates,TestEvents> machine =
@@ -191,7 +189,7 @@ public class TransitionTests extends AbstractStateMachineTests {
@Test
public void testTransitDirectlyToSubstateSkipInitial() throws InterruptedException {
context.register(BaseConfig.class, Config7.class);
context.register(Config7.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
@SuppressWarnings("unchecked")
@@ -215,7 +213,7 @@ public class TransitionTests extends AbstractStateMachineTests {
@Test
public void testTransitDeepDirectlyToSubstateSkipInitial() throws InterruptedException {
context.register(BaseConfig.class, Config8.class);
context.register(Config8.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
@SuppressWarnings("unchecked")
@@ -240,7 +238,7 @@ public class TransitionTests extends AbstractStateMachineTests {
@SuppressWarnings("unchecked")
@Test
public void testAnonymousTransitionInSubmachine() throws InterruptedException {
context.register(BaseConfig.class, Config9.class);
context.register(Config9.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
@@ -266,97 +264,6 @@ public class TransitionTests extends AbstractStateMachineTests {
assertThat(testAction2.testHeader, is("testValue"));
}
@SuppressWarnings("unchecked")
@Test
public void testAnonymousTransitionInSubmachineWithThreading() throws InterruptedException {
context.register(Config9.class, ExecutorConfig.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
HeaderTestAction testAction1 = context.getBean("testAction1", HeaderTestAction.class);
HeaderTestAction testAction2 = context.getBean("testAction2", HeaderTestAction.class);
TestListener listener = new TestListener();
machine.addStateListener(listener);
machine.start();
assertThat(listener.stateMachineStartedLatch.await(2, TimeUnit.SECONDS), is(true));
assertThat(machine.getState().getIds(), contains(TestStates.S1));
listener.reset(4);
machine.sendEvent(MessageBuilder.withPayload(TestEvents.E1).setHeader("testHeader", "testValue").build());
assertThat(listener.stateChangedLatch.await(2, TimeUnit.SECONDS), is(true));
assertThat(listener.stateChangedCount, is(4));
assertThat(machine.getState().getIds(), contains(TestStates.S2, TestStates.S212));
assertThat(testAction1.testHeader, is("testValue"));
assertThat(testAction2.testHeader, is("testValue"));
}
@SuppressWarnings("unchecked")
@Test
public void testAnonymousTransitionInSubmachineWithExitWithThreading1() throws InterruptedException {
context.register(Config10.class, ExecutorConfig.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
HeaderTestAction testAction1 = context.getBean("testAction1", HeaderTestAction.class);
HeaderTestAction testAction2 = context.getBean("testAction2", HeaderTestAction.class);
TestListener listener = new TestListener();
machine.addStateListener(listener);
machine.start();
assertThat(listener.stateMachineStartedLatch.await(2, TimeUnit.SECONDS), is(true));
assertThat(machine.getState().getIds(), contains(TestStates.S1));
listener.reset(5);
machine.sendEvent(MessageBuilder.withPayload(TestEvents.E1).setHeader("testHeader", "testValue").build());
assertThat(listener.stateChangedLatch.await(2, TimeUnit.SECONDS), is(true));
assertThat(listener.stateChangedCount, is(5));
assertThat(machine.getState().getIds(), contains(TestStates.S1));
assertThat(testAction1.testHeader, is("testValue"));
assertThat(testAction2.testHeader, is("testValue"));
}
@SuppressWarnings("unchecked")
@Test
public void testAnonymousTransitionInSubmachineWithExitWithThreading2() throws InterruptedException {
context.register(Config11.class, ExecutorConfig.class);
context.refresh();
assertTrue(context.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
ObjectStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
HeaderTestAction testAction1 = context.getBean("testAction1", HeaderTestAction.class);
TestListener listener = new TestListener();
machine.addStateListener(listener);
machine.start();
assertThat(listener.stateMachineStartedLatch.await(2, TimeUnit.SECONDS), is(true));
assertThat(machine.getState().getIds(), contains(TestStates.S1));
listener.reset(3);
machine.sendEvent(MessageBuilder.withPayload(TestEvents.E1).setHeader("testHeader", "testValue").build());
assertThat(testAction1.latch.await(2, TimeUnit.SECONDS), is(true));
assertThat(listener.s20Latch.await(2, TimeUnit.SECONDS), is(true));
assertThat(listener.stateChangedLatch.await(2, TimeUnit.SECONDS), is(true));
assertThat(listener.stateChangedCount, is(3));
assertThat(machine.getState().getIds(), contains(TestStates.S1));
assertThat(testAction1.testHeader, is("testValue"));
}
@Configuration
@EnableStateMachine
public static class Config1 extends EnumStateMachineConfigurerAdapter<TestStates, TestEvents> {
@@ -907,16 +814,4 @@ public class TransitionTests extends AbstractStateMachineTests {
}
}
@Configuration
static class ExecutorConfig {
@Bean(name=StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME)
public TaskExecutor taskExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(3);
taskExecutor.setMaxPoolSize(3);
return taskExecutor;
}
}
}

View File

@@ -68,7 +68,7 @@ public class TimerTriggerTests extends AbstractStateMachineTests {
@Test
public void testListenerEvents() throws Exception {
context.register(BaseConfig.class, Config1.class);
context.register(Config1.class);
context.refresh();
final CountDownLatch latch = new CountDownLatch(2);
@@ -89,7 +89,7 @@ public class TimerTriggerTests extends AbstractStateMachineTests {
@Test
public void testTimerTransitions() throws Exception {
context.register(BaseConfig.class, Config2.class);
context.register(Config2.class);
context.refresh();
StateMachine<TestStates, TestEvents> machine = resolveMachine(context);
TestTimerAction action = context.getBean("testTimerAction", TestTimerAction.class);
@@ -150,7 +150,7 @@ public class TimerTriggerTests extends AbstractStateMachineTests {
@Test
public void testTimerDelayFireOnlyOnState() throws Exception {
context.register(BaseConfig.class, Config4.class);
context.register(Config4.class);
context.refresh();
StateMachine<TestStates, TestEvents> machine = resolveMachine(context);
TestTimerAction action = context.getBean("testTimerAction", TestTimerAction.class);

View File

@@ -40,6 +40,7 @@ import org.springframework.statemachine.config.builders.StateMachineTransitionCo
import org.springframework.statemachine.guard.Guard;
import org.springframework.statemachine.listener.AbstractCompositeListener;
import org.springframework.statemachine.recipes.support.RunnableAction;
import org.springframework.statemachine.region.RegionExecutionPolicy;
import org.springframework.statemachine.state.PseudoStateKind;
import org.springframework.statemachine.state.State;
import org.springframework.statemachine.support.DefaultStateMachineContext;
@@ -228,9 +229,9 @@ public class TasksHandler {
StateMachineBuilder.Builder<String, String> builder = StateMachineBuilder.builder();
int taskCount = topLevelTaskCount(tasks);
builder.configureConfiguration().withConfiguration()
.taskExecutor(taskExecutor != null ? taskExecutor : taskExecutor(taskCount));
if (taskCount > 1) {
builder.configureConfiguration().withConfiguration().regionExecutionPolicy(RegionExecutionPolicy.PARALLEL);
}
StateMachineStateConfigurer<String, String> stateMachineStateConfigurer = builder.configureStates();
StateMachineTransitionConfigurer<String, String> stateMachineTransitionConfigurer = builder.configureTransitions();
@@ -317,13 +318,6 @@ public class TasksHandler {
return builder.build();
}
private static TaskExecutor taskExecutor(int taskCount) {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.afterPropertiesSet();
taskExecutor.setCorePoolSize(taskCount);
return taskExecutor;
}
private static int topLevelTaskCount(List<TaskWrapper> tasks) {
Tree<TaskWrapper> tree = new Tree<TaskWrapper>();
for (TaskWrapper wrapper : tasks) {

View File

@@ -25,7 +25,6 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.statemachine.StateMachine;
@@ -135,7 +134,6 @@ public class PersistStateMachineHandlerTests {
builder.configureConfiguration()
.withConfiguration()
.taskExecutor(new SyncTaskExecutor())
.autoStartup(true);
builder.configureStates()
@@ -160,7 +158,6 @@ public class PersistStateMachineHandlerTests {
builder.configureConfiguration()
.withConfiguration()
.taskExecutor(new SyncTaskExecutor())
.autoStartup(true);
builder.configureStates()

View File

@@ -23,12 +23,9 @@ import java.util.Map;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.shell.Bootstrap;
import org.springframework.statemachine.StateContext;
import org.springframework.statemachine.StateMachineSystemConstants;
import org.springframework.statemachine.action.Action;
import org.springframework.statemachine.annotation.OnTransition;
import org.springframework.statemachine.config.EnableStateMachine;

View File

@@ -28,7 +28,6 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.statemachine.StateMachine;
import org.springframework.statemachine.config.EnableStateMachine;
import org.springframework.statemachine.config.StateMachineConfigurerAdapter;
import org.springframework.statemachine.config.builders.StateMachineConfigurationConfigurer;
import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;
@@ -184,13 +183,6 @@ public class StateMachineTestingTests extends AbstractStateMachineTests {
@EnableStateMachine
static class Config2 extends StateMachineConfigurerAdapter<String, String> {
@Override
public void configure(StateMachineConfigurationConfigurer<String, String> config) throws Exception {
config
.withConfiguration()
.taskExecutor(taskExecutor());
}
@Override
public void configure(StateMachineStateConfigurer<String, String> states) throws Exception {
states

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2018 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@ import static org.hamcrest.collection.IsMapContaining.hasEntry;
//end::snippetC[]
import org.junit.Test;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.statemachine.StateMachine;
import org.springframework.statemachine.config.StateMachineBuilder;
import org.springframework.statemachine.test.StateMachineTestPlan;
@@ -64,7 +63,6 @@ public class DocsTestSampleTests {
builder.configureConfiguration()
.withConfiguration()
.taskExecutor(new SyncTaskExecutor())
.autoStartup(true);
builder.configureStates()

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,7 +30,6 @@ import org.springframework.context.SmartLifecycle;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.statemachine.StateContext;
@@ -791,7 +790,6 @@ public class ZookeeperStateMachineTests extends AbstractZookeeperTests {
builder.configureConfiguration()
.withConfiguration()
.taskExecutor(new SyncTaskExecutor())
.autoStartup(true)
.and()
.withDistributed()
@@ -897,7 +895,6 @@ public class ZookeeperStateMachineTests extends AbstractZookeeperTests {
builder.configureConfiguration()
.withConfiguration()
.taskExecutor(new SyncTaskExecutor())
.autoStartup(true)
.and()
.withDistributed()