Skip to content

Commit 1d62522

Browse files
committed
Backport retry DB and RCU creation
1 parent ef9a32f commit 1d62522

File tree

3 files changed

+279
-206
lines changed

3 files changed

+279
-206
lines changed

integration-tests/src/test/java/oracle/kubernetes/operator/ItJrfPvWlst.java

Lines changed: 97 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -14,137 +14,163 @@
1414
import oracle.kubernetes.operator.utils.TestUtils;
1515
import org.junit.jupiter.api.AfterAll;
1616
import org.junit.jupiter.api.AfterEach;
17-
import org.junit.jupiter.api.Assertions;
1817
import org.junit.jupiter.api.BeforeAll;
1918
import org.junit.jupiter.api.BeforeEach;
2019
import org.junit.jupiter.api.MethodOrderer.Alphanumeric;
2120
import org.junit.jupiter.api.Test;
2221
import org.junit.jupiter.api.TestMethodOrder;
2322

23+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
24+
import static org.junit.jupiter.api.Assertions.assertNotNull;
25+
2426
@TestMethodOrder(Alphanumeric.class)
2527

2628
public class ItJrfPvWlst extends BaseTest {
2729
private static String rcuSchemaPrefix = "jrfdomain";
28-
private static Operator operator1;
30+
private static Operator operator;
2931
private static String domainNS;
3032
private static String domainUid = "";
3133
private static String restartTmpDir = "";
3234
private static boolean testCompletedSuccessfully;
3335
private static String testClassName;
3436
private static StringBuffer namespaceList;
37+
private static int dbPort;
38+
private static String dbrcuNamespace;
39+
private static String dbUrl;
40+
private static JrfDomain jrfdomain;
3541

3642
/**
37-
* This method gets called only once before any of the test methods are executed. It does the
38-
* initialization of the integration test properties defined in OperatorIT.properties and setting
39-
* the resultRoot, pvRoot and projectRoot attributes. It also creates Oracle DB pod which used for
40-
* RCU.
41-
*
42-
* @throws Exception - if an error occurs when load property file or create DB pod
43-
*/
43+
* This method gets called only once before any of the test methods are executed. It does the
44+
* initialization of the integration test properties defined in OperatorIT.properties and sets
45+
* the resultRoot, pvRoot and projectRoot attributes.
46+
*/
4447
@BeforeAll
45-
public static void staticPrepare() throws Exception {
48+
public static void staticPrepare() {
4649
namespaceList = new StringBuffer();
4750
testClassName = new Object() {
4851
}.getClass().getEnclosingClass().getSimpleName();
49-
// initialize test properties
50-
initialize(APP_PROPS_FILE, testClassName);
52+
53+
LoggerHelper.getLocal().log(Level.INFO, "setting up properties, directories for: {0}",
54+
testClassName);
55+
assertDoesNotThrow(() -> initialize(APP_PROPS_FILE, testClassName),
56+
"Failed: initial setup");
5157
}
5258

5359
/**
54-
* Prepare test.
55-
* @throws Exception on failure
60+
* This method gets called before every test. It creates the result/pv root directories
61+
* for the test. It also creates RCU schema, operator.
5662
*/
5763
@BeforeEach
58-
public void prepare() throws Exception {
59-
if (QUICKTEST) {
60-
createResultAndPvDirs(testClassName);
61-
62-
TestUtils.execOrAbortProcess(
63-
"cp -rf "
64-
+ BaseTest.getProjectRoot()
65-
+ "/kubernetes/samples/scripts "
66-
+ getResultDir(),
67-
true);
68-
//delete leftover pods caused by test being aborted
69-
DbUtils.deleteRcuPod(getResultDir());
70-
DbUtils.stopOracleDB(getResultDir());
71-
72-
DbUtils.startOracleDB(getResultDir());
73-
DbUtils.createRcuSchema(getResultDir(),rcuSchemaPrefix);
74-
75-
// create operator1
76-
if (operator1 == null) {
77-
Map<String, Object> operatorMap = createOperatorMap(getNewSuffixCount(),
78-
true, testClassName);
79-
operator1 = TestUtils.createOperator(operatorMap, Operator.RestCertType.SELF_SIGNED);
80-
Assertions.assertNotNull(operator1);
81-
domainNS = ((ArrayList<String>) operatorMap.get("domainNamespaces")).get(0);
82-
namespaceList.append((String)operatorMap.get("namespace"));
83-
namespaceList.append(" ").append(domainNS);
84-
}
85-
}
64+
public void prepare() {
65+
LoggerHelper.getLocal().log(Level.INFO, "Creating result/pv root directories");
66+
assertDoesNotThrow(() -> createResultAndPvDirs(testClassName),
67+
"Failed: createResultAndPvDirs");
68+
69+
LoggerHelper.getLocal().log(Level.INFO, "Copying sample dir to the result dir");
70+
assertDoesNotThrow(() -> TestUtils.execOrAbortProcess(
71+
"cp -rf "
72+
+ BaseTest.getProjectRoot()
73+
+ "/kubernetes/samples/scripts "
74+
+ getResultDir(),
75+
true),
76+
"Failed: Copy sample dir to the result dir");
77+
78+
//start DB and create RCU
79+
dbrcuNamespace = "dbrcu" + String.valueOf(getNewSuffixCount());
80+
dbPort = 30011 + getNewSuffixCount();
81+
dbUrl = "oracle-db." + dbrcuNamespace + ".svc.cluster.local:1521/devpdb.k8s";
82+
assertDoesNotThrow(() -> DbUtils.setupRcuDatabase(getResultDir(), dbPort, dbUrl,
83+
rcuSchemaPrefix, dbrcuNamespace));
84+
85+
// create operator
86+
if (operator == null) {
87+
Map<String, Object> operatorMap = createOperatorMap(getNewSuffixCount(),
88+
true, testClassName);
89+
operator = assertDoesNotThrow(() -> TestUtils.createOperator(operatorMap,
90+
Operator.RestCertType.SELF_SIGNED));
91+
assertNotNull(operator);
92+
LoggerHelper.getLocal().log(Level.INFO, "Operator is created for {0}", testClassName);
93+
94+
domainNS = ((ArrayList<String>) operatorMap.get("domainNamespaces")).get(0);
95+
namespaceList.append((String)operatorMap.get("namespace"));
96+
namespaceList.append(" ").append(domainNS);
97+
}
8698
}
87-
99+
100+
/**
101+
* This method will run once after every test method is finished. It delete both RCU and DB pods.
102+
*/
88103
@AfterEach
89-
public void unPrepare() throws Exception {
90-
DbUtils.deleteRcuPod(getResultDir());
91-
DbUtils.stopOracleDB(getResultDir());
104+
public void unPrepare() {
105+
LoggerHelper.getLocal().log(Level.INFO, "Is going to drop RCU schema and stop DB for {0}", testClassName);
106+
assertDoesNotThrow(() -> DbUtils.deleteRcuPod(getResultDir()),
107+
"Failed: drop RCU schema");
108+
assertDoesNotThrow(() -> DbUtils.deleteDbPod(getResultDir()),
109+
"Failed: stop DB");
92110
}
93-
111+
94112
/**
95-
* This method will run once after all test methods are finished. It Releases k8s cluster lease,
96-
* archives result, pv directories.
97-
*
98-
* @throws Exception - if any error occurs
99-
*/
113+
* Releases k8s cluster lease, archives result, pv directories.
114+
*/
100115
@AfterAll
101-
public static void staticUnPrepare() throws Exception {
102-
tearDown(new Object() {
103-
}.getClass().getEnclosingClass().getSimpleName(), namespaceList.toString());
104-
105-
LoggerHelper.getLocal().log(Level.INFO,"SUCCESS");
116+
public static void staticUnPrepare() {
117+
assertDoesNotThrow(() -> tearDown(new Object() {
118+
}.getClass().getEnclosingClass().getSimpleName(), namespaceList.toString()),
119+
"tearDown failed");
106120
}
107-
121+
122+
/**
123+
* Create and deploy a JRF domain. Verify the domain is created successfully.
124+
*/
108125
@Test
109-
public void testJrfDomainOnPvUsingWlst() throws Exception {
126+
public void testJrfDomainOnPvUsingWlst() {
110127
if (QUICKTEST) {
111128
String testMethodName = new Object() {
112129
}.getClass().getEnclosingMethod().getName();
113-
logTestBegin(testMethodName);
114130
LoggerHelper.getLocal().log(Level.INFO,
115-
"Creating Operator & waiting for the script to complete execution");
116-
117-
JrfDomain jrfdomain = null;
131+
"+++++++++++++++++++++++++++++++++---------------------------------+");
132+
LoggerHelper.getLocal().log(Level.INFO, "BEGIN " + testMethodName);
133+
118134
boolean testCompletedSuccessfully = false;
119135

120136
try {
121137
// create JRF domain
122138
Map<String, Object> domainMap = createDomainMap(getNewSuffixCount(), testClassName);
123139
domainMap.put("namespace", domainNS);
124140
domainMap.put("initialManagedServerReplicas", new Integer("2"));
125-
domainMap.put("image", "container-registry.oracle.com/middleware/fmw-infrastructure:12.2.1.4");
126141
domainMap.put("clusterName", "infra-cluster");
127142
domainMap.put("managedServerNameBase", "infraserver");
143+
domainMap.put("domainHomeSourceType", "PersistentVolume");
128144
domainMap.put("rcuSchemaPrefix", "jrfdomain");
129-
domainMap.put("rcuDatabaseURL", "oracle-db.default.svc.cluster.local:1521/devpdb.k8s");
145+
LoggerHelper.getLocal().log(Level.INFO, "DEBUG " + testClassName + "domain: dbUrl: "
146+
+ dbUrl);
147+
domainMap.put("rcuDatabaseURL", dbUrl);
130148
domainUid = (String) domainMap.get("domainUID");
131149
LoggerHelper.getLocal().log(Level.INFO,
132150
"Creating and verifying the domain creation with domainUid: " + domainUid);
133151

134-
jrfdomain = new JrfDomain(domainMap);
135-
jrfdomain.verifyDomainCreated(80);
136-
152+
jrfdomain = assertDoesNotThrow(() -> new JrfDomain(domainMap),
153+
"Failed: JRF domain creation");
154+
LoggerHelper.getLocal().log(Level.INFO, "JRF domain is created for {0}",
155+
testClassName);
156+
assertDoesNotThrow(() -> jrfdomain.verifyDomainCreated(),
157+
"Failed: domain verification");
158+
LoggerHelper.getLocal().log(Level.INFO, "JRF domain verification succeeded for {0}",
159+
testClassName);
160+
137161
// basic test cases
138-
testBasicUseCases(jrfdomain, false);
162+
assertDoesNotThrow(() -> testBasicUseCases(jrfdomain, false));
163+
LoggerHelper.getLocal().log(Level.INFO, "JRF domain BasicUseCases succeeded for {0}",
164+
testClassName);
139165

140166
testCompletedSuccessfully = true;
141167
} finally {
142168
if (jrfdomain != null && (JENKINS || testCompletedSuccessfully)) {
143-
jrfdomain.shutdownUsingServerStartPolicy();
169+
assertDoesNotThrow(() -> jrfdomain.shutdownUsingServerStartPolicy());
144170
}
145171
}
146172

147173
LoggerHelper.getLocal().log(Level.INFO, "SUCCESS - " + testMethodName);
148174
}
149175
}
150-
}
176+
}

0 commit comments

Comments
 (0)