Hello,

All our micro-services are sending execution data to the same socket server 
and on the same port. These are the Jacoco agent parameters we are setting. 

java -javaagent:$PWD/coverage/jacocoagent.jar=output=tcpclient,destfile=$PWD
/jacoco-server.exec,includes=*,address=1XX.XX.XX.XX,port=6300


We are running given ExecutionDataServer.java class from address=1XX.XX.XX.
XX machine which listens for incoming execution data.

First, Could you please tell me, is it a good practice to collect execution 
data from multiple services to the same server socket?

If yes, Then are we missed anything in below ExecutionDataServer class? as 
we are missing coverage from some of the services.

When we start services, we get "Retrieving execution Data for session: 
<SERVICE_NAME>" log in ExecutionDataServer's class output for all services. 
But then we are not getting this log statement again even though we hit the 
code of that service.

Please help.

public final class ExecutionDataServer {

    private static String DESTFILE = "jacoco-server.exec";

    private static String ADDRESS = "localhost";

    private static int PORT = 6300;

    /**
     * Start the server as a standalone program.
     * 
     * @param args
     * @throws IOException
     */
    public static void main(final String[] args) throws IOException {
        final ExecutionDataWriter fileWriter = new ExecutionDataWriter(new 
FileOutputStream(DESTFILE));
        final ServerSocket server = new ServerSocket(PORT, 0, 
InetAddress.getByName(ADDRESS));
        while (true) {
            try {
                final Handler handler = new Handler(server.accept(), 
fileWriter);
                new Thread(handler).start();
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println(e.getMessage());
            }
        }
    }

    private static class Handler implements Runnable, ISessionInfoVisitor, 
IExecutionDataVisitor {

        private final Socket socket;

        private final RemoteControlReader reader;

        private final RemoteControlWriter writer;

        private final ExecutionDataWriter fileWriter;

        Handler(final Socket socket, final ExecutionDataWriter fileWriter) 
throws IOException {
            this.socket = socket;
            this.fileWriter = fileWriter;

            // Just send a valid header:
            writer = new RemoteControlWriter(socket.getOutputStream());

            reader = new RemoteControlReader(socket.getInputStream());
            reader.setSessionInfoVisitor(this);
            reader.setExecutionDataVisitor(this);
        }

        public void run() {
            try {
                writer.visitDumpCommand(true, false);
                while (reader.read()) {
                }
                socket.close();
                synchronized (fileWriter) {
                    fileWriter.flush();
                }
            } catch (final IOException e) {
                e.printStackTrace();
            }
        }

        public void visitSessionInfo(final SessionInfo info) {
            System.out.printf("Retrieving execution Data for session: 
%s%n", info.getId());
            synchronized (fileWriter) {
                fileWriter.visitSessionInfo(info);
            }
        }

        public void visitClassExecution(final ExecutionData data) {
            synchronized (fileWriter) {
                fileWriter.visitClassExecution(data);
            }
        }
    }

    private ExecutionDataServer() {
    }
}


-- 
You received this message because you are subscribed to the Google Groups 
"JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jacoco/34854dc9-1a80-4019-bfd2-8b0571d9a993%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to