Search in sources :

Example 26 with BuildTask

use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.

the class DatastoreAdapterTest method shouldStoreRepourResult.

@Test
public void shouldStoreRepourResult() throws DatastoreException {
    // given
    DatastoreMock datastore = new DatastoreMock();
    DatastoreAdapter datastoreAdapter = new DatastoreAdapter(datastore);
    RepourResult repourResult = RepourResultMock.mock();
    // when
    BuildConfiguration buildConfiguration = BuildConfiguration.Builder.newBuilder().name("Configuration.").build();
    BuildConfigurationAudited buildConfigurationAudited = BuildConfigurationAudited.Builder.newBuilder().buildConfiguration(buildConfiguration).build();
    BuildTask buildTask = mockBuildTask();
    BuildExecutionConfiguration buildExecutionConfiguration = mock(BuildExecutionConfiguration.class);
    BuildResult buildResult = new BuildResult(CompletionStatus.SUCCESS, Optional.empty(), "", Optional.of(buildExecutionConfiguration), Optional.of(BuildDriverResultMock.mockResult(BuildStatus.SUCCESS)), Optional.of(RepositoryManagerResultMock.mockResult()), Optional.of(EnvironmentDriverResultMock.mock()), Optional.of(repourResult));
    datastoreAdapter.storeResult(buildTask, buildResult);
    // then
    List<BuildRecord> buildRecords = datastore.getBuildRecords();
    Assert.assertEquals(1, buildRecords.size());
    BuildRecord buildRecord = buildRecords.get(0);
    Assert.assertEquals(buildRecord.getStatus(), BuildStatus.SUCCESS);
    Assert.assertEquals(repourResult.getExecutionRootName(), buildRecord.getExecutionRootName());
    Assert.assertEquals(repourResult.getExecutionRootVersion(), buildRecord.getExecutionRootVersion());
    Assert.assertEquals(repourResult.getLog(), buildRecord.getRepourLog());
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildResult(org.jboss.pnc.spi.BuildResult) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) RepourResult(org.jboss.pnc.spi.repour.RepourResult) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Example 27 with BuildTask

use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.

the class StatusUpdatesTest method BuildTaskCallbacksShouldBeCalled.

@Test
@InSequence(30)
public void BuildTaskCallbacksShouldBeCalled() throws DatastoreException, CoreException {
    User user = User.Builder.newBuilder().id(3).username("test-user-3").build();
    Set<BuildTask> buildTasks = initializeBuildTaskSet(configurationBuilder, user, (buildConfigSetRecord) -> {
    }).getBuildTasks();
    Set<String> tasksIds = buildTasks.stream().map((BuildTask::getId)).collect(Collectors.toSet());
    Set<String> receivedUpdatesForId = new HashSet<>();
    Consumer<BuildStatusChangedEvent> statusChangeEventConsumer = (statusChangedEvent) -> {
        receivedUpdatesForId.add(statusChangedEvent.getBuild().getId());
    };
    tasksIds.forEach((id) -> buildStatusNotifications.subscribe(new BuildCallBack(id, statusChangeEventConsumer)));
    buildTasks.forEach((bt) -> buildCoordinator.updateBuildTaskStatus(bt, BuildCoordinationStatus.DONE));
    System.out.println("Received updates: " + receivedUpdatesForId);
    tasksIds.forEach((id) -> Assert.assertTrue("Did not receive update for task " + id, receivedUpdatesForId.contains(id)));
}
Also used : BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildStatusNotifications(org.jboss.pnc.coordinator.notifications.buildTask.BuildStatusNotifications) Arquillian(org.jboss.arquillian.junit.Arquillian) BuildCoordinationStatus(org.jboss.pnc.enums.BuildCoordinationStatus) LoggerFactory(org.slf4j.LoggerFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) User(org.jboss.pnc.model.User) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) BuildResult(org.jboss.pnc.spi.BuildResult) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) Set(java.util.Set) BuildStatus(org.jboss.pnc.enums.BuildStatus) Collectors(java.util.stream.Collectors) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) CoreException(org.jboss.pnc.spi.exception.CoreException) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent) Optional(java.util.Optional) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) IndyRepositoryManagerResult(org.jboss.pnc.indyrepositorymanager.IndyRepositoryManagerResult) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) BuildSetStatus(org.jboss.pnc.spi.BuildSetStatus) RunWith(org.junit.runner.RunWith) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) BuildSetStatusNotifications(org.jboss.pnc.coordinator.notifications.buildSetTask.BuildSetStatusNotifications) BuildCallBack(org.jboss.pnc.coordinator.notifications.buildTask.BuildCallBack) RebuildMode(org.jboss.pnc.enums.RebuildMode) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) Supplier(java.util.function.Supplier) Inject(javax.inject.Inject) HashSet(java.util.HashSet) BuildCoordinatorDeployments(org.jboss.pnc.coordinator.test.BuildCoordinatorDeployments) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) BuildTasksInitializer(org.jboss.pnc.coordinator.builder.BuildTasksInitializer) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) BuildQueue(org.jboss.pnc.coordinator.builder.BuildQueue) Event(javax.enterprise.event.Event) Logger(org.slf4j.Logger) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence) Consumer(java.util.function.Consumer) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) Deployment(org.jboss.arquillian.container.test.api.Deployment) Assert(org.junit.Assert) Sequence(org.jboss.pnc.common.concurrent.Sequence) Collections(java.util.Collections) User(org.jboss.pnc.model.User) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) BuildCallBack(org.jboss.pnc.coordinator.notifications.buildTask.BuildCallBack) HashSet(java.util.HashSet) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 28 with BuildTask

use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.

the class ReadDependenciesTest method createDependenciesTestCase.

@Test
public void createDependenciesTestCase() throws DatastoreException {
    BuildConfigurationSet buildConfigurationSet = configurationBuilder.buildConfigurationSet(1);
    User user = User.Builder.newBuilder().id(1).username("test-user").build();
    BuildSetTask buildSetTask = null;
    try {
        buildSetTask = createBuildSetTask(buildConfigurationSet, user);
    } catch (CoreException e) {
        Assert.fail(e.getMessage());
    }
    Assert.assertEquals("Missing build tasks in set.", 5, buildSetTask.getBuildTasks().size());
    BuildTask buildTask2 = buildSetTask.getBuildTasks().stream().filter(task -> task.getBuildConfigurationAudited().getId().equals(2)).findFirst().get();
    Assert.assertEquals("Wrong number of dependencies.", 2, buildTask2.getDependencies().size());
}
Also used : BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) User(org.jboss.pnc.model.User) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) CoreException(org.jboss.pnc.spi.exception.CoreException) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) Test(org.junit.Test)

Example 29 with BuildTask

use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.

the class SingleProjectBuildTest method buildWithAdvancedOptionsTest.

@Test
public void buildWithAdvancedOptionsTest() throws Exception {
    // given
    BuildOptions originalBuildOptions = new BuildOptions(true, true, true, true, RebuildMode.FORCE, AlignmentPreference.PREFER_PERSISTENT);
    DatastoreMock datastoreMock = new DatastoreMock();
    TestProjectConfigurationBuilder configurationBuilder = new TestProjectConfigurationBuilder(datastoreMock);
    List<BuildStatusChangedEvent> receivedStatuses = new CopyOnWriteArrayList<>();
    // when
    BuildCoordinator coordinator = buildCoordinatorFactory.createBuildCoordinator(datastoreMock).coordinator;
    BuildTask buildTask = buildProject(configurationBuilder.build(1, "c1-java"), coordinator, receivedStatuses::add, originalBuildOptions);
    // then
    List<BuildRecord> buildRecords = datastoreMock.getBuildRecords();
    Assert.assertEquals("Wrong datastore results count.", 1, buildRecords.size());
    Assert.assertEquals(originalBuildOptions, buildTask.getBuildOptions());
}
Also used : BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildOptions(org.jboss.pnc.spi.BuildOptions) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) BuildRecord(org.jboss.pnc.model.BuildRecord) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.Test)

Example 30 with BuildTask

use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.

the class SingleProjectBuildTest method buildWithBasicOptionsTest.

@Test
public void buildWithBasicOptionsTest() throws Exception {
    // given
    DatastoreMock datastoreMock = new DatastoreMock();
    TestProjectConfigurationBuilder configurationBuilder = new TestProjectConfigurationBuilder(datastoreMock);
    List<BuildStatusChangedEvent> receivedStatuses = new CopyOnWriteArrayList<>();
    // when
    BuildCoordinator coordinator = buildCoordinatorFactory.createBuildCoordinator(datastoreMock).coordinator;
    BuildTask buildTask = buildProject(configurationBuilder.build(1, "c1-java"), coordinator, receivedStatuses::add);
    // then
    List<BuildRecord> buildRecords = datastoreMock.getBuildRecords();
    Assert.assertEquals("Wrong datastore results count.", 1, buildRecords.size());
    Assert.assertEquals(new BuildOptions(), buildTask.getBuildOptions());
}
Also used : BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildOptions(org.jboss.pnc.spi.BuildOptions) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) BuildRecord(org.jboss.pnc.model.BuildRecord) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.Test)

Aggregations

BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)43 Test (org.junit.Test)23 BuildRecord (org.jboss.pnc.model.BuildRecord)15 BuildSetTask (org.jboss.pnc.spi.coordinator.BuildSetTask)15 Build (org.jboss.pnc.dto.Build)13 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)13 BuildCoordinator (org.jboss.pnc.spi.coordinator.BuildCoordinator)13 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)12 BuildOptions (org.jboss.pnc.spi.BuildOptions)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 Inject (javax.inject.Inject)11 BuildConfigurationSet (org.jboss.pnc.model.BuildConfigurationSet)11 CoreException (org.jboss.pnc.spi.exception.CoreException)11 User (org.jboss.pnc.model.User)10 BuildStatusChangedEvent (org.jboss.pnc.spi.events.BuildStatusChangedEvent)10 Date (java.util.Date)9 Set (java.util.Set)9 HashSet (java.util.HashSet)8 List (java.util.List)8