use of com.teamscale.report.jacoco.CoverageFile 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);
}
use of com.teamscale.report.jacoco.CoverageFile in project teamscale-jacoco-agent by cqse.
the class HttpZipUploaderBase method tryUpload.
/**
* Performs the upload and returns <code>true</code> if successful.
*/
protected boolean tryUpload(CoverageFile coverageFile) {
logger.debug("Uploading coverage to {}", uploadUrl);
File zipFile;
try {
zipFile = createZipFile(coverageFile);
} catch (IOException e) {
logger.error("Failed to compile coverage zip file for upload to {}", uploadUrl, e);
return false;
}
try {
Response<ResponseBody> response = uploadCoverageZip(zipFile);
if (response.isSuccessful()) {
return true;
}
String errorBody = "<no server response>";
if (response.errorBody() != null) {
errorBody = response.errorBody().string();
}
logger.error("Failed to upload coverage to {}. Request failed with error code {}. Error:\n{}", uploadUrl, response.code(), errorBody);
return false;
} catch (IOException e) {
logger.error("Failed to upload coverage to {}. Probably a network problem", uploadUrl, e);
return false;
} catch (UploaderException e) {
logger.error("Failed to upload coverage to {}. The configuration is probably incorrect", uploadUrl, e);
return false;
} finally {
zipFile.delete();
}
}
use of com.teamscale.report.jacoco.CoverageFile in project teamscale-jacoco-agent by cqse.
the class HttpZipUploaderBase method createZipFile.
/**
* Creates the zip file in the system temp directory to upload which includes the given coverage XML and all {@link
* #additionalMetaDataFiles}. The file is marked to be deleted on exit.
*/
private File createZipFile(CoverageFile coverageFile) throws IOException {
File zipFile = Files.createTempFile(coverageFile.getNameWithoutExtension(), ".zip").toFile();
zipFile.deleteOnExit();
try (FileOutputStream fileOutputStream = new FileOutputStream(zipFile);
ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream)) {
fillZipFile(zipOutputStream, coverageFile);
return zipFile;
}
}
Aggregations