JBoss Application Server Jacoco Coverage

918 views
Skip to first unread message

leonc...@gmail.com

unread,
Nov 29, 2016, 3:53:21 AM11/29/16
to JaCoCo and EclEmma Users
Hi,

I have a remote application running on a JBoss server. I'm currently running tests which make REST calls to this service. Is it possible to generate coverage reports of code on the server side?

Regards
Leon

leonc...@gmail.com

unread,
Nov 29, 2016, 4:54:28 AM11/29/16
to JaCoCo and EclEmma Users, leonc...@gmail.com
To add on to this question, is it possible to generate the report without having the shutdown the JBoss server?

Marc R. Hoffmann

unread,
Nov 29, 2016, 9:57:02 AM11/29/16
to jac...@googlegroups.com
Hi Leon,

this szenario is supported by JaCoCo. You need to configure the JaCoCo
agent for your application server, see documentation:

http://www.eclemma.org/jacoco/trunk/doc/agent.html

There are several options to retrieve execution data without shutting
down the JBoss server:

1) Enable JMX control and trigger dump via JMX console (or request
execution data directly)
2) configure output=tcpserver and use the Maven goal or Ant task to
retrieve executin data.

Cheers,
-marc

leonc...@gmail.com

unread,
Nov 29, 2016, 9:03:54 PM11/29/16
to JaCoCo and EclEmma Users
Hi Marc,

Thanks for the reply. On the remote server, I've had Jacoco added to my remote application and have a java agent running with this property: javaagent:%DELIVERABLE_HOME%/jacoco/lib/jacocoagent.jar=output=tcpserver,address=*,port=6300,append=true,includes=com.myproject.*

I have an Ant build with the following tasks:

<target name="clean">
<delete dir="${report.dir}" />
</target>

<target name="dump" depends="clean">
<jacoco:dump address="${server.address}" port="${server.port}" reset="true" destfile="${jacocoexec.dir}/${jacocoexec.filename}" dump="true" />
</target>

<target name="coverage_report" depends="dump">
<jacoco:report>
<executiondata>
<file file="${jacoco.exec.file}" />
</executiondata>
<structure name="JaCoCo Ant Coverage Reports">
<classfiles>
<fileset dir="${instrumented.classes.dir}" includes="**/*.class" />
</classfiles>

<!-- Jacoco Source Files -->
<sourcefiles encoding="UTF-8">
<fileset dir="./coverage_output/source_dir/projects/myprojects/src/main/java" />
<fileset dir="./coverage_output/source_dir/projects/myprojects2/src/main/java" />
</sourcefiles>
</structure>
<html destdir="${report.dir}" />
<csv destfile="${report.dir}/report.csv" />
<xml destfile="${report.dir}/report.xml" />
</jacoco:report>
</target>

At the same time, I have a Node server running in the same directory, with the server address pointing to my machine's IP address. When I tried running the report generation Ant task, the generated reports would be empty and the session data is empty as well. Am I doing anything wrong in this case?

Marc R. Hoffmann

unread,
Nov 30, 2016, 1:34:33 AM11/30/16
to jac...@googlegroups.com
Hi Leon,

so the session page on the report (link in the top right corner) is
completely empty, right?

Let's clarify some things first:

- the Ant variables e.g. ${jacoco.exec.file} are properly defined and
point to the right locations?
- Why is the variable ${instrumented.classes.dir} named like this?
JaCoCo needs the original class files for report generation (the exact
same class files as deployed to your app server).

Can you please provide the Ant log output?

Regards,
-marc

leonc...@gmail.com

unread,
Dec 1, 2016, 1:44:46 AM12/1/16
to JaCoCo and EclEmma Users
Hi Marc,

Yes the session page is completely empty.

Yes, the variables are pointing to the right locations. For the original class files, I forgot to mention that I have the java agent running with "classdumpdir=%DELIVERABLE_HOME%/jacoco/class_dumps" on my remote server. I'm running a scp command to retrieve them from the server before running the Ant build, which is pointing to the folder containing the class files.

Here are the Ant logs:
clean:

dump:
[antlib:org.jacoco.ant] Could not load definitions from resource org/jacoco/ant/antlib.xml. It could not be found.
[jacoco:dump] Connecting to /10.238.83.64:6300
[jacoco:dump] Dumping execution data to /Users/lechin/Documents/git-paypal/Hackathon/code_coverage/coverage_output/jacoco/jacoco.exec

BUILD FAILED
/Users/lechin/Documents/git-paypal/Hackathon/code_coverage/build.xml:50: Unable to dump coverage data
at org.jacoco.ant.DumpTask.execute(DumpTask.java:156)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
at org.apache.tools.ant.Main.runBuild(Main.java:854)
at org.apache.tools.ant.Main.startAnt(Main.java:236)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at java.net.SocketInputStream.read(SocketInputStream.java:210)
at java.io.DataInputStream.readByte(DataInputStream.java:265)
at org.jacoco.core.data.ExecutionDataReader.read(ExecutionDataReader.java:82)
at org.jacoco.ant.DumpTask.execute(DumpTask.java:151)
... 16 more

Regards
Leon

Marc Hoffmann

unread,
Dec 1, 2016, 2:21:20 AM12/1/16
to jac...@googlegroups.com
Hi Leon,

as you can see from the stack trace the dump cannot be created. For
whatever reason the TCP connection is disconnected during reading the
dump data. Hard to tell what the reason is:

- Process under test is terminated at the same time?
- Firewall issues?
- At the target port some different service that the JaCoCo agent is
running?

Regards,
-marc

leonc...@gmail.com

unread,
Dec 1, 2016, 3:16:25 AM12/1/16
to JaCoCo and EclEmma Users
Hi Marc,

This is my current scenario. I've been running a test through a TestNG Eclipse plugin. Through the test case, it is hitting my JBoss application via a REST call. Upon termination of the test case, I am performing the Ant build.

Assuming that the target port is available and there are no firewall issues, is this how it supposed to run?

Apologies if it's confusing.

Regards
Leon

Marc Hoffmann

unread,
Dec 1, 2016, 3:33:38 AM12/1/16
to jac...@googlegroups.com
Absolutely. This is exactly how it is supposed to work.

When you use Eclipse anyways you could also connect to you JBoss server
from Eclipse with the import wizzard:

http://www.eclemma.org/userdoc/importexport.html

(Assuming that you deployed JBoss with class files form your Eclipse
workspace)

Regards,
-marc

Marc Hoffmann

unread,
Dec 1, 2016, 3:39:32 AM12/1/16
to jac...@googlegroups.com
BTW, we have an integration test for this scenario which we run with
every build:

https://github.com/jacoco/jacoco/blob/master/org.jacoco.ant.test/src/org/jacoco/ant/DumpTaskWithServerTest.xml

Regards,
-marc

On 2016-12-01 09:16, leonc...@gmail.com wrote:

leonc...@gmail.com

unread,
Dec 6, 2016, 2:48:06 AM12/6/16
to JaCoCo and EclEmma Users
Hi Marc,

Thank you for your replies. I've been trying to get it work and finally found the problem with the report generation. I had to specify the specific address in the javaagent address parameter, which I pointed to the Unix server that my JBoss application was running on.

It was only after I had done that, was I able to obtain a report from running the ant build.

Thank you for your help!

Cheers

Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages