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);
}
}
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);
}
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);
}
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();
}
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();
}
Aggregations