Skip to content

Commit bfc927e

Browse files
authored
Merge pull request #1193 from oracle/coherence_test
Adding a managed coherence test
2 parents 70031db + befc686 commit bfc927e

File tree

17 files changed

+1568
-1
lines changed

17 files changed

+1568
-1
lines changed

integration-tests/USECASES.MD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,7 @@ Configuration Overrides Usecases
162162
| Add initContainers with different names at different level | Add a multiple initContainers object at domain level and server level and verify all of the init containers are run before Weblogic server pods are started |
163163
| Add initContainers with same names at different level | Add a multiple initContainers object at domain level and server level and verify only the server level init containers are run before Weblogic server pods are started |
164164

165+
| Managed Coherence Tests | Use Case |
166+
| --- | --- |
167+
| Managed Coherence - Domain on PV | Sanity testing of managed coherence in domain on pv using WLST. The test adds data to be stored in the cache, retrieves it and clears the cache |
168+
| Managed Coherence - Domain in image | Sanity testing of managed coherence in domain in image using WLST. The test adds data to be stored in the cache, retrieves it and clears the cache |
Lines changed: 338 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,338 @@
1+
// Copyright 2019, 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 oracle.kubernetes.operator.utils.*;
8+
import org.junit.*;
9+
10+
import java.nio.file.Files;
11+
import java.nio.file.Paths;
12+
import java.nio.file.StandardCopyOption;
13+
import java.nio.file.StandardOpenOption;
14+
import java.util.Map;
15+
16+
import static org.junit.Assert.assertFalse;
17+
import static org.junit.Assert.assertTrue;
18+
import static org.junit.Assert.assertNotNull;
19+
20+
public class ItManagedCoherence extends BaseTest {
21+
22+
private static final String COHERENCE_CLUSTER_SCRIPT = "create-domain-coherence-cluster.py";
23+
private static final String COHERENCE_CLUSTER_IN_IMAGE_SCRIPT = "create-domain-in-image-coherence-cluster.py";
24+
private static final String DOMAINUID = "cmdomonpv";
25+
private static final String DOMAINUID1 = "cmdominimage";
26+
private static String customDomainTemplate;
27+
private static final String testAppName = "coherenceapp";
28+
private static final String appToDeploy = "CoherenceApp";
29+
private static final String scriptName = "buildDeployCoherenceAppInPod.sh";
30+
31+
private static Operator operator1;
32+
Domain domain = null;
33+
34+
/**
35+
* This method gets called only once before any of the test methods are executed. It does the
36+
* initialization of the integration test properties defined in OperatorIT.properties and setting
37+
* the resultRoot, pvRoot and projectRoot attributes.
38+
*
39+
* @throws Exception exception
40+
*/
41+
@BeforeClass
42+
public static void staticPrepare() throws Exception {
43+
if (!QUICKTEST) {
44+
// initialize test properties and create the directories
45+
initialize(APP_PROPS_FILE);
46+
String template =
47+
BaseTest.getProjectRoot() + "/kubernetes/samples/scripts/common/domain-template.yaml";
48+
String add =
49+
" - clusterName: dataCluster\n"
50+
+ " serverStartState: \"RUNNING\"\n"
51+
+ " replicas: %INITIAL_MANAGED_SERVER_REPLICAS%\n";
52+
customDomainTemplate = BaseTest.getResultDir() + "/customDomainTemplate.yaml";
53+
54+
Files.copy(
55+
Paths.get(template),
56+
Paths.get(customDomainTemplate),
57+
StandardCopyOption.REPLACE_EXISTING);
58+
Files.write(Paths.get(customDomainTemplate), add.getBytes(), StandardOpenOption.APPEND);
59+
60+
}
61+
}
62+
63+
/**
64+
* Releases k8s cluster lease, archives result, pv directories.
65+
*
66+
* @throws Exception exception
67+
*/
68+
@AfterClass
69+
public static void staticUnPrepare() throws Exception {
70+
logger.info("+++++++++++++++++++++++++++++++++---------------------------------+");
71+
logger.info("BEGIN");
72+
logger.info("Run once, release cluster lease");
73+
74+
tearDown(new Object() {}.getClass().getEnclosingClass().getSimpleName());
75+
76+
logger.info("SUCCESS");
77+
}
78+
79+
/**
80+
* Create operator and verify its deployed successfully. Create domain with 2 Managed coherence
81+
* clusters verify domain is started. Deploy an application to the cluster with no storage enabled
82+
* and the GAR file to the cluster with storage enabled. Verify that data can be added and stored
83+
* in the cache and can also be retrieved from cache.
84+
*
85+
* @throws Exception exception
86+
*/
87+
@Test
88+
public void testCreateCoherenceDomainOnPvUsingWlst() throws Exception {
89+
Assume.assumeFalse(QUICKTEST);
90+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
91+
92+
logTestBegin(testMethodName);
93+
logger.info("Creating coeherence domain on pv using wlst and testing the cache");
94+
95+
boolean testCompletedSuccessfully = false;
96+
domain = null;
97+
98+
// create operator1
99+
if (operator1 == null) {
100+
operator1 = TestUtils.createOperator(OPERATOR1_YAML);
101+
}
102+
103+
try {
104+
Map<String, Object> domainMap = TestUtils.loadYaml(DOMAINONPV_WLST_YAML);
105+
domainMap.put("domainUID", DOMAINUID);
106+
domainMap.put("clusterType", "DYNAMIC");
107+
domainMap.put("clusterName", "appCluster");
108+
domainMap.put("initialManagedServerReplicas", new Integer("2"));
109+
domainMap.put("customDomainTemplate", customDomainTemplate);
110+
domainMap.put(
111+
"createDomainPyScript",
112+
"integration-tests/src/test/resources/domain-home-on-pv/"
113+
+ COHERENCE_CLUSTER_SCRIPT);
114+
if ((System.getenv("LB_TYPE") != null && System.getenv("LB_TYPE").equalsIgnoreCase("VOYAGER"))
115+
|| (domainMap.containsKey("loadBalancer")
116+
&& ((String) domainMap.get("loadBalancer")).equalsIgnoreCase("VOYAGER"))) {
117+
domainMap.put("voyagerWebPort", new Integer("30366"));
118+
}
119+
domain = TestUtils.createDomain(domainMap);
120+
domain.verifyDomainCreated();
121+
String[] pods = {
122+
DOMAINUID + "-" + domain.getAdminServerName(),
123+
DOMAINUID + "-managed-server",
124+
DOMAINUID + "-managed-server1",
125+
DOMAINUID + "-managed-server2",
126+
DOMAINUID + "-new-managed-server1",
127+
DOMAINUID + "-new-managed-server2",
128+
};
129+
verifyServersStatus(domain, pods, DOMAINUID);
130+
131+
// Build WAR in the admin pod and deploy it from the admin pod to a weblogic target
132+
TestUtils.buildDeployCoherenceAppInPod(domain,
133+
testAppName, scriptName, BaseTest.getUsername(), BaseTest.getPassword(),
134+
appToDeploy, "dataCluster");
135+
136+
coherenceCacheTest();
137+
138+
testCompletedSuccessfully = true;
139+
} finally {
140+
if (domain != null && !SMOKETEST && (JENKINS || testCompletedSuccessfully)) {
141+
domain.destroy();
142+
}
143+
}
144+
logger.info("SUCCESS - " + testMethodName);
145+
}
146+
147+
/**
148+
* Create operator and verify its deployed successfully. Create domain with 2 Managed coherence
149+
* clusters verify domain is started. Deploy an application to the cluster with no storage enabled
150+
* and the GAR file to the cluster with storage enabled. Verify that data can be added and stored
151+
* in the cache and can also be retrieved from cache.
152+
*
153+
* @throws Exception exception
154+
*/
155+
@Test
156+
public void testCreateCoherenceDomainInImageUsingWlst() throws Exception {
157+
Assume.assumeFalse(QUICKTEST);
158+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
159+
160+
logTestBegin(testMethodName);
161+
logger.info("Creating coeherence domain in image using wlst and testing the cache");
162+
163+
boolean testCompletedSuccessfully = false;
164+
domain = null;
165+
166+
// create operator1
167+
if (operator1 == null) {
168+
operator1 = TestUtils.createOperator(OPERATOR1_YAML);
169+
}
170+
171+
try {
172+
Map<String, Object> domainMap = TestUtils.loadYaml(DOMAININIMAGE_WLST_YAML);
173+
domainMap.put("domainUID", DOMAINUID1);
174+
domainMap.put("clusterType", "DYNAMIC");
175+
domainMap.put("clusterName", "appCluster");
176+
domainMap.put("initialManagedServerReplicas", new Integer("2"));
177+
domainMap.put("customDomainTemplate", customDomainTemplate);
178+
domainMap.put(
179+
"createDomainPyScript",
180+
"integration-tests/src/test/resources/"
181+
+ COHERENCE_CLUSTER_IN_IMAGE_SCRIPT);
182+
if ((System.getenv("LB_TYPE") != null && System.getenv("LB_TYPE").equalsIgnoreCase("VOYAGER"))
183+
|| (domainMap.containsKey("loadBalancer")
184+
&& ((String) domainMap.get("loadBalancer")).equalsIgnoreCase("VOYAGER"))) {
185+
domainMap.put("voyagerWebPort", new Integer("30366"));
186+
}
187+
domain = TestUtils.createDomain(domainMap);
188+
domain.verifyDomainCreated();
189+
String[] pods = {
190+
DOMAINUID1 + "-" + domain.getAdminServerName(),
191+
DOMAINUID1 + "-managed-server",
192+
DOMAINUID1 + "-managed-server1",
193+
DOMAINUID1 + "-managed-server2",
194+
DOMAINUID1 + "-new-managed-server1",
195+
DOMAINUID1 + "-new-managed-server2",
196+
};
197+
verifyServersStatus(domain, pods, DOMAINUID1);
198+
199+
// Build WAR in the admin pod and deploy it from the admin pod to a weblogic target
200+
TestUtils.buildDeployCoherenceAppInPod(domain,
201+
testAppName, scriptName, BaseTest.getUsername(), BaseTest.getPassword(),
202+
appToDeploy, "dataCluster");
203+
204+
coherenceCacheTest();
205+
206+
testCompletedSuccessfully = true;
207+
} finally {
208+
if (domain != null && !SMOKETEST && (JENKINS || testCompletedSuccessfully)) {
209+
domain.destroy();
210+
}
211+
}
212+
logger.info("SUCCESS - " + testMethodName);
213+
}
214+
/**
215+
* Verifies all of the servers in the cluster are in Running status.
216+
*
217+
* @param domain Domain
218+
* @param pods array pod names to check the status for
219+
*/
220+
private static void verifyServersStatus(Domain domain, String[] pods, String domainUID) {
221+
K8sTestUtils testUtil = new K8sTestUtils();
222+
String domain1LabelSelector = String.format("weblogic.domainUID in (%s)", domainUID);
223+
String namespace = domain.getDomainNs();
224+
for (String pod : pods) {
225+
assertTrue(
226+
pod + " Pod not running", testUtil.isPodRunning(namespace, domain1LabelSelector, pod));
227+
}
228+
}
229+
230+
private void coherenceCacheTest() throws Exception {
231+
232+
String[] firstNameList = {"Frodo", "Samwise", "Bilbo", "peregrin", "Meriadoc", "Gandalf"};
233+
String[] secondNameList = {"Baggins", "Gamgee", "Baggins", "Took", "Brandybuck", "TheGrey"};
234+
ExecResult result;
235+
236+
for (int i = 0; i < firstNameList.length; i++) {
237+
result = addDataToCache(firstNameList[i], secondNameList[i]);
238+
logger.info("addDataToCache returned" + result.stdout());
239+
}
240+
//check if cache size is 6
241+
result = getCacheSize();
242+
logger.info("number of records in cache = " + result.stdout());
243+
if (!(result.stdout().equals("6"))) {
244+
logger.info("number of records in cache = " + result.stdout());
245+
assertFalse("Expected 6 records", "6".equals(result.stdout()));
246+
}
247+
//get the data from cache
248+
result = getCacheContents();
249+
logger.info("Cache contains the following entries \n" + result.stdout());
250+
251+
//Now clear the cache
252+
result = clearCache();
253+
logger.info("Cache is cleared and should be empty" + result.stdout());
254+
255+
}
256+
257+
private ExecResult addDataToCache(String firstName, String secondName) throws Exception {
258+
logger.info("Add initial data to cache");
259+
260+
StringBuffer curlCmd = new StringBuffer("curl --silent ");
261+
curlCmd.append("-d 'action=add&first=")
262+
.append(firstName)
263+
.append("&second=")
264+
.append(secondName)
265+
.append("' ")
266+
.append("-X POST -H 'host: ")
267+
.append(domain.getDomainUid())
268+
.append(".org' ")
269+
.append("http://")
270+
.append(domain.getHostNameForCurl())
271+
.append(":")
272+
.append(domain.getLoadBalancerWebPort())
273+
.append("/")
274+
.append(appToDeploy)
275+
.append("/")
276+
.append(appToDeploy);
277+
logger.info("curlCmd is " + curlCmd.toString());
278+
return TestUtils.exec(curlCmd.toString());
279+
}
280+
281+
private ExecResult getCacheSize() throws Exception {
282+
logger.info("get the number of records in cache");
283+
284+
StringBuffer curlCmd = new StringBuffer("curl --silent ");
285+
curlCmd.append("-d 'action=size' ")
286+
.append("-H 'host: ")
287+
.append(domain.getDomainUid())
288+
.append(".org' ")
289+
.append("http://")
290+
.append(domain.getHostNameForCurl())
291+
.append(":")
292+
.append(domain.getLoadBalancerWebPort())
293+
.append("/")
294+
.append(appToDeploy)
295+
.append("/")
296+
.append(appToDeploy);
297+
return TestUtils.exec(curlCmd.toString());
298+
}
299+
300+
private ExecResult getCacheContents() throws Exception {
301+
logger.info("get the records from cache");
302+
303+
StringBuffer curlCmd = new StringBuffer("curl --silent ");
304+
curlCmd.append("-d 'action=get' ")
305+
.append("-H 'host: ")
306+
.append(domain.getDomainUid())
307+
.append(".org' ")
308+
.append("http://")
309+
.append(domain.getHostNameForCurl())
310+
.append(":")
311+
.append(domain.getLoadBalancerWebPort())
312+
.append("/")
313+
.append(appToDeploy)
314+
.append("/")
315+
.append(appToDeploy);
316+
return TestUtils.exec(curlCmd.toString());
317+
}
318+
319+
private ExecResult clearCache() throws Exception {
320+
logger.info("clear the cache");
321+
322+
StringBuffer curlCmd = new StringBuffer("curl --silent ");
323+
curlCmd.append("-d 'action=clear' ")
324+
.append("-H 'host: ")
325+
.append(domain.getDomainUid())
326+
.append(".org' ")
327+
.append("http://")
328+
.append(domain.getHostNameForCurl())
329+
.append(":")
330+
.append(domain.getLoadBalancerWebPort())
331+
.append("/")
332+
.append(appToDeploy)
333+
.append("/")
334+
.append(appToDeploy);
335+
return TestUtils.exec(curlCmd.toString());
336+
}
337+
338+
}

0 commit comments

Comments
 (0)