Skip to content

Commit 07275b0

Browse files
authored
Introduce custom condition factory (#3740)
* Since introspector pod is created and deleted within seconds the existing conditionfactory objects are not useful to catch the introspector pod lifecycle. Introducing this custom condition factort to start the checking right away.
1 parent f749703 commit 07275b0

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import oracle.weblogic.kubernetes.annotations.IntegrationTest;
3333
import oracle.weblogic.kubernetes.annotations.Namespaces;
3434
import oracle.weblogic.kubernetes.logging.LoggingFacade;
35+
import org.awaitility.core.ConditionFactory;
3536
import org.junit.jupiter.api.BeforeAll;
3637
import org.junit.jupiter.api.DisplayName;
3738
import org.junit.jupiter.api.MethodOrderer;
@@ -67,6 +68,7 @@
6768
import static oracle.weblogic.kubernetes.utils.ClusterUtils.stopCluster;
6869
import static oracle.weblogic.kubernetes.utils.CommonMiiTestUtils.verifyPodsNotRolled;
6970
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReadyAndServiceExists;
71+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createCustomConditionFactory;
7072
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getNextFreePort;
7173
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.testUntil;
7274
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.withLongRetryPolicy;
@@ -254,7 +256,8 @@ void testAddReplaceClusterResource() {
254256

255257
//verify the introspector pod is created and runs
256258
String introspectPodNameBase2 = getIntrospectJobName(domainUid);
257-
checkPodExists(introspectPodNameBase2, domainUid, domainNamespace);
259+
ConditionFactory customConditionFactory = createCustomConditionFactory(0, 1, 5);
260+
checkPodExists(customConditionFactory, introspectPodNameBase2, domainUid, domainNamespace);
258261
checkPodDoesNotExist(introspectPodNameBase2, domainUid, domainNamespace);
259262

260263
// check managed server pods from cluster-1 are shutdown
@@ -363,7 +366,8 @@ void testDomainStatusMatchesClusterResourceStatus() {
363366

364367
//verify the introspector pod is created and runs
365368
String introspectPodNameBase2 = getIntrospectJobName(domainUid);
366-
checkPodExists(introspectPodNameBase2, domainUid, domainNamespace);
369+
ConditionFactory customConditionFactory = createCustomConditionFactory(0, 1, 5);
370+
checkPodExists(customConditionFactory, introspectPodNameBase2, domainUid, domainNamespace);
367371
checkPodDoesNotExist(introspectPodNameBase2, domainUid, domainNamespace);
368372

369373
// check managed server pods from cluster-1 are shutdown

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/CommonTestUtils.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ private static ConditionFactory createStandardRetryPolicyWithAtMost(long minutes
129129

130130
private static final String TMP_FILE_NAME = "temp-download-file.out";
131131

132+
/**
133+
* Create a condition factory with custom values for pollDelay, pollInterval and atMost time.
134+
*
135+
* @param polldelay starting delay before checking for the condition in seconds
136+
* @param pollInterval interval time between checking for the condition in seconds
137+
* @param atMostMinutes how long should it wait for the condition becomes true in minutes
138+
* @return ConditionFactory custom condition factory
139+
*/
140+
public static ConditionFactory createCustomConditionFactory(int polldelay, int pollInterval, int atMostMinutes) {
141+
return with().pollDelay(polldelay, SECONDS)
142+
.and().with().pollInterval(pollInterval, SECONDS)
143+
.atMost(atMostMinutes, MINUTES).await();
144+
}
132145

133146
/**
134147
* Test assertion using standard retry policy over time until it passes or the timeout expires.

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/PodUtils.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,27 @@ public static void checkPodExists(String podName, String domainUid, String domai
9494
domainNamespace);
9595
}
9696

97+
/**
98+
* Check pod exists in the specified namespace.
99+
*
100+
* @param conditionFactory Configuration for Awaitility condition factory
101+
* @param podName pod name to check
102+
* @param domainUid the label the pod is decorated with
103+
* @param domainNamespace the domain namespace in which the domain exists
104+
*/
105+
public static void checkPodExists(ConditionFactory conditionFactory, String podName,
106+
String domainUid, String domainNamespace) {
107+
LoggingFacade logger = getLogger();
108+
testUntil(conditionFactory,
109+
assertDoesNotThrow(() -> podExists(podName, domainUid, domainNamespace),
110+
String.format("podExists failed with ApiException for pod %s in namespace %s",
111+
podName, domainNamespace)),
112+
logger,
113+
"pod {0} to be created in namespace {1}",
114+
podName,
115+
domainNamespace);
116+
}
117+
97118
/**
98119
* Check pod is ready.
99120
*

0 commit comments

Comments
 (0)