use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class TemporaryBuildsCleanerTest method shouldReturnOnlyTopLevelTemporaryBuilds.
@Test
public void shouldReturnOnlyTopLevelTemporaryBuilds() throws Exception {
// with
// top level BR1
BuildRecord br1 = initBuildRecordBuilder().temporaryBuild(true).build();
br1 = buildRecordRepository.save(br1);
Artifact art1br1 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br1).build();
Artifact art2br1 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br1).build();
artifactRepository.save(art1br1);
artifactRepository.save(art2br1);
Set<Artifact> depArtBr2 = new HashSet<>();
// independent BR2
BuildRecord br2 = initBuildRecordBuilder().temporaryBuild(true).dependencies(depArtBr2).build();
br2 = buildRecordRepository.save(br2);
Artifact art1br2 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br2).build();
Artifact art2br2 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br2).build();
artifactRepository.save(art1br2);
artifactRepository.save(art2br2);
Set<Artifact> depArtBr3 = new HashSet<>();
depArtBr3.add(art1br1);
depArtBr3.add(art1br2);
// create implicitly dependent BR3 (BR3 is dependent on BR1)
BuildRecord br3 = initBuildRecordBuilder().temporaryBuild(true).dependencies(depArtBr3).build();
br3 = buildRecordRepository.save(br3);
Artifact art1br3 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br3).build();
Artifact art2br3 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br3).build();
artifactRepository.save(art1br3);
artifactRepository.save(art2br3);
Set<Artifact> depArtBr4 = new HashSet<>();
depArtBr4.add(art2br2);
depArtBr4.add(art1br3);
// create implicitly dependent BR4 (BR4 is dependent on BR2 and BR3)
BuildRecord br4 = initBuildRecordBuilder().temporaryBuild(true).dependencies(depArtBr4).build();
br4 = buildRecordRepository.save(br4);
Artifact art1br4 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br4).build();
Artifact art2br4 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br4).build();
artifactRepository.save(art1br4);
artifactRepository.save(art2br4);
BuildRecord finalBr1 = br1;
Condition<Build> hasBr1 = new Condition<>((build -> build.getId().equals(BuildMapper.idMapper.toDto(finalBr1.getId()))), "Is Br1 with id " + BuildMapper.idMapper.toDto(finalBr1.getId()));
BuildRecord finalBr2 = br2;
Condition<Build> hasBr2 = new Condition<>((build -> build.getId().equals(BuildMapper.idMapper.toDto(finalBr2.getId()))), "Is Br2 with id " + BuildMapper.idMapper.toDto(finalBr2.getId()));
BuildRecord finalBr3 = br3;
Condition<Build> hasBr3 = new Condition<>((build -> build.getId().equals(BuildMapper.idMapper.toDto(finalBr3.getId()))), "Is Br3 with id " + BuildMapper.idMapper.toDto(finalBr3.getId()));
BuildRecord finalBr4 = br4;
Condition<Build> hasBr4 = new Condition<>((build -> build.getId().equals(BuildMapper.idMapper.toDto(finalBr4.getId()))), "Is Br4 with id " + BuildMapper.idMapper.toDto(finalBr4.getId()));
// when #1
Page<Build> builds = buildProvider.getAllIndependentTemporaryOlderThanTimestamp(0, 50, null, null, new Date().getTime());
// then #1
assertThat(builds.getContent()).doNotHave(hasBr1).doNotHave(hasBr2).doNotHave(hasBr3).haveExactly(1, hasBr4);
// when #2
temporaryBuildsCleaner.deleteTemporaryBuild(br4.getId(), "");
builds = buildProvider.getAllIndependentTemporaryOlderThanTimestamp(0, 50, null, null, new Date().getTime());
// then #2
assertThat(builds.getContent()).doNotHave(hasBr1).doNotHave(hasBr2).haveExactly(1, hasBr3).doNotHave(hasBr4);
// when #3
temporaryBuildsCleaner.deleteTemporaryBuild(br3.getId(), "");
builds = buildProvider.getAllIndependentTemporaryOlderThanTimestamp(0, 50, null, null, new Date().getTime());
// then #3
assertThat(builds.getContent()).haveExactly(1, hasBr1).haveExactly(1, hasBr2).doNotHave(hasBr3).doNotHave(hasBr4);
}
use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class TemporaryBuildsCleanerTest method shouldNotDeleteNonTemporaryBuildTest.
@Test(expected = ValidationException.class)
public void shouldNotDeleteNonTemporaryBuildTest() throws ValidationException {
// given
BuildRecord nonTempBr = initBuildRecordBuilder().temporaryBuild(false).build();
buildRecordRepository.save(nonTempBr);
// when - then
temporaryBuildsCleaner.deleteTemporaryBuild(nonTempBr.getId(), "");
fail("Deletion of non-temporary build should be prohibited");
}
use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class TemporaryBuildsCleanerTest method shouldNotDeleteNonTemporaryArtifacts.
@Test
public void shouldNotDeleteNonTemporaryArtifacts() {
// given
Artifact artifact = initArtifactBuilder().artifactQuality(ArtifactQuality.NEW).build();
artifactRepository.save(artifact);
Set<Artifact> builtArtifacts = new HashSet<>();
builtArtifacts.add(artifact);
BuildRecord tempBr = initBuildRecordBuilder().temporaryBuild(true).build();
BuildRecord savedTempBr = buildRecordRepository.save(tempBr);
artifact.setBuildRecord(savedTempBr);
artifactRepository.save(artifact);
// when - then
try {
temporaryBuildsCleaner.deleteTemporaryBuild(tempBr.getId(), "");
} catch (Exception ex) {
logger.info("Received exception:", ex);
if (ex.getCause().getClass().equals(PersistenceException.class)) {
return;
}
}
fail("Deletion of non-temporary artifacts should be prohibited");
}
use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class VerifyManualDeletionOfBuildRepoTest method manuallyPromoteBuildRepoToChainGroup.
@Test
public void manuallyPromoteBuildRepoToChainGroup() throws Exception {
String path = "/org/myproj/myproj/1.0/myproj-1.0.pom";
String content = "This is a test " + System.currentTimeMillis();
String buildId = "build";
// create a dummy non-chained build execution and a repo session based on it
BuildExecution execution = new TestBuildExecution(buildId);
RepositorySession session = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, Collections.emptyMap(), false);
String pkgType = MAVEN_PKG_KEY;
// simulate a build deploying a file.
StoreKey hostedKey = new StoreKey(pkgType, StoreType.hosted, buildId);
indy.module(IndyFoloContentClientModule.class).store(buildId, hostedKey, path, new ByteArrayInputStream(content.getBytes()));
// now, extract the build artifacts. This will trigger promotion of the build hosted repo to the chain group.
RepositoryManagerResult result = session.extractBuildArtifacts(true);
// do some sanity checks while we're here
List<Artifact> deps = result.getBuiltArtifacts();
assertThat(deps.size(), equalTo(1));
Artifact a = deps.get(0);
assertThat(a.getFilename(), equalTo(new File(path).getName()));
// construct a dummy BuildRecord for use below
BuildRecord record = new BuildRecord();
record.setBuildContentId(buildId);
// unset the readonly flag on the hosted repo to allow its deletion
IndyStoresClientModule indyStoreAdmin = indy.stores();
StoreKey key = new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, record.getBuildContentId());
HostedRepository store = indyStoreAdmin.load(key, HostedRepository.class);
store.setReadonly(false);
indyStoreAdmin.update(store, "Unsetting readonly-flag to allow deletion");
// manually delete the build to the public group (since it's convenient)
RunningRepositoryDeletion deletion = driver.deleteBuild(record, pkgType, accessToken);
deletion.monitor(completed -> assertThat("Manual deletion failed.", completed.isSuccessful(), equalTo(true)), error -> {
error.printStackTrace();
fail("Failed to manually delete: " + error.getMessage());
});
// end result: the build hosted repo should no longer exist.
assertThat(indyStoreAdmin.exists(hostedKey), equalTo(false));
}
use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class VerifyManualPromotionOfBuildRepoTest method manuallyPromoteBuildRepoToChainGroup.
@Test
public void manuallyPromoteBuildRepoToChainGroup() throws Exception {
String path = "/org/myproj/myproj/1.0/myproj-1.0.pom";
String content = "This is a test " + System.currentTimeMillis();
// String chainId = "chain";
String buildId = "build";
// create a dummy non-chained build execution and a repo session based on it
BuildExecution execution = new TestBuildExecution(buildId);
RepositorySession session = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, Collections.emptyMap(), false);
String pkgType = MAVEN_PKG_KEY;
// simulate a build deploying a file.
StoreKey hostedKey = new StoreKey(pkgType, StoreType.hosted, buildId);
indy.module(IndyFoloContentClientModule.class).store(buildId, hostedKey, path, new ByteArrayInputStream(content.getBytes()));
// now, extract the build artifacts. This will trigger promotion of the build hosted repo to the chain group.
RepositoryManagerResult result = session.extractBuildArtifacts(true);
// do some sanity checks while we're here
List<Artifact> deps = result.getBuiltArtifacts();
assertThat(deps.size(), equalTo(1));
Artifact a = deps.get(0);
assertThat(a.getFilename(), equalTo(new File(path).getName()));
// construct a dummy BuildRecord for use below
BuildRecord record = new BuildRecord();
record.setBuildContentId(buildId);
// manually promote the build to the public group (since it's convenient)
RunningRepositoryPromotion promotion = driver.promoteBuild(record, pkgType, PUBLIC, accessToken);
promotion.monitor(completed -> assertThat("Manual promotion failed.", completed.isSuccessful(), equalTo(true)), error -> {
error.printStackTrace();
fail("Failed to manually promote: " + error.getMessage());
});
// end result: the chain group should contain the build hosted repo.
StoreKey publicKey = new StoreKey(pkgType, StoreType.group, PUBLIC);
Group publicGroup = indy.stores().load(publicKey, Group.class);
System.out.println("public group constituents: " + publicGroup.getConstituents());
assertThat(publicGroup.getConstituents().contains(hostedKey), equalTo(true));
}
Aggregations