Search in sources :

Example 1 with AgentOptions

use of com.teamscale.jacoco.agent.options.AgentOptions in project teamscale-jacoco-agent by cqse.

the class CoverageToTeamscaleStrategyTest method testValidCallSequence.

@Test
public void testValidCallSequence() throws Exception {
    List<PrioritizableTestCluster> clusters = Collections.singletonList(new PrioritizableTestCluster("cluster", Collections.singletonList(new PrioritizableTest("mytest"))));
    when(client.getImpactedTests(any(), any(), any(), any(), anyBoolean(), anyBoolean(), anyBoolean())).thenReturn(Response.success(clusters));
    TestwiseCoverage testwiseCoverage = getDummyTestwiseCoverage("mytest");
    when(reportGenerator.convert(any(File.class))).thenReturn(testwiseCoverage);
    AgentOptions options = mockOptions();
    JacocoRuntimeController controller = mock(JacocoRuntimeController.class);
    CoverageToTeamscaleStrategy strategy = new CoverageToTeamscaleStrategy(controller, options, reportGenerator);
    strategy.testRunStart(Collections.singletonList(new ClusteredTestDetails("mytest", "mytest", "content", "cluster")), false, true, true, null);
    strategy.testStart("mytest");
    strategy.testEnd("mytest", new TestExecution("mytest", 0L, ETestExecutionResult.PASSED));
    strategy.testRunEnd();
    verify(client).uploadReport(eq(EReportFormat.TESTWISE_COVERAGE), matches("\\Q{\"tests\":[{\"content\":\"content\",\"duration\":\\E[^,]*\\Q,\"paths\":[{\"files\":[{\"coveredLines\":\"1-4\",\"fileName\":\"Main.java\"}],\"path\":\"src/main/java\"}],\"result\":\"PASSED\",\"sourcePath\":\"mytest\",\"uniformPath\":\"mytest\"}]}\\E"), any(), any(), any(), any());
}
Also used : TestwiseCoverage(com.teamscale.report.testwise.model.TestwiseCoverage) ClusteredTestDetails(com.teamscale.client.ClusteredTestDetails) JacocoRuntimeController(com.teamscale.jacoco.agent.JacocoRuntimeController) TestExecution(com.teamscale.report.testwise.model.TestExecution) PrioritizableTestCluster(com.teamscale.client.PrioritizableTestCluster) File(java.io.File) AgentOptions(com.teamscale.jacoco.agent.options.AgentOptions) PrioritizableTest(com.teamscale.client.PrioritizableTest) PrioritizableTest(com.teamscale.client.PrioritizableTest) Test(org.junit.jupiter.api.Test)

Example 2 with AgentOptions

use of com.teamscale.jacoco.agent.options.AgentOptions in project teamscale-jacoco-agent by cqse.

the class TestwiseCoverageAgentTest method testAccessViaTiaClientAndReportUploadToTeamscale.

@Test
public void testAccessViaTiaClientAndReportUploadToTeamscale() throws Exception {
    List<ClusteredTestDetails> availableTests = Arrays.asList(new ClusteredTestDetails("test1", "test1", "content", "cluster"), new ClusteredTestDetails("test2", "test2", "content", "cluster"));
    List<PrioritizableTestCluster> impactedClusters = Collections.singletonList(new PrioritizableTestCluster("cluster", Collections.singletonList(new PrioritizableTest("test2"))));
    when(client.getImpactedTests(any(), any(), any(), any(), anyBoolean(), anyBoolean(), anyBoolean())).thenReturn(Response.success(impactedClusters));
    when(reportGenerator.convert(any(File.class))).thenReturn(CoverageToTeamscaleStrategyTest.getDummyTestwiseCoverage("test2"));
    int port = PORT_COUNTER.incrementAndGet();
    AgentOptions options = mockOptions(port);
    when(options.createTempFile(any(), any())).thenReturn(new File(tempDir, "test"));
    new TestwiseCoverageAgent(options, null, reportGenerator);
    TiaAgent agent = new TiaAgent(false, HttpUrl.get("http://localhost:" + port));
    TestRunWithClusteredSuggestions testRun = agent.startTestRun(availableTests);
    assertThat(testRun.getPrioritizedClusters()).hasSize(1);
    assertThat(testRun.getPrioritizedClusters().get(0).tests).hasSize(1);
    PrioritizableTest test = testRun.getPrioritizedClusters().get(0).tests.get(0);
    assertThat(test.uniformPath).isEqualTo("test2");
    RunningTest runningTest = testRun.startTest(test.uniformPath);
    runningTest.endTest(new TestRun.TestResultWithMessage(ETestExecutionResult.PASSED, "message"));
    testRun.endTestRun();
    verify(client).uploadReport(eq(EReportFormat.TESTWISE_COVERAGE), matches("\\Q{\"tests\":[{\"content\":\"content\",\"paths\":[],\"sourcePath\":\"test1\",\"uniformPath\":\"test1\"},{\"content\":\"content\",\"duration\":\\E[^,]*\\Q,\"message\":\"message\",\"paths\":[{\"files\":[{\"coveredLines\":\"1-4\",\"fileName\":\"Main.java\"}],\"path\":\"src/main/java\"}],\"result\":\"PASSED\",\"sourcePath\":\"test2\",\"uniformPath\":\"test2\"}]}\\E"), any(), any(), any(), any());
}
Also used : RunningTest(com.teamscale.tia.client.RunningTest) ClusteredTestDetails(com.teamscale.client.ClusteredTestDetails) TiaAgent(com.teamscale.tia.client.TiaAgent) TestRunWithClusteredSuggestions(com.teamscale.tia.client.TestRunWithClusteredSuggestions) PrioritizableTestCluster(com.teamscale.client.PrioritizableTestCluster) PrioritizableTest(com.teamscale.client.PrioritizableTest) TestRun(com.teamscale.tia.client.TestRun) File(java.io.File) AgentOptions(com.teamscale.jacoco.agent.options.AgentOptions) PrioritizableTest(com.teamscale.client.PrioritizableTest) Test(org.junit.jupiter.api.Test) RunningTest(com.teamscale.tia.client.RunningTest)

Example 3 with AgentOptions

use of com.teamscale.jacoco.agent.options.AgentOptions in project teamscale-jacoco-agent by cqse.

the class AgentHttpServerTest method setup.

/**
 * Starts the http server to control the agent
 */
@BeforeEach
public void setup() throws Exception {
    AgentOptions options = new TestAgentOptionsBuilder().withHttpServerPort(httpServerPort).withTeamscaleMessage(defaultCommitMessage).withTeamscalePartition(defaultPartition).create();
    agent = new Agent(options, null);
}
Also used : TestAgentOptionsBuilder(com.teamscale.jacoco.agent.options.TestAgentOptionsBuilder) AgentOptions(com.teamscale.jacoco.agent.options.AgentOptions) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with AgentOptions

use of com.teamscale.jacoco.agent.options.AgentOptions in project teamscale-jacoco-agent by cqse.

the class AgentBase method premain.

/**
 * Called by the actual premain method once the agent is isolated from the rest of the application.
 */
public static void premain(String options, Instrumentation instrumentation) throws Exception {
    AgentOptions agentOptions;
    DelayedLogger delayedLogger = new DelayedLogger();
    try {
        agentOptions = AgentOptionsParser.parse(options, delayedLogger);
    } catch (AgentOptionParseException e) {
        try (LoggingUtils.LoggingResources ignored = initializeFallbackLogging(options, delayedLogger)) {
            delayedLogger.error("Failed to parse agent options: " + e.getMessage(), e);
            System.err.println("Failed to parse agent options: " + e.getMessage());
            // we perform actual logging output after writing to console to
            // ensure the console is reached even in case of logging issues
            // (see TS-23151). We use the Agent class here (same as below)
            Logger logger = LoggingUtils.getLogger(Agent.class);
            delayedLogger.logTo(logger);
            throw e;
        }
    }
    loggingResources = LoggingUtils.initializeLogging(agentOptions.getLoggingConfig());
    Logger logger = LoggingUtils.getLogger(Agent.class);
    delayedLogger.logTo(logger);
    HttpUtils.setShouldValidateSsl(agentOptions.shouldValidateSsl());
    logger.info("Starting JaCoCo's agent");
    JacocoAgentBuilder agentBuilder = new JacocoAgentBuilder(agentOptions);
    org.jacoco.agent.rt.internal_3570298.PreMain.premain(agentBuilder.createJacocoAgentOptions(), instrumentation);
    AgentBase agent = agentBuilder.createAgent(instrumentation);
    agent.registerShutdownHook();
}
Also used : LoggingResources(com.teamscale.jacoco.agent.util.LoggingUtils.LoggingResources) AgentOptionParseException(com.teamscale.jacoco.agent.options.AgentOptionParseException) JacocoAgentBuilder(com.teamscale.jacoco.agent.options.JacocoAgentBuilder) Logger(org.slf4j.Logger) AgentOptions(com.teamscale.jacoco.agent.options.AgentOptions)

Example 5 with AgentOptions

use of com.teamscale.jacoco.agent.options.AgentOptions in project teamscale-jacoco-agent by cqse.

the class CoverageToTeamscaleStrategyTest method mockOptions.

private AgentOptions mockOptions() throws IOException {
    AgentOptions options = mock(AgentOptions.class);
    when(options.createTeamscaleClient()).thenReturn(client);
    when(options.createTempFile(any(), any())).thenReturn(new File(tempDir, "test"));
    TeamscaleServer server = new TeamscaleServer();
    server.commit = new CommitDescriptor("branch", "12345");
    server.url = HttpUrl.get("http://doesnt-exist.io");
    server.userName = "build";
    server.userAccessToken = "token";
    server.partition = "partition";
    when(options.getTeamscaleServerOptions()).thenReturn(server);
    when(options.createTeamscaleClient()).thenReturn(client);
    return options;
}
Also used : TeamscaleServer(com.teamscale.client.TeamscaleServer) CommitDescriptor(com.teamscale.client.CommitDescriptor) File(java.io.File) AgentOptions(com.teamscale.jacoco.agent.options.AgentOptions)

Aggregations

AgentOptions (com.teamscale.jacoco.agent.options.AgentOptions)7 File (java.io.File)4 PrioritizableTest (com.teamscale.client.PrioritizableTest)3 Test (org.junit.jupiter.api.Test)3 ClusteredTestDetails (com.teamscale.client.ClusteredTestDetails)2 CommitDescriptor (com.teamscale.client.CommitDescriptor)2 PrioritizableTestCluster (com.teamscale.client.PrioritizableTestCluster)2 TeamscaleServer (com.teamscale.client.TeamscaleServer)2 TestExecution (com.teamscale.report.testwise.model.TestExecution)2 TestwiseCoverage (com.teamscale.report.testwise.model.TestwiseCoverage)2 JacocoRuntimeController (com.teamscale.jacoco.agent.JacocoRuntimeController)1 AgentOptionParseException (com.teamscale.jacoco.agent.options.AgentOptionParseException)1 JacocoAgentBuilder (com.teamscale.jacoco.agent.options.JacocoAgentBuilder)1 TestAgentOptionsBuilder (com.teamscale.jacoco.agent.options.TestAgentOptionsBuilder)1 LoggingResources (com.teamscale.jacoco.agent.util.LoggingUtils.LoggingResources)1 RunningTest (com.teamscale.tia.client.RunningTest)1 TestRun (com.teamscale.tia.client.TestRun)1 TestRunWithClusteredSuggestions (com.teamscale.tia.client.TestRunWithClusteredSuggestions)1 TiaAgent (com.teamscale.tia.client.TiaAgent)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1