基于 https://GitHub.com/flapdoodle-oss/de.flapdoodle.embed.process 的嵌入式 MySQL
基于 https://GitHub.com/flapdoodle-oss/de.flapdoodle.embed.process 的嵌入式 MySQL
[DEPRECATED] - mostly due to substantial changes in packaging between version changes and emergence of new and better ways to run embedded mysql. Please check-out Testcontainers as a better alternative.
Add dependency to your pom.xml:
com.wix
wix-embedded-mysql
x.y.z
test
You can start an embedded mysql with defaults and a single schema:
import com.wix.mysql.EmbeddedMysql;
import static com.wix.mysql.EmbeddedMysql.anEmbeddedMysql;
import static com.wix.mysql.ScriptResolver.classPathScript;
import static com.wix.mysql.distribution.Version.v5_7_latest;
EmbeddedMysql mysqld = anEmbeddedMysql(v5_7_latest)
.addSchema("aschema", classPathScript("db/001_init.sql"))
.start();
//do work
mysqld.stop(); //optional, as there is a shutdown hookIf you need more control in configuring embeded mysql instance, you can use MysqldConfig builder:
…In addition you can control additional settings of embedded mysql by providing configs that have base type of AdditionalConfig by providing those to anEmbeddedMysql builder:
…EmbeddedMysql supports multiple schemas and additional configuration options provided via SchemaConfig builder:
…It is intended to be started once per test-suite, but you can reset schema in between tests which recreates database and applies provided migrations:
import com.wix.mysql.EmbeddedMysql;
import static com.wix.mysql.EmbeddedMysql.anEmbeddedMysql;
import static com.wix.mysql.ScriptResolver.classPathScript;
import static com.wix.mysql.distribution.Version.v5_6_latest;
EmbeddedMysql mysqld = anEmbeddedMysql(v5_6_latest)
.addSchema("aschema", classPathScript("db/001_init.sql"))
.start();
//do work
mysqld.reloadSchema("aschema", classPathScript("db/001_init.sql"));
//continue on doing work
mysqld.stop(); //optional, as there is a shutdown hookSource for examples can be found here
Some build tools strongly encourages you to have tests which are isolated from the internet.
To support such a use-case you can use the wix-embedded-mysql-download-and-extract utility.
It produces a runnable jar (wix-embedded-mysql-download-and-extract-[[VERSION]]-jar-with-dependencies.jar) which you can call with java -jar wix-embedded-mysql-download-and-extract-[[VERSION]]-jar-with-dependencies.jar $downloadDir $majorVersion $minorVersion and it will download and extract the needed installer for you.
Additionally you should pass the download directory to your test so that it can configure your DownloadConfig#withCacheDir to use that directory instead of downloading it from the internet.
Build on top of de.flapdoodle.embed.process
libaio1.so needs to be pre-installed on linux, but that is not the case for some linux distributions. Proper error is emitted if it's missing and you have to install it manually (ex. ubuntu):sudo apt-get install libaio1libncurses5:sudo apt-get install libncurses5libnuma1 libssl1.0 libcrypto++6Use of this source code is governed by a BSD License, which basically means you can use and modify it freely.
MariaDB4j is an unrelated similar project.
暂无开放 Issues,或尚未同步最近议题。