Skip to content

Split the MiiSample classes to ItMiiWlsAuxiliaryImageSample and ItMiiFmwAuxiliaryImageSample to seedup test execution in parallel #2455

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

Merged
merged 6 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
More minor changes
  • Loading branch information
huizhao committed Jul 19, 2021
commit 4ba4c8a5b8b6a937a157d3fd2bb61dfb719402e2
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ public class ItMiiSampleFmwAux {
*/
@BeforeAll
public static void init(@Namespaces(4) List<String> namespaces) {
ItMiiSampleHelper.setDomainType(ItMiiSampleHelper.DomainType.JRF);
ItMiiSampleHelper.setImageType(ItMiiSampleHelper.ImageType.AUX);
ItMiiSampleHelper.initAll(namespaces);
ItMiiSampleHelper.initAll(namespaces, ItMiiSampleHelper.DomainType.JRF, ItMiiSampleHelper.ImageType.AUX);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ public class ItMiiSampleFmwMain {
*/
@BeforeAll
public static void init(@Namespaces(4) List<String> namespaces) {
ItMiiSampleHelper.setDomainType(ItMiiSampleHelper.DomainType.JRF);
ItMiiSampleHelper.setImageType(ItMiiSampleHelper.ImageType.MAIN);
ItMiiSampleHelper.initAll(namespaces);
ItMiiSampleHelper.initAll(namespaces, ItMiiSampleHelper.DomainType.JRF, ItMiiSampleHelper.ImageType.MAIN);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ public class ItMiiSampleWlsAux {
*/
@BeforeAll
public static void init(@Namespaces(3) List<String> namespaces) {
ItMiiSampleHelper.setDomainType(ItMiiSampleHelper.DomainType.WLS);
ItMiiSampleHelper.setImageType(ItMiiSampleHelper.ImageType.AUX);
ItMiiSampleHelper.initAll(namespaces);
ItMiiSampleHelper.initAll(namespaces, ItMiiSampleHelper.DomainType.WLS, ItMiiSampleHelper.ImageType.AUX);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package oracle.weblogic.kubernetes;

import java.util.List;
import java.util.Map;

import oracle.weblogic.kubernetes.annotations.IntegrationTest;
import oracle.weblogic.kubernetes.annotations.Namespaces;
Expand All @@ -18,8 +17,6 @@
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;

import static oracle.weblogic.kubernetes.TestConstants.WEBLOGIC_IMAGE_NAME;

/**
* Tests to verify MII sample.
*/
Expand All @@ -35,9 +32,7 @@ public class ItMiiSampleWlsMain {
*/
@BeforeAll
public static void init(@Namespaces(3) List<String> namespaces) {
ItMiiSampleHelper.setDomainType(ItMiiSampleHelper.DomainType.WLS);
ItMiiSampleHelper.setImageType(ItMiiSampleHelper.ImageType.MAIN);
ItMiiSampleHelper.initAll(namespaces);
ItMiiSampleHelper.initAll(namespaces, ItMiiSampleHelper.DomainType.WLS, ItMiiSampleHelper.ImageType.MAIN);
}

/**
Expand All @@ -49,14 +44,8 @@ public static void init(@Namespaces(3) List<String> namespaces) {
@DisabledIfEnvironmentVariable(named = "SKIP_CHECK_SAMPLE", matches = "true")
@DisplayName("Test to verify MII Sample source")
public void testCheckMiiSampleSource() {
Map<String, String> envMap = ItMiiSampleHelper.getEnvMap();
envMap.remove("BASE_IMAGE_NAME");
ItMiiSampleHelper.execTestScriptAndAssertSuccess(
ItMiiSampleHelper.DomainType.WLS,
"-check-sample",
ItMiiSampleHelper.callCheckMiiSampleSource("-check-sample",
"Sample source doesn't match with the generated source");
envMap.put("BASE_IMAGE_NAME", WEBLOGIC_IMAGE_NAME);
ItMiiSampleHelper.setEnvMap(envMap);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public class ItMiiSampleHelper {
private static Map<String, String> envMap = null;
private static LoggingFacade logger = null;
private static boolean previousTestSuccessful = true;
private static DomainType domainTypeName = null;
private static ImageType imageTypeName = null;
private static DomainType domainType = null;
private static ImageType imageType = null;

public enum DomainType {
JRF,
Expand All @@ -85,9 +85,13 @@ public enum ImageType {
* Install Operator.
* @param namespaces list of namespaces created by the IntegrationTestWatcher by the
* JUnit engine parameter resolution mechanism
* @param domainTypeParam domain type names
* @param imageTypeParam image type names
*/
public static void initAll(List<String> namespaces) {
public static void initAll(List<String> namespaces, DomainType domainTypeParam, ImageType imageTypeParam) {
logger = getLogger();
ItMiiSampleHelper.domainType = domainTypeParam;
ItMiiSampleHelper.imageType = imageTypeParam;
// get a new unique opNamespace
logger.info("Creating unique namespace for Operator");
assertNotNull(namespaces.get(0), "Namespace list is null");
Expand All @@ -101,9 +105,6 @@ public static void initAll(List<String> namespaces) {
assertNotNull(namespaces.get(2), "Namespace list is null");
traefikNamespace = namespaces.get(2);

assertNotNull(domainTypeName, "DomainType name is null");
assertNotNull(imageTypeName, "ImageType name list is null");

// install and verify operator
installAndVerifyOperator(opNamespace, domainNamespace);

Expand All @@ -119,7 +120,7 @@ public static void initAll(List<String> namespaces) {
envMap.put("IMAGE_PULL_SECRET_NAME", OCIR_SECRET_NAME); //ocir secret
envMap.put("K8S_NODEPORT_HOST", K8S_NODEPORT_HOST);
envMap.put("OKD", "" + OKD);
envMap.put("DO_AI", String.valueOf(auxiliaryImageEnabled()));
envMap.put("DO_AI", String.valueOf(imageType == ImageType.AUX));

// kind cluster uses openjdk which is not supported by image tool
String witJavaHome = System.getenv("WIT_JAVA_HOME");
Expand Down Expand Up @@ -148,7 +149,7 @@ public static void initAll(List<String> namespaces) {
logger.info("Docker registry secret {0} created successfully in namespace {1}",
OCIR_SECRET_NAME, domainNamespace);

if (domainTypeName.equals(DomainType.JRF)) {
if (domainType.equals(DomainType.JRF)) {
// install db for FMW test cases
logger.info("Creating unique namespace for Database");
assertNotNull(namespaces.get(3), "Namespace list is null");
Expand Down Expand Up @@ -231,6 +232,7 @@ public static void execTestScriptAndAssertSuccess(DomainType domainType,

String outStr = errString;
outStr += ", domainType=" + domainType + "\n";
outStr += ", imageType=" + imageType + "\n";
outStr += ", command=\n{\n" + command + "\n}\n";
outStr += ", stderr=\n{\n" + (result != null ? result.stderr() : "") + "\n}\n";
outStr += ", stdout=\n{\n" + (result != null ? result.stdout() : "") + "\n}\n";
Expand All @@ -246,12 +248,12 @@ public static void execTestScriptAndAssertSuccess(DomainType domainType,
* Test MII sample WLS or JRF initial use case.
*/
public static void callInitialUseCase() {
String imageName = (domainTypeName.equals(DomainType.WLS))
String imageName = (domainType.equals(DomainType.WLS))
? MII_SAMPLE_WLS_IMAGE_NAME_V1 : MII_SAMPLE_JRF_IMAGE_NAME_V1;
previousTestSuccessful = true;
envMap.put("MODEL_IMAGE_NAME", imageName);

if (domainTypeName.equals(DomainType.JRF)) {
if (domainType.equals(DomainType.JRF)) {
String dbImageName = (KIND_REPO != null
? KIND_REPO + DB_IMAGE_NAME.substring(BASE_IMAGES_REPO.length() + 1) : DB_IMAGE_NAME);
String jrfBaseImageName = (KIND_REPO != null
Expand All @@ -270,11 +272,11 @@ public static void callInitialUseCase() {

// run JRF use cases irrespective of WLS use cases fail/pass
previousTestSuccessful = true;
execTestScriptAndAssertSuccess(domainTypeName, "-db,-rcu", "DB/RCU creation failed");
execTestScriptAndAssertSuccess(domainType, "-db,-rcu", "DB/RCU creation failed");
}

execTestScriptAndAssertSuccess(
domainTypeName,
domainType,
"-initial-image,-check-image-and-push,-initial-main",
"Initial use case failed"
);
Expand All @@ -286,12 +288,23 @@ public static void callInitialUseCase() {
public static void callUpdateUseCase(String args,
String errString) {
if (args.contains("update3")) {
String imageName = (domainTypeName.equals(DomainType.WLS))
String imageName = (domainType.equals(DomainType.WLS))
? MII_SAMPLE_WLS_IMAGE_NAME_V2 : MII_SAMPLE_JRF_IMAGE_NAME_V2;
envMap.put("MODEL_IMAGE_NAME", imageName);
}

execTestScriptAndAssertSuccess(domainTypeName, args, errString);
execTestScriptAndAssertSuccess(domainType, args, errString);
}

/**
* Test MII sample WLS or JRF update1 use case.
*/
public static void callCheckMiiSampleSource(String args,
String errString) {
final String baseImageNameKey = "BASE_IMAGE_NAME";
envMap.remove(baseImageNameKey);
execTestScriptAndAssertSuccess(domainType, args, errString);
envMap.put(baseImageNameKey, WEBLOGIC_IMAGE_NAME);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: This looks like a refactoring issue. If, sometime in the future, the suite was changed so that this test was called from a different location and this is not fixed, then the test would potentially break the next test. The code shouldn't force WEBLOGIC_IMAGE_NAME -- instead, the code should restore the image that was originally in the envMap, similar to the original code, and it should ideally do this in a finally.

}

/**
Expand All @@ -308,69 +321,12 @@ public static void tearDownAll() {
}

// db cleanup or deletion
if (domainTypeName.equals(DomainType.JRF) && envMap != null) {
if (domainType.equals(DomainType.JRF) && envMap != null) {
logger.info("Running samples DB cleanup");
Command.withParams(new CommandParams()
.command(MII_SAMPLES_SCRIPT + " -precleandb")
.env(envMap)
.redirect(true)).execute();
}
}


/**
* Set env variables map.
* @param newEnvMap a map contains env variables
*/
public static void setEnvMap(Map<String, String> newEnvMap) {
ItMiiSampleHelper.envMap = newEnvMap;
}

/**
* Set domain type.
* @param domainTypeName domain type name
*/
public static void setDomainType(DomainType domainTypeName) {
ItMiiSampleHelper.domainTypeName = domainTypeName;
}

/**
* Set image type.
* @param imageTypeName image type names
*/
public static void setImageType(ImageType imageTypeName) {
ItMiiSampleHelper.imageTypeName = imageTypeName;
}

/**
* Get env variables map.
* @return a map containing env variables
*/
public static Map<String, String> getEnvMap() {
return ItMiiSampleHelper.envMap;
}

/**
* Get domain type.
* @return domain type name
*/
public static DomainType getDomainType() {
return domainTypeName;
}

/**
* Get image type.
* @return image type names
*/
public static ImageType getImageType() {
return ItMiiSampleHelper.imageTypeName;
}

/**
* Check whether to use auxiliary image or not.
* @return true to test auxiliary image and false to test non-auxiliary image
*/
public static boolean auxiliaryImageEnabled() {
return (imageTypeName.equals(ImageType.AUX)) ? true : false;
}
}