mysql - 使用 MySQL 数据库上传到 CircleCI 时出错 - 在 Maven 测试之前运行时,Maven Clean 也会产生问题
问题描述
我在 IntelliJ 中使用 Hibernate 框架和 Maven。我正在创建一个 MySQL 数据库,我还有一些映射 MySQL 数据库的 ORM 类,然后我正在运行一些 JUNIT 测试以确保一切正常。
我遇到麻烦的地方有两个地方,它们彼此相关:
- 当我运行时
mvn test
,有时我的 JUNIT 测试工作正常并且能够查询模拟数据库、建立连接(即使它只是与模拟数据库)、执行语句等。但是,有时,如果我在运行mvn clean
之前运行mvn test
,而JUNIT 测试仍然执行,测试输出失败(不是错误,只是失败,当然认为这仍然很糟糕)。 - 当我上传到 GitHub 并运行 CircleCI 时,#1 中概述的问题本质上是重复的(这并不奇怪,因为 CircleCI
mvn test
在进行集成测试时会运行)。我的大部分上传都失败了,但其中一个终于成功了。但是,我不确定为什么“最终”上传成功而其他人没有成功。
我从mvn test
或 CircleCI 构建中获得的错误消息通常如下所示。这些错误来自我的最后一次上传,即我在下一次上传之前所做的一个实际有效的上传:
java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
com.mysql.cj.exceptions.CJException: Public Key Retrieval is not allowed
java.sql.SQLNonTransientConnectionException: Could not create connection to database server
我还应该注意,我的意图是先运行mvn clean
,然后上传到 CircleCI,但是,运行mvn clean
似乎以某种方式使这些错误永久存在。
至于我正在使用的不同资源,它们就在这里。如果我忘记了什么,请告诉我,我应该能够将其包括在内。
在我的 hibernate.cfg.xml 文件中,我有以下几行:
<property name="connection.url">jdbc:mysql://localhost:3306/stocks</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
在第一行“股票”一词的末尾,我有时会附加以下任何一项(有时我只附加以下一项,有时我将它们组合起来,具体取决于来自 Maven 或 CircleCI 的错误)。添加这些行的某些组合似乎有助于使事情正常进行,但运行mvn clean
似乎停止了这些添加所产生的任何影响:
autoReconnect=true
useSSL=false
allowPublicKeyRetrieval=true
从 IntelliJ 中运行 JUNIT 测试通常可以工作,但如果我mvn clean
先运行,那么 IntelliJ 通常将无法工作,除非我随后返回此文件并附加?autoReconnect=true&useSSL=false
. 如果我这样做,那么 IntelliJ 将正常运行 JUNIT 测试。
在 CircleCI 的 config.yml 文件中,我有以下代码。根据我所做的其他研究,在 MAVEN_OPTS 中添加了某些语句以试图抵消我得到的错误,但我不知道这些语句是否以某种方式产生任何影响:
# Java Maven CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-java/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/openjdk:8-jdk
# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/postgres:9.4
- image: circleci/mysql:latest-ram
environment:
- MYSQL_ROOT_PASSWORD: (my real password goes here)
- MYSQL_DATABASE: stocks
- MYSQL_USER: bob
- MYSQL_PASSWORD: (the real password goes here)
working_directory: ~/repo
environment:
# Customize the JVM maximum heap limit
MAVEN_OPTS: -Xmx3200m -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dmaven.wagon.http.ssl.ignore.validity.dates=true
steps:
- checkout
- run: sudo apt install -y mysql-client
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "pom.xml" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: mvn dependency:go-offline
- save_cache:
paths:
- ~/.m2
key: v1-dependencies-{{ checksum "pom.xml" }}
# run tests!
- run: mvn integration-test
如果有人知道发生了什么,我感谢您的帮助。我的目标是能够通过首先运行上传到 CircleCI,mvn clean
因此只有src
文件、pom.xml
文件和.circleci
文件夹包含在上传中。另外,不要强调这一点,但我最近上传到 CircleCI 确实有效,但我不确定是什么让那个构建工作,而所有其他的都没有。
解决方案
推荐阅读
- angular - 带有材料的Angular 6,单击事件无法正常工作
- r - ROracle 安装期间未找到 _OCIArrayDescriptorAlloc
- java - 如何在重新运行测试用例的 Testng 报告中删除失败的测试
- reactjs - React - 获取多个获取请求
- amazon-web-services - 如何使用 AWS DMS 从一个区域到另一个区域?
- python - 将 _io.BufferedReader 转换为 str 以进行 write()
- javascript - 如何在每列的末尾显示显示隐藏选项
- javascript - Hyperledger-Composer:无法从事务处理器函数中访问 javaScript split() 函数
- graphql - AppSync订阅授权问题
- javascript - Express.js 两个路由,例如单个模块中的注册和登录