use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class BuildProviderImplTest method dependencyGraphTest.
@Test
public void dependencyGraphTest() {
// given
BuildTask bt100002 = mock(BuildTask.class);
when(bt100002.getId()).thenReturn("100002");
BuildTask bt110000 = mock(BuildTask.class);
when(bt110000.getId()).thenReturn("110000");
when(bt110000.getDependencies()).thenReturn(Collections.emptySet());
when(bt110000.getDependants()).thenReturn(Collections.singleton(bt100002));
runningBuilds.add(bt110000);
mockBuildRecord(new Base32LongID(100000L), new Long[] { 100002L }, new Long[] {});
mockBuildRecord(new Base32LongID(100001L), new Long[] { 100002L }, new Long[] {});
BuildRecord currentBuild = mockBuildRecord(new Base32LongID(100002L), new Long[] { 100003L, 100005L, 100006L }, new Long[] { 100000L, 100001L, Long.valueOf(bt110000.getId()) });
BuildRecord buildRecord100003 = mockBuildRecord(new Base32LongID(100003L), new Long[] { 100004L }, new Long[] { 100002L });
mockBuildRecord(new Base32LongID(100004L), new Long[] {}, new Long[] { 100003L });
mockBuildRecord(new Base32LongID(100005L), new Long[] {}, new Long[] { 100002L });
mockBuildRecord(new Base32LongID(100006L), new Long[] {}, new Long[] { 100002L });
// when
Graph<Build> dependencyGraph = provider.getDependencyGraph(bt100002.getId());
// then
logger.info("Graph: {}", dependencyGraph.toString());
assertEquals(8, dependencyGraph.getVertices().size());
Vertex<Build> vertex = getBuildVertexByName(dependencyGraph, BuildMapper.idMapper.toDto(currentBuild.getId()));
Build build = vertex.getData();
assertEquals(BuildMapper.idMapper.toDto(currentBuild.getId()), build.getId());
assertEquals(4, getOutgoingEdges(dependencyGraph, vertex).count());
assertEquals(3, getIncommingEdges(dependencyGraph, vertex).count());
Vertex<Build> vertex3 = getBuildVertexByName(dependencyGraph, BuildMapper.idMapper.toDto(buildRecord100003.getId()));
assertEquals(1, getOutgoingEdges(dependencyGraph, vertex3).count());
assertEquals(1, getIncommingEdges(dependencyGraph, vertex3).count());
// then from running build
Graph<Build> dependencyGraphFromRunning = provider.getDependencyGraph(bt110000.getId());
Vertex<Build> runningVertex = getBuildVertexByName(dependencyGraphFromRunning, bt110000.getId());
assertEquals(1, getOutgoingEdges(dependencyGraphFromRunning, runningVertex).count());
assertEquals(1, getIncommingEdges(dependencyGraphFromRunning, runningVertex).count());
}
use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class BuildProviderImplTest method testGetSpecificFinished.
@Test
public void testGetSpecificFinished() {
BuildRecord record = mockBuildRecord();
Build specific = provider.getSpecific(BuildMapper.idMapper.toDto(record.getId()));
assertThat(specific.getId()).isEqualTo(BuildMapper.idMapper.toDto(record.getId()));
assertThat(specific.getSubmitTime()).isEqualTo(record.getSubmitTime().toInstant());
}
use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class BuildProviderImplTest method mockBuildRecord.
private BuildRecord mockBuildRecord(Base32LongID buildRecordId, Long[] dependencies, Long[] dependents) {
Integer buildConfigurationId = intId.incrementAndGet();
Base32LongID[] depcies = Arrays.stream(dependencies).map(Base32LongID::new).toArray(Base32LongID[]::new);
Base32LongID[] depts = Arrays.stream(dependents).map(Base32LongID::new).toArray(Base32LongID[]::new);
BuildRecord br = BuildRecord.Builder.newBuilder().id(buildRecordId).dependencyBuildRecordIds(depcies).dependentBuildRecordIds(depts).submitTime(new Date()).buildConfigurationAudited(BuildConfigurationAudited.Builder.newBuilder().rev(1).buildConfiguration(BuildConfiguration.Builder.newBuilder().id(buildConfigurationId).name(buildConfigurationId.toString()).build()).build()).buildConfigurationAuditedId(buildConfigurationId).buildConfigurationAuditedRev(1).build();
try {
// make sure there are no two builds with the same start date
Thread.sleep(1L);
} catch (InterruptedException e) {
logger.error("I can get no sleep.", e);
}
repositoryList.add(0, br);
return br;
}
use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class BuildProviderImplTest method shouldThrowCorruptedDataExceptionTest.
@Test(expected = CorruptedDataException.class)
public void shouldThrowCorruptedDataExceptionTest() {
// given
mockBuildRecord(new Base32LongID(200000L), new Long[] {}, new Long[] {});
BuildRecord buildRecord = mockBuildRecord(new Base32LongID(200001L), new Long[] { 200000L, 220000L }, new Long[] {});
// when
Graph<Build> dependencyGraph = provider.getDependencyGraph(BuildMapper.idMapper.toDto(buildRecord.getId()));
}
use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class BuildProviderImplTest method testGetAll.
@Test
public void testGetAll() throws InterruptedException {
BuildRecord buildRecord1 = mockBuildRecord();
// make sure new start time is in the next millisecond
Thread.sleep(1L);
BuildRecord buildRecord2 = mockBuildRecord();
// make sure new start time is in the next millisecond
Thread.sleep(1L);
BuildRecord buildRecord3 = mockBuildRecord();
Page<Build> all = provider.getAll(0, 10, null, null);
assertThat(all.getContent()).hasSize(3).haveExactly(1, new Condition<>(b -> buildRecord1.getSubmitTime().toInstant().equals(b.getSubmitTime()), "Build present")).haveExactly(1, new Condition<>(b -> buildRecord2.getSubmitTime().toInstant().equals(b.getSubmitTime()), "Build present")).haveExactly(1, new Condition<>(b -> buildRecord3.getSubmitTime().toInstant().equals(b.getSubmitTime()), "Build present"));
}
Aggregations