Search in sources :

Example 1 with CoverageFile

use of com.teamscale.report.jacoco.CoverageFile in project teamscale-jacoco-agent by cqse.

the class Agent method dumpReportUnsafe.

private void dumpReportUnsafe() {
    Dump dump;
    try {
        dump = controller.dumpAndReset();
    } catch (JacocoRuntimeController.DumpException e) {
        logger.error("Dumping failed, retrying later", e);
        return;
    }
    try (Benchmark ignored = new Benchmark("Generating the XML report")) {
        File outputFile = options.createTempFile("jacoco", "xml");
        CoverageFile coverageFile = generator.convert(dump, outputFile);
        uploader.upload(coverageFile);
    } catch (IOException e) {
        logger.error("Converting binary dump to XML failed", e);
    } catch (EmptyReportException e) {
        logger.error("No coverage was collected. " + e.getMessage(), e);
    }
}
Also used : CoverageFile(com.teamscale.report.jacoco.CoverageFile) Dump(com.teamscale.report.jacoco.dump.Dump) EmptyReportException(com.teamscale.report.jacoco.EmptyReportException) Benchmark(com.teamscale.jacoco.agent.util.Benchmark) IOException(java.io.IOException) CoverageFile(com.teamscale.report.jacoco.CoverageFile) File(java.io.File)

Example 2 with CoverageFile

use of com.teamscale.report.jacoco.CoverageFile in project teamscale-jacoco-agent by cqse.

the class DelayedUploaderTest method shouldStoreToCacheIfCommitIsNotKnown.

@Test
public void shouldStoreToCacheIfCommitIsNotKnown(@TempDir Path outputPath) throws IOException {
    Path coverageFilePath = outputPath.resolve(String.format("jacoco-%d.xml", ZonedDateTime.now().toInstant().toEpochMilli()));
    CoverageFile coverageFile = new CoverageFile(Files.createFile(coverageFilePath).toFile());
    InMemoryUploader destination = new InMemoryUploader();
    DelayedUploader<?> store = new DelayedUploader<>(commit -> destination, outputPath);
    store.upload(coverageFile);
    assertThat(Files.list(outputPath).collect(Collectors.toList())).contains(coverageFilePath);
    assertThat(destination.getUploadedFiles()).doesNotContain(coverageFile);
}
Also used : Path(java.nio.file.Path) CoverageFile(com.teamscale.report.jacoco.CoverageFile) InMemoryUploader(com.teamscale.jacoco.agent.util.InMemoryUploader) Test(org.junit.jupiter.api.Test)

Example 3 with CoverageFile

use of com.teamscale.report.jacoco.CoverageFile in project teamscale-jacoco-agent by cqse.

the class DelayedUploaderTest method shouldStoreToDestinationIfCommitIsKnown.

@Test
public void shouldStoreToDestinationIfCommitIsKnown(@TempDir Path outputPath) throws IOException {
    Path coverageFilePath = outputPath.resolve(String.format("jacoco-%d.xml", ZonedDateTime.now().toInstant().toEpochMilli()));
    CoverageFile coverageFile = new CoverageFile(Files.createFile(coverageFilePath).toFile());
    InMemoryUploader destination = new InMemoryUploader();
    DelayedUploader<String> store = new DelayedUploader<>(commit -> destination, outputPath);
    store.setCommitAndTriggerAsynchronousUpload("a2afb54566aaa");
    store.upload(coverageFile);
    assertThat(Files.list(outputPath).collect(Collectors.toList())).doesNotContain(coverageFilePath);
    assertThat(destination.getUploadedFiles()).contains(coverageFile);
}
Also used : Path(java.nio.file.Path) CoverageFile(com.teamscale.report.jacoco.CoverageFile) InMemoryUploader(com.teamscale.jacoco.agent.util.InMemoryUploader) Test(org.junit.jupiter.api.Test)

Example 4 with CoverageFile

use of com.teamscale.report.jacoco.CoverageFile in project teamscale-jacoco-agent by cqse.

the class ArtifactoryUploaderTest method testUseApiKeyHeaderWhenOptionIsPresent.

/**
 * Tests if the {@link ArtifactoryConfig#ARTIFACTORY_API_KEY_OPTION} is set, it will be used as authentication
 * method against artifactory in the {@link ArtifactoryUploader#ARTIFACTORY_API_HEADER}
 */
@Test
public void testUseApiKeyHeaderWhenOptionIsPresent(@TempDir File tmpDir) throws IOException, InterruptedException {
    MockWebServer mockWebServer = new MockWebServer();
    mockWebServer.enqueue(new MockResponse().setResponseCode(200));
    mockWebServer.start();
    HttpUrl serverUrl = mockWebServer.url("/artifactory/");
    ArtifactoryConfig artifactoryConfig = generateBasicArtifacotryConfig(serverUrl);
    artifactoryConfig.apiKey = "some_api_key";
    ArtifactoryUploader artifactoryUploader = new ArtifactoryUploader(artifactoryConfig, new ArrayList<>());
    File tmpFile = new File(tmpDir.getPath() + File.separator + "tmpfile");
    tmpFile.createNewFile();
    artifactoryUploader.upload(new CoverageFile(tmpFile));
    RecordedRequest recordedRequest = mockWebServer.takeRequest(5, TimeUnit.SECONDS);
    assert recordedRequest != null;
    assertThat(recordedRequest.getHeader(ArtifactoryUploader.ARTIFACTORY_API_HEADER)).as("Artifactory API Header (" + ArtifactoryUploader.ARTIFACTORY_API_HEADER + ") not used when the option" + ArtifactoryConfig.ARTIFACTORY_API_KEY_OPTION + "is set.").isNotNull();
    mockWebServer.shutdown();
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) CoverageFile(com.teamscale.report.jacoco.CoverageFile) MockWebServer(okhttp3.mockwebserver.MockWebServer) CoverageFile(com.teamscale.report.jacoco.CoverageFile) File(java.io.File) HttpUrl(okhttp3.HttpUrl) Test(org.junit.jupiter.api.Test)

Example 5 with CoverageFile

use of com.teamscale.report.jacoco.CoverageFile in project teamscale-jacoco-agent by cqse.

the class DelayedCommitDescriptorRetrievalTest method locatorShouldTriggerUploadOfCachedXmls.

@Test
public void locatorShouldTriggerUploadOfCachedXmls(@TempDir Path outputPath) throws Exception {
    ExecutorService storeExecutor = Executors.newSingleThreadExecutor();
    Path coverageFilePath = outputPath.resolve(String.format("jacoco-%d.xml", ZonedDateTime.now().toInstant().toEpochMilli()));
    CoverageFile coverageFile = new CoverageFile(Files.createFile(coverageFilePath).toFile());
    InMemoryUploader destination = new InMemoryUploader();
    DelayedUploader<String> store = new DelayedUploader<>(commit -> destination, outputPath, storeExecutor);
    ExecutorService locatorExecutor = Executors.newSingleThreadExecutor();
    GitPropertiesLocator<String> locator = new GitPropertiesLocator<>(store, GitPropertiesLocatorUtils::getRevisionFromGitProperties, locatorExecutor);
    store.upload(coverageFile);
    locator.searchFileForGitPropertiesAsync(new File(getClass().getResource("git-properties.jar").toURI()), true);
    locatorExecutor.shutdown();
    locatorExecutor.awaitTermination(5, TimeUnit.SECONDS);
    storeExecutor.shutdown();
    storeExecutor.awaitTermination(5, TimeUnit.SECONDS);
    assertThat(Files.list(outputPath).anyMatch(path -> path.equals(coverageFilePath))).isFalse();
    assertThat(destination.getUploadedFiles().contains(coverageFile)).isTrue();
}
Also used : Path(java.nio.file.Path) CoverageFile(com.teamscale.report.jacoco.CoverageFile) InMemoryUploader(com.teamscale.jacoco.agent.util.InMemoryUploader) ExecutorService(java.util.concurrent.ExecutorService) GitPropertiesLocatorUtils(com.teamscale.jacoco.agent.commit_resolution.git_properties.GitPropertiesLocatorUtils) GitPropertiesLocator(com.teamscale.jacoco.agent.commit_resolution.git_properties.GitPropertiesLocator) CoverageFile(com.teamscale.report.jacoco.CoverageFile) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

CoverageFile (com.teamscale.report.jacoco.CoverageFile)8 File (java.io.File)5 Test (org.junit.jupiter.api.Test)5 InMemoryUploader (com.teamscale.jacoco.agent.util.InMemoryUploader)4 Path (java.nio.file.Path)4 IOException (java.io.IOException)2 ExecutorService (java.util.concurrent.ExecutorService)2 GitPropertiesLocator (com.teamscale.jacoco.agent.commit_resolution.git_properties.GitPropertiesLocator)1 GitPropertiesLocatorUtils (com.teamscale.jacoco.agent.commit_resolution.git_properties.GitPropertiesLocatorUtils)1 Benchmark (com.teamscale.jacoco.agent.util.Benchmark)1 EmptyReportException (com.teamscale.report.jacoco.EmptyReportException)1 Dump (com.teamscale.report.jacoco.dump.Dump)1 FileOutputStream (java.io.FileOutputStream)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 HttpUrl (okhttp3.HttpUrl)1 ResponseBody (okhttp3.ResponseBody)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 MockWebServer (okhttp3.mockwebserver.MockWebServer)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1