Skip to content

Commit 2f27ba1

Browse files
authored
Rethrow the exception caught in the BeforeAll, BeforeEach and AfterEach (#1599)
* Rethrow the exception caught in the BeforeAll, BeforeEach and AfterEach methods * Get the LOGS_DIR from TestConstants * Fix the volume Name in PVC
1 parent b42cd8f commit 2f27ba1

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItSimpleDomainValidation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void setup(@Namespaces(1) List<String> namespaces) {
8181
.spec(new V1PersistentVolumeClaimSpec()
8282
.addAccessModesItem("ReadWriteMany")
8383
.storageClassName(domainUid + "-weblogic-domain-storage-class")
84-
.volumeName(domainUid + "-weblogic-pv")
84+
.volumeName(pvName)
8585
.resources(new V1ResourceRequirements()
8686
.putRequestsItem("storage", Quantity.fromString("10Gi"))))
8787
.metadata(new V1ObjectMetaBuilder()

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/TestConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ public interface TestConstants {
3030
.orElse("");
3131
public static final String BRANCH_NAME_FROM_JENKINS = Optional.ofNullable(System.getenv("BRANCH"))
3232
.orElse("");
33+
public static final String LOGS_DIR = System.getenv().getOrDefault("RESULT_ROOT",
34+
System.getProperty("java.io.tmpdir")) + "/diagnosticlogs";
3335
}

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/extensions/IntegrationTestWatcher.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.List;
1313

1414
import io.kubernetes.client.openapi.ApiException;
15+
import oracle.weblogic.kubernetes.TestConstants;
1516
import oracle.weblogic.kubernetes.annotations.Namespaces;
1617
import oracle.weblogic.kubernetes.utils.LoggingUtil;
1718
import org.junit.jupiter.api.extension.AfterAllCallback;
@@ -59,12 +60,6 @@ public class IntegrationTestWatcher implements
5960
private List namespaces = null;
6061
private static final String START_TIME = "start time";
6162

62-
/**
63-
* Directory to store logs.
64-
*/
65-
private static final String LOGS_DIR = System.getProperty("RESULT_ROOT",
66-
System.getProperty("java.io.tmpdir"));
67-
6863
/**
6964
* Determine if this resolver supports resolution of an argument for the
7065
* Parameter in the supplied ParameterContext for the supplied ExtensionContext.
@@ -129,6 +124,7 @@ public void beforeAll(ExtensionContext context) {
129124
throws Throwable {
130125
printHeader(String.format("BeforeAll failed %s", className), "!");
131126
collectLogs(context, "beforeAll");
127+
throw throwable;
132128
}
133129

134130
/**
@@ -153,6 +149,7 @@ public void beforeEach(ExtensionContext context) {
153149
throws Throwable {
154150
printHeader(String.format("BeforeEach failed for %s", methodName), "!");
155151
collectLogs(context, "beforeEach");
152+
throw throwable;
156153
}
157154

158155
/**
@@ -252,6 +249,7 @@ public void afterEach(ExtensionContext context) {
252249
throws Throwable {
253250
printHeader(String.format("AfterEach failed for %s", methodName), "!");
254251
collectLogs(context, "afterEach");
252+
throw throwable;
255253
}
256254

257255
/**
@@ -326,7 +324,7 @@ private void collectLogs(ExtensionContext extensionContext, String failedStage)
326324
}
327325
Path resultDir = null;
328326
try {
329-
resultDir = Files.createDirectories(Paths.get(LOGS_DIR,
327+
resultDir = Files.createDirectories(Paths.get(TestConstants.LOGS_DIR,
330328
extensionContext.getRequiredTestClass().getSimpleName(),
331329
getExtDir(extensionContext, failedStage)));
332330
} catch (IOException ex) {

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.List;
1414

1515
import io.kubernetes.client.openapi.ApiException;
16+
import oracle.weblogic.kubernetes.TestConstants;
1617
import oracle.weblogic.kubernetes.actions.impl.primitive.Kubernetes;
1718

1819
import static io.kubernetes.client.util.Yaml.dump;
@@ -23,16 +24,10 @@
2324
*/
2425
public class LoggingUtil {
2526

26-
/**
27-
* Directory to store logs.
28-
*/
29-
private static final String LOGS_DIR = System.getProperty("RESULT_ROOT",
30-
System.getProperty("java.io.tmpdir"));
31-
3227
/**
3328
* Collect logs for artifacts in Kubernetes cluster for current running test object. This method can be called
3429
* anywhere in the test by passing the test instance object and list namespaces.
35-
*
30+
*
3631
* <p>The collected logs are written in the LOGS_DIR/IT_TEST_CLASSNAME/CURRENT_TIMESTAMP directory.
3732
*
3833
* @param itInstance the integration test instance
@@ -43,7 +38,7 @@ public static void collectLogs(Object itInstance, List namespaces) {
4338
String resultDirExt = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
4439
try {
4540
Path resultDir = Files.createDirectories(
46-
Paths.get(LOGS_DIR, itInstance.getClass().getSimpleName(),
41+
Paths.get(TestConstants.LOGS_DIR, itInstance.getClass().getSimpleName(),
4742
resultDirExt));
4843
for (var namespace : namespaces) {
4944
LoggingUtil.generateLog((String) namespace, resultDir);

0 commit comments

Comments
 (0)