From 26e835c499fc493ac414e0adae547a93e7e2502c Mon Sep 17 00:00:00 2001 From: Jiri Danek Date: Thu, 17 Oct 2024 08:35:53 +0200 Subject: [PATCH] ISSUE-160: fix(test/utils): migrate from `java.util.Date` to `java.time.Instant` to resolve fabric8 crash Instants are the recommended way to deal with time and date in Java 8+. The problem was caused by the wrongly encoded `+` in the timestamp string when it's a part of a URL. Because Instants represent time in UTC timezone (`Z`), we don't get the timezone part of timestamp now (`+02:00`), so there's no plus problem. --- src/main/java/io/odh/test/TestConstants.java | 4 ++-- src/main/java/io/odh/test/utils/UpgradeUtils.java | 4 ++-- src/test/java/io/odh/test/e2e/upgrade/BundleUpgradeST.java | 4 ++-- src/test/java/io/odh/test/e2e/upgrade/OlmUpgradeST.java | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/odh/test/TestConstants.java b/src/main/java/io/odh/test/TestConstants.java index c25ba544..5074617d 100644 --- a/src/main/java/io/odh/test/TestConstants.java +++ b/src/main/java/io/odh/test/TestConstants.java @@ -4,8 +4,8 @@ */ package io.odh.test; -import java.text.SimpleDateFormat; import java.time.Duration; +import java.time.format.DateTimeFormatter; public class TestConstants { public static final String DEFAULT_NAMESPACE = "default"; @@ -35,7 +35,7 @@ public class TestConstants { public static final String CHANNEL_STABLE = "stable"; public static final String CHANNEL_LATEST = "latest"; - public static final SimpleDateFormat TIMESTAMP_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX"); + public static final DateTimeFormatter TIMESTAMP_DATE_FORMAT = DateTimeFormatter.ISO_INSTANT; private TestConstants() { } diff --git a/src/main/java/io/odh/test/utils/UpgradeUtils.java b/src/main/java/io/odh/test/utils/UpgradeUtils.java index 23446bbc..03c1a4f7 100644 --- a/src/main/java/io/odh/test/utils/UpgradeUtils.java +++ b/src/main/java/io/odh/test/utils/UpgradeUtils.java @@ -7,14 +7,14 @@ import io.odh.test.TestConstants; import io.skodjob.testframe.resources.KubeResourceManager; -import java.util.Date; +import java.time.Instant; import static io.odh.test.framework.matchers.Matchers.logHasNoUnexpectedErrors; import static org.hamcrest.MatcherAssert.assertThat; public class UpgradeUtils { - public static void deploymentLogIsErrorEmpty(String namespace, String deploymentName, Date sinceTimestamp) { + public static void deploymentLogIsErrorEmpty(String namespace, String deploymentName, Instant sinceTimestamp) { // Check that operator doesn't contain errors in logs since sec String operatorLog = KubeResourceManager.getKubeClient().getClient().apps().deployments() .inNamespace(namespace).withName(deploymentName).sinceTime(TestConstants.TIMESTAMP_DATE_FORMAT.format(sinceTimestamp)).getLog(); diff --git a/src/test/java/io/odh/test/e2e/upgrade/BundleUpgradeST.java b/src/test/java/io/odh/test/e2e/upgrade/BundleUpgradeST.java index c76b0d87..ce34c48e 100644 --- a/src/test/java/io/odh/test/e2e/upgrade/BundleUpgradeST.java +++ b/src/test/java/io/odh/test/e2e/upgrade/BundleUpgradeST.java @@ -27,7 +27,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; -import java.util.Date; +import java.time.Instant; import java.util.Map; @SuiteDoc( @@ -107,7 +107,7 @@ void testUpgradeBundle() throws IOException { LabelSelector labelSelector = KubeResourceManager.getKubeClient().getClient().apps().deployments() .inNamespace(OdhConstants.CONTROLLERS_NAMESPACE).withName(OdhConstants.DASHBOARD_CONTROLLER).get().getSpec().getSelector(); PodUtils.verifyThatPodsAreStable(OdhConstants.CONTROLLERS_NAMESPACE, labelSelector); - Date operatorLogCheckTimestamp = new Date(); + Instant operatorLogCheckTimestamp = Instant.now(); // Verify that NTB pods are stable PodUtils.waitForPodsReady(ntbNamespace, lblSelector, 1, true, () -> { }); diff --git a/src/test/java/io/odh/test/e2e/upgrade/OlmUpgradeST.java b/src/test/java/io/odh/test/e2e/upgrade/OlmUpgradeST.java index d7326c4b..8623e453 100644 --- a/src/test/java/io/odh/test/e2e/upgrade/OlmUpgradeST.java +++ b/src/test/java/io/odh/test/e2e/upgrade/OlmUpgradeST.java @@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; -import java.util.Date; +import java.time.Instant; import java.util.Map; @SuiteDoc( @@ -110,7 +110,7 @@ void testUpgradeOlm() throws IOException, InterruptedException { LabelSelector labelSelector = KubeResourceManager.getKubeClient().getClient() .apps().deployments().inNamespace(OdhConstants.CONTROLLERS_NAMESPACE).withName(OdhConstants.DASHBOARD_CONTROLLER).get().getSpec().getSelector(); PodUtils.verifyThatPodsAreStable(OdhConstants.CONTROLLERS_NAMESPACE, labelSelector); - Date operatorLogCheckTimestamp = new Date(); + Instant operatorLogCheckTimestamp = Instant.now(); // Verify that NTB pods are stable PodUtils.waitForPodsReady(ntbNamespace, lblSelector, 1, true, () -> { });