Application startup problems when running tests via the #QuarkusTest annotation - kotlin

Reservation: I am not sure if this is a bug or a work limitation of the annotation #QuarkusTest. This is our first big project on this framework, so please do not judge strictly.
My team and I write a project using Kotlin, Quarkus as the main framework, Gradle as the build system and Smallrye GraphQL. We have an application that is covered with tests. The problem arises when we write integration HTTP tests for our EndPoints. The tests work out correctly, but only when we run them having the application started manually before. If we do not start the application using ./gradlew web:quarkusDev and put the #QuarkusTest annotation, which, according to the documentation, should run the application without any additional commands before running the tests, an exception occurs:
"Connection refused: no further information
java.net.ConnectException: Connection refused: no further information"
It seems like the application does not start at all.
This is the link to our small test project on github, which reproduces the problem.
We understand that requests should be sent to http://localhost:8081/mapins but it does not work. We get such response: "GraphQL Schema not generated. Make sure you have a GraphQL Endpoint. Go to https://quarkus.io/guides/microprofile-graphql to learn how". When we exclude the path from requests for autoconfiguration we get the same result as in the case when we send requests to http://localhost:8081/ - responses are just empty. We have already tried using quarkus.http.test-port but results are the same...
We searched for information about this problem, but the only thing we found was a bit similar question on StackOverflow, where the solution was - to connect "io.quarkus:quarkus-resteasy-reactive-jackson". We tried this option, but it did not help.
Maybe the problem is that our application is multimodule and needs to be started from concrete module and #QuarkusTest uses some kind of default command? ./gradlew web:quarkusDev has to be called for appropriate startup and maybe quarkus uses some other command during autoconfiguration. Is it possible to set starting command for tests manually?
Output of java -version:
Java 17, Kotlin 1.6.21
Quarkus version:
2.11.1.Final
Build tool (output of gradlew --version):
Gradle 7.4.2

Related

#QuarkusTest unit tests take a long time

I started a project and have about 7 tests in my project now and it takes already more than a minute to execute the whole test suite using gradle test.
From the additional output (--info flag) I can see that the whole quarkus application and also dependencies like the mongodb instance are restarted for every test class and method.
This is the exact opposite of what the quarkus documentation says on the testing guide page:
So far in all our examples we only start Quarkus once for all tests. Before the first test is run Quarkus will boot, then all tests will run, then Quarkus will shutdown at the end. This makes for a very fast testing experience however it is a bit limited as you can’t test different configurations.
All the tests are annotated with #QuarkusTest and every test just tests a single endpoint.
I use "pure" kotlin (1.5.21), Quarkus version 2.2.2.Final and gradle 6.9.
Installed features: cdi, config-yaml, jacoco, kotlin, mongodb-client, mongodb-panache-kotlin, narayana-jta, rest-client, rest-client-jackson, resteasy, resteasy-jackson, smallrye-context-propagation, smallrye-health, smallrye-openapi, swagger-ui
Is that a normal behaviour? If yes, an application with multiple hundred tests could easily take ~20 minutes or more to run the entire test suite.
I didn't try out maven yet, so I can't verify that it's not a gradle related issue.
While trying to reproduce it with a fresh project, I think I found the issue with my code:
I also used #QuarkusTestResources with restrictToAnnotatedClass=true on my tests.
This means the configuration & test profiles must be reloaded and therefore also the quarkus application.
Apparently all the DevServices get restarted, too (in my case it was a mongodb, since I'm using the panache extension), which explains the long runtimes of the tests.
I reorganized my tests a little bit, so they work with the "global" test resources (it was a WireMockServer in my case).
Now quarkus only gets started once before the tests and the total runtime of the gradle test task is acceptable.

How to delegate all building and all executing to maven

Lately (even after cache cleanup/reinstalls) I have issues with idea, where builds are failing, run configuration is failing. The problem is, that it is idea thing, maven builds just fine, run from cli runs just fine.
In idea I already checked "delegate build/run configurations to maven", and run configuration does not have any action to be done before build. Yet for some reason when I click run, it tries to download some libraries and then it fails. Second later java -jar from cli using previously outside of intellij build jar WORKS.
How to turn all these clever (and for me dysfunctional) stuff? I just want idea to run java -jar and that's it to minimize number of places, where it can fail. I know about possibility starting code externally from java and just connect with debugger, but I'd like to avoid it as it is not that convenient, and if I have ultimate edition, I'd like to be able to start debugging session from ide.
EDIT:
maven project is freshly updated, jdk is the same as one used maven. Yet for some reason project run produces:
java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration.propertySourcesPlaceholderConfigurer
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration] from ClassLoader
Caused by: java.lang.NoClassDefFoundError: javax/servlet/Filter
second later, java -jar using fat jar works.

gravitee.io can not debug policy in intellij

I am using intellij CE and trying to debug the gravitee.io policy locally. I am struggling from several days with no avail. I am C# developer and very novice to intellij. If someone can help me nail down the issue of my debugging, I will truly appreciate it. Here is my setup:
I have cloned 1.30.x branch of gateway and management-api in following respective directories:
C:\Work\Java\gravitee.io\git\gravitee-gateway-1.30.x
C:\Work\Java\gravitee.io\git\gravitee-management-rest-api-1.30.x
I also downloaded gravitee.io 1.30.1 binaries and placed it in the following respective directories:
C:\Work\Java\gravitee.io\1.30.1\graviteeio-gateway-1.30.1
C:\Work\Java\gravitee.io\1.30.1\graviteeio-management-api-1.30.1
As per guide, I need to run the standalone container for both gateway and management-api in debug mode.
So here is my debug configuration for both gateway and management-api
Gateway
Management-api
These both are working fine in debug mode.
Now I created a maven policy and in pom.xml, I use maven-resources-plugin to copy compiled policy into following directories:
C:\Work\Java\gravitee.io\1.30.1\graviteeio-gateway-1.30.1\plugins
C:\Work\Java\gravitee.io\1.30.1\graviteeio-management-api-1.30.1\plugins
I would like to debug this policy and hit my breakpoints. Can someone please guide me setting this up?
Without debugging, development of any project is just not possible whether it be C# or Java.
It will not automatically hit my breakpoints I believe.. In .Net world, we have a concept of debug symbols.. I am sure something similar will be available in Java to find m code and hit breakpoint. I still don't understand once I deploy my plugin (zip file) to the respective plugins directory in gateway and management-api, there is no magical thing which will let it find my code and hit the breakpoint.
I am sure I am missing something on either my policy project OR gateway and management-api debug configuration that can help gateway and management-api find my code.
I also would like to mention that policy is loaded just fine in both gateway and management-api since I already see logs in gateway console coming out of my policy.
Any help is truly appreciated. As I mentioned, I am very novice to intellij and Java world but not to programming.
Thanks

Hudson CI: cannot test grails-app

I've tried in each and every way to test a grails-app using hudson. I've tried testing with maven, I've tried testing with the grails plugin and I've tried testing with a shell builder it seems that building via shell is the only thing that works..
Every time I get the same error:
org.hibernate.HibernateException:
contains is not valid without active
transaction
But If i go to a shell and type
grails test-app
everything runs fine.
Does anyone have any idea on what's going on?
I'm using CentOS with Java 1.6, no slaves, just a simple hudson deploy over Tomcat6.
I've tried both with maven and grails builder, both fail.
Edit: it seems that if I run both unit and integration tests on the same command (either with grails or with mvn) the integration tests fail always.
Hudson/Jenkins usually just use the command line for executing grails plugins (You should be able to confirm that from the build output). You could probably add a pre build step to dump the environment, so you can see if anything there (or in your own shell) cause it to be fundamentally different.
Otherwise try to log in as the hudson user and find the hudson workspace and repeat the process manually. That has been the easiest way to debug hard problems like this..
regards

GRAILS plugin error

All,
I am trying to test my grails app using Hudson. I have in grails I will run the command of test-app -unit and will recieve the following message:
Running script /home/test/grails-1.1.1/scripts/TestApp.groovy
Environment set to test
Plugin [hibernate-1.1.1] not
installed, resolving..
Reading remote plugin list ...
Error reading remote plugin list
[Connection timed out], building
locally...
Unable to list plugins, please check
you have a valid internet connection:
Connection timed out
Reading remote plugin list ... Error
reading remote plugin list [Connection
timed out], building locally...
Unable to list plugins, please check
you have a valid internet connection:
Connection timed out
Plugin 'hibernate' was not found in
repository. If it is not stored in a
configured repository you will need to
install it manually. Type 'grails
list-plugins' to find out what plugins
are available. Finished: FAILURE
I believe the reason for this is that I do not have access to an external network on the server. If I do a list-plugins there is no returns it just times out.
I also beleive that this is a grails issue not a hudson issue.
The answer is the following:
navigate to the /path/to/hudson/Jobs/JOBNAME/
run - grails install-plugin /location/to/grails-1.1.1/plugins/grails-hibernate-1.1.1.zip
This will install the hibernate plugin for the specific job. This workaround can also be used for other plugins needed.
This has been tested in hudson.
Grails is going to need the Internet somehow to get plugin information. What you might be able to do is get Grails installed on a machine that does have access, get all of the plugins you need (i.e. by running what Hudson would normally run, test-app or whatever), and then copy over the entire grails installation to $GRAILS_HOME on your Hudson machine.
I can't say I've ever tried this, but it seems like it should work.