Search in sources :

Example 6 with RemoteControlWriter

use of org.jacoco.core.runtime.RemoteControlWriter 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 7 with RemoteControlWriter

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

the class TcpConnectionTest method testRemoteDump.

@Test
public void testRemoteDump() throws Exception {
    data.getExecutionData(Long.valueOf(0x12345678), "Foo", 42).getProbes()[0] = true;
    data.setSessionId("stubid");
    final RemoteControlWriter remoteWriter = new RemoteControlWriter(mockConnection.getSocketB().getOutputStream());
    final TcpConnection con = new TcpConnection(mockConnection.getSocketA(), data);
    con.init();
    final Future<Void> f = executor.submit(new Callable<Void>() {

        public Void call() throws Exception {
            con.run();
            return null;
        }
    });
    assertBlocks(f);
    remoteWriter.visitDumpCommand(true, false);
    readAndAssertData();
    con.close();
    f.get();
}
Also used : RemoteControlWriter(org.jacoco.core.runtime.RemoteControlWriter) IOException(java.io.IOException) Test(org.junit.Test)

Example 8 with RemoteControlWriter

use of org.jacoco.core.runtime.RemoteControlWriter 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 RemoteControlWriter

use of org.jacoco.core.runtime.RemoteControlWriter 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

RemoteControlWriter (org.jacoco.core.runtime.RemoteControlWriter)9 RemoteControlReader (org.jacoco.core.runtime.RemoteControlReader)8 IOException (java.io.IOException)7 Socket (java.net.Socket)4 Test (org.junit.Test)3 ExecutionDataStore (org.jacoco.core.data.ExecutionDataStore)2 SessionInfo (org.jacoco.core.data.SessionInfo)2 SessionInfoStore (org.jacoco.core.data.SessionInfoStore)2 IRemoteCommandVisitor (org.jacoco.core.runtime.IRemoteCommandVisitor)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