Search in sources :

Example 1 with DatastoreAdapter

use of org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter 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 DatastoreAdapter

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

the class DatastoreAdapterTest method shouldStoreRepositoryManagerError.

@Test
public void shouldStoreRepositoryManagerError() throws DatastoreException {
    // given
    DatastoreMock datastore = new DatastoreMock();
    DatastoreAdapter datastoreAdapter = new DatastoreAdapter(datastore);
    BuildStatus buildStatus = BuildStatus.SUCCESS;
    CompletionStatus completionStatus = CompletionStatus.FAILED;
    // when
    storeResult(datastoreAdapter, buildStatus, completionStatus);
    // then
    List<BuildRecord> buildRecords = datastore.getBuildRecords();
    Assert.assertEquals(1, buildRecords.size());
    BuildRecord buildRecord = buildRecords.get(0);
    Assert.assertEquals(BuildStatus.FAILED, buildRecord.getStatus());
    Assert.assertTrue(buildRecord.getBuildLog().contains(BUILD_LOG));
    Assert.assertTrue(buildRecord.getBuildLog().contains(REPOSITORY_MANAGER_LOG));
}
Also used : CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) BuildStatus(org.jboss.pnc.enums.BuildStatus) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Example 3 with DatastoreAdapter

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

the class DatastoreAdapterTest method shouldStoreNoRequiredRebuild.

@Test
public void shouldStoreNoRequiredRebuild() throws DatastoreException {
    // given
    DatastoreMock datastore = new DatastoreMock();
    DatastoreAdapter datastoreAdapter = new DatastoreAdapter(datastore);
    // when
    datastoreAdapter.storeRecordForNoRebuild(mockBuildTask());
    // then
    List<BuildRecord> buildRecords = datastore.getBuildRecords();
    Assert.assertEquals(1, buildRecords.size());
    BuildRecord buildRecord = buildRecords.get(0);
    Assert.assertEquals(BuildStatus.NO_REBUILD_REQUIRED, buildRecord.getStatus());
}
Also used : DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Example 4 with DatastoreAdapter

use of org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter 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 DatastoreAdapter

use of org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter 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)

Aggregations

DatastoreAdapter (org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter)7 DatastoreMock (org.jboss.pnc.mock.datastore.DatastoreMock)5 BuildRecord (org.jboss.pnc.model.BuildRecord)5 Test (org.junit.Test)5 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 BuildStatus (org.jboss.pnc.enums.BuildStatus)2 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)2 BuildCoordinator (org.jboss.pnc.spi.coordinator.BuildCoordinator)2 CompletionStatus (org.jboss.pnc.spi.coordinator.CompletionStatus)2 BuildExecutionConfiguration (org.jboss.pnc.spi.executor.BuildExecutionConfiguration)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 TestProjectConfigurationBuilder (org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder)1 ArtifactRepositoryMock (org.jboss.pnc.mock.repository.ArtifactRepositoryMock)1