Skip to content

Commit 9d1c1ce

Browse files
Sync ItCrossDomainTransaction tests from main (#2962)
* Sync ItCrossDomainTransaction tests from main Co-authored-by: [email protected] <[email protected]>
1 parent a036f38 commit 9d1c1ce

File tree

1 file changed

+52
-63
lines changed

1 file changed

+52
-63
lines changed

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItCrossDomainTransaction.java

Lines changed: 52 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,29 @@
3333
import oracle.weblogic.kubernetes.assertions.TestAssertions;
3434
import oracle.weblogic.kubernetes.logging.LoggingFacade;
3535
import oracle.weblogic.kubernetes.utils.ExecResult;
36-
import org.awaitility.core.ConditionFactory;
3736
import org.junit.jupiter.api.BeforeAll;
37+
import org.junit.jupiter.api.BeforeEach;
3838
import org.junit.jupiter.api.DisplayName;
39-
import org.junit.jupiter.api.MethodOrderer;
40-
import org.junit.jupiter.api.Order;
4139
import org.junit.jupiter.api.Test;
42-
import org.junit.jupiter.api.TestMethodOrder;
4340

4441
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_PASSWORD_DEFAULT;
4542
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_USERNAME_DEFAULT;
4643
import static oracle.weblogic.kubernetes.TestConstants.DB_IMAGE_TO_USE_IN_SPEC;
4744
import static oracle.weblogic.kubernetes.TestConstants.DOMAIN_API_VERSION;
4845
import static oracle.weblogic.kubernetes.TestConstants.DOMAIN_VERSION;
49-
import static oracle.weblogic.kubernetes.TestConstants.K8S_NODEPORT_HOST;
5046
import static oracle.weblogic.kubernetes.TestConstants.OCIR_SECRET_NAME;
5147
import static oracle.weblogic.kubernetes.TestConstants.RESULTS_ROOT;
5248
import static oracle.weblogic.kubernetes.TestConstants.WEBLOGIC_SLIM;
5349
import static oracle.weblogic.kubernetes.actions.ActionConstants.APP_DIR;
5450
import static oracle.weblogic.kubernetes.actions.ActionConstants.MODEL_DIR;
51+
import static oracle.weblogic.kubernetes.actions.ActionConstants.WORK_DIR;
5552
import static oracle.weblogic.kubernetes.actions.TestActions.createDomainCustomResource;
5653
import static oracle.weblogic.kubernetes.actions.TestActions.getPodIP;
5754
import static oracle.weblogic.kubernetes.actions.TestActions.getServiceNodePort;
5855
import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainExists;
5956
import static oracle.weblogic.kubernetes.utils.ApplicationUtils.checkAppIsActive;
6057
import static oracle.weblogic.kubernetes.utils.BuildApplication.buildApplication;
61-
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkServiceExists;
58+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReadyAndServiceExists;
6259
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getHostAndPort;
6360
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getNextFreePort;
6461
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.testUntil;
@@ -73,8 +70,6 @@
7370
import static oracle.weblogic.kubernetes.utils.ImageUtils.dockerLoginAndPushImageToRegistry;
7471
import static oracle.weblogic.kubernetes.utils.OKDUtils.createRouteForOKD;
7572
import static oracle.weblogic.kubernetes.utils.OperatorUtils.installAndVerifyOperator;
76-
import static oracle.weblogic.kubernetes.utils.PodUtils.checkPodExists;
77-
import static oracle.weblogic.kubernetes.utils.PodUtils.checkPodReady;
7873
import static oracle.weblogic.kubernetes.utils.PodUtils.getExternalServicePodName;
7974
import static oracle.weblogic.kubernetes.utils.PodUtils.setPodAntiAffinity;
8075
import static oracle.weblogic.kubernetes.utils.SecretUtils.createSecretWithUsernamePassword;
@@ -87,7 +82,6 @@
8782
/**
8883
* Cross domain transaction tests.
8984
*/
90-
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
9185
@DisplayName("Verify cross domain transaction is successful")
9286
@IntegrationTest
9387
class ItCrossDomainTransaction {
@@ -107,7 +101,6 @@ class ItCrossDomainTransaction {
107101
private static String opNamespace = null;
108102
private static String domain1Namespace = null;
109103
private static String domain2Namespace = null;
110-
private static ConditionFactory withStandardRetryPolicy = null;
111104
private static String domainUid1 = "domain1";
112105
private static String domainUid2 = "domain2";
113106
private static int domain1AdminServiceNodePort = -1;
@@ -126,6 +119,7 @@ class ItCrossDomainTransaction {
126119
private static String adminExtSvcRouteHost = null;
127120
private static String hostAndPort = null;
128121
private static String dbPodIP = null;
122+
private static int dbPort = 1521;
129123

130124
/**
131125
* Install Operator.
@@ -181,6 +175,23 @@ public static void initAll(@Namespaces(3) List<String> namespaces) {
181175
buildApplicationsAndDomains();
182176
}
183177

178+
/**
179+
* Verify all server pods are running.
180+
* Verify k8s services for all servers are created.
181+
*/
182+
@BeforeEach
183+
public void beforeEach() {
184+
int replicaCount = 2;
185+
for (int i = 1; i <= replicaCount; i++) {
186+
checkPodReadyAndServiceExists(domain2ManagedServerPrefix + i,
187+
domainUid2, domain2Namespace);
188+
}
189+
for (int i = 1; i <= replicaCount; i++) {
190+
checkPodReadyAndServiceExists(domain1ManagedServerPrefix + i,
191+
domainUid1, domain1Namespace);
192+
}
193+
}
194+
184195
private static void updatePropertyFile() {
185196
//create a temporary directory to copy and update the properties file
186197
Path target = Paths.get(PROPS_TEMP_DIR);
@@ -214,17 +225,20 @@ private static void addToPropertyFile(String propFileName, String domainNamespac
214225

215226
FileOutputStream out = new FileOutputStream(PROPS_TEMP_DIR + "/" + propFileName);
216227
props.setProperty("NAMESPACE", domainNamespace);
217-
props.setProperty("K8S_NODEPORT_HOST", K8S_NODEPORT_HOST);
218-
props.setProperty("DBPORT", Integer.toString(dbNodePort));
228+
props.setProperty("K8S_NODEPORT_HOST", dbPodIP);
229+
props.setProperty("DBPORT", Integer.toString(dbPort));
219230
props.store(out, null);
220231
out.close();
221232
}
222233

223234
private static void buildApplicationsAndDomains() {
224235

225236
//build application archive
237+
238+
Path targetDir = Paths.get(WORK_DIR,
239+
ItCrossDomainTransaction.class.getName() + "/txforward");
226240
Path distDir = buildApplication(Paths.get(APP_DIR, "txforward"), null, null,
227-
"build", domain1Namespace);
241+
"build", domain1Namespace, targetDir);
228242
logger.info("distDir is {0}", distDir.toString());
229243
assertTrue(Paths.get(distDir.toString(),
230244
"txforward.ear").toFile().exists(),
@@ -233,8 +247,10 @@ private static void buildApplicationsAndDomains() {
233247
logger.info("Application is in {0}", appSource);
234248

235249
//build application archive
250+
targetDir = Paths.get(WORK_DIR,
251+
ItCrossDomainTransaction.class.getName() + "/cdtservlet");
236252
distDir = buildApplication(Paths.get(APP_DIR, "cdtservlet"), null, null,
237-
"build", domain1Namespace);
253+
"build", domain1Namespace, targetDir);
238254
logger.info("distDir is {0}", distDir.toString());
239255
assertTrue(Paths.get(distDir.toString(),
240256
"cdttxservlet.war").toFile().exists(),
@@ -243,8 +259,10 @@ private static void buildApplicationsAndDomains() {
243259
logger.info("Application is in {0}", appSource1);
244260

245261
//build application archive for JMS Send/Receive
262+
targetDir = Paths.get(WORK_DIR,
263+
ItCrossDomainTransaction.class.getName() + "/jmsservlet");
246264
distDir = buildApplication(Paths.get(APP_DIR, "jmsservlet"), null, null,
247-
"build", domain1Namespace);
265+
"build", domain1Namespace, targetDir);
248266
logger.info("distDir is {0}", distDir.toString());
249267
assertTrue(Paths.get(distDir.toString(),
250268
"jmsservlet.war").toFile().exists(),
@@ -269,8 +287,10 @@ private static void buildApplicationsAndDomains() {
269287
"Could not modify the domain2Namespace in MDB Template file");
270288

271289
//build application archive for MDB
290+
targetDir = Paths.get(WORK_DIR,
291+
ItCrossDomainTransaction.class.getName() + "/mdbtopic");
272292
distDir = buildApplication(Paths.get(PROPS_TEMP_DIR, "mdbtopic"), null, null,
273-
"build", domain1Namespace);
293+
"build", domain1Namespace, targetDir);
274294
logger.info("distDir is {0}", distDir.toString());
275295
assertTrue(Paths.get(distDir.toString(),
276296
"mdbtopic.jar").toFile().exists(),
@@ -394,7 +414,6 @@ void testCrossDomainTransaction() {
394414
* domain2 and the transaction should commit.
395415
*
396416
*/
397-
@Order(2)
398417
@Test
399418
@DisplayName("Check cross domain transaction with TMAfterTLogBeforeCommitExit property commits")
400419
void testCrossDomainTransactionWithFailInjection() {
@@ -431,7 +450,6 @@ void testCrossDomainTransactionWithFailInjection() {
431450
* targeted to a cluster of two servers, onMessage() will be triggered
432451
* for both instance of MDB for a message sent to Distributed Topic
433452
*/
434-
@Order(3)
435453
@Test
436454
@DisplayName("Check cross domain transcated MDB communication ")
437455
void testCrossDomainTranscatedMDB() {
@@ -467,27 +485,19 @@ void testCrossDomainTranscatedMDB() {
467485
"Expected number of message not found in Accounting Queue");
468486
}
469487

470-
471488
private boolean checkLocalQueue() {
472489
String curlString = String.format("curl -v --show-error --noproxy '*' "
473-
+ "\"http://%s:%s/jmsservlet/jmstest?"
490+
+ "\"http://%s/jmsservlet/jmstest?"
474491
+ "url=t3://localhost:7001&"
475492
+ "action=receive&dest=jms.testAccountingQueue\"",
476-
K8S_NODEPORT_HOST, domain1AdminServiceNodePort);
493+
hostAndPort);
477494

478495
logger.info("curl command {0}", curlString);
479496

480-
withStandardRetryPolicy
481-
.conditionEvaluationListener(
482-
condition -> logger.info("Waiting for local queue to be updated "
483-
+ "(elapsed time {0} ms, remaining time {1} ms)",
484-
condition.getElapsedTimeInMS(),
485-
condition.getRemainingTimeInMS()))
486-
.until(assertDoesNotThrow(() -> {
487-
return () -> {
488-
return exec(new String(curlString), true).stdout().contains("Messages are distributed");
489-
};
490-
}));
497+
testUntil(
498+
() -> exec(new String(curlString), true).stdout().contains("Messages are distributed"),
499+
logger,
500+
"local queue to be updated");
491501
return true;
492502
}
493503

@@ -507,55 +517,34 @@ private static void createDomain(String domainUid, String domainNamespace, Strin
507517
replicaCount, domainImage);
508518

509519
// wait for the domain to exist
510-
logger.info("Checking for domain custom resource in namespace {0}", domainNamespace);
520+
logger.info("Check for domain custom resource in namespace {0}", domainNamespace);
511521
testUntil(
512522
domainExists(domainUid, DOMAIN_VERSION, domainNamespace),
513523
logger,
514524
"domain {0} to be created in namespace {1}",
515525
domainUid,
516-
domainNamespace);
526+
domainNamespace
527+
);
517528

518529
// check admin server pod exists
530+
// check admin server services created
519531
logger.info("Check for admin server pod {0} existence in namespace {1}",
520532
adminServerPodName, domainNamespace);
521-
checkPodExists(adminServerPodName, domainUid, domainNamespace);
522-
533+
checkPodReadyAndServiceExists(adminServerPodName, domainUid, domainNamespace);
523534
// check managed server pods exist
524-
for (int i = 1; i <= replicaCount; i++) {
525-
logger.info("Check for managed server pod {0} existence in namespace {1}",
526-
managedServerPrefix + i, domainNamespace);
527-
checkPodExists(managedServerPrefix + i, domainUid, domainNamespace);
528-
}
529-
530-
// check admin server pod is ready
531-
logger.info("Wait for admin server pod {0} to be ready in namespace {1}",
532-
adminServerPodName, domainNamespace);
533-
checkPodReady(adminServerPodName, domainUid, domainNamespace);
534-
535-
// check managed server pods are ready
536-
for (int i = 1; i <= replicaCount; i++) {
537-
logger.info("Wait for managed server pod {0} to be ready in namespace {1}",
538-
managedServerPrefix + i, domainNamespace);
539-
checkPodReady(managedServerPrefix + i, domainUid, domainNamespace);
540-
}
541-
542-
logger.info("Check admin service {0} is created in namespace {1}",
543-
adminServerPodName, domainNamespace);
544-
checkServiceExists(adminServerPodName, domainNamespace);
545-
546535
// check managed server services created
547536
for (int i = 1; i <= replicaCount; i++) {
548-
logger.info("Check managed server service {0} is created in namespace {1}",
537+
logger.info("Check for managed server pod {0} existence in namespace {1}",
549538
managedServerPrefix + i, domainNamespace);
550-
checkServiceExists(managedServerPrefix + i, domainNamespace);
539+
checkPodReadyAndServiceExists(managedServerPrefix + i, domainUid, domainNamespace);
551540
}
552541

553542
adminExtSvcRouteHost = createRouteForOKD(getExternalServicePodName(adminServerPodName), domainNamespace);
554543
// The fail inject test case, the response to the curl command takes longer than the default timeout of 30s
555544
// So, have to increase the proxy timeout for the route
556-
String command = "oc -n " + domainNamespace + " annotate route "
557-
+ getExternalServicePodName(adminServerPodName)
558-
+ " --overwrite haproxy.router.openshift.io/timeout=600s";
545+
String command = "oc -n " + domainNamespace + " annotate route "
546+
+ getExternalServicePodName(adminServerPodName)
547+
+ " --overwrite haproxy.router.openshift.io/timeout=600s";
559548
logger.info("command to set timeout = {0}", command);
560549
assertDoesNotThrow(
561550
() -> exec(command, true));

0 commit comments

Comments
 (0)