Can I run Jacoco against multiple WAR files in a docker container?

1,156 views
Skip to first unread message

Michael Furmaniuk

unread,
Feb 19, 2017, 10:38:36 AM2/19/17
to JaCoCo and EclEmma Users
I'd like to capture some code coverage in our setup, that uses Docker to run our environment locally.  We have one called AppServer that runs Tomcat.

Can I run Jacoco with the tcpserver option in Tomcat, load the WAR files, then connect and download the report?  I've been able to get Tomcat up and running with Jacoco loading through the Dockerfile, connecting to the tcpserver port 6300 the agent only ever downloads 44 bytes of data, which looks only to be the localhost name and not much else.

Should this configuration work, or is Jacoco going to be limited to what it will capture with Tomcat?

Evgeny Mandrikov

unread,
Feb 19, 2017, 4:09:43 PM2/19/17
to JaCoCo and EclEmma Users
Yes, it should work. The same way it works without container.

Michael Furmaniuk

unread,
Feb 21, 2017, 2:59:15 PM2/21/17
to JaCoCo and EclEmma Users
Is there a particular way to access the tcpserver?  I have a docker profile setup where I can see the port LISTENing in the docker VM, with a balancer in the VM set with a 6300 port using tcp.  So I should be able to access it.

My Catalina Opt is set as:

-javaagent:/data/shared/jacoco/lib/jacocoagent.jar=includes=*,output=tcpserver,address=*,port=6300


With the Report Agent as:

java -javaagent:./lib/jacocoagent.jar=port=6300,address=*,destfile=/jacoco/reports/jacoco.exec


Whenever I run the Report Agent the exec file is 44 bytes and seems to have nothing more than the localhost name and some binary data.

Evgeny Mandrikov

unread,
Feb 21, 2017, 5:23:10 PM2/21/17
to JaCoCo and EclEmma Users
I don't know what you mean by "Report Agent" - your second command prints usage instructions for "java" command, 44 bytes - is an empty coverage session that only contains name of a session.

You need to explicitly request dump. For example using Ant task - http://www.jacoco.org/jacoco/trunk/doc/ant.html#dump

Michael Furmaniuk

unread,
Feb 21, 2017, 7:42:57 PM2/21/17
to JaCoCo and EclEmma Users
I'm using the Java Agent on the command line to get my report - http://www.jacoco.org/jacoco/trunk/doc/agent.html

  • TCP Socket Server: External tools can connect to the JVM and retrieve execution data over the socket connection. Optional execution data reset and execution data dump on VM exit is possible.
I thought making the request, with my second command, would generate the dump

Evgeny Mandrikov

unread,
Feb 22, 2017, 2:51:50 AM2/22/17
to JaCoCo and EclEmma Users
As was said earlier - second command does not make a request.

Either use integration with build tool to request dump -  see for example Ant Task dump at http://www.jacoco.org/jacoco/trunk/doc/ant.html , Maven goal dump at http://www.jacoco.org/jacoco/trunk/doc/maven.html , either do it programmatically by youself - see ExecutionDataClient example at http://www.jacoco.org/jacoco/trunk/doc/api.html

Either use standard output to file instead of "tcpserver" mode and simply copy it from container at the end of container execution before you destroy it.

Michael Furmaniuk

unread,
Feb 23, 2017, 8:57:23 AM2/23/17
to JaCoCo and EclEmma Users
Is there a reason why the JacocoAgent.jar is included in the archive if it is not usable in this way?

The http://www.jacoco.org/jacoco/trunk/doc/agent.html pages notes that we can use it against a tcpserver to obtain the report file, after fighting with this I did end up using the ExecutionDataClient example to finally get a report out.  So, thank you for that!

At this point I am just curious as to what the use of the jar file is.

Evgeny Mandrikov

unread,
Feb 23, 2017, 1:51:22 PM2/23/17
to JaCoCo and EclEmma Users
On Thursday, February 23, 2017 at 2:57:23 PM UTC+1, Michael Furmaniuk wrote:
Is there a reason why the JacocoAgent.jar is included in the archive if it is not usable in this way?

jacocoagent.jar is a Java agent that performs instrumentation. If it will not be provided, then how you'll execute your first command? ;)

The http://www.jacoco.org/jacoco/trunk/doc/agent.html pages notes that we can use it against a tcpserver to obtain the report file,

There is no such statement. There are statements that were misinterpreted by you and I think you're the first one in this ;)
tcpserver = collect data and write it to client, when it connects (note - not another agent, but some client)
tcpclient = collect data and write it to specified server (note - not another agent, but some server)

There is no single word "read" on this page - all the words are "write".

Also to be precise: agent does not give you a report, but data (in an internal binary format) that then used to generate report.

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