Testing quarkus app, with my rest endpoint /init
Installed features: [cdi, resteasy, resteasy-jackson]
I found that when run app as java (not native), then check
http://localhost:8080/init
{
"user": {
"username": "u name",
"firstName": "f name",
"lastName": "l name",
"email": null
},
"logoutUrl": "url!!!!"
}
and as native,
And running native-ly like this:
package -Dnative -f pom.xml
Then run ./my-service-1.0-SNAPSHOT-runner:
it gets empty result:
http://localhost:8080/init
{}
The Jackson configure like this:
#Singleton
public class RegisterCustomModuleCustomizer implements ObjectMapperCustomizer {
public void customize(final ObjectMapper objectMapper) {
objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
}
}
No exception.
InitData defined like this, as normal bean class:
public class InitData {
private .. some fields
What could be missing? In't it supposed to works same for native/java?
UPDATE:
when run as java, compile quarkus:dev -f pom.xml:
[INFO] Scanning for projects... [INFO] [INFO] ------------<
my.compnay:my-service >------------ [INFO] Building my-service
1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] ---
maven-resources-plugin:2.6:resources (default-resources) # my-service
--- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] [INFO] ---
maven-compiler-plugin:3.8.1:compile (default-compile) # my-service ---
[INFO] Changes detected - recompiling the module! [INFO] Compiling 41
source files to
/home/me/projects/my-project/v2/my-service-quarkus/target/classes
[INFO] [INFO] --- quarkus-maven-plugin:1.0.0.CR1:dev (default-cli) #
my-service --- Listening for transport dt_socket at address: 5005
2019-11-12 14:17:43,027 INFO [io.qua.dep.QuarkusAugmentor] (main)
Beginning quarkus augmentation 2019-11-12 14:17:43,599 INFO
[io.qua.arc.pro.BeanProcessor] (build-1) Found unrecommended usage of
private members (use package-private instead) in application beans:
- #Inject field my.compnay.application.InitResource#initFacadeService 2019-11-12 14:17:43,658 INFO [io.qua.dep.QuarkusAugmentor] (main)
Quarkus augmentation completed in 631ms 2019-11-12 14:17:44,104 INFO
[io.quarkus] (main) Quarkus 1.0.0.CR1 started in 1.260s. Listening on:
http://0.0.0.0:8080 2019-11-12 14:17:44,105 INFO [io.quarkus] (main)
Profile dev activated. Live Coding activated. 2019-11-12 14:17:44,105
INFO [io.quarkus] (main) Installed features: [cdi, resteasy,
resteasy-jackson]
Then hit: http://localhost:8080/init
2019-11-12 14:19:52,423 INFO [com.dis.pla.app.ser.fil.LoggingFilter]
(vert.x-worker-thread-1) Request GET /init from IP
0:0:0:0:0:0:0:1:48810 2019-11-12 14:19:52,425 INFO
[com.dis.pla.app.InitResource] (vert.x-worker-thread-1) Init with user
f name my.compnay.api.UserData#37ac6925
--
#RegisterForReflection (from here) is the annotation to use over the Data objects IF your Resource doe snot return that data object directly.
I.e. in my case:
#GET
public Response getInit(
thus it would not work innately until you put:
#RegisterForReflection
class InitData { ...
But still.
I think I should be a bug. It should all behave same way. Native or not.
I also thought it was a bug, but they explain it better here (quarkus.io):
When building a native executable, GraalVM operates with a closed world assumption. It analyzes the call tree and removes all the classes/methods/fields that are not used directly.
The elements used via reflection are not part of the call tree so they are dead code eliminated (if not called directly in other cases). To include these elements in your native executable, you need to register them for reflection explicitly.
Related
I am using spring-boot-starter-parent:2.2.6.RELEASE and cucumber-java8:5.6.0 to execute e2e tests using Cucumber Runner/Spring Boot/JUnit5/Maven Surefire. I have installed latest Jenkins Community LTS v2.222.1 on a Linux VM and connected my laptop as a slave.
When I execute the tests on my laptop using IDE / command prompt it works fine (using mvn clean test). However same tests are not running when triggered from Jenkins. It's bit confusing since I am using same config/tools.
Jenkins Console O/P:
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 10 source files to C:\Jenkins\workspace\Sanity\core\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) # project-core ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
Apr 07, 2020 1:08:45 PM net.masterthought.cucumber.ReportParser parseForFeature
INFO: File {0} does not contain features
Apr 07, 2020 1:08:45 PM net.masterthought.cucumber.ReportParser parseJsonFiles
INFO: File 'C:\Users\User\AppData\Local\Temp\2\cucumber5203280546924184867.json' contains 0 features
Apr 07, 2020 1:08:45 PM net.masterthought.cucumber.ReportBuilder generateErrorPage
INFO: Unexpected error
net.masterthought.cucumber.ValidationException: Passed files have no features!
...
IDE Console O/P:
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 10 source files to C:\Code\project\core\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) # project-core ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.x.y.z.CucumberTests
2020-04-07 13:22:52.330 INFO --- [ main] .b.t.c.SpringBootTestContextBootstrapper : Neither #ContextConfiguration nor #ContextHierarchy found for test class [com.x.y.z.stepdefs.LogVerificationSteps], using SpringBootContextLoader
...
CucumberTests.java:
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(
plugin = {"pretty", "de.monochromata.cucumber.report.PrettyReports:target"},
features = "src/test/resources/features")
public class CucumberTests {
}
This is multi-module maven project, the features are available under:
root
\__core
\__src/test/resources/features/*
So basically in Jenkins features/tests are not being run at all - why is it happening, any idea folks?
Is it possible to override the default deployment naming in jkube? I want to do something similar to the docker image naming where I can provide a pattern.
The deployment section in the resources documentation looked promising but those options are not present in the plugin.
The default naming appears to be the maven ${project.artifactId} but I have not found that documented anywhere. Digging through the code I can see the ResourceConfig is out of sync with the documentation and the examples.
I'm from Eclipse JKube/FMP's development team. I think you should be able to override default controller name by either using jkube.enricher.jkube-controller.name property or by providing XML configuration for jkube-controller (Enricher which is responsible for default Deployment by plugin) like this:
<plugin>
<groupId>org.eclipse.jkube</groupId>
<artifactId>kubernetes-maven-plugin</artifactId>
<version>1.0.0-alpha-1</version>
<configuration>
<enricher>
<config>
<jkube-controller>
<name>some-deployment</name>
</jkube-controller>
</config>
</enricher>
</configuration>
</plugin>
When I tried this, I was able to see Deployment's name being changed as per our configuration:
~/work/repos/eclipse-jkube-demo-project : $ mvn k8s:resource k8s:apply
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< meetup:random-generator >-----------------------
[INFO] Building random-generator 0.0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- kubernetes-maven-plugin:1.0.0-alpha-1:resource (default-cli) # random-generator ---
[INFO] k8s: Running generator spring-boot
[INFO] k8s: spring-boot: Using Docker image fabric8/java-centos-openjdk8-jdk:1.5 as base / builder
[INFO] k8s: jkube-controller: Adding a default Deployment
[INFO] k8s: jkube-service: Adding a default service 'random-generator' with ports [8080]
[INFO] k8s: jkube-healthcheck-spring-boot: Adding readiness probe on port 8080, path='/actuator/health', scheme='HTTP', with initial delay 10 seconds
[INFO] k8s: jkube-healthcheck-spring-boot: Adding liveness probe on port 8080, path='/actuator/health', scheme='HTTP', with initial delay 180 seconds
[INFO] k8s: jkube-revision-history: Adding revision history limit to 2
[INFO]
[INFO] --- kubernetes-maven-plugin:1.0.0-alpha-1:apply (default-cli) # random-generator ---
[INFO] k8s: Using Kubernetes at https://192.168.39.93:8443/ in namespace default with manifest /home/rohaan/work/repos/eclipse-jkube-demo-project/target/classes/META-INF/jkube/kubernetes.yml
[INFO] k8s: Using namespace: default
[INFO] k8s: Creating a Service from kubernetes.yml namespace default name random-generator
[INFO] k8s: Created Service: target/jkube/applyJson/default/service-random-generator.json
[INFO] k8s: Creating a Deployment from kubernetes.yml namespace default name some-deployment
[INFO] k8s: Created Deployment: target/jkube/applyJson/default/deployment-some-deployment.json
[INFO] k8s: HINT: Use the command `kubectl get pods -w` to watch your pods start up
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.076 s
[INFO] Finished at: 2020-04-03T16:57:04+05:30
[INFO] ------------------------------------------------------------------------
~/work/repos/eclipse-jkube-demo-project : $ kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
some-deployment 0/1 1 0 8s
~/work/repos/eclipse-jkube-demo-project : $ kubectl get pods
NAME READY STATUS RESTARTS AGE
some-deployment-97495447b-z9p48 0/1 Running 0 15s
I would like to complete Maven build lifecycle after wildfly:run goal's execution.
The fact is that wildfly:run goal starts a standalone application server and from that point the CLI shows Wildfly's Log messages only.
[INFO] --- wildfly-maven-plugin:2.1.0.Beta1-SNAPSHOT:run (default) # PrimeFaces1 ---
[WARNING] The POM for org.wildfly.plugins:wildfly-plugin-core:jar:2.1.0.Beta1-SNAPSHOT is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO] JAVA_HOME : C:\Program Files\Java\jdk1.8.0_201\jre
[INFO] JBOSS_HOME: C:\Users\Consul19\eclipse-workspace\MultiRunTest\PrimeFaces1\target\wildfly-18.0.1.Final
[INFO] JAVA_OPTS : -Xms64m -Xmx512m -Djava.net.preferIPv4Stack=true -Djava.awt.headless=true -Djboss.modules.system.pkgs=org.jboss.byteman
[INFO] Server is starting up. Press CTRL + C to stop the server.
[INFO] JBoss Threads version 2.3.3.Final
[INFO] JBoss Remoting version 5.0.12.Final
[INFO] XNIO version 3.7.2.Final
[INFO] XNIO NIO Implementation Version 3.7.2.Final
[INFO] ELY00001: WildFly Elytron version 1.9.1.Final
13:04:25,585 INFO [org.jboss.modules] (main) JBoss Modules version 1.9.1.Final
13:04:26,228 INFO [org.jboss.msc] (main) JBoss MSC version 1.4.11.Final
13:04:26,248 INFO [org.jboss.threads] (main) JBoss Threads version 2.3.3.Final
13:04:26,472 INFO [org.jboss.as] (MSC service thread 1-2) WFLYSRV0049: WildFly Full 18.0.1.Final (WildFly Core 10.0.3.Final) starting
13:04:27,800 INFO [org.wildfly.security] (ServerService Thread Pool -- 28) ELY00001: WildFly Elytron version 1.10.4.Final
Actually I would like to run next goals but the server takes control of the CLI
Besides, in the pom.xml, I've tried to sobstitute wildfly:run with the wildfly:deploy goal, which deploy the artifact on the local JBOSS server(already started), And in this case the maven build goes on until the end.
[INFO] --- maven-war-plugin:2.2:war (default-war) # PrimeFaces1 ---
[INFO] Packaging webapp
[INFO] Assembling webapp [PrimeFaces1] in [C:\Users\Consul19\eclipse-workspace\MultiRunTest\PrimeFaces1\target\PrimeFaces1-1.0-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\Users\Consul19\eclipse-workspace\MultiRunTest\PrimeFaces1\src\main\webapp]
[INFO] Webapp assembled in [128 msecs]
[INFO] Building war: C:\Users\Consul19\eclipse-workspace\MultiRunTest\PrimeFaces1\target\PrimeFaces1-1.0-SNAPSHOT.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO]
[INFO] <<< wildfly-maven-plugin:2.1.0.Beta1-SNAPSHOT:deploy (default-cli) < package # PrimeFaces1 <<<
[INFO]
[INFO]
[INFO] --- wildfly-maven-plugin:2.1.0.Beta1-SNAPSHOT:deploy (default-cli) # PrimeFaces1 ---
[INFO] JBoss Threads version 2.3.3.Final
[INFO] JBoss Remoting version 5.0.12.Final
[INFO] XNIO version 3.7.2.Final
[INFO] XNIO NIO Implementation Version 3.7.2.Final
[INFO] ELY00001: WildFly Elytron version 1.9.1.Final
[INFO]
[INFO] --------------------< com.mkyong.core:PrimeFaces2 >---------------------
[INFO] Building PrimeFaces2 1.0-SNAPSHOT [3/3]
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] >>> wildfly-maven-plugin:2.1.0.Beta1-SNAPSHOT:deploy (default-cli) > package # PrimeFaces2 >>>
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) # PrimeFaces2 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Consul19\eclipse-workspace\MultiRunTest\PrimeFaces2\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # PrimeFaces2 ---
[INFO] Nothing to compile - all classes are up to date
As you can see in this case the deploy goal doesn't "lock" the CLI but the build process still continues until the end
This behaviour is expected for the wildfly:run command, you're supposed to interrupt the server from the outside once you're done testing. Quoting the goal's documentation,
This goal will block until cancelled or a shutdown is invoked from a management client.
If that doesn't suit you, you can instead use wildlfy:start followed by wildfly:deploy.
I used the getting-started-project from the quarkus quickstart and compiled it. I started it with ./mvnw compile quarkus:dev. However, it starts after about 1.495s. In the documentation it is reached in about 0.668s. So in my case it is about 2 times slower than documented in the quarkus website. Btw, I restarted it a few times to check if it will be faster without changing/compiling any file. However, it starts always about 1.495s. Why the big difference?
[INFO] ----------------------< org.acme:getting-started >----------------------
[INFO] Building getting-started 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # getting-started ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # getting-started ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- quarkus-maven-plugin:1.0.0.Final:dev (default-cli) # getting-started ---
Listening for transport dt_socket at address: 5005
2019-11-27 13:11:13,904 INFO [io.quarkus] (main) Quarkus 1.0.0.Final started in 1.495s. Listening on: http://0.0.0.0:8080
2019-11-27 13:11:13,923 INFO [io.quarkus] (main) Profile dev activated. Live Coding activated.
2019-11-27 13:11:13,924 INFO [io.quarkus] (main) Installed features: [cdi, resteasy]
My machine: JDK 12 / MacBook 2018 / RAM: 16GB
I already set my hosts file by https://thoeni.io/post/macos-sierra-java/.
Methodology for start times shown on the website is documented here: https://quarkus.io/guides/performance-measure#how-do-we-measure-startup-time. It is important to note that the advertised start time measurements are from starting the application to processing the first request. First request time is not represented in the Info log message.
There are a large number of factors that influence the absolute start times observed, including (but not limited to) platform O/S, CPU specification, Java version, GC implementation, power management, hostname resolution etc.
It is unlikely that you will observe the same absolute start times, it is also possible to observe better start times than have been measured on our lab environment.
What is important to note in the start times displayed on the home page of the website is the difference between startup times for different deployment scenarios; more importantly the relative speed up from other frameworks.
I am tryinf a apporach to run a single test method from commandline using maven or either Junit. My project is build in Junit Framework with Maven.
I have parallel execution in place to run methods in parallel. When I try to run this from commandline, it is still running all testmenthds in parallel.
mvn -Dtest=<Classname>#<testmethodname> test
Would anyone help, how to acheive to run single testmethod or sepcific test methods from commandline.
Versions:
junit - 4.9
maven-compiler-plugin - 2.5.1
maven-surefire-plugin - 2.8
this is log for refrence
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building <ProjectName> 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) # ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) # ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.8:test (default-test) # ---
[INFO] Surefire report directory: C:\Automation\......\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Concurrency config is parallel='methods', perCoreThreadCount=false, threadCount=6, useUnlimitedThreads=false
Destroying 1 processes
Destroying process..
Destroyed 1 processes
Terminate batch job (Y/N)?
Spelling mistake spotted buddy, correct one is -Dtest and not -DTest
mvn -Dtest=<Classname>#<testmethodname> test
Additionally, as you are already running multiple tests in parallel, you can also use below mentioned pattern to execute like test methods.
Example:
mvn -Dtest=Classname#testMethod1+testMethod2+testMethod3 test
Enjoy... ;)
The surefire parameter for excuting a single test is test not Test so you should invoke the following Maven command:
mvn -Dtest=<ClassName>#<TestMethodName> test
For example, given ...
A test FooTest with a test method: foo()
A test BarTest with a test method: bar()
... you could invoke the following:
Run FooTest.foo()
mvn -Dtest=FooTest#foo test
Run FooTest.foo() and BarTest.bar()
mvn -Dtest=FooTest#foo,FooTest#bar test