Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behavior for database containers launched via JDBC URL scheme #2544

Open
Lewox opened this issue Apr 9, 2020 · 11 comments
Open
Labels

Comments

@Lewox
Copy link

Lewox commented Apr 9, 2020

Version: 1.13.0
Spring Boot: yes
Container: mariadb:10.4

According to Database containers launched via JDBC URL scheme's note:
We will use /// (host-less URIs) from now on to emphasis the unimportance of the host:port pair.
From Testcontainers' perspective, jdbc:mysql:5.7.22://localhost:3306/databasename and jdbc:mysql:5.7.22:///databasename is the same URI.

This URL jdbc:tc:mariadb:10.4:///users?TC_INITSCRIPT=sql/init.sql should behave as jdbc:tc:mariadb:10.4://localhost:33306/users?TC_INITSCRIPT=sql/init.sql

The result for the first is URL is:
Waiting for database connection to become available at jdbc:mariadb://localhost:32795/test using query 'SELECT 1'

This results in failed TC_INITSCRIPT due to permissions.

For the second is:
Waiting for database connection to become available at jdbc:mariadb://localhost:32797/users using query 'SELECT 1'

This might be missing from #566 and #617.

@vektory79
Copy link
Contributor

Hi! Same here with postgresql in Testcontainers 1.3.0.

In org.testcontainers.containers.JdbcDatabaseContainer#createConnection the url is assigned to the value:

jdbc:postgresql://localhost:33048/test?loggerLevel=OFF?password=somepwd&fsync=off&initScript=&volumePath=/media/data/Docker/src/javister/javister-docker-postgresql/tests/simple/target/test-classes/../simpleWithVolumeTest-9_5&user=system

Note the ?loggerLevel=OFF? substring, that lead to the error. It's because the getJdbcUrl method is returning string:

jdbc:postgresql://localhost:33048/test?loggerLevel=OFF

in one hand, and the ConnectionUrl.getQueryString method starts constructing the query from the ? symbol again.

vektory79 added a commit to javister/javister-docker-postgresql that referenced this issue Apr 10, 2020
@vektory79
Copy link
Contributor

One more thing: I have update the PostgreSQL JDBC driver from version 42.0.0 to 42.2.12.

@bsideup
Copy link
Member

bsideup commented Apr 10, 2020

@vektory79 your issue seems to be unrelated and fixed in #2049

@stale
Copy link

stale bot commented Jul 10, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this is a mistake, please reply to this comment to keep it open. If there isn't one already, a PR to fix or at least reproduce the problem in a test case will always help us get back on track to tackle this.

@stale stale bot added the stale label Jul 10, 2020
@Lewox
Copy link
Author

Lewox commented Jul 10, 2020

Seems this issue is still valid, it shouldn't be closed.

@stale
Copy link

stale bot commented Jul 25, 2020

This issue has been automatically closed due to inactivity. We apologise if this is still an active problem for you, and would ask you to re-open the issue if this is the case.

@alex-lx
Copy link

alex-lx commented Dec 22, 2020

Issue still exists with 1.15.1.

@chadlwilson
Copy link
Contributor

See #4121 (comment) for a re-prod. This still seems to be broken with 1.16.0.

@rnorth rnorth reopened this Oct 14, 2021
@rnorth
Copy link
Member

rnorth commented Oct 14, 2021

@chadlwilson thanks for the prompt. We've removed the stale bot altogether, and I've reopened this issue.

@eschulma
Copy link

Still a problem in 1.17.6. Could you please update the documentation at least? This cost me a day of effort.

@molleafauss
Copy link

molleafauss commented Jan 7, 2024

Can confirm I stumbled upon this also. I have a liquibase script which fails (and very curiously only on second migration, the first gets successfully executed).
The error I get from MySQL is like ALTER command denied to user 'test'@'172.17.0.1' for table ...

When adding a hostname:port in the URL, testcontainer correctly creates the database with the expected name and doesn't fail for permissions.

Testcontainers 1.19.3
docker:
Server Version: 24.0.6
API Version: 1.43
Operating System: Docker Desktop (macos 13.6.3)

With this url: jdbc:tc:mysql:8:///rfs
I see in the logs:

Waiting for database connection to become available at jdbc:mysql://localhost:55226/test using query 'SELECT 1'

and then the liquibase migration fail with the following (see how the the first migration succeeds):

INFO 07/01/2024, 20:45: liquibase: classpath:db/changelog-master.xml: db/changelog-1.0.sql::1::author: Custom SQL executed
INFO 07/01/2024, 20:45: liquibase: classpath:db/changelog-master.xml: db/changelog-1.0.sql::1::author: ChangeSet db/changelog-1.0.sql::1::author ran successfully in 47ms
SEVERE 07/01/2024, 20:45: liquibase: classpath:db/changelog-master.xml: db/changelog-1.0.sql::2::author: Change Set db/changelog-1.0.sql::2::author failed.  Error: ALTER command denied to user 'test'@'172.17.0.1' for table 'Catalog' [Failed SQL: ALTER TABLE rfs.Catalog MODIFY COLUMN id VARCHAR(100)]

When I change the url to: jdbc:tc:mysql:8://localhost/rfs

Waiting for database connection to become available at jdbc:mysql://localhost:55308/rfs using query 'SELECT 1'
[...]

INFO 07/01/2024, 20:47: liquibase: Successfully acquired change log lock
INFO 07/01/2024, 20:47: liquibase: Creating database history table with name: rfs.DATABASECHANGELOG
INFO 07/01/2024, 20:47: liquibase: Reading from rfs.DATABASECHANGELOG
INFO 07/01/2024, 20:47: liquibase: classpath:db/changelog-master.xml: db/changelog-1.0.sql::1::author: Custom SQL executed
INFO 07/01/2024, 20:47: liquibase: classpath:db/changelog-master.xml: db/changelog-1.0.sql::1::author: ChangeSet db/changelog-1.0.sql::1::author ran successfully in 38ms
INFO 07/01/2024, 20:47: liquibase: classpath:db/changelog-master.xml: db/changelog-1.0.sql::2::author: Custom SQL executed
INFO 07/01/2024, 20:47: liquibase: classpath:db/changelog-master.xml: db/changelog-1.0.sql::2::author: ChangeSet db/changelog-1.0.sql::2::author ran successfully in 23ms
[...]
INFO 07/01/2024, 20:47: liquibase: Successfully released change log lock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants