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();
}
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));
}
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());
}
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());
}
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());
}
Aggregations