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

Error with testcontainers and version 1.2.0 #76

Closed
radovanradic opened this issue Feb 26, 2024 · 5 comments · Fixed by #80
Closed

Error with testcontainers and version 1.2.0 #76

radovanradic opened this issue Feb 26, 2024 · 5 comments · Fixed by #80

Comments

@radovanradic
Copy link

radovanradic commented Feb 26, 2024

Hello,

We are using r2dbc test containers for junit tests for MariaDB. There were no issues with url like this r2dbc:tc:mariadb:///databasename?TC_IMAGE_TAG=latest in previous version (1.1.4). After upgrading to 1.2.0 we are getting this error

java.lang.IllegalArgumentException: Wrong argument value '' for HaMode

Stack Trace:

Exception in thread "main" java.util.concurrent.CompletionException: java.lang.IllegalArgumentException: Wrong argument value '' for HaMode
	at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315)
	at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:649)
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1773)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)
	Suppressed: java.lang.Exception: #block terminated with an error
		at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:103)
		at reactor.core.publisher.Mono.block(Mono.java:1712)
		at org.example.Main.main(Main.java:23)
Caused by: java.lang.IllegalArgumentException: Wrong argument value '' for HaMode
	at org.mariadb.r2dbc.HaMode.from(HaMode.java:107)
	at org.mariadb.r2dbc.MariadbConnectionConfiguration.<init>(MariadbConnectionConfiguration.java:99)
	at org.mariadb.r2dbc.MariadbConnectionConfiguration.<init>(MariadbConnectionConfiguration.java:25)
	at org.mariadb.r2dbc.MariadbConnectionConfiguration$Builder.build(MariadbConnectionConfiguration.java:792)
	at org.mariadb.r2dbc.MariadbConnectionFactoryProvider.createConfiguration(MariadbConnectionFactoryProvider.java:61)
	at org.mariadb.r2dbc.MariadbConnectionFactoryProvider.create(MariadbConnectionFactoryProvider.java:66)
	at org.mariadb.r2dbc.MariadbConnectionFactoryProvider.create(MariadbConnectionFactoryProvider.java:16)
	at io.r2dbc.spi.ConnectionFactories.find(ConnectionFactories.java:110)
	at org.testcontainers.r2dbc.TestcontainersR2DBCConnectionFactory.lambda$null$4(TestcontainersR2DBCConnectionFactory.java:66)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:646)

Attached is simple reproducing example (just run Main). If you change implementation("org.mariadb:r2dbc-mariadb:1.2.0") in build.gradle.kts to implementation("org.mariadb:r2dbc-mariadb:1.1.4") then app works without errors.

Example to reproduce the error:
mariadb-test.zip

The fix looks simple, just check null or empty but not sure if there is something additional to be changed.

Thanks,
Radovan

@mdeso
Copy link
Contributor

mdeso commented Apr 16, 2024

This can be fixed by changing line 99 of MariadbConnectionConfiguration to
this.haMode = haMode == null || haMode.equals("") ? HaMode.NONE : HaMode.from(haMode);
(|| haMode.equals("") added)

@mdeso
Copy link
Contributor

mdeso commented Apr 16, 2024

I have investigated a possible fix for this but noticed that this only occurs if the connection string contains an explicit Parameter &haMode= (i.e., with an empty value string). The code in the MariaDB driver for parsing haMode hasn't changed recently and for the URL parsing it uses io.r2dbc.spi.ConnectionFactoryOptions. Therefore, I think this error is due to a regression in either Micronaut, Testcontainers, or maybe ConnectionFactoryOptions, although the latter would probably have caused problems in other areas too and haMode is specific to the MariaDB driver. I don't think that the driver should consider an empty value in this case as valid.

@mdeso
Copy link
Contributor

mdeso commented Apr 17, 2024

I was able got get testcontainers working again with MariaDB R2DBC by using protocol: "mariadb:none" in my application-test.yml. This is probably not a driver issue and the issue can be closed.

@radovanradic
Copy link
Author

Yes, the example I posted in the issue is not using Micronaut dependencies, only testcontainers. Most likely something changed in 1.2.0 mariadb client. Or maybe testcontainers needs to adjust to this change to resolve the issue. The example uses just this connection url from test containers r2dbc:tc:mariadb:///databasename?TC_IMAGE_TAG=latest

@mdeso
Copy link
Contributor

mdeso commented Apr 23, 2024

Ok, I think I found the problem in the change log of 1.2.0. HaMode now supports a list of aliases and in previous versions the HaMode NONE had the alias "" but now the alias list is initialized with new String[0] which is causing the error. The fix is to change the initialization to new String[] {""}. I will provide a PR with that fix.

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

Successfully merging a pull request may close this issue.

2 participants