Search in sources :

Example 1 with InMemoryUploader

use of com.teamscale.jacoco.agent.util.InMemoryUploader 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 2 with InMemoryUploader

use of com.teamscale.jacoco.agent.util.InMemoryUploader 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 3 with InMemoryUploader

use of com.teamscale.jacoco.agent.util.InMemoryUploader 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)

Example 4 with InMemoryUploader

use of com.teamscale.jacoco.agent.util.InMemoryUploader in project teamscale-jacoco-agent by cqse.

the class DelayedUploaderTest method shouldAsynchronouslyStoreToDestinationOnceCommitIsKnown.

@Test
public void shouldAsynchronouslyStoreToDestinationOnceCommitIsKnown(@TempDir Path outputPath) throws Exception {
    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();
    ExecutorService executor = Executors.newSingleThreadExecutor();
    DelayedUploader<String> store = new DelayedUploader<>(commit -> destination, outputPath, executor);
    store.upload(coverageFile);
    store.setCommitAndTriggerAsynchronousUpload("a2afb54566aaa");
    executor.shutdown();
    executor.awaitTermination(5, TimeUnit.SECONDS);
    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) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.jupiter.api.Test)

Aggregations

InMemoryUploader (com.teamscale.jacoco.agent.util.InMemoryUploader)4 CoverageFile (com.teamscale.report.jacoco.CoverageFile)4 Path (java.nio.file.Path)4 Test (org.junit.jupiter.api.Test)4 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 File (java.io.File)1