Search in sources :

Example 1 with Build

use of org.jboss.pnc.dto.Build in project pnc by project-ncl.

the class TemporaryBuildsCleanerTest method shouldNotReturnWithNewNoRebuildRecord.

@Test
public void shouldNotReturnWithNewNoRebuildRecord() throws Exception {
    // given
    BuildRecord tempBr = initBuildRecordBuilder().submitTime(Date.from(Instant.now().minus(2, ChronoUnit.DAYS))).endTime(Date.from(Instant.now().minus(2, ChronoUnit.DAYS))).temporaryBuild(true).build();
    tempBr = buildRecordRepository.save(tempBr);
    BuildRecord tempNRRBr = initBuildRecordBuilder().status(BuildStatus.NO_REBUILD_REQUIRED).noRebuildCause(tempBr).temporaryBuild(true).build();
    tempNRRBr = buildRecordRepository.save(tempNRRBr);
    // when
    Page<Build> builds = buildProvider.getAllIndependentTemporaryOlderThanTimestamp(0, 50, null, null, Date.from(Instant.now().minus(1, ChronoUnit.DAYS)).getTime());
    // then
    assertThat(builds.getContent()).extracting("id", String.class).doesNotContain(BuildMapper.idMapper.toDto(tempBr.getId()), BuildMapper.idMapper.toDto(tempNRRBr.getId()));
}
Also used : Build(org.jboss.pnc.dto.Build) BuildRecord(org.jboss.pnc.model.BuildRecord) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 2 with Build

use of org.jboss.pnc.dto.Build 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);
}
Also used : Condition(org.assertj.core.api.Condition) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Arquillian(org.jboss.arquillian.junit.Arquillian) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BuildConfigurationSetRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationSetRepository) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationAuditedRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationAuditedRepository) ArtifactRepository(org.jboss.pnc.spi.datastore.repositories.ArtifactRepository) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildConfigSetRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigSetRecordRepository) Assert.fail(org.junit.Assert.fail) Deployments.addBuildExecutorMock(org.jboss.pnc.integration.setup.Deployments.addBuildExecutorMock) Deployments(org.jboss.pnc.integration.setup.Deployments) BuildConfigurationRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationRepository) TargetRepository(org.jboss.pnc.model.TargetRepository) User(org.jboss.pnc.model.User) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) Artifact(org.jboss.pnc.model.Artifact) EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) MethodHandles(java.lang.invoke.MethodHandles) BuildProvider(org.jboss.pnc.facade.providers.api.BuildProvider) Datastore(org.jboss.pnc.spi.datastore.Datastore) Set(java.util.Set) UUID(java.util.UUID) Category(org.junit.experimental.categories.Category) Instant(java.time.Instant) BuildStatus(org.jboss.pnc.enums.BuildStatus) UserRepository(org.jboss.pnc.spi.datastore.repositories.UserRepository) List(java.util.List) RemoteBuildsCleanerMock(org.jboss.pnc.integration.mock.RemoteBuildsCleanerMock) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) PersistenceException(javax.persistence.PersistenceException) HeuristicMixedException(javax.transaction.HeuristicMixedException) TargetRepositoryRepository(org.jboss.pnc.spi.datastore.repositories.TargetRepositoryRepository) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) RunWith(org.junit.runner.RunWith) ArtifactQuality(org.jboss.pnc.enums.ArtifactQuality) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) BuildMapper(org.jboss.pnc.mapper.api.BuildMapper) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Inject(javax.inject.Inject) HashSet(java.util.HashSet) RollbackException(javax.transaction.RollbackException) ProductVersionRepository(org.jboss.pnc.spi.datastore.repositories.ProductVersionRepository) TemporaryBuildsCleaner(org.jboss.pnc.coordinator.maintenance.TemporaryBuildsCleaner) Before(org.junit.Before) ValidationException(org.jboss.pnc.spi.exception.ValidationException) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) UserTransaction(javax.transaction.UserTransaction) Test(org.junit.Test) BuildRecord(org.jboss.pnc.model.BuildRecord) EntityManager(javax.persistence.EntityManager) Page(org.jboss.pnc.dto.response.Page) NotSupportedException(javax.transaction.NotSupportedException) Build(org.jboss.pnc.dto.Build) ChronoUnit(java.time.temporal.ChronoUnit) Assert.assertNull(org.junit.Assert.assertNull) Deployment(org.jboss.arquillian.container.test.api.Deployment) SystemException(javax.transaction.SystemException) Condition(org.assertj.core.api.Condition) Sequence(org.jboss.pnc.common.concurrent.Sequence) Assert.assertEquals(org.junit.Assert.assertEquals) Build(org.jboss.pnc.dto.Build) BuildRecord(org.jboss.pnc.model.BuildRecord) Artifact(org.jboss.pnc.model.Artifact) Date(java.util.Date) HashSet(java.util.HashSet) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 3 with Build

use of org.jboss.pnc.dto.Build in project pnc by project-ncl.

the class BuildTest method shouldTriggerBuildWithADependencyAndFinishWithoutProblems.

@Test
public void shouldTriggerBuildWithADependencyAndFinishWithoutProblems() throws ClientException {
    // given - A BC with a dependency on pnc-1.0.0.DR1
    BuildConfiguration buildConfigurationParent = buildConfigurationClient.getAll(Optional.empty(), Optional.of("name==dependency-analysis-1.3")).iterator().next();
    // Update dependency
    BuildConfiguration buildConfigurationChild = buildConfigurationClient.getAll(Optional.empty(), Optional.of("name==pnc-1.0.0.DR1")).iterator().next();
    BuildConfiguration updatedBuildConfigurationChild = buildConfigurationChild.toBuilder().description(buildConfigurationChild.getDescription() + ".").build();
    buildConfigurationClient.update(buildConfigurationChild.getId(), updatedBuildConfigurationChild);
    // The update of the description should not have changed the lastModificationDate
    assertThat(buildConfigurationChild.getModificationTime()).isEqualTo(updatedBuildConfigurationChild.getModificationTime());
    // when
    Build build = buildConfigurationClient.trigger(buildConfigurationParent.getId(), getBuildParameters(false, true));
    BuildsFilterParameters parameters = new BuildsFilterParameters();
    parameters.setRunning(true);
    RemoteCollection<Build> childBuildCol = buildConfigurationClient.getBuilds(buildConfigurationChild.getId(), parameters);
    Build childBuild = childBuildCol.getAll().iterator().next();
    // then
    assertThat(childBuildCol.size()).isEqualTo(1);
    assertThat(buildConfigurationParent.getDependencies().size()).isEqualTo(1);
    assertThat(build).isNotNull().extracting("id").isNotNull().isNotEqualTo("");
    EnumSet<BuildStatus> isIn = EnumSet.of(BuildStatus.SUCCESS);
    ResponseUtils.waitSynchronouslyFor(() -> buildToFinish(build.getId(), isIn, null), 15, TimeUnit.SECONDS);
    ResponseUtils.waitSynchronouslyFor(() -> buildToFinish(childBuild.getId(), isIn, null), 15, TimeUnit.SECONDS);
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) GroupBuild(org.jboss.pnc.dto.GroupBuild) Build(org.jboss.pnc.dto.Build) BuildStatus(org.jboss.pnc.enums.BuildStatus) BuildsFilterParameters(org.jboss.pnc.rest.api.parameters.BuildsFilterParameters) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 4 with Build

use of org.jboss.pnc.dto.Build in project pnc by project-ncl.

the class BuildTest method shouldHaveNoRebuildCauseFilled.

@Test
public void shouldHaveNoRebuildCauseFilled() throws Exception {
    // with
    BuildConfiguration buildConfiguration = buildConfigurationClient.getAll().iterator().next();
    // when #1
    Build build = buildConfigurationClient.trigger(buildConfiguration.getId(), getPersistentParameters(true));
    assertThat(build).isNotNull().extracting("id").isNotNull().isNotEqualTo("");
    EnumSet<BuildStatus> isIn = EnumSet.of(BuildStatus.SUCCESS);
    ResponseUtils.waitSynchronouslyFor(() -> buildToFinish(build.getId(), isIn, null), 15, TimeUnit.SECONDS);
    // when #2
    EnumSet<BuildStatus> isNotIn = EnumSet.of(BuildStatus.SUCCESS, BuildStatus.FAILED);
    Build rebuild = buildConfigurationClient.trigger(buildConfiguration.getId(), getBuildParameters(false, false));
    ResponseUtils.waitSynchronouslyFor(() -> buildToFinish(rebuild.getId(), EnumSet.of(BuildStatus.NO_REBUILD_REQUIRED), isNotIn), 15, TimeUnit.SECONDS);
    // then
    Build refresh = buildClient.getSpecific(rebuild.getId());
    assertThat(refresh.getNoRebuildCause()).isNotNull().extracting("id").isEqualTo(build.getId());
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) GroupBuild(org.jboss.pnc.dto.GroupBuild) Build(org.jboss.pnc.dto.Build) BuildStatus(org.jboss.pnc.enums.BuildStatus) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 5 with Build

use of org.jboss.pnc.dto.Build in project pnc by project-ncl.

the class BuildTest method shouldTriggerBuildAndFinishWithoutProblems.

@Test
public void shouldTriggerBuildAndFinishWithoutProblems() throws ClientException {
    // with
    BuildConfiguration buildConfiguration = buildConfigurationClient.getAll().iterator().next();
    // when
    Build build = buildConfigurationClient.trigger(buildConfiguration.getId(), getPersistentParameters(true));
    assertThat(build).isNotNull().extracting("id").isNotNull().isNotEqualTo("");
    EnumSet<BuildStatus> isIn = EnumSet.of(BuildStatus.SUCCESS);
    ResponseUtils.waitSynchronouslyFor(() -> buildToFinish(build.getId(), isIn, null), 15, TimeUnit.SECONDS);
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) GroupBuild(org.jboss.pnc.dto.GroupBuild) Build(org.jboss.pnc.dto.Build) BuildStatus(org.jboss.pnc.enums.BuildStatus) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Aggregations

Build (org.jboss.pnc.dto.Build)71 Test (org.junit.Test)52 ContainerTest (org.jboss.pnc.test.category.ContainerTest)35 BuildClient (org.jboss.pnc.client.BuildClient)20 BuildRecord (org.jboss.pnc.model.BuildRecord)18 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)16 BuildStatus (org.jboss.pnc.enums.BuildStatus)15 GroupBuild (org.jboss.pnc.dto.GroupBuild)14 BuildPageInfo (org.jboss.pnc.facade.providers.api.BuildPageInfo)14 ArrayList (java.util.ArrayList)12 BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)11 HashSet (java.util.HashSet)10 List (java.util.List)10 Set (java.util.Set)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 Date (java.util.Date)9 Page (org.jboss.pnc.dto.response.Page)9 BuildMapper (org.jboss.pnc.mapper.api.BuildMapper)9 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)9