Using jacoco agent inside container with tcpserver but getting connection refused

779 views
Skip to first unread message

deep...@gmail.com

unread,
Nov 20, 2018, 2:43:50 AM11/20/18
to JaCoCo and EclEmma Users
Hi,
I am using jacoco in tcp server mode to collect coverage data for integration tests. To launch my application, I use the following jvm argument
"-Djavaagent:org.jacoco.agent-0.8.2.jar=output=tcpserver,port=36302,address=*"


The application launches fine but when I try connecting to the port 36302 on ip 127.0.0.1, inisde the container, I get connection refused. What am I doing incorrect here ?

Connecting to 127.0.0.1 PORT:6300
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:244)
at ExecutionDataClient.main(ExecutionDataClient.java:29)

-------------------------

I am using ExecutionDataClient to dump data
public static void main(final String[] args) throws IOException {
String address = (String) args[0];
int port = Integer.parseInt(args[1]);
final FileOutputStream localFile = new FileOutputStream(DESTFILE);
final ExecutionDataWriter localWriter = new ExecutionDataWriter(
localFile);

// Open a socket to the coverage agent:
System.out.println("Connecting to " + address + " PORT:" + port );
// final Socket socket = new Socket(InetAddress.getByName(address), port);
final Socket socket = new Socket(InetAddress.getByName(address), port);
final RemoteControlWriter writer = new RemoteControlWriter(
socket.getOutputStream());
final RemoteControlReader reader = new RemoteControlReader(
socket.getInputStream());
reader.setSessionInfoVisitor(localWriter);
reader.setExecutionDataVisitor(localWriter);

// Send a dump command and read the response:
writer.visitDumpCommand(true, false);
if (!reader.read()) {
throw new IOException("Socket closed unexpectedly.");
}

socket.close();
localFile.close();
}

Evgeny Mandrikov

unread,
Nov 20, 2018, 3:40:11 AM11/20/18
to JaCoCo and EclEmma Users
Hi,


On Tuesday, November 20, 2018 at 8:43:50 AM UTC+1, deep...@gmail.com wrote:
Hi,
     I am using jacoco in tcp server mode to collect coverage data for integration tests.  To launch my application, I use the following jvm argument
"-Djavaagent:org.jacoco.agent-0.8.2.jar=output=tcpserver,port=36302,address=*"


The application launches fine but when I try connecting to the port 36302 on ip 127.0.0.1, inisde the container, I get connection refused. What am I doing incorrect here ?



Before even trying "output=tcpserver" please make sure that default "output=file" works.

Deepti Sogani

unread,
Nov 20, 2018, 4:53:56 PM11/20/18
to jac...@googlegroups.com
Thanks so much Evgeny. That was indeed the core issue. I am able to get data now.
For the interested folks, the org.jacoco.agent-0.8.2.jar gives out errors so use the org.jacoco.agent-0.8.2-runtime.jar (pointed out in another thread in this group).
The jar can be found here: https://repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/0.8.2/



--
You received this message because you are subscribed to a topic in the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jacoco/PGMmFF0I2y8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/e1ce9e37-ba57-4d1b-b3d7-75119cf601a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages