Tomcat crashes after setting environment for Jacoco Agent - spring-boot

I have a simple Spring boot application having some REST API's exposed.
I want to test the coverage for code by calling the these rest endpoints from of my testcases, below are the constraints for me:
The application is running on a remote machine, inside tomcat.
My prefered way is to use Jacoco to generate the coverage report
with maven-surefire or maven-failsafe plugins.
Currently, I'm trying to attach jacoco agent to Tomcat (where my application is deployed).
Below are the variables that I'm setting in setenv file in tomcat:
SET JACOCO= -javaagent:"C:\packages\jars\org.jacoco.agent-0.7.5.201505241946.jar"=destfile="C:\jacoco.exec",append=true,includes=*
SET JAVA_OPTS=%JAVA_OPTS% %JACOCO%
But, when I try to start tomcat with this configuration it crashes without any logs, can anyone suggest any other way to generate the coverage for remotely running application?

Related

Calling self's API on application Restart(Grails 3.3.9) (Tomcat Restart)

While building a grails 3.3.9 application, I've encountered a scenario where I need to call its own API on application restart (for a specific purpose). I long as I know we can't make an API calls via boostrap.groovy, So an alternate option I found the Application.main method from where I can make own API calls.
But this is only working on Grails - run mode. I need to make this working on Grails - war mode-as I have to deploy the war in the production environment once it verified in QC.
I can have the cron setup to do this but I am looking for the grails inbuilt function.
Others information:
Grails:3.3.9
Gradle:4.10.3
Tomcat 8.5.50

Pass command-line argument for a particular Tomcat web-application startup

For my Spring-Boot project, I have used jasypt library for encrypting my datasource.password in application.properties file. In my localhost setup, I have configured VM arguments in eclipse and it works completely fine.
-Djasypt.encryptor.password
-Djasypt.encryptor.algorithm
Now, I want to deploy my application to Tomcat server where I am not able to figure out where to configure these VM arguments so that Tomcat picks them when I click on "start" button from Tomcat Manager GUI.
Read solutions about setenv.sh but I think that works at complete Tomcat server level. I need to pass these arguments only for my current application without affecting other applications which are already hosted.
Any help is appreciated.

Running jacoco report where integration tests are in one code base and source code is in another code base

I recently started working on creating jacoco reports for maven projects including unit and integration tests and they seem to work out correctly.
Now I have encountered a different scenario which I am not sure how to approach.
I have one workspace which consists of integration test cases - application A, but the source code does not exist in the same workspace/code base. The source code which actually runs on invoking these integration test scripts are in a different workspace/code base - application B(they are invoked using rest api calls with the localhost urls. The jboss server is started for application B so that the localhost context is up) from the integration tests.
The aim is to invoke these integration tests from application A, which in turn calls the source code of these tests in application B generating the jacoco report of the code coverage for application B.
I am not actually sure how to achieve this.
Can someone provide some input.
Thanks.
If I understand you correctly, you actually have 2 different processes in your scenario:
The "client" process that runs the integration tests and for which jacoco can be easily applied, but it's not what you need
The "server" process that runs the actual JBoss server and executes the actual code.
Client process contacts the server via HTTP.
In this case, I'm afraid jacoco won't be able to provide a coverage for you if you're running the tests from maven/gradle, because jacoco instruments only bytecode on the running JVM. So you have to be "creative" here :)
I'll list here some possible approaches
Disclaimer: I haven't tried them though (didn't work with jboss/java ee), but maybe you'll be able to at least borrow some ideas
The first approach would be running the tests together with the application somehow, like its done for example in spring tests (I'm not sure whether JBoss provides similar capabilities).
The idea is simple:
You run the integration test, it runs the jboss "embedded in the same jvm" and you can inject beans / EJB session beans into the test (like autowiring with spring).
The advantage of such a method is that you'll be able just to use jacoco maven plugin and it will instrument everything for you
I don't know how easy will be achieving this architecture technically, I know that recent jboss versions support embedded mode, So maybe you'll find This link to be a useful foundation
Another direction is to take a look at Arquillian project. They have some jacoco extension that probably will help, but I've never tried it.
And the last approach I can think of is running the jboss server with jacoco agent directly instead of relying on the build system that runs jacoco for you.
The idea here is to stream the results of covered server code into some file / tcp endpoint. So you run the jboss with -javaagent:[yourpath/]jacocoagent.jar and it starts streaming the results wherever you need it to stream. After the tests you should gather these results and prepare a report. You can find Here more information about this approach

Arquillian: how to run a test without packaging/deploy/start/stop tomcat

I'm wrinting a junit test with #RunWith(Arquillian.class) annotation like described in https://docs.jboss.org/author/display/ARQ/Drone
While writing the test I would like to rin it without wait package war, start tomcat, deploy war, stop tomcat each time.
I run test inside eclipse and I can run tomcat with my web application once and run test multiple times inside the IDE.
Is there any parameter to let Arquillian use an already deployed and running application, without change the source of my test class?
Nope.
Arquillian is about creating deployable archive and testing it inside true server container.
By the way: if you are looking for ways to speed up your development, then take look at tomcat remote adapter. Generally with remote adapter you don't have server startup for each test launch. Just start it manually once.

How to run web applications using jersey in an easy way?

I created a web application using Jersey through this maven code:
mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-webapp \
-DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false \
-DgroupId=com.example -DartifactId=simple-service-webapp -Dpackage=com.example \
-DarchetypeVersion=2.4.1
And I am using Tomcat v7 as my Java server. When I finish writing some code, I use mvn's package command to generate a .war file, copy this file to the /webapps folder and then start tomcat to run my application and test it on browser. But I think I waste lots of time doing these things. So I want to ask if there is an easier way test my code on browsers. How do you guys run your web applications, especially Jersey app, on your server?
And I am using Intellij Idea, does it have some features that help me build and run Jersey apps, or other J2EE apps? how to use them?
In IntelliJ IDEA you can create a Tomcat Run/Debug configuration. In that configuration you can specify "before launch" tasks/options, including running a maven goal. So by running the Tomcat configuration, IDEA will run the maven goal, deploy your code to Tomcat, start the tomcat server, and (if desired) open you web browser to a specified page.
JetBrains has a Getting Started with Spring MVC, Hibernate and JSON tutorial. What you want to do is very similar. The main difference is you will need to remove the default "make" option in the "Before Launch" section at the bottom of the run/debug configuration and instead have it run your maven task.
There is also the Creating a simple Web application and deploying it to Tomcat tutorial. It's a little older and some of the options on the run/debug dialog have changed. But at the core, its still valid. Combined with the above, you should be in good shape.
Finally take a look at the Run/Debug Configuration: Tomcat page in the help guide (also available in the online webhelp).

Resources