Search in sources :

Example 1 with TestProjectConfigurationBuilder

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);
}
Also used : TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) Test(org.junit.Test)

Example 2 with TestProjectConfigurationBuilder

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);
}
Also used : BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 3 with TestProjectConfigurationBuilder

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;
        }
    }
}
Also used : BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) Logger(org.slf4j.Logger) Arquillian(org.jboss.arquillian.junit.Arquillian) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildStatus(org.jboss.pnc.enums.BuildStatus) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Consumer(java.util.function.Consumer) List(java.util.List) CoreException(org.jboss.pnc.spi.exception.CoreException) Deployment(org.jboss.arquillian.container.test.api.Deployment) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) Assert(org.junit.Assert) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) ArrayList(java.util.ArrayList) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) Test(org.junit.Test)

Example 4 with TestProjectConfigurationBuilder

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());
}
Also used : BuildQueue(org.jboss.pnc.coordinator.builder.BuildQueue) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) DefaultBuildCoordinator(org.jboss.pnc.coordinator.builder.DefaultBuildCoordinator) SystemConfig(org.jboss.pnc.common.json.moduleconfig.SystemConfig) BpmTask(org.jboss.pnc.bpm.BpmTask) 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) BuildResultRest(org.jboss.pnc.bpm.model.BuildResultRest) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) BuildOptions(org.jboss.pnc.spi.BuildOptions) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) DefaultBuildCoordinator(org.jboss.pnc.coordinator.builder.DefaultBuildCoordinator) Test(org.junit.Test)

Example 5 with TestProjectConfigurationBuilder

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);
}
Also used : BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) Logger(org.slf4j.Logger) Arquillian(org.jboss.arquillian.junit.Arquillian) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildStatus(org.jboss.pnc.enums.BuildStatus) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Consumer(java.util.function.Consumer) List(java.util.List) CoreException(org.jboss.pnc.spi.exception.CoreException) Deployment(org.jboss.arquillian.container.test.api.Deployment) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) Assert(org.junit.Assert) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) ArrayList(java.util.ArrayList) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Aggregations

TestProjectConfigurationBuilder (org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder)8 Test (org.junit.Test)8 DatastoreMock (org.jboss.pnc.mock.datastore.DatastoreMock)7 BuildRecord (org.jboss.pnc.model.BuildRecord)7 BuildCoordinator (org.jboss.pnc.spi.coordinator.BuildCoordinator)7 BuildStatusChangedEvent (org.jboss.pnc.spi.events.BuildStatusChangedEvent)6 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)5 BuildOptions (org.jboss.pnc.spi.BuildOptions)4 List (java.util.List)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 Inject (javax.inject.Inject)3 Deployment (org.jboss.arquillian.container.test.api.Deployment)3 Arquillian (org.jboss.arquillian.junit.Arquillian)3 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)3 Assert (org.junit.Assert)3 RunWith (org.junit.runner.RunWith)3 ArrayList (java.util.ArrayList)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Consumer (java.util.function.Consumer)2 BuildStatus (org.jboss.pnc.enums.BuildStatus)2