• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MySQLContainer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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);
}
 
开发者ID:schemaspy,项目名称:schemaspy,代码行数:18,代码来源:MysqlXMLIT.java


示例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);
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:20,代码来源:CustomizableMysqlTest.java


示例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();
    }
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:17,代码来源:SimpleMySQLTest.java


示例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();
    }
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:17,代码来源:SimpleMySQLTest.java


示例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();
    }
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:17,代码来源:SimpleMySQLTest.java


示例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;
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:16,代码来源:SimpleMySQLTest.java


示例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;
}
 
开发者ID:bitbrain,项目名称:jpersis,代码行数:14,代码来源:MySQLDriverFactory.java


示例8: startDriverContainer

import org.testcontainers.containers.MySQLContainer; //导入依赖的package包/类
@Override
protected GenericContainer startDriverContainer() {
    MySQLContainer container = new MySQLContainer();
    container.start();
    return container;
}
 
开发者ID:bitbrain,项目名称:jpersis,代码行数:7,代码来源:MySQLDriverFactory.java



注:本文中的org.testcontainers.containers.MySQLContainer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SAXSourceLocator类代码示例发布时间:2022-05-23
下一篇:
Java Recurrence类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap