Skip to content

Commit 57d4440

Browse files
managed coherence tests
1 parent 4391ebe commit 57d4440

File tree

16 files changed

+1645
-2
lines changed

16 files changed

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

0 commit comments

Comments
 (0)