Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Fix/double for strategy #1226

Merged
merged 17 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.google.common.collect.Maps;
import java.time.Duration;
import java.time.Instant;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -247,7 +248,7 @@ public String type() {
}

public List<Step> subSteps() {
return steps;
return Collections.unmodifiableList(steps);
}

public StepExecutor executor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,23 @@ public Status execute(ScenarioExecution scenarioExecution,
.peek(p -> step.addStepExecution(p.getLeft()))
.toList();

iterations.forEach(it ->
DefaultStepExecutionStrategy.instance.execute(scenarioExecution, it.getLeft()/*step*/, scenarioContext, it.getRight()/*localContext*/, strategies));
iterations.forEach(it -> {
Map<String, Object> mergedContext = new HashMap<>(localContext);
mergedContext.putAll(it.getRight());
DefaultStepExecutionStrategy.instance.execute(scenarioExecution, it.getLeft(), scenarioContext, mergedContext, strategies);
});

} else {
List<Pair<Step, Map<String, Object>>> iterations = dataset.stream()
.map(iterationContext -> buildIteration(indexName, index.getAndIncrement(), step, iterationContext))
.peek(e -> step.addStepExecution(e.getKey()))
.toList();

iterations.forEach(it -> it.getLeft().execute(scenarioExecution, scenarioContext, it.getRight()));
iterations.forEach(it -> {
Map<String, Object> mergedContext = new HashMap<>(localContext);
mergedContext.putAll(it.getRight());
it.getLeft().execute(scenarioExecution, scenarioContext, mergedContext);
});
}
step.endExecution(scenarioExecution);
return step.status();
Expand All @@ -88,20 +95,20 @@ private static List<Map<String, Object>> getDataset(Step step, ScenarioContext s
if (dataset.isEmpty()) {
throw new IllegalArgumentException("Step iteration cannot have empty dataset");
}
List<Map<String, Object>> evaluatedDataset = dataset.stream()

return dataset.stream()
.map(iterationData -> iterationData.entrySet().stream()
.map(e -> Map.entry(e.getKey(), evaluator.evaluate(e.getValue(), scenarioContext)))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))
.toList();
return evaluatedDataset;
}

private Pair<Step, Map<String, Object>> buildParentIteration(String indexName, Integer index, Step step, List<Step> subSteps, Map<String, Object> iterationContext) {

StepDefinition newDef = iterationDefinition(indexName, index, step.definition(), new StepStrategyDefinition("", new StrategyProperties()));
List<Step> newSubSteps = subSteps.stream().map(
subStep -> buildIterationDefinition(indexName, index, subStep.dataEvaluator(), subStep.definition(), subStep.executor(), subStep.subSteps(), subStep.strategy().orElse(new StepStrategyDefinition("", new StrategyProperties())))
).collect(Collectors.toList());
).toList();

return Pair.of(
new Step(step.dataEvaluator(), newDef, step.executor(), newSubSteps),
Expand All @@ -118,7 +125,7 @@ private Pair<Step, Map<String, Object>> buildIteration(String indexName, Integer

private Step buildIterationDefinition(String indexName, Integer index, StepDataEvaluator dataEvaluator, StepDefinition definition, StepExecutor executor, List<Step> subStep, StepStrategyDefinition strategy) {
StepDefinition iterationDefinition = iterationDefinition(indexName, index, definition, Optional.ofNullable(strategy).orElse(new StepStrategyDefinition("", new StrategyProperties())));
return new Step(dataEvaluator, iterationDefinition, executor, subStep.stream().map(step -> buildIterationDefinition(indexName, index, step.dataEvaluator(), step.definition(), step.executor(), step.subSteps(), step.strategy().orElse(null))).toList());
return new Step(dataEvaluator, iterationDefinition, executor, subStep.stream().map(step -> buildIterationDefinition(indexName, index, step.dataEvaluator(), step.definition(), step.executor(), step.subSteps(), step.strategy().orElse(null))).collect(Collectors.toList())); // We need this list to be mutable because of the clear in step.removeStepExecution()
}

private StepDefinition iterationDefinition(String indexName, Integer index, StepDefinition definition, StepStrategyDefinition strategyDefinition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@

package com.chutneytesting.engine.domain.execution.strategies;

import static java.util.Collections.emptyMap;

import com.chutneytesting.engine.domain.execution.ScenarioExecution;
import com.chutneytesting.engine.domain.execution.engine.scenario.ScenarioContext;
import com.chutneytesting.engine.domain.execution.engine.step.Step;
import com.chutneytesting.engine.domain.execution.report.Status;
import java.util.Collections;
import java.util.Map;

/**
Expand All @@ -34,10 +35,10 @@ public interface StepExecutionStrategy {
String getType();

default Status execute(ScenarioExecution scenarioExecution,
Step step,
ScenarioContext scenarioContext,
StepExecutionStrategies strategies) {
return execute(scenarioExecution, step, scenarioContext, Collections.emptyMap(), strategies);
Step step,
ScenarioContext scenarioContext,
StepExecutionStrategies strategies) {
return execute(scenarioExecution, step, scenarioContext, emptyMap(), strategies);
}

Status execute(ScenarioExecution scenarioExecution,
Expand Down
Loading
Loading