Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fattest.simplicity method to check if feature files exist before running a repeat #30393

Open
wants to merge 1 commit into
base: integration
Choose a base branch
from
Open
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 @@ -91,4 +91,9 @@ public String getID() {
return ID;
}

@Override
public RepeatTestAction checkIfFeaturesPresent(boolean checkIfFeaturesPresent) {
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.ibm.websphere.simplicity.config.ServerConfigurationFactory;
import com.ibm.websphere.simplicity.log.Log;

import componenttest.common.apiservices.Bootstrap;
import componenttest.custom.junit.runner.Mode.TestMode;
import componenttest.custom.junit.runner.TestModeFilter;
import componenttest.rules.repeater.RepeatActions.SEVersion;
Expand Down Expand Up @@ -167,6 +168,7 @@ public static FeatureReplacementAction BETA_OPTION() {
private final Set<String> serverConfigPaths = new HashSet<String>();
private boolean calledForServers = false;
private boolean calledForServerConfigPaths = false;
protected boolean checkFeaturesPresent = false;

private static final String pathToAutoFVTTestFiles = "lib/LibertyFATTestFiles/";
private static final String pathToAutoFVTTestServers = "publish/servers/";
Expand Down Expand Up @@ -495,9 +497,70 @@ public FeatureReplacementAction withBeta() {
return this;
}

@Override
public RepeatTestAction checkIfFeaturesPresent(boolean checkIfFeaturesPresent) {
this.checkFeaturesPresent = checkIfFeaturesPresent;
return this;
}

@Override
public boolean isEnabled() {
return checkEnabled();
boolean enabled = checkEnabled();
if (enabled && checkFeaturesPresent) {
enabled = checkAllFeatureFilesPresent();
}
return enabled;
}

public boolean checkAllFeatureFilesPresent() {
Bootstrap b;
try {
b = Bootstrap.getInstance();
} catch (Exception e) {
Log.info(c, "checkAllFeatureFilesPresent", "Skipping action '" + toString() + "' because Bootstrap.getInstance() failed.");
return false;
}
String installRoot = b.getValue("libertyInstallPath");

Set<String> featuresToCheck = new HashSet<String>();
featuresToCheck.addAll(addFeatures);
featuresToCheck.addAll(alwaysAddFeatures);

final String path = installRoot + "/lib/features/";
final String oldPrefix = "com.ibm.websphere.appserver.";
final String newPrefix = "io.openliberty.";
final String newPrefixWithJakarta = "io.openliberty.jakarta.";
final String suffix = ".mf";

//We occasionally create features that only exist for fat tests and will not always be present in the liberty image.
// To account for this we'll tolerate a 20% failure ratio.
int failures = 0;
String skipMessage = "Skipping action '" + toString() + "' because ";

for (String feature : featuresToCheck) {

File oldFileLocation = new File(path + oldPrefix + feature + suffix);
File newFileLocation = new File(path + newPrefix + feature + suffix);
File newFileJakartaLocation = new File(path + newPrefixWithJakarta + feature + suffix);
File noPrefixFileLocation = new File(path + feature + suffix);

if (!oldFileLocation.exists() && !newFileLocation.exists() && !noPrefixFileLocation.exists()) {
skipMessage = skipMessage + System.lineSeparator() + feature + " was not found in any of: "
+ System.lineSeparator() + oldFileLocation.getAbsolutePath()
+ System.lineSeparator() + newFileLocation.getAbsolutePath()
+ System.lineSeparator() + newFileJakartaLocation.getAbsolutePath()
+ System.lineSeparator() + noPrefixFileLocation.getAbsolutePath();
failures++;
}
}

double threshold = (featuresToCheck.size() * 0.20d);
if (failures <= threshold) {
return true;
} else {
Log.info(c, "checkAllFeatureFilesPresent", skipMessage);
return false;
}
}

public boolean checkEnabled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class FeatureSet {
private final Set<String> features;
private final EEVersion eeVersion;
private final SEVersion minJavaLevel;
private boolean checkIfFeaturesPresent = false;

/**
* Create a new FeatureSet with the given ID and set of features
Expand All @@ -33,7 +34,7 @@ public class FeatureSet {
* @param eeVersion The EE Version that the features are based on. May be null.
*/
public FeatureSet(String id, Set<String> features, EEVersion eeVersion) {
this(id, features, eeVersion, eeVersion.getMinJavaLevel());
this(id, features, eeVersion, eeVersion.getMinJavaLevel(), false);
}

/**
Expand All @@ -44,13 +45,14 @@ public FeatureSet(String id, Set<String> features, EEVersion eeVersion) {
* @param eeVersion The EE Version that the features are based on. May be null.
* @param minJavaLevel The minimum Java SE Version which this FeatureSet can run on.
*/
public FeatureSet(String id, Set<String> features, EEVersion eeVersion, SEVersion minJavaLevel) {
public FeatureSet(String id, Set<String> features, EEVersion eeVersion, SEVersion minJavaLevel, boolean checkIfFeaturesPresent) {
if (id == null)
throw new NullPointerException();
this.id = id;
this.features = Collections.unmodifiableSet(new HashSet<>(features));
this.eeVersion = eeVersion;
this.minJavaLevel = minJavaLevel;
this.checkIfFeaturesPresent = checkIfFeaturesPresent;
}

/**
Expand Down Expand Up @@ -164,6 +166,7 @@ public static class FeatureSetBuilder {
private final HashSet<String> features;
private final EEVersion eeVersion;
private SEVersion minJavaLevel;
private boolean checkIfFeaturesPresent;

/**
* Create a new builder, starting with the same set of features from an existing FeatureSet
Expand Down Expand Up @@ -217,15 +220,29 @@ public FeatureSetBuilder setMinJavaLevel(SEVersion minJavaLevel) {
return this;
}

/**
* Set if the FeatureSet needs to check if the mf feature files for all its features exist before running
*
* @param minJavaLevel the minimum Java SE Version
*/
public FeatureSetBuilder setCheckIfFeaturesPresent(boolean checkIfFeaturesPresent) {
this.checkIfFeaturesPresent = checkIfFeaturesPresent;
return this;
}

/**
* Create a new FeatureSet with the given ID and the features currently in the builder
*
* @param id the ID of the new FeatureSet. Must be unique.
* @return the new FeatureSet
*/
public FeatureSet build(String id) {
return new FeatureSet(id, this.features, this.eeVersion, this.minJavaLevel);
return new FeatureSet(id, this.features, this.eeVersion, this.minJavaLevel, this.checkIfFeaturesPresent);
}
}

public boolean checkIfFeaturesPresent() {
return checkIfFeaturesPresent;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ public class MicroProfileActions {
public static final FeatureSet MP60 = new FeatureSet(MP60_ID, MP60_FEATURE_SET, EEVersion.EE10);
public static final FeatureSet MP61 = new FeatureSet(MP61_ID, MP61_FEATURE_SET, EEVersion.EE10);
public static final FeatureSet MP70_EE10 = new FeatureSet(MP70_EE10_ID, MP70_EE10_FEATURE_SET, EEVersion.EE10);
public static final FeatureSet MP70_EE11 = new FeatureSet(MP70_EE11_ID, MP70_EE11_FEATURE_SET, EEVersion.EE11);
public static final FeatureSet MP70_EE11_APP_MODE = new FeatureSet(MP70_EE11_APP_MODE_ID, MP70_EE11_FEATURE_SET, EEVersion.EE11);
public static final FeatureSet MP70_EE11 = new FeatureSet(MP70_EE11_ID, MP70_EE11_FEATURE_SET, EEVersion.EE11, EEVersion.EE11.getMinJavaLevel(), true);
public static final FeatureSet MP70_EE11_APP_MODE = new FeatureSet(MP70_EE11_APP_MODE_ID, MP70_EE11_FEATURE_SET, EEVersion.EE11, EEVersion.EE11.getMinJavaLevel(), true);

//All MicroProfile FeatureSets - must be descending order
private static final FeatureSet[] ALL_SETS_ARRAY = { MP70_EE11, MP70_EE10, MP61, MP60, MP50, MP41, MP40, MP33, MP32, MP30, MP22, MP21, MP20, MP14, MP13, MP12, MP10 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ public static FeatureReplacementAction forFeatureSet(List<FeatureSet> allFeature
action = new FeatureReplacementAction();
}
action.withMinJavaLevel(featureSet.getMinJavaLevel());
action.checkIfFeaturesPresent(featureSet.checkIfFeaturesPresent());
if (action instanceof JakartaEEAction) {
((JakartaEEAction) action).setSkipTransformation(skipTransformation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,15 @@ public interface RepeatTestAction {
* If clean up is needed to undo the setup changes after running the action then override this method.
*/
default public void cleanup() throws Exception {}

/**
* If set to true when running this action first check the liberty image for the presence of the mf files
* needed to run the test. This can be used to ensure we do not attempt to run features that are in beta
* against an image that lacks beta features.
*
* @return this object
*/
public default RepeatTestAction checkIfFeaturesPresent(boolean checkIfFeaturesPresent) {
return this; //Custom repeat actions in fat buckets usually won't need this.
}
}