本文整理汇总了Java中org.testcontainers.containers.MySQLContainer类的典型用法代码示例。如果您正苦于以下问题:Java MySQLContainer类的具体用法?Java MySQLContainer怎么用?Java MySQLContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MySQLContainer类属于org.testcontainers.containers包,在下文中一共展示了MySQLContainer类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateXML
import org.testcontainers.containers.MySQLContainer; //导入依赖的package包/类
@BeforeClass
public static void generateXML() throws Exception {
MySQLContainer container = jdbcContainerRule.getContainer();
String[] args = new String[] {
"-t", "mysql",
"-db", "test",
"-s", "test",
"-host", container.getContainerIpAddress() + ":" + String.valueOf(container.getMappedPort(3306)),
"-port", String.valueOf(container.getMappedPort(3306)),
"-u", container.getUsername(),
"-p", container.getPassword(),
"-nohtml",
"-o", "target/mysqlxmlit",
"-connprops","useSSL\\=false"
};
Main.main(args);
}
示例2: testSimple
import org.testcontainers.containers.MySQLContainer; //导入依赖的package包/类
@Test
public void testSimple() throws SQLException {
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setJdbcUrl("jdbc:mysql://"
+ mysql.getContainerIpAddress()
+ ":" + mysql.getMappedPort(MySQLContainer.MYSQL_PORT)
+ "/" + DB_NAME);
hikariConfig.setUsername(USER);
hikariConfig.setPassword(PWD);
HikariDataSource ds = new HikariDataSource(hikariConfig);
Statement statement = ds.getConnection().createStatement();
statement.execute("SELECT 1");
ResultSet resultSet = statement.getResultSet();
assertEquals("There is a result", resultSet.next(), true);
int resultSetInt = resultSet.getInt(1);
assertEquals("A basic SELECT query succeeds", 1, resultSetInt);
}
示例3: testSimple
import org.testcontainers.containers.MySQLContainer; //导入依赖的package包/类
@Test
public void testSimple() throws SQLException {
MySQLContainer mysql = (MySQLContainer) new MySQLContainer()
.withConfigurationOverride("somepath/mysql_conf_override")
.withLogConsumer(new Slf4jLogConsumer(logger));
mysql.start();
try {
ResultSet resultSet = performQuery(mysql, "SELECT 1");
int resultSetInt = resultSet.getInt(1);
assertEquals("A basic SELECT query succeeds", 1, resultSetInt);
} finally {
mysql.stop();
}
}
示例4: testSpecificVersion
import org.testcontainers.containers.MySQLContainer; //导入依赖的package包/类
@Test
public void testSpecificVersion() throws SQLException {
MySQLContainer mysqlOldVersion = (MySQLContainer) new MySQLContainer("mysql:5.5")
.withConfigurationOverride("somepath/mysql_conf_override")
.withLogConsumer(new Slf4jLogConsumer(logger));
mysqlOldVersion.start();
try {
ResultSet resultSet = performQuery(mysqlOldVersion, "SELECT VERSION()");
String resultSetString = resultSet.getString(1);
assertTrue("The database version can be set using a container rule parameter", resultSetString.startsWith("5.5"));
} finally {
mysqlOldVersion.stop();
}
}
示例5: testMySQLWithCustomIniFile
import org.testcontainers.containers.MySQLContainer; //导入依赖的package包/类
@Test
public void testMySQLWithCustomIniFile() throws SQLException {
assumeFalse(SystemUtils.IS_OS_WINDOWS);
MySQLContainer mysqlCustomConfig = new MySQLContainer("mysql:5.6")
.withConfigurationOverride("somepath/mysql_conf_override");
mysqlCustomConfig.start();
try {
ResultSet resultSet = performQuery(mysqlCustomConfig, "SELECT @@GLOBAL.innodb_file_format");
String result = resultSet.getString(1);
assertEquals("The InnoDB file format has been set by the ini file content", "Barracuda", result);
} finally {
mysqlCustomConfig.stop();
}
}
示例6: performQuery
import org.testcontainers.containers.MySQLContainer; //导入依赖的package包/类
@NonNull
protected ResultSet performQuery(MySQLContainer containerRule, String sql) throws SQLException {
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setJdbcUrl(containerRule.getJdbcUrl());
hikariConfig.setUsername(containerRule.getUsername());
hikariConfig.setPassword(containerRule.getPassword());
HikariDataSource ds = new HikariDataSource(hikariConfig);
Statement statement = ds.getConnection().createStatement();
statement.execute(sql);
ResultSet resultSet = statement.getResultSet();
resultSet.next();
return resultSet;
}
示例7: extractConnectionData
import org.testcontainers.containers.MySQLContainer; //导入依赖的package包/类
@Override
protected ConnectionData extractConnectionData(GenericContainer container) {
ConnectionData data = new ConnectionData();
if (container instanceof MySQLContainer) {
MySQLContainer mysql = (MySQLContainer)container;
data.db = "test";
data.username = mysql.getUsername();
data.password = mysql.getPassword();
data.host = mysql.getContainerIpAddress();
data.port = String.valueOf(mysql.getMappedPort((Integer) mysql.getExposedPorts().get(0)));
}
return data;
}
示例8: startDriverContainer
import org.testcontainers.containers.MySQLContainer; //导入依赖的package包/类
@Override
protected GenericContainer startDriverContainer() {
MySQLContainer container = new MySQLContainer();
container.start();
return container;
}