Search in sources :

Example 1 with BuildQueue

use of org.jboss.pnc.coordinator.builder.BuildQueue in project pnc by project-ncl.

the class AbstractDependentBuildTest method initialize.

@Before
@SuppressWarnings("unchecked")
public void initialize() throws DatastoreException, ConfigurationParseException {
    MockitoAnnotations.initMocks(this);
    builtTasks = new ArrayList<>();
    user = new User();
    user.setId(375939);
    user.setUsername("username");
    Configuration config = mock(Configuration.class);
    SystemConfig systemConfig = mock(SystemConfig.class);
    when(systemConfig.getCoordinatorThreadPoolSize()).thenReturn(1);
    when(systemConfig.getCoordinatorMaxConcurrentBuilds()).thenReturn(1);
    when(systemConfig.getTemporaryBuildsLifeSpan()).thenReturn(1);
    when(config.getModuleConfig(any())).thenReturn(systemConfig);
    buildQueue = new BuildQueue(config.getModuleConfig(new PncConfigProvider<>(SystemConfig.class)));
    if (buildConfigurationRepository == null) {
        buildConfigurationRepository = new BuildConfigurationRepositoryMock();
    }
    buildRecordRepository = new BuildRecordRepositoryMock();
    buildConfigurationAuditedRepository = new BuildConfigurationAuditedRepositoryMock();
    TargetRepositoryRepository targetRepositoryRepository = new TargetRepositoryRepositoryMock();
    DefaultDatastore datastore = new DefaultDatastore(new ArtifactRepositoryMock(), buildRecordRepository, buildConfigurationRepository, buildConfigurationAuditedRepository, new BuildConfigSetRecordRepositoryMock(), new UserRepositoryMock(), targetRepositoryRepository);
    DatastoreAdapter datastoreAdapter = new DatastoreAdapter(datastore);
    if (buildSchedulerFactory == null) {
        buildSchedulerFactory = new MockBuildSchedulerFactory();
    }
    coordinator = new DefaultBuildCoordinator(datastoreAdapter, mock(Event.class), mock(Event.class), buildSchedulerFactory, buildQueue, systemConfig, mock(GroupBuildMapper.class), mock(BuildMapper.class));
    buildQueue.initSemaphore();
    coordinator.start();
}
Also used : BuildQueue(org.jboss.pnc.coordinator.builder.BuildQueue) SystemConfig(org.jboss.pnc.common.json.moduleconfig.SystemConfig) User(org.jboss.pnc.model.User) BuildConfigSetRecordRepositoryMock(org.jboss.pnc.mock.repository.BuildConfigSetRecordRepositoryMock) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) RepositoryConfiguration(org.jboss.pnc.model.RepositoryConfiguration) Configuration(org.jboss.pnc.common.Configuration) BuildRecordRepositoryMock(org.jboss.pnc.mock.repository.BuildRecordRepositoryMock) TargetRepositoryRepositoryMock(org.jboss.pnc.mock.repository.TargetRepositoryRepositoryMock) BuildConfigurationRepositoryMock(org.jboss.pnc.mock.repository.BuildConfigurationRepositoryMock) BuildConfigurationAuditedRepositoryMock(org.jboss.pnc.mock.repository.BuildConfigurationAuditedRepositoryMock) TargetRepositoryRepository(org.jboss.pnc.spi.datastore.repositories.TargetRepositoryRepository) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) DefaultBuildCoordinator(org.jboss.pnc.coordinator.builder.DefaultBuildCoordinator) DefaultDatastore(org.jboss.pnc.datastore.DefaultDatastore) ArtifactRepositoryMock(org.jboss.pnc.mock.repository.ArtifactRepositoryMock) UserRepositoryMock(org.jboss.pnc.mock.repository.UserRepositoryMock) Before(org.junit.Before)

Example 2 with BuildQueue

use of org.jboss.pnc.coordinator.builder.BuildQueue 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 3 with BuildQueue

use of org.jboss.pnc.coordinator.builder.BuildQueue 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);
}
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) BuildSchedulerFactory(org.jboss.pnc.coordinator.builder.BuildSchedulerFactory) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) DefaultBuildCoordinator(org.jboss.pnc.coordinator.builder.DefaultBuildCoordinator)

Aggregations

SystemConfig (org.jboss.pnc.common.json.moduleconfig.SystemConfig)3 BuildQueue (org.jboss.pnc.coordinator.builder.BuildQueue)3 DefaultBuildCoordinator (org.jboss.pnc.coordinator.builder.DefaultBuildCoordinator)3 DatastoreAdapter (org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter)3 BuildCoordinator (org.jboss.pnc.spi.coordinator.BuildCoordinator)2 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 BpmTask (org.jboss.pnc.bpm.BpmTask)1 BuildResultRest (org.jboss.pnc.bpm.model.BuildResultRest)1 Configuration (org.jboss.pnc.common.Configuration)1 BuildSchedulerFactory (org.jboss.pnc.coordinator.builder.BuildSchedulerFactory)1 DefaultDatastore (org.jboss.pnc.datastore.DefaultDatastore)1 DatastoreMock (org.jboss.pnc.mock.datastore.DatastoreMock)1 TestProjectConfigurationBuilder (org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder)1 ArtifactRepositoryMock (org.jboss.pnc.mock.repository.ArtifactRepositoryMock)1 BuildConfigSetRecordRepositoryMock (org.jboss.pnc.mock.repository.BuildConfigSetRecordRepositoryMock)1 BuildConfigurationAuditedRepositoryMock (org.jboss.pnc.mock.repository.BuildConfigurationAuditedRepositoryMock)1 BuildConfigurationRepositoryMock (org.jboss.pnc.mock.repository.BuildConfigurationRepositoryMock)1 BuildRecordRepositoryMock (org.jboss.pnc.mock.repository.BuildRecordRepositoryMock)1 TargetRepositoryRepositoryMock (org.jboss.pnc.mock.repository.TargetRepositoryRepositoryMock)1 UserRepositoryMock (org.jboss.pnc.mock.repository.UserRepositoryMock)1