use of org.jboss.pnc.spi.coordinator.BuildCoordinator in project pnc by project-ncl.
the class ProjectBuilder method buildProjectsAndWaitForUpdates.
private BuildSetTask buildProjectsAndWaitForUpdates(BuildConfigurationSet buildConfigurationSet, BuildCoordinator buildCoordinator, int nStatusUpdates, Consumer<BuildStatusChangedEvent> onStatusUpdate, List<BuildStatusChangedEvent> receivedStatuses, List<BuildSetStatusChangedEvent> receivedSetStatuses) throws InterruptedException, CoreException {
Consumer<BuildStatusChangedEvent> onStatusUpdateInternal = (statusUpdate) -> {
log.debug("Received status change event [" + (i++) + "]: {}.", statusUpdate);
receivedStatuses.add(statusUpdate);
onStatusUpdate.accept(statusUpdate);
};
final Semaphore semaphore = registerReleaseListenersAndAcquireSemaphore(onStatusUpdateInternal, nStatusUpdates);
final Semaphore buildSetSemaphore = registerBuildSetListeners(receivedSetStatuses, BUILD_SET_STATUS_UPDATES);
BuildOptions buildOptions = new BuildOptions();
buildOptions.setRebuildMode(RebuildMode.FORCE);
BuildSetTask buildSetTask = buildCoordinator.build(buildConfigurationSet, MockUser.newTestUser(1), buildOptions);
assertBuildStartedSuccessfully(buildSetTask);
log.info("Waiting to receive all {} status updates...", nStatusUpdates);
waitForStatusUpdates(nStatusUpdates, semaphore, "");
log.debug("All status updates should be received. Semaphore has {} free entries.", semaphore.availablePermits());
log.info("Waiting to receive all {} build set status updates...", BUILD_SET_STATUS_UPDATES);
waitForStatusUpdates(BUILD_SET_STATUS_UPDATES, buildSetSemaphore, "build set task: " + buildSetTask);
log.debug("All status updates should be received. Semaphore has {} free entries.", semaphore.availablePermits());
return buildSetTask;
}
use of org.jboss.pnc.spi.coordinator.BuildCoordinator 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());
}
use of org.jboss.pnc.spi.coordinator.BuildCoordinator in project pnc by project-ncl.
the class SingleProjectBuildTest method buildSingleProjectTestCase.
@Test
public void buildSingleProjectTestCase() throws Exception {
// given
DatastoreMock datastoreMock = new DatastoreMock();
TestProjectConfigurationBuilder configurationBuilder = new TestProjectConfigurationBuilder(datastoreMock);
List<BuildStatusChangedEvent> receivedStatuses = new CopyOnWriteArrayList<>();
// when
BuildCoordinator coordinator = buildCoordinatorFactory.createBuildCoordinator(datastoreMock).coordinator;
buildProject(configurationBuilder.build(1, "c1-java"), coordinator, receivedStatuses::add);
// expect
List<BuildRecord> buildRecords = datastoreMock.getBuildRecords();
Assert.assertEquals("Wrong datastore results count.", 1, buildRecords.size());
BuildRecord buildRecord = buildRecords.get(0);
String buildLog = buildRecord.getBuildLog();
Assert.assertTrue("Invalid build log.", buildLog.contains(BuildDriverResultMock.BUILD_LOG));
assertArtifactsPresent(buildRecord.getBuiltArtifacts());
assertArtifactsPresent(buildRecord.getDependencies());
Assert.assertNotNull(buildRecord.getSubmitTime());
Assert.assertNotNull(buildRecord.getStartTime());
Assert.assertNotNull(buildRecord.getEndTime());
receivedStatuses.stream().filter(e -> e.getNewStatus().isFinal()).forEach(e -> Assert.assertNotNull("Final event " + e + " should have end build time.", e.getBuild().getEndTime()));
}
use of org.jboss.pnc.spi.coordinator.BuildCoordinator 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());
}
use of org.jboss.pnc.spi.coordinator.BuildCoordinator in project pnc by project-ncl.
the class BuildCoordinatorFactory method createBuildCoordinator.
public BuildCoordinatorBeans createBuildCoordinator(DatastoreMock datastore) {
DatastoreAdapter datastoreAdapter = new DatastoreAdapter(datastore);
SystemConfig systemConfig = createConfiguration();
BuildQueue queue = new BuildQueue(systemConfig);
LocalBuildSchedulerMock localBuildScheduler = new LocalBuildSchedulerMock();
BuildSchedulerFactory buildSchedulerFactory = new BuildSchedulerFactory() {
@Override
public BuildScheduler getBuildScheduler() {
return localBuildScheduler;
}
};
BuildCoordinator coordinator = new DefaultBuildCoordinator(datastoreAdapter, buildStatusChangedEventNotifier, buildSetStatusChangedEventNotifier, buildSchedulerFactory, queue, systemConfig, groupBuildMapper, buildMapper);
localBuildScheduler.setBuildCoordinator(coordinator);
coordinator.start();
queue.initSemaphore();
return new BuildCoordinatorBeans(queue, coordinator);
}
Aggregations