Search in sources :

Example 1 with AgentOptions

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

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

the class TcpServerOutputTest method setup.

@Before
public void setup() throws Exception {
    options = new AgentOptions();
    logger = new ExceptionRecorder();
    serverSocket = new MockServerSocket();
    controller = new TcpServerOutput(logger) {

        @Override
        protected ServerSocket createServerSocket(AgentOptions options) throws IOException {
            return serverSocket;
        }
    };
    data = new RuntimeData();
    controller.startup(options, data);
}
Also used : RuntimeData(org.jacoco.core.runtime.RuntimeData) ExceptionRecorder(org.jacoco.agent.rt.internal.ExceptionRecorder) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) AgentOptions(org.jacoco.core.runtime.AgentOptions) Before(org.junit.Before)

Example 3 with AgentOptions

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

the class PreMain method premain.

/**
 * This method is called by the JVM to initialize Java agents.
 *
 * @param options
 *            agent options
 * @param inst
 *            instrumentation callback provided by the JVM
 * @throws Exception
 *             in case initialization fails
 */
public static void premain(final String options, final Instrumentation inst) throws Exception {
    final AgentOptions agentOptions = new AgentOptions(options);
    final Agent agent = Agent.getInstance(agentOptions);
    final IRuntime runtime = createRuntime(inst);
    runtime.startup(agent.getData());
    inst.addTransformer(new CoverageTransformer(runtime, agentOptions, IExceptionLogger.SYSTEM_ERR));
}
Also used : AgentOptions(org.jacoco.core.runtime.AgentOptions) IRuntime(org.jacoco.core.runtime.IRuntime)

Example 4 with AgentOptions

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

the class AgentTest method shutdown_should_log_exception.

@Test
public void shutdown_should_log_exception() throws Exception {
    final Exception expected = new Exception();
    Agent agent = new Agent(options, this) {

        @Override
        IAgentOutput createAgentOutput() {
            return new IAgentOutput() {

                public void startup(AgentOptions options, RuntimeData data) {
                }

                public void shutdown() throws Exception {
                    throw expected;
                }

                public void writeExecutionData(boolean reset) {
                }
            };
        }
    };
    agent.startup();
    agent.shutdown();
    assertSame(expected, loggedException);
}
Also used : RuntimeData(org.jacoco.core.runtime.RuntimeData) IAgentOutput(org.jacoco.agent.rt.internal.output.IAgentOutput) IOException(java.io.IOException) InstanceNotFoundException(javax.management.InstanceNotFoundException) AgentOptions(org.jacoco.core.runtime.AgentOptions) Test(org.junit.Test)

Example 5 with AgentOptions

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

the class AgentTest method setup.

@Before
public void setup() {
    options = new AgentOptions();
    options.setOutput(OutputMode.file);
    // avoid network access (DNS lookup for id generation):
    options.setSessionId("test");
}
Also used : AgentOptions(org.jacoco.core.runtime.AgentOptions) Before(org.junit.Before)

Aggregations

AgentOptions (org.jacoco.core.runtime.AgentOptions)11 RuntimeData (org.jacoco.core.runtime.RuntimeData)7 Test (org.junit.Test)5 IOException (java.io.IOException)4 Before (org.junit.Before)4 FileOutput (org.jacoco.agent.rt.internal.output.FileOutput)3 File (java.io.File)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 ExceptionRecorder (org.jacoco.agent.rt.internal.ExceptionRecorder)2 IAgentOutput (org.jacoco.agent.rt.internal.output.IAgentOutput)2 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1 MockSocket (org.jacoco.agent.rt.internal.output.MockSocketConnection.MockSocket)1 IRuntime (org.jacoco.core.runtime.IRuntime)1 RemoteControlReader (org.jacoco.core.runtime.RemoteControlReader)1 RemoteControlWriter (org.jacoco.core.runtime.RemoteControlWriter)1