Search in sources :

Example 66 with BuildRecord

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());
}
Also used : Base32LongID(org.jboss.pnc.model.Base32LongID) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) Build(org.jboss.pnc.dto.Build) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Example 67 with BuildRecord

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());
}
Also used : Build(org.jboss.pnc.dto.Build) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Example 68 with BuildRecord

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;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Base32LongID(org.jboss.pnc.model.Base32LongID) BuildRecord(org.jboss.pnc.model.BuildRecord) Date(java.util.Date)

Example 69 with BuildRecord

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()));
}
Also used : Base32LongID(org.jboss.pnc.model.Base32LongID) Build(org.jboss.pnc.dto.Build) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Example 70 with BuildRecord

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"));
}
Also used : PageInfo(org.jboss.pnc.spi.datastore.repositories.api.PageInfo) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Arrays(java.util.Arrays) Date(java.util.Date) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationAuditedRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationAuditedRepository) Repository(org.jboss.pnc.spi.datastore.repositories.api.Repository) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) BuildConfigSetRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigSetRecordRepository) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BDDMockito.given(org.mockito.BDDMockito.given) UserService(org.jboss.pnc.facade.util.UserService) Graph(org.jboss.pnc.dto.response.Graph) Assert.fail(org.junit.Assert.fail) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) User(org.jboss.pnc.model.User) SortInfoProducer(org.jboss.pnc.spi.datastore.repositories.SortInfoProducer) ResultStatus(org.jboss.pnc.enums.ResultStatus) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) Result(org.jboss.pnc.spi.coordinator.Result) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) Assert.assertFalse(org.junit.Assert.assertFalse) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) WireMock.matchingJsonPath(com.github.tomakehurst.wiremock.client.WireMock.matchingJsonPath) Base32LongID(org.jboss.pnc.model.Base32LongID) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) Predicate(org.jboss.pnc.spi.datastore.repositories.api.Predicate) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) WireMock.postRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor) BuildPageInfo(org.jboss.pnc.facade.providers.api.BuildPageInfo) BuildMapper(org.jboss.pnc.mapper.api.BuildMapper) ArrayList(java.util.ArrayList) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) HashSet(java.util.HashSet) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Edge(org.jboss.pnc.dto.response.Edge) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) CorruptedDataException(org.jboss.pnc.facade.validation.CorruptedDataException) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) WireMock.equalTo(com.github.tomakehurst.wiremock.client.WireMock.equalTo) Logger(org.slf4j.Logger) LongStream(java.util.stream.LongStream) Iterator(java.util.Iterator) Test(org.junit.Test) BuildRecord(org.jboss.pnc.model.BuildRecord) Mockito.when(org.mockito.Mockito.when) TemporaryBuildsCleanerAsyncInvoker(org.jboss.pnc.coordinator.maintenance.TemporaryBuildsCleanerAsyncInvoker) Page(org.jboss.pnc.dto.response.Page) Vertex(org.jboss.pnc.dto.response.Vertex) Consumer(java.util.function.Consumer) Build(org.jboss.pnc.dto.Build) Condition(org.assertj.core.api.Condition) RandomUtils.randInt(org.jboss.pnc.common.util.RandomUtils.randInt) WireMock.urlEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo) Comparator(java.util.Comparator) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.same(org.mockito.ArgumentMatchers.same) Condition(org.assertj.core.api.Condition) Build(org.jboss.pnc.dto.Build) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Aggregations

BuildRecord (org.jboss.pnc.model.BuildRecord)92 Test (org.junit.Test)50 Base32LongID (org.jboss.pnc.model.Base32LongID)19 Build (org.jboss.pnc.dto.Build)15 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)15 ContainerTest (org.jboss.pnc.test.category.ContainerTest)14 HashSet (java.util.HashSet)13 Artifact (org.jboss.pnc.model.Artifact)13 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)13 SortInfo (org.jboss.pnc.spi.datastore.repositories.api.SortInfo)13 Date (java.util.Date)12 List (java.util.List)12 BuildConfigSetRecord (org.jboss.pnc.model.BuildConfigSetRecord)12 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)12 DatastoreMock (org.jboss.pnc.mock.datastore.DatastoreMock)11 PageInfo (org.jboss.pnc.spi.datastore.repositories.api.PageInfo)11 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 Inject (javax.inject.Inject)10 BuildStatus (org.jboss.pnc.enums.BuildStatus)10