use of org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder in project pnc by project-ncl.
the class ProjectWithDependenciesBuildTest method buildProjectTestCase.
@Test
public void buildProjectTestCase() throws Exception {
clearSemaphores();
// given
testCDIBuildSetStatusChangedReceiver.addBuildSetStatusChangedEventListener(this::collectEvent);
DatastoreMock datastoreMock = new DatastoreMock();
TestProjectConfigurationBuilder configurationBuilder = new TestProjectConfigurationBuilder(datastoreMock);
// when
BuildCoordinatorBeans coordinator = buildCoordinatorFactory.createBuildCoordinator(datastoreMock);
buildProjects(configurationBuilder.buildConfigurationSet(BUILD_SET_ID), coordinator.coordinator);
// expect
List<BuildRecord> buildRecords = datastoreMock.getBuildRecords();
log.trace("Found build records: {}", buildRecords.stream().map(br -> "Br.id: " + br.getId() + ", " + br.getBuildConfigurationAudited().getId().toString()).collect(Collectors.joining("; ")));
Assert.assertEquals("Wrong datastore results count.", 5, buildRecords.size());
BuildRecord buildRecord = buildRecords.get(0);
String buildLog = buildRecord.getBuildLog();
Assert.assertTrue("Invalid build log.", buildLog.contains("Finished: SUCCESS"));
assertArtifactsPresent(buildRecord.getBuiltArtifacts());
assertArtifactsPresent(buildRecord.getDependencies());
BuildConfigSetRecord buildConfigSetRecord = datastoreMock.getBuildConfigSetRecords().get(0);
Assert.assertNotNull("End time not set! Record: " + buildConfigSetRecord, buildConfigSetRecord.getEndTime());
Assert.assertTrue(buildConfigSetRecord.getEndTime().getTime() > buildConfigSetRecord.getStartTime().getTime());
Assert.assertEquals(BuildStatus.SUCCESS, buildConfigSetRecord.getStatus());
String events = eventsReceived.stream().map(Object::toString).collect(Collectors.joining("; "));
Assert.assertEquals("Invalid number of received events. Received events: " + events, 2, eventsReceived.size());
Wait.forCondition(coordinator.queue::isEmpty, 1, ChronoUnit.SECONDS, "Not empty build queue: " + coordinator.queue);
}
use of org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder in project pnc by project-ncl.
the class ProjectWithFailedTransitiveDependenciesBuildTest method buildFailingProjectTestCase.
@Test
@InSequence(10)
public void buildFailingProjectTestCase() throws Exception {
TestProjectConfigurationBuilder configurationBuilder = new TestProjectConfigurationBuilder(datastore);
BuildCoordinatorBeans buildCoordinatorBeans = buildCoordinatorFactory.createBuildCoordinator(datastore);
BuildCoordinator coordinator = buildCoordinatorBeans.coordinator;
buildQueue = buildCoordinatorBeans.queue;
buildFailingProject(configurationBuilder.buildConfigurationSetWithFailedDependenciesAndDelay(1), 1, 2, coordinator);
}
use of org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder in project pnc by project-ncl.
the class CancelledBuildTest method cancelBuildingConfigSetTestCase.
@Test(timeout = 5_000)
public void cancelBuildingConfigSetTestCase() throws Exception {
// given
DatastoreMock datastoreMock = new DatastoreMock();
TestProjectConfigurationBuilder configurationBuilder = new TestProjectConfigurationBuilder(datastoreMock);
BuildCoordinator coordinator = buildCoordinatorFactory.createBuildCoordinator(datastoreMock).coordinator;
BuildConfigurationSet configurationSet = configurationBuilder.buildConfigurationSetForCancel(1);
List<BuildStatusChangedEvent> receivedStatuses = new ArrayList<>();
Consumer<BuildStatusChangedEvent> onStatusUpdate = (event) -> {
receivedStatuses.add(event);
if (event.getBuild().getBuildConfigRevision().getId().equals("2") && event.getNewStatus().equals(BuildStatus.BUILDING)) {
CompletableFuture.runAsync(() -> {
try {
// wait a bit for build execution to start
Thread.sleep(250);
// we need to get buildConfigSet id to cancel BuildGroup, it is not provided by event class
// directly, so we need to dit it up from buildTaskId that event provides
log.info("Cancelling ...");
coordinator.cancelSet(getBuildConfigSetId(coordinator, event.getBuild().getId()));
} catch (CoreException | InterruptedException e) {
log.error("Unable to cancel the build.", e);
Assert.fail("Unable to cancel the build.");
}
});
}
};
// when
BuildSetTask buildSetTask = buildProjects(configurationSet, coordinator, onStatusUpdate, 2);
// expect
List<BuildRecord> buildRecords = datastoreMock.getBuildRecords();
Assert.assertEquals("Incorrect number of build records in datastore: " + buildRecords, 3, buildRecords.size());
for (BuildRecord buildRecord : buildRecords) {
Assert.assertNotNull(buildRecord.getSubmitTime());
switch(buildRecord.getBuildConfigurationId()) {
case 1:
Assert.assertEquals(BuildStatus.CANCELLED, buildRecord.getStatus());
continue;
case 2:
Assert.assertEquals(BuildStatus.CANCELLED, buildRecord.getStatus());
break;
case 3:
Assert.assertEquals(BuildStatus.SUCCESS, buildRecord.getStatus());
break;
default:
Assert.fail("Invalid build configuration ID");
break;
}
Assert.assertNotNull(buildRecord.getStartTime());
Assert.assertNotNull(buildRecord.getEndTime());
}
// 3 is independent, 2 is dependent on 3, 1 is dependent on 2
for (BuildTask buildTask : buildSetTask.getBuildTasks()) {
String buildTaskId = buildTask.getId();
switch(buildTask.getBuildConfigurationAudited().getId()) {
case 1:
// Building status is skipped (cancelled before it can start building)
assertStatusUpdateReceived(receivedStatuses, BuildStatus.WAITING_FOR_DEPENDENCIES, buildTaskId);
assertStatusUpdateReceived(receivedStatuses, BuildStatus.CANCELLED, buildTaskId);
break;
case 2:
assertStatusUpdateReceived(receivedStatuses, BuildStatus.WAITING_FOR_DEPENDENCIES, buildTaskId);
assertStatusUpdateReceived(receivedStatuses, BuildStatus.ENQUEUED, buildTaskId);
assertStatusUpdateReceived(receivedStatuses, BuildStatus.BUILDING, buildTaskId);
assertStatusUpdateReceived(receivedStatuses, BuildStatus.CANCELLED, buildTaskId);
break;
case 3:
assertStatusUpdateReceived(receivedStatuses, BuildStatus.ENQUEUED, buildTaskId);
assertStatusUpdateReceived(receivedStatuses, BuildStatus.BUILDING, buildTaskId);
assertStatusUpdateReceived(receivedStatuses, BuildStatus.SUCCESS, buildTaskId);
break;
default:
break;
}
}
}
use of org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder in project pnc by project-ncl.
the class CancelledBuildByBpmTest method buildSingleProjectTestCase.
@Test(timeout = 5_000)
public void buildSingleProjectTestCase() throws Exception {
// given
DatastoreMock datastoreMock = new DatastoreMock();
TestProjectConfigurationBuilder configurationBuilder = new TestProjectConfigurationBuilder(datastoreMock);
DatastoreAdapter datastoreAdapter = new DatastoreAdapter(datastoreMock);
SystemConfig systemConfig = createConfiguration();
BuildQueue queue = new BuildQueue(systemConfig);
BlockingQueue<BuildStatusChangedEvent> receivedStatuses = new ArrayBlockingQueue<>(5);
Consumer<BuildStatusChangedEvent> onStatusUpdate = receivedStatuses::add;
EventListener buildStatusChangedEventNotifier = new EventListener(onStatusUpdate);
BlockingQueue<BpmTask> task = new ArrayBlockingQueue<>(5);
Consumer<BpmTask> onBpmTaskCreated = task::add;
BuildSchedulerFactory buildSchedulerFactory = new BuildSchedulerFactory(onBpmTaskCreated);
BuildCoordinator coordinator = new DefaultBuildCoordinator(datastoreAdapter, buildStatusChangedEventNotifier, null, buildSchedulerFactory, queue, systemConfig, groupBuildMapper, buildMapper);
coordinator.start();
queue.initSemaphore();
coordinator.build(configurationBuilder.buildConfigurationToCancel(1, "c1-bpm"), MockUser.newTestUser(1), new BuildOptions());
waitForStatus(receivedStatuses, BuildStatus.BUILDING);
BpmTask bpmTask = task.poll(1, TimeUnit.SECONDS);
BuildResultRest result = new BuildResultRest();
result.setCompletionStatus(CompletionStatus.CANCELLED);
// when
bpmTask.notify(BUILD_COMPLETE, result);
waitForStatus(receivedStatuses, BuildStatus.CANCELLED);
// expect
List<BuildRecord> buildRecords = datastoreMock.getBuildRecords();
Assert.assertEquals("Too many build records in datastore: " + buildRecords, 1, buildRecords.size());
BuildRecord buildRecord = buildRecords.get(0);
Assert.assertNotNull(buildRecord.getSubmitTime());
Assert.assertNotNull(buildRecord.getStartTime());
Assert.assertNotNull(buildRecord.getEndTime());
Assert.assertEquals(BuildStatus.CANCELLED, buildRecord.getStatus());
}
use of org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder in project pnc by project-ncl.
the class CancelledBuildTest method buildSingleProjectTestCase.
@Test(timeout = 5_000)
public void buildSingleProjectTestCase() throws Exception {
// given
TestProjectConfigurationBuilder configurationBuilder = new TestProjectConfigurationBuilder(datastore);
BuildCoordinator coordinator = buildCoordinatorFactory.createBuildCoordinator(datastore).coordinator;
List<BuildStatusChangedEvent> receivedStatuses = new ArrayList<>();
Consumer<BuildStatusChangedEvent> onStatusUpdate = (event) -> {
receivedStatuses.add(event);
if (event.getNewStatus().equals(BuildStatus.BUILDING)) {
CompletableFuture.runAsync(() -> {
try {
// wait a bit for build execution to start
Thread.sleep(250);
coordinator.cancel(event.getBuild().getId());
} catch (CoreException | InterruptedException e) {
log.error("Unable to cancel the build.", e);
Assert.fail("Unable to cancel the build.");
}
});
}
};
// when
BuildTask buildTask = buildProject(configurationBuilder.buildConfigurationToCancel(1, "c1-java"), coordinator, onStatusUpdate);
// expect
List<BuildRecord> buildRecords = datastore.getBuildRecords();
Assert.assertEquals("Too many build records in datastore: " + buildRecords, 1, buildRecords.size());
BuildRecord buildRecord = buildRecords.get(0);
Assert.assertNotNull(buildRecord.getSubmitTime());
Assert.assertNotNull(buildRecord.getStartTime());
Assert.assertNotNull(buildRecord.getEndTime());
Assert.assertEquals(BuildStatus.CANCELLED, buildRecord.getStatus());
String buildTaskId = buildTask.getId();
assertStatusUpdateReceived(receivedStatuses, BuildStatus.BUILDING, buildTaskId);
assertStatusUpdateReceived(receivedStatuses, BuildStatus.CANCELLED, buildTaskId);
}
Aggregations