Skip to content

Commit

Permalink
Adapting execution modes to Mutational Test (#220)
Browse files Browse the repository at this point in the history
* Updated the ConfigValueHandler
* Making compatibility work
* Adapted tests to the New Execution Mode
* Renamed ExecutionType to ExecutionModes, the previous notion of mode is now behavior types
* extracted Phases from the MutationListener
* Completely removed Phases from Mutational
* enriched tests
* Preparing the correspondance between phases and executionMode
* #204 Extracted the Phases from the PhasedTestListener
* #204 Extracted the Phases from the PhasedTestManager
* Made non-interruptive compliant with ExecutionModes
* #204 Renamed DEFAULT to STANDARD
* #204 Updated the docs
* Updated README
  • Loading branch information
baubakg authored Nov 26, 2024
1 parent 41db1df commit 94ef416
Show file tree
Hide file tree
Showing 23 changed files with 4,497 additions and 884 deletions.
178 changes: 143 additions & 35 deletions README.md

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
991 changes: 291 additions & 700 deletions diagrams/PhasedDiagrams.drawio

Large diffs are not rendered by default.

Binary file added diagrams/permutation-expanded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added diagrams/permutation-normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public enum ConfigValueHandlerPhased {
PHASED_TEST_DETECT_ORDER("PHASED.TESTS.DETECT.ORDER", "false", false),
PHASED_TEST_NONPHASED_LEGACY( "PHASED.TESTS.NONPHASED.LEGACY", "false", false ),
PROP_SCENARIO_EXPORTED_PREFIX("PHASED.TESTS.STORAGE.SCENARIO.PREFIX", "[TC]", false),
EVENT_TARGET("PHASED.EVENTS.TARGET", null, false );
EVENT_TARGET("PHASED.EVENTS.TARGET", null, false ),
PROP_EXECUTION_MODE("MUTATIONAL.EXECUTION.MODE", "DEFAULT", false);

public final String systemName;
public final String defaultValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/*
* MIT License
*
* © Copyright 2020 Adobe. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.adobe.campaign.tests.integro.phased;

import com.adobe.campaign.tests.integro.phased.exceptions.MutationRampUpException;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public enum ExecutionMode {
STANDARD(false, new ArrayList<>()),
//We need to revise this as execution in a suite may not require a precision
NON_INTERRUPTIVE(false, Arrays.asList( "23", "33" )) {

public boolean isSelected() {
return this.equals(getCurrentMode()) || Phases.ASYNCHRONOUS.isSelected();
};
},
INTERRUPTIVE(false, Arrays.asList( "PRODUCER", "CONSUMER" )) {
public boolean isSelected() {
return this.equals(getCurrentMode()) || Phases.PRODUCER.isSelected()
|| Phases.CONSUMER.isSelected();
};
public boolean isSelected(String in_executionMode) {

return this.fetchBehavior().equals(in_executionMode) || (in_executionMode.equals("PRODUCER") && Phases.PRODUCER.isSelected())
|| (in_executionMode.equals("CONSUMER") && Phases.CONSUMER.isSelected());
};
},
PERMUTATIONAL(true, Arrays.asList());

boolean hasSplittingEvent;
List<String> behaviorTypes;

ExecutionMode(boolean in_isInPhase, List<String> in_phaseTypes) {
hasSplittingEvent = in_isInPhase;
behaviorTypes = in_phaseTypes;
}

/**
* Returns the Phased Test state in which the current test session is being executed
* <p>
* Author : gandomi
*
* @return The phase which is currently being executed
*/
public static ExecutionMode getCurrentMode() {
if (ConfigValueHandlerPhased.PROP_EXECUTION_MODE.isSet()) {
return fetchCorrespondingMode(ConfigValueHandlerPhased.PROP_EXECUTION_MODE.fetchValue());
}
return Phases.getCurrentPhase().fetchRunValues().getExecutionMode();
}

/**
* We find a corresponding PhasedTest state given a string. If none are found we return INACTIVE
* <p>
* Author : gandomi
*
* @param in_stateValue Returns a Phase given a string representation of its value
* @return A state corresponding to the given Phased State, if none found we return inactive
*/
public static ExecutionMode fetchCorrespondingMode(String in_stateValue) {
for (ExecutionMode lt_ptState : ExecutionMode.values()) {
if (in_stateValue.toUpperCase().startsWith(lt_ptState.toString().toUpperCase())) {
return lt_ptState;
}
}
return STANDARD;
}

/**
* Provides an array of Phases that contain a splitting Event aka PhasedEvent
* <p>
* Author : gandomi
*
* @return An array of Phases that have a Splitting Event
*/
public static ExecutionMode[] fetchPhasesWithEvents() {
return Arrays.stream(ExecutionMode.values())
.filter(p -> p.hasSplittingEvent)
.toArray(ExecutionMode[]::new);
}

/**
* Checks if the selected Execution Mode is the given one
* @param in_executionMode A given execution mode to check
* @return
*/
public static boolean is(ExecutionMode in_executionMode) {
return in_executionMode.equals(getCurrentMode());
}

public static String getCurrentModeAsString() {
return getCurrentMode().fetchRunValues().toString();
}

public RunValues fetchRunValues() {
return new RunValues(getCurrentMode(), getCurrentMode().fetchBehavior());
}

public boolean isTypeValid() {
String l_currentType = fetchBehavior();
if (behaviorTypes.isEmpty()) {
return l_currentType.isEmpty();
}
return behaviorTypes.contains(l_currentType);
}

/**
* Checks if the current entry is active. I.e. either producer or consumer
* <p>
* Author : gandomi
*
* @return true if we are the active state
*/
public boolean isSelected() {
return this.equals(getCurrentMode());
}

/**
* Lets us know if the current phase will include a splitting event
* <p>
* Author : gandomi
*
* @return True if the the phase could have a splitting event.
*/
public boolean hasSplittingEvent() {
return this.hasSplittingEvent;
}

/**
* Activates the given phase
* <p>
* Author : gandomi
*/
void activate() {
ConfigValueHandlerPhased.PROP_EXECUTION_MODE.activate(this.name());
}

/**
* Activates the given execution type with the given mode
* @param in_executionMode
*/
public void activate(String in_executionMode) {
if (!behaviorTypes.contains(in_executionMode)) {
throw new MutationRampUpException("The given execution mode type is not valid for this execution type. Please use one of the following: " + behaviorTypes.toString());
}

ConfigValueHandlerPhased.PROP_EXECUTION_MODE.activate(this.name() + "(" + in_executionMode + ")");
}

/**
* Fetches the mode of the current execution type
* @return The mode set at runtime
*/
public String fetchBehavior() {
if (ConfigValueHandlerPhased.PROP_EXECUTION_MODE.isSet()) {
String l_value = ConfigValueHandlerPhased.PROP_EXECUTION_MODE.fetchValue();
int l_startIndex = l_value.indexOf("(");
int l_endIndex = l_value.indexOf(")");

if (l_startIndex != -1 && l_endIndex != -1) {
return l_value.substring(l_startIndex + 1, l_endIndex);
}
return "";
} else {
return Phases.getCurrentPhase().behavior;
}

}

/**
* Checks if the given Type and mode are selected. If the execution type does not expect a mode, we simply ignore
* the given mode.
*
* @param in_executionMode The mode that is expected to be selected
* @return True if the given execution type and mode are selected
*/
public boolean isSelected(String in_executionMode) {
//Ignore the argument if none are expected
return this.behaviorTypes.isEmpty() ? isSelected() : this.fetchBehavior().equals(in_executionMode);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void alter(List<XmlSuite> suites) {
IAlterSuiteListener.super.alter(suites);

log.debug("{} in alter - current Execution State is : {}", PhasedTestManager.PHASED_TEST_LOG_PREFIX
, Phases.getCurrentPhase());
, ExecutionMode.getCurrentMode());

// *** Import DataBroker ***
String l_phasedDataBrokerClass = null;
Expand All @@ -51,7 +51,7 @@ public void alter(List<XmlSuite> suites) {
.containsKey(ConfigValueHandlerPhased.PROP_PHASED_TEST_DATABROKER.systemName)) {
l_phasedDataBrokerClass = suites.get(0)
.getParameter(ConfigValueHandlerPhased.PROP_PHASED_TEST_DATABROKER.systemName);
} else if (!Phases.NON_PHASED.isSelected()) {
} else if (!ExecutionMode.STANDARD.isSelected()) {
log.info("{} No PhasedDataBroker set. Using the file system path {}/{} instead ",
PhasedTestManager.PHASED_TEST_LOG_PREFIX, PhasedTestManager.STD_STORE_DIR,
PhasedTestManager.STD_STORE_FILE
Expand All @@ -69,7 +69,7 @@ public void alter(List<XmlSuite> suites) {

// *** import context for consumer ***
//The second condition is there for testing purposes. You can bypass the file by filling the Test
if (Phases.CONSUMER.isSelected() && PhasedTestManager.getPhasedCache().isEmpty()) {
if (ExecutionMode.INTERRUPTIVE.isSelected("CONSUMER") && PhasedTestManager.getPhasedCache().isEmpty()) {
PhasedTestManager.importPhaseData();
}

Expand Down Expand Up @@ -123,7 +123,7 @@ public void transform(ITestAnnotation annotation, Class testClass, Constructor t
}

if (PhasedTestManager.isPhasedTest(l_currentClass)) {
if (Phases.NON_PHASED.isSelected()) {
if (ExecutionMode.STANDARD.isSelected()) {
annotation.setDataProvider(
ConfigValueHandlerPhased.PHASED_TEST_NONPHASED_LEGACY.is("true") ? PhasedDataProvider.SINGLE : PhasedDataProvider.DEFAULT);

Expand Down Expand Up @@ -226,7 +226,7 @@ public List<IMethodInstance> intercept(List<IMethodInstance> list, ITestContext
log.info("{} Generating Phased Providers", PhasedTestManager.PHASED_TEST_LOG_PREFIX);
//NIA
PhasedTestManager.generatePhasedProviders(l_classMethodMap, PhasedTestManager.getStepDependencies(),
Phases.getCurrentPhase());
ExecutionMode.getCurrentMode().fetchRunValues());
//}

//Start by adding the non-phased tests
Expand Down Expand Up @@ -282,7 +282,7 @@ public void onTestStart(ITestResult result) {
+ " due to failure in step " + PhasedTestManager.getScenarioContext()
.get(PhasedTestManager.fetchScenarioName(result)).getFailedStep() + " in Phase "
+ PhasedTestManager.getScenarioContext()
.get(PhasedTestManager.fetchScenarioName(result)).getFailedInPhase().name();
.get(PhasedTestManager.fetchScenarioName(result)).getFailedInPhase();

log.info(skipMessageSKIPFAILURE);
result.setStatus(ITestResult.SKIP);
Expand Down Expand Up @@ -311,14 +311,14 @@ public void onFinish(ITestContext context) {
ITestListener.super.onFinish(context);

//Once the tests have finished in producer mode we, need to export the data
if (Phases.PRODUCER.isSelected()) {
if (ExecutionMode.INTERRUPTIVE.isSelected("PRODUCER")) {
log.info("{} At the end. Exporting data", PhasedTestManager.PHASED_TEST_LOG_PREFIX);
PhasedTestManager.exportPhaseData();
}
log.debug("{} Purging results - Keeping one method per test class",
PhasedTestManager.PHASED_TEST_LOG_PREFIX);

if (Phases.ASYNCHRONOUS.isSelected()) {
if (ExecutionMode.NON_INTERRUPTIVE.isSelected()) {
PhasedEventManager.stopEventExecutor();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,26 @@ public static String fetchScenarioName(String in_classFullName, String in_shuffl
*
* @param in_className The name of the scenario
* @param in_phaseGroup The phase group in which we are in
* @param in_phase The phase in which we are in
* @param in_runValues The set execution mode and behavior
* @return An array of two entries. The first entry is the start index and the second entry is the end index
*/
public static Integer[] fetchExecutionIndex(String in_className, String in_phaseGroup, Phases in_phase) {
public static Integer[] fetchExecutionIndex(String in_className, String in_phaseGroup, RunValues in_runValues) {
Integer[] lr_result = new Integer[2];

//FetchNr Of Steps
int l_nrOfMethods = PhasedTestManager.getMethodMap().keySet().stream().filter(m -> m.startsWith(in_className))
.collect(Collectors.toList()).size();

Integer[] l_boundaries = in_phase.hasSplittingEvent() ? PhasedTestManager.fetchShuffledStepCount(
Integer[] l_boundaries = in_runValues.getExecutionMode().equals(ExecutionMode.INTERRUPTIVE)? PhasedTestManager.fetchShuffledStepCount(
in_phaseGroup) : new Integer[] {
0, l_nrOfMethods };

switch (in_phase) {
case PRODUCER:
switch (in_runValues.getBehavior()) {
case "PRODUCER":
lr_result[0] = 0;
lr_result[1] = l_boundaries[0];
break;
case CONSUMER:
case "CONSUMER":
lr_result[0] = l_boundaries[0];
lr_result[1] = l_nrOfMethods;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ public void scenario(String phaseGroup) throws Throwable {

Map<String, ScenarioStepDependencies> l_scenarioDependencies = PhasedTestManager.getStepDependencies();

List<StepDependencies> l_orderList = Phases.getCurrentPhase()
.equals(Phases.PERMUTATIONAL) ? l_scenarioDependencies.get(l_executingClass.getTypeName())
List<StepDependencies> l_orderList = ExecutionMode.is(ExecutionMode.PERMUTATIONAL) ? l_scenarioDependencies.get(
l_executingClass.getTypeName())
.fetchScenarioPermutations().get(phaseGroup) : l_scenarioDependencies.get(
l_executingClass.getTypeName()).fetchExecutionOrderList();

// var nrOfSteps = Phases.getCurrentPhase().hasSplittingEvent() ? PhasedTestManager.fetchShuffledStepCount(
// phaseGroup)[0] : l_orderList.size();

Integer[] l_boundaries = MutationManager.fetchExecutionIndex(l_executingClass.getTypeName(), phaseGroup,
Phases.getCurrentPhase());
ExecutionMode.getCurrentMode().fetchRunValues());
// System.out.println(nrOfSteps + " - " + phaseGroup);
//for (Method stepMethod : l_executingClass.getDeclaredMethods()) {
//for (StepDependencies stepOrdering : stepOrder) {
Expand All @@ -60,7 +60,7 @@ public void scenario(String phaseGroup) throws Throwable {

PhasedTestManager.storePhasedContext(ClassPathParser.fetchFullName(stepMethod), phaseGroup);

if (Phases.ASYNCHRONOUS.isSelected()) {
if (ExecutionMode.NON_INTERRUPTIVE.isSelected()) {

//Check if there is an event declared
String lt_event = PhasedEventManager.fetchEvent(stepMethod, phaseGroup);
Expand All @@ -75,7 +75,7 @@ public void scenario(String phaseGroup) throws Throwable {
stepMethod.invoke(ourInstance, phaseGroup);
long l_end = System.currentTimeMillis();

if (Phases.ASYNCHRONOUS.isSelected()) {
if (ExecutionMode.NON_INTERRUPTIVE.isSelected()) {
//Check if there is an event declared
String lt_event = PhasedEventManager.fetchEvent(stepMethod, phaseGroup);
if (lt_event != null) {
Expand Down
Loading

0 comments on commit 94ef416

Please sign in to comment.