Search in sources :

Example 1 with RemoteControlWriter

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

the class TcpConnectionTest method testRemoteReset.

@Test
public void testRemoteReset() throws Exception {
    data.getExecutionData(Long.valueOf(123), "Foo", 1).getProbes()[0] = true;
    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(false, true);
    final RemoteControlReader remoteReader = new RemoteControlReader(mockConnection.getSocketB().getInputStream());
    final ExecutionDataStore execStore = new ExecutionDataStore();
    remoteReader.setExecutionDataVisitor(execStore);
    final SessionInfoStore infoStore = new SessionInfoStore();
    remoteReader.setSessionInfoVisitor(infoStore);
    assertTrue(remoteReader.read());
    assertTrue(infoStore.getInfos().isEmpty());
    assertTrue(execStore.getContents().isEmpty());
    assertFalse(data.getExecutionData(Long.valueOf(123), "Foo", 1).getProbes()[0]);
    con.close();
    f.get();
}
Also used : RemoteControlWriter(org.jacoco.core.runtime.RemoteControlWriter) ExecutionDataStore(org.jacoco.core.data.ExecutionDataStore) SessionInfoStore(org.jacoco.core.data.SessionInfoStore) IOException(java.io.IOException) RemoteControlReader(org.jacoco.core.runtime.RemoteControlReader) Test(org.junit.Test)

Example 2 with RemoteControlWriter

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

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

the class TcpConnection method init.

public void init() throws IOException {
    this.writer = new RemoteControlWriter(socket.getOutputStream());
    this.reader = new RemoteControlReader(socket.getInputStream());
    this.reader.setRemoteCommandVisitor(this);
    this.initialized = true;
}
Also used : RemoteControlWriter(org.jacoco.core.runtime.RemoteControlWriter) RemoteControlReader(org.jacoco.core.runtime.RemoteControlReader)

Example 4 with RemoteControlWriter

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

the class TcpClientOutputTest method setup.

@Before
public void setup() throws Exception {
    logger = new ExceptionRecorder();
    final MockSocketConnection con = new MockSocketConnection();
    localSocket = con.getSocketA();
    remoteSocket = con.getSocketB();
    remoteWriter = new RemoteControlWriter(remoteSocket.getOutputStream());
    controller = new TcpClientOutput(logger) {

        @Override
        protected Socket createSocket(AgentOptions options) throws IOException {
            return localSocket;
        }
    };
    data = new RuntimeData();
    controller.startup(new AgentOptions(), data);
    remoteReader = new RemoteControlReader(remoteSocket.getInputStream());
}
Also used : RemoteControlWriter(org.jacoco.core.runtime.RemoteControlWriter) RuntimeData(org.jacoco.core.runtime.RuntimeData) ExceptionRecorder(org.jacoco.agent.rt.internal.ExceptionRecorder) IOException(java.io.IOException) AgentOptions(org.jacoco.core.runtime.AgentOptions) Socket(java.net.Socket) MockSocket(org.jacoco.agent.rt.internal.output.MockSocketConnection.MockSocket) RemoteControlReader(org.jacoco.core.runtime.RemoteControlReader) Before(org.junit.Before)

Example 5 with RemoteControlWriter

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

the class TcpServerOutputTest method testWriteExecutionData.

@Test
public void testWriteExecutionData() throws Exception {
    data.getExecutionData(Long.valueOf(0x12345678), "Foo", 42).getProbes()[0] = true;
    data.setSessionId("stubid");
    final Socket socket = serverSocket.connect();
    final RemoteControlWriter remoteWriter = new RemoteControlWriter(socket.getOutputStream());
    final RemoteControlReader remoteReader = new RemoteControlReader(socket.getInputStream());
    // First process a NOP command to ensure the connection is initialized:
    remoteWriter.visitDumpCommand(false, false);
    remoteReader.read();
    // Now the actual test starts:
    controller.writeExecutionData(false);
    final ExecutionDataStore execStore = new ExecutionDataStore();
    remoteReader.setExecutionDataVisitor(execStore);
    final SessionInfoStore infoStore = new SessionInfoStore();
    remoteReader.setSessionInfoVisitor(infoStore);
    remoteReader.read();
    assertEquals("Foo", execStore.get(0x12345678).getName());
    final List<SessionInfo> infos = infoStore.getInfos();
    assertEquals(1, infos.size());
    assertEquals("stubid", infos.get(0).getId());
    logger.assertNoException();
    controller.shutdown();
}
Also used : RemoteControlWriter(org.jacoco.core.runtime.RemoteControlWriter) ExecutionDataStore(org.jacoco.core.data.ExecutionDataStore) SessionInfo(org.jacoco.core.data.SessionInfo) SessionInfoStore(org.jacoco.core.data.SessionInfoStore) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) RemoteControlReader(org.jacoco.core.runtime.RemoteControlReader) Test(org.junit.Test)

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