Search in sources :

Example 6 with RemoteControlReader

use of org.jacoco.core.runtime.RemoteControlReader in project jacoco by jacoco.

the class DumpTest method serveRequest.

private void serveRequest(Socket socket) throws IOException {
    final RemoteControlWriter writer = new RemoteControlWriter(socket.getOutputStream());
    final RemoteControlReader reader = new RemoteControlReader(socket.getInputStream());
    reader.setRemoteCommandVisitor(new IRemoteCommandVisitor() {

        public void visitDumpCommand(boolean dump, boolean reset) throws IOException {
            writer.sendCmdOk();
        }
    });
    while (reader.read()) {
    }
}
Also used : RemoteControlWriter(org.jacoco.core.runtime.RemoteControlWriter) IRemoteCommandVisitor(org.jacoco.core.runtime.IRemoteCommandVisitor) IOException(java.io.IOException) RemoteControlReader(org.jacoco.core.runtime.RemoteControlReader)

Example 7 with RemoteControlReader

use of org.jacoco.core.runtime.RemoteControlReader in project jacoco by jacoco.

the class ExecDumpClientTest method handleConnection.

private void handleConnection(Socket socket) throws IOException {
    final RemoteControlWriter writer = new RemoteControlWriter(socket.getOutputStream());
    final RemoteControlReader reader = new RemoteControlReader(socket.getInputStream());
    reader.setRemoteCommandVisitor(new IRemoteCommandVisitor() {

        public void visitDumpCommand(boolean dump, boolean reset) throws IOException {
            dumpRequested = dump;
            resetRequested = reset;
            if (dump) {
                writer.visitSessionInfo(new SessionInfo("TestId", 100, 200));
            }
            writer.sendCmdOk();
        }
    });
    reader.read();
}
Also used : RemoteControlWriter(org.jacoco.core.runtime.RemoteControlWriter) IRemoteCommandVisitor(org.jacoco.core.runtime.IRemoteCommandVisitor) SessionInfo(org.jacoco.core.data.SessionInfo) IOException(java.io.IOException) RemoteControlReader(org.jacoco.core.runtime.RemoteControlReader)

Example 8 with RemoteControlReader

use of org.jacoco.core.runtime.RemoteControlReader in project jacoco by jacoco.

the class ExecDumpClient method dump.

/**
 * Requests a dump from the given end-point.
 *
 * @param address
 *            host name or IP-Address to connect to
 * @param port
 *            port to connect to
 * @return container for the dumped data
 * @throws IOException
 *             in case the dump can not be requested
 */
public ExecFileLoader dump(final InetAddress address, final int port) throws IOException {
    final ExecFileLoader loader = new ExecFileLoader();
    final Socket socket = tryConnect(address, port);
    try {
        final RemoteControlWriter remoteWriter = new RemoteControlWriter(socket.getOutputStream());
        final RemoteControlReader remoteReader = new RemoteControlReader(socket.getInputStream());
        remoteReader.setSessionInfoVisitor(loader.getSessionInfoStore());
        remoteReader.setExecutionDataVisitor(loader.getExecutionDataStore());
        remoteWriter.visitDumpCommand(dump, reset);
        if (!remoteReader.read()) {
            throw new IOException("Socket closed unexpectedly.");
        }
    } finally {
        socket.close();
    }
    return loader;
}
Also used : RemoteControlWriter(org.jacoco.core.runtime.RemoteControlWriter) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) Socket(java.net.Socket) RemoteControlReader(org.jacoco.core.runtime.RemoteControlReader)

Example 9 with RemoteControlReader

use of org.jacoco.core.runtime.RemoteControlReader in project jacoco by jacoco.

the class ExecutionDataClient method main.

/**
 * Starts the execution data request.
 *
 * @param args
 * @throws IOException
 */
public static void main(final String[] args) throws IOException {
    final FileOutputStream localFile = new FileOutputStream(DESTFILE);
    final ExecutionDataWriter localWriter = new ExecutionDataWriter(localFile);
    // Open a socket to the coverage agent:
    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();
}
Also used : RemoteControlWriter(org.jacoco.core.runtime.RemoteControlWriter) FileOutputStream(java.io.FileOutputStream) ExecutionDataWriter(org.jacoco.core.data.ExecutionDataWriter) IOException(java.io.IOException) Socket(java.net.Socket) RemoteControlReader(org.jacoco.core.runtime.RemoteControlReader)

Aggregations

RemoteControlReader (org.jacoco.core.runtime.RemoteControlReader)9 RemoteControlWriter (org.jacoco.core.runtime.RemoteControlWriter)8 IOException (java.io.IOException)6 Socket (java.net.Socket)4 ExecutionDataStore (org.jacoco.core.data.ExecutionDataStore)3 SessionInfo (org.jacoco.core.data.SessionInfo)3 SessionInfoStore (org.jacoco.core.data.SessionInfoStore)3 IRemoteCommandVisitor (org.jacoco.core.runtime.IRemoteCommandVisitor)2 Test (org.junit.Test)2 FileOutputStream (java.io.FileOutputStream)1 InterruptedIOException (java.io.InterruptedIOException)1 ServerSocket (java.net.ServerSocket)1 ExceptionRecorder (org.jacoco.agent.rt.internal.ExceptionRecorder)1 MockSocket (org.jacoco.agent.rt.internal.output.MockSocketConnection.MockSocket)1 ExecutionDataWriter (org.jacoco.core.data.ExecutionDataWriter)1 AgentOptions (org.jacoco.core.runtime.AgentOptions)1 RuntimeData (org.jacoco.core.runtime.RuntimeData)1 Before (org.junit.Before)1