Skip to content

MySQLContainer does not have getter for the databaseName field #473

Closed

Description

@dmatej

In Java EE containers like Payara is JDBC pool and JDBC driver configured via properties, not URL. It is more useful to provide username, password, serverName, portName and databaseName etc. than URL.
getJdbcUrl is higher abstraction layer over it.

Activity

  1. bsideup commented on Nov 6, 2017

    @bsideup
    Member

    Hi @dmatej,

    At least in TestContainers 1.4.3, there is getUsername, getPassword, getContainerIpAddress and getFirstMappedPort/getExposedPort(0) for that.

    DB name ATM is static and has test value. There is also withDatabaseName to override it, but then you know it upfront :)

  2. dmatej commented on Nov 6, 2017

    @dmatej
    Author

    The problem is not about setting the test container but with using it's active configuration for the creation of the JDBC resource, this is why URL is not useful. I would like to simply use getters to configure the JDBC pool from the test container's getters but now I have to duplicate values or use sometimes getters sometimes static values. The code is inconsistent and programming not intuitive, I had to find out where can I get values I needed.

    getFirstMappedPort has another implementation than getUrl uses - this is the reason why I wrote the getUrl method parsing port from the url instead (but now I see both ways give same result, ok).

    It would be much more transparent to have standard JDBC getters and let user to access all useful values. Or maybe to create some transfer object for that and provide getJdbcConfiguration?.

        LOG.info("Starting the MySql docker service...");
        mysql = new MySQLContainer<>().withDatabaseName(DB_NAME)//
            .withEnv("MYSQL_LOG_QUERIES_ENABLED", "1")//
            .withEnv("TC_INITFUNCTION", ArquillianDaoUnitTest.class.getCanonicalName() + "::initCollation")//
            .withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger(ArquillianDaoUnitTest.class)));//
        mysql.start();
    
          runCommand("create-jdbc-connection-pool", "--ping", "--restype", "javax.sql.DataSource", //
              "--datasourceclassname", "com.mysql.cj.jdbc.MysqlDataSource", "--property",
              "user=" + mysql.getUsername() + ":password=" + mysql.getPassword() + ":DatabaseName=" + DB_NAME //
                  + ":ServerName=" + mysql.getContainerIpAddress() + ":port=" + getJdbcPort()
                  + ":zeroDateTimeBehavior=convertToNull:useUnicode=true:useJDBCCompliantTimezoneShift=true"
                  + ":useLegacyDatetimeCode=true:serverTimezone=UTC:characterEncoding=UTF-8"
                  + ":useInformationSchema=true:nullCatalogMeansCurrent=true:nullNamePatternMatchesAll=false", //
              "xxx-test");
          runCommand("list-jdbc-connection-pools", "--echo=true", "--terse=true");
          runCommand("set", "resources.jdbc-connection-pool.xxx-test.steady-pool-size=5");
          runCommand("set", "resources.jdbc-connection-pool.xxx-test.max-pool-size=20");
          runCommand("set", "resources.jdbc-connection-pool.xxx-test.connection-validation-method=auto-commit");
          runCommand("set", "resources.jdbc-connection-pool.xxx-test.is-connection-validation-required=true");
          runCommand("set", "resources.jdbc-connection-pool.xxx-test.fail-all-connections=true");
          runCommand("create-jdbc-resource", "--connectionpoolid", "xxx-test", "jdbc/xxx-jta");
    
  3. kiview commented on Nov 7, 2017

    @kiview
    Member

    @bsideup I suppose there is no damage in adding a getter for databaseName, so we have a consistent API?

  4. added a commit that references this issue on Dec 18, 2017
    da1d63e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions