Skip to content

Commit 8612a81

Browse files
authored
Merge pull request #350 from oracle/feature/java-integration-tests
Feature/java integration tests
2 parents a1608a6 + 3bdaf76 commit 8612a81

18 files changed

+636
-31
lines changed

integration-tests/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,12 @@
153153
</goals>
154154
<phase>integration-test</phase>
155155
<configuration>
156-
<skipTests>false</skipTests>
156+
<excludes>
157+
<exclude>**/*Test.java</exclude>
158+
<!-- exclude>**/IT*.java</exclude -->
159+
</excludes>
160+
<!-- just run test suite -->
161+
<includes> <include>**/*TestSuite.java</include> </includes>
157162
</configuration>
158163
</execution>
159164
<execution>

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,19 @@ public static String getBranchName() {
153153
return branchName;
154154
}
155155

156+
public static ExecResult cleanup() throws Exception {
157+
String cmd =
158+
"export RESULT_ROOT="
159+
+ getResultRoot()
160+
+ " export PV_ROOT="
161+
+ getPvRoot()
162+
+ " && "
163+
+ getProjectRoot()
164+
+ "/src/integration-tests/bash/cleanup.sh";
165+
logger.info("Command to call cleanup script " + cmd);
166+
return ExecCommand.exec(cmd);
167+
}
168+
156169
protected void logTestBegin(String testName) throws Exception {
157170
logger.info("+++++++++++++++++++++++++++++++++---------------------------------+");
158171
logger.info("BEGIN " + testName);

integration-tests/src/test/java/oracle/kubernetes/operator/ITSingleDomain.java renamed to integration-tests/src/test/java/oracle/kubernetes/operator/ITFirstDomain.java

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
import java.util.Properties;
88
import oracle.kubernetes.operator.utils.Domain;
9-
import oracle.kubernetes.operator.utils.ExecCommand;
109
import oracle.kubernetes.operator.utils.ExecResult;
1110
import oracle.kubernetes.operator.utils.Operator;
1211
import oracle.kubernetes.operator.utils.TestUtils;
1312
import org.junit.AfterClass;
13+
import org.junit.Assume;
1414
import org.junit.BeforeClass;
1515
import org.junit.Test;
1616

@@ -20,14 +20,14 @@
2020
* <p>This test is used for creating Operator and a single domain which the Operator manages and
2121
* verifies both.
2222
*/
23-
public class ITSingleDomain extends BaseTest {
23+
public class ITFirstDomain extends BaseTest {
2424
public static final String TESTWEBAPP = "testwebapp";
2525

2626
// property file used to customize operator properties for operator inputs yaml
27-
private static String opPropsFile = "ITSingleDomain_op.properties";
27+
private static String opPropsFile = "ITFirstOperator.properties";
2828

2929
// property file used to customize domain properties for domain inputs yaml
30-
private static String domainPropsFile = "ITSingleDomain_domain.properties";
30+
private static String domainPropsFile = "ITFirstDomain.properties";
3131

3232
// property file used to configure constants for integration tests
3333
private static String appPropsFile = "OperatorIT.properties";
@@ -54,6 +54,18 @@ public static void staticPrepare() throws Exception {
5454

5555
// initialize test properties and create the directories
5656
initialize(appPropsFile);
57+
58+
// delete k8s artifacts created if any, delete PV directories
59+
if (System.getenv("WERCKER") == null && System.getenv("JENKINS") == null) {
60+
ExecResult result = cleanup();
61+
if (result.exitValue() != 0) {
62+
throw new RuntimeException(
63+
"FAILED: Command to call cleanup script failed " + result.stderr());
64+
}
65+
logger.info(
66+
"Command to call cleanup script returned " + result.stdout() + "\n" + result.stderr());
67+
}
68+
5769
// renew lease at the begining for every test method, leaseId is set only for Wercker
5870
TestUtils.renewK8sClusterLease(getProjectRoot(), getLeaseId());
5971

@@ -80,28 +92,17 @@ public static void staticPrepare() throws Exception {
8092
*/
8193
@AfterClass
8294
public static void staticUnPrepare() throws Exception {
95+
Assume.assumeTrue(
96+
System.getenv("QUICKTEST") != null && System.getenv("QUICKTEST").equalsIgnoreCase("true"));
8397
logger.info("+++++++++++++++++++++++++++++++++---------------------------------+");
8498
logger.info("BEGIN");
85-
logger.info("Run once, shutdown/deleting operator, domain, pv, etc");
86-
// shutdown operator, domain and cleanup all artifacts and pv dir
87-
try {
88-
if (domain != null) domain.destroy();
89-
if (operator != null) operator.destroy();
90-
} finally {
91-
String cmd =
92-
"export RESULT_ROOT="
93-
+ getResultRoot()
94-
+ " export PV_ROOT="
95-
+ getPvRoot()
96-
+ " && "
97-
+ getProjectRoot()
98-
+ "/src/integration-tests/bash/cleanup.sh";
99-
ExecResult result = ExecCommand.exec(cmd);
100-
if (result.exitValue() != 0) {
101-
logger.info("FAILED: command to call cleanup script " + cmd + " failed " + result.stderr());
102-
}
103-
logger.info("Command " + cmd + " returned " + result.stdout() + "\n" + result.stderr());
99+
logger.info("Run once, release cluster lease");
100+
101+
if (getLeaseId() != "") {
102+
logger.info("Release the k8s cluster lease");
103+
TestUtils.releaseLease(getProjectRoot(), getLeaseId());
104104
}
105+
105106
logger.info("SUCCESS");
106107
}
107108

@@ -233,4 +234,8 @@ public void testOperatorLifecycle() throws Exception {
233234
domain.verifyDomainCreated();
234235
logger.info("SUCCESS");
235236
}
237+
238+
public static Domain getDomain() {
239+
return domain;
240+
}
236241
}
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at
3+
// http://oss.oracle.com/licenses/upl.
4+
5+
package oracle.kubernetes.operator;
6+
7+
import java.util.Properties;
8+
import oracle.kubernetes.operator.utils.Domain;
9+
import oracle.kubernetes.operator.utils.Operator;
10+
import oracle.kubernetes.operator.utils.TestUtils;
11+
import org.junit.AfterClass;
12+
import org.junit.Assume;
13+
import org.junit.BeforeClass;
14+
import org.junit.Test;
15+
16+
/**
17+
* Simple JUnit test file used for testing Operator.
18+
*
19+
* <p>This test is used for creating Operator and a single domain which the Operator manages and
20+
* verifies both.
21+
*/
22+
public class ITFourthDomain extends BaseTest {
23+
public static final String TESTWEBAPP = "testwebapp";
24+
25+
// property file used to customize operator properties for operator inputs yaml
26+
private static String opPropsFile = "ITSecondOperator.properties";
27+
28+
// property file used to customize domain properties for domain inputs yaml
29+
private static String domainPropsFile = "ITFourthDomain.properties";
30+
31+
// property file used to configure constants for integration tests
32+
private static String appPropsFile = "OperatorIT.properties";
33+
34+
private static Operator operator;
35+
private static Domain domain;
36+
37+
// properties of operator/domain to use in the test methods
38+
private static Properties operatorProps;
39+
private static Properties domainProps;
40+
41+
private static String domainUid, domainNS;
42+
/**
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 setting
45+
* the resultRoot, pvRoot and projectRoot attributes. It also creates the Operator and domain.
46+
*
47+
* @throws Exception
48+
*/
49+
@BeforeClass
50+
public static void staticPrepare() throws Exception {
51+
Assume.assumeTrue(
52+
System.getenv("QUICKTEST") == null || System.getenv("QUICKTEST").equalsIgnoreCase("false"));
53+
logger.info("+++++++++++++++++++++++++++++++++---------------------------------+");
54+
logger.info("BEGIN");
55+
56+
// initialize test properties and create the directories
57+
initialize(appPropsFile);
58+
// renew lease at the begining for every test method, leaseId is set only for Wercker
59+
TestUtils.renewK8sClusterLease(getProjectRoot(), getLeaseId());
60+
61+
logger.info("Run once, Creating Operator & " + "waiting for the script to complete execution");
62+
// create operator
63+
operator = TestUtils.createOperator(opPropsFile);
64+
operatorProps = operator.getOperatorProps();
65+
66+
// create domain
67+
domain = TestUtils.createDomain(domainPropsFile);
68+
domainProps = domain.getDomainProps();
69+
70+
// initialize attributes to use in the tests
71+
domainUid = domainProps.getProperty("domainUID");
72+
domainNS = domainProps.getProperty("namespace");
73+
// logger.info("Domain props "+domainProps);
74+
logger.info("SUCCESS");
75+
}
76+
77+
/**
78+
* Shutdown operator and domain
79+
*
80+
* @throws Exception
81+
*/
82+
@AfterClass
83+
public static void staticUnPrepare() throws Exception {
84+
logger.info("+++++++++++++++++++++++++++++++++---------------------------------+");
85+
logger.info("BEGIN");
86+
logger.info("Run once, release cluster lease");
87+
88+
if (getLeaseId() != "") {
89+
logger.info("Release the k8s cluster lease");
90+
TestUtils.releaseLease(getProjectRoot(), getLeaseId());
91+
}
92+
93+
logger.info("SUCCESS");
94+
}
95+
/**
96+
* verify domain1 is unaffected
97+
*
98+
* @throws Exception
99+
*/
100+
public void verifyDomain1() throws Exception {
101+
ITFirstDomain.getDomain().verifyDomainCreated();
102+
}
103+
104+
/**
105+
* Access Operator REST endpoint using admin node host and node port
106+
*
107+
* @throws Exception
108+
*/
109+
@Test
110+
public void testAdminServerExternalService() throws Exception {
111+
logTestBegin("testAdminServerExternalService");
112+
domain.verifyAdminServerExternalService(getUsername(), getPassword());
113+
logger.info("SUCCESS");
114+
}
115+
116+
/**
117+
* Verify t3channel port by deploying webapp using the port
118+
*
119+
* @throws Exception
120+
*/
121+
@Test
122+
public void testAdminT3Channel() throws Exception {
123+
logTestBegin("testAdminT3Channel");
124+
// check if the property is set to true
125+
Boolean exposeAdmint3Channel = new Boolean(domainProps.getProperty("exposeAdminT3Channel"));
126+
127+
if (exposeAdmint3Channel != null && exposeAdmint3Channel.booleanValue()) {
128+
domain.deployWebAppViaWLST(
129+
TESTWEBAPP,
130+
getProjectRoot() + "/src/integration-tests/apps/testwebapp.war",
131+
getUsername(),
132+
getPassword());
133+
} else {
134+
throw new RuntimeException("FAILURE: exposeAdminT3Channel is not set or false");
135+
}
136+
domain.verifyWebAppLoadBalancing(TESTWEBAPP);
137+
logger.info("SUCCESS");
138+
}
139+
140+
/**
141+
* Scale the cluster up/down using Operator REST endpoint, load balancing should adjust
142+
* accordingly.
143+
*
144+
* @throws Exception
145+
*/
146+
@Test
147+
public void testClusterScaling() throws Exception {
148+
logTestBegin("testClusterScaling");
149+
String managedServerNameBase = domainProps.getProperty("managedServerNameBase");
150+
int replicas = 3;
151+
String podName = domainUid + "-" + managedServerNameBase + replicas;
152+
String clusterName = domainProps.getProperty("clusterName");
153+
154+
logger.info("Scale domain " + domainUid + " Up to " + replicas + " managed servers");
155+
operator.scale(domainUid, domainProps.getProperty("clusterName"), replicas);
156+
157+
logger.info("Checking if managed pod(" + podName + ") is Running");
158+
TestUtils.checkPodCreated(podName, domainNS);
159+
160+
logger.info("Checking if managed server (" + podName + ") is Running");
161+
TestUtils.checkPodReady(podName, domainNS);
162+
163+
logger.info("Checking if managed service(" + podName + ") is created");
164+
TestUtils.checkServiceCreated(podName, domainNS);
165+
166+
int replicaCnt = TestUtils.getClusterReplicas(domainUid, clusterName, domainNS);
167+
if (replicaCnt != replicas) {
168+
throw new RuntimeException(
169+
"FAILURE: Cluster replica doesn't match with scaled up size "
170+
+ replicaCnt
171+
+ "/"
172+
+ replicas);
173+
}
174+
175+
domain.verifyWebAppLoadBalancing(TESTWEBAPP);
176+
177+
replicas = 2;
178+
podName = domainUid + "-" + managedServerNameBase + (replicas + 1);
179+
logger.info("Scale down to " + replicas + " managed servers");
180+
operator.scale(domainUid, clusterName, replicas);
181+
182+
logger.info("Checking if managed pod(" + podName + ") is deleted");
183+
TestUtils.checkPodDeleted(podName, domainNS);
184+
185+
replicaCnt = TestUtils.getClusterReplicas(domainUid, clusterName, domainNS);
186+
if (replicaCnt != replicas) {
187+
throw new RuntimeException(
188+
"FAILURE: Cluster replica doesn't match with scaled down size "
189+
+ replicaCnt
190+
+ "/"
191+
+ replicas);
192+
}
193+
194+
domain.verifyWebAppLoadBalancing(TESTWEBAPP);
195+
196+
// verfiy scaling has no impact on domains1
197+
ITFirstDomain.getDomain().verifyDomainCreated();
198+
logger.info("SUCCESS");
199+
}
200+
201+
/**
202+
* test delete and recreate domain1 has no impact on domain4
203+
*
204+
* @throws Exception
205+
*/
206+
@Test
207+
public void testDeleteAndRecreteDomain1() throws Exception {
208+
209+
Domain domain1 = ITFirstDomain.getDomain();
210+
domain1.destroy();
211+
domain1.create();
212+
213+
// verify domain4 has no impact
214+
domain.verifyDomainCreated();
215+
}
216+
217+
public static Domain getDomain() {
218+
return domain;
219+
}
220+
}

0 commit comments

Comments
 (0)