从 Oracle 反序列化 ZonedDateTime 在 Azure 管道上生成不同的毫秒数

问题描述 投票:0回答:1

我正在使用 Oracle 数据库和 Spring JPA。我在尝试通过 Azure 管道运行单元测试用例时遇到了奇怪的情况。

我已在本地计算机上安装了 JAVA 17.0.8,而 Azure 管道在 JAVA 17.0.10(供应商:Eclipse Adoptium)上运行。这可能是 Eclipse Adoptium 提供的 JAVA 版本 17.0.10 的错误。

请注意,当我尝试使用 Oracle 数据库 docker 容器在本地运行单元测试用例时,所有测试用例都运行成功。但是,当我尝试通过 Azure 管道运行测试用例时,出现以下错误。

2024-05-02T09:54:41.8995194Z [ERROR]   MyCustomer.testUpdateCustomerEndDate:145 Multiple Failures (1 failure)
2024-05-02T09:54:41.8996036Z    org.opentest4j.AssertionFailedError: expected: <2024-05-02T09:54:39.709796802Z[Etc/UTC]> but was: <2024-05-02T09:54:39.709797Z[Etc/UTC]>|

在这里,我们可以看到,从 Oracle 数据库反序列化的毫秒数(709796802Z 与 709797Z)存在非常小的差异。

我正在 Azure 管道中使用以下 Maven@4 任务来运行测试用例。

- task: Maven@4
  displayName: 'Run Unit Test'
  inputs:
    mavenPomFile: 'pom.xml'
    goals: 'test'
    publishJUnitResults: true
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
    testRunTitle: 'Unit Test Over Oracle Container'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '17'
    mavenAuthenticateFeed: true
    effectivePomSkip: true
    options: '-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER) -DfailIfNoTests=false -Dunit-test=true'

下面是我的测试用例类中的代码一瞥,其中我设置 endDate 并调用 JPA 方法来更新 MyCustomer 实体对象。

ZonedDateTime now = ZonedDateTime.now();
        int updateCount = MyCustomerDao.updateCustomerEndDate(customer.getId(), , now);

        assertEquals(1, updateCount);

        MyCustomer customerSaved = MyCustomerDao.findCustomerById(customer.getId());

        assertAll(
                () -> assertNotNull(customerSaved),
                () -> assertEquals(now, customerSaved.getEndDate())
        );

当我尝试使用 “mvn test” 命令在本地笔记本电脑上运行相同的测试用例时,它工作正常。可能是什么问题?任何建议/反馈表示赞赏。


编辑:如果我在 Azure Maven@4 任务中将 Java 版本从 17 更改为 1.11,则测试用例运行成功,如下所示。

因此,这个问题似乎与 Azure 管道更加具体,因为我已经在安装了 Java“17.0.8”的本地计算机上成功运行了测试

- task: Maven@4
  displayName: 'Run Unit Test'
  inputs:
    mavenPomFile: 'pom.xml'
    goals: 'test'
    publishJUnitResults: true
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
    testRunTitle: 'Unit Test Over Oracle Container'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.11'
    mavenAuthenticateFeed: true
    effectivePomSkip: true
    options: '-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER) -DfailIfNoTests=false -Dunit-test=true'
jpa azure-devops java-17
1个回答
0
投票

我暂时解决了这个问题。

此问题似乎更具体于在 Azure DevOps 的 ubuntu 代理上运行的 Java 版本 17.0.10(供应商:Eclipse Adoptium)。

我将JAVA版本降级到1.11,测试用例运行成功。 将来,我需要将所有管道迁移到JAVA17,所以我正在等待平台团队提供ubuntu代理上JAVA17的新版本。

© www.soinside.com 2019 - 2024. All rights reserved.