diff --git a/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/StateMachineBuilder.java b/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/StateMachineBuilder.java index 55bdbebf..d0766c30 100644 --- a/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/StateMachineBuilder.java +++ b/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/StateMachineBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 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,6 +15,8 @@ */ 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; @@ -121,9 +123,13 @@ public class StateMachineBuilder { } 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) { diff --git a/spring-statemachine-core/src/test/java/org/springframework/statemachine/config/ManualBuilderTests.java b/spring-statemachine-core/src/test/java/org/springframework/statemachine/config/ManualBuilderTests.java index c44ffcc5..cd484e87 100644 --- a/spring-statemachine-core/src/test/java/org/springframework/statemachine/config/ManualBuilderTests.java +++ b/spring-statemachine-core/src/test/java/org/springframework/statemachine/config/ManualBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 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,6 +30,7 @@ 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.StateMachineConfigurationConfig; @@ -187,6 +188,28 @@ public class ManualBuilderTests { assertThat(stateMachine.getState().getIds(), containsInAnyOrder("S2")); } + @Test + public void testManualBuildDefaultTaskExecutor() throws Exception { + Builder 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 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 builder = StateMachineBuilder.builder();