-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(simulator): different running modes
the property `citrus.simulator.mode=[async/sync]` steers the mode the simulator will use to execute simulations. note that while the synchronous modus is simpler, it disallows the simulation of any intermediate messaging with synchronous protocols.
- Loading branch information
Showing
16 changed files
with
547 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
.../main/java/org/citrusframework/simulator/service/runner/AsyncScenarioExecutorService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright 2024 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 | ||
* | ||
* http://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.citrusframework.simulator.service.runner; | ||
|
||
import com.google.common.util.concurrent.ThreadFactoryBuilder; | ||
import org.citrusframework.Citrus; | ||
import org.citrusframework.simulator.config.SimulatorConfigurationProperties; | ||
import org.citrusframework.simulator.model.ScenarioParameter; | ||
import org.citrusframework.simulator.scenario.SimulatorScenario; | ||
import org.citrusframework.simulator.service.ScenarioExecutionService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.DisposableBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.event.ContextClosedEvent; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.ExecutorService; | ||
|
||
import static java.util.concurrent.Executors.newFixedThreadPool; | ||
|
||
/** | ||
* Asynchronous Legay | ||
* {@inheritDoc} | ||
*/ | ||
@Service | ||
@ConditionalOnProperty(name = "citrus.simulator.mode", havingValue = "async") | ||
public class AsyncScenarioExecutorService extends DefaultScenarioExecutorService implements ApplicationListener<ContextClosedEvent>, DisposableBean { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(AsyncScenarioExecutorService.class); | ||
|
||
private final ExecutorService executorService; | ||
|
||
public AsyncScenarioExecutorService(ApplicationContext applicationContext, Citrus citrus, ScenarioExecutionService scenarioExecutionService, SimulatorConfigurationProperties properties) { | ||
super(applicationContext, citrus, scenarioExecutionService); | ||
|
||
this.executorService = newFixedThreadPool( | ||
properties.getExecutorThreads(), | ||
new ThreadFactoryBuilder() | ||
.setDaemon(true) | ||
.setNameFormat("execution-svc-thread-%d") | ||
.build() | ||
); | ||
} | ||
|
||
@Override | ||
public void destroy() throws Exception { | ||
shutdownExecutor(); | ||
} | ||
|
||
@Override | ||
public void onApplicationEvent(ContextClosedEvent event) { | ||
shutdownExecutor(); | ||
} | ||
|
||
@Override | ||
public void startScenario(Long executionId, String name, SimulatorScenario scenario, List<ScenarioParameter> scenarioParameters) { | ||
startScenarioAsync(executionId, name, scenario, scenarioParameters); | ||
} | ||
|
||
private void startScenarioAsync(Long executionId, String name, SimulatorScenario scenario, List<ScenarioParameter> scenarioParameters) { | ||
executorService.submit(() -> super.startScenario(executionId, name, scenario, scenarioParameters)); | ||
} | ||
|
||
private void shutdownExecutor() { | ||
logger.debug("Request to shutdown executor"); | ||
|
||
if (!executorService.isShutdown()) { | ||
logger.trace("Shutting down executor"); | ||
executorService.shutdownNow(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...spring-boot/src/main/java/org/citrusframework/simulator/service/runner/SimulatorMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2024 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 | ||
* | ||
* http://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.citrusframework.simulator.service.runner; | ||
|
||
public enum SimulatorMode { | ||
|
||
ASYNC, | ||
SYNC | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.