use of org.jboss.pnc.common.Configuration 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.common.Configuration in project pnc by project-ncl.
the class BuildDriverFactoryTest method shouldSkipDriversWhichAreNotMentionedInConfiguration.
@Test(expected = ExecutorException.class)
public void shouldSkipDriversWhichAreNotMentionedInConfiguration() throws Exception {
// given
ProperDriver testedBuildDriver = new ProperDriver();
TestInstance<BuildDriver> allDrivers = new TestInstance<>(testedBuildDriver);
Configuration configuration = new Configuration();
BuildDriverFactory factory = new BuildDriverFactory(allDrivers, configuration);
factory.initConfiguration();
// when
factory.getBuildDriver();
}
use of org.jboss.pnc.common.Configuration in project pnc by project-ncl.
the class BuildEnvironmentTest method runBuild.
private void runBuild(BuildConfiguration buildConfiguration, Set<BuildExecutionStatusChangedEvent> statusChangedEvents, ObjectWrapper<BuildResult> buildExecutionResultWrapper, boolean keepAliveOnFailure) throws ExecutorException {
DefaultBuildExecutor executor = null;
try {
executor = new DefaultBuildExecutor(repositoryManagerFactory, buildDriverFactory, environmentDriverFactory, new Configuration(), null);
} catch (ConfigurationParseException e) {
log.error(e.toString());
}
Consumer<BuildExecutionStatusChangedEvent> onBuildExecutionStatusChangedEvent = (statusChangedEvent) -> {
log.debug("Received execution status update {}.", statusChangedEvent);
statusChangedEvents.add(statusChangedEvent);
if (statusChangedEvent.getNewStatus().isCompleted()) {
BuildResult buildResult = statusChangedEvent.getBuildResult().get();
buildExecutionResultWrapper.set(buildResult);
}
};
BuildExecutionConfiguration buildExecutionConfiguration = new DefaultBuildExecutionConfiguration("1", "build-content-id", "1", buildConfiguration.getBuildScript(), buildConfiguration.getId().toString(), buildConfiguration.getName(), buildConfiguration.getRepositoryConfiguration().getInternalUrl(), buildConfiguration.getScmRevision(), null, buildConfiguration.getRepositoryConfiguration().getExternalUrl(), buildConfiguration.getRepositoryConfiguration().isPreBuildSyncEnabled(), buildConfiguration.getBuildType(), buildConfiguration.getBuildEnvironment().getSystemImageId(), buildConfiguration.getBuildEnvironment().getSystemImageRepositoryUrl(), buildConfiguration.getBuildEnvironment().getSystemImageType(), keepAliveOnFailure, null, buildConfiguration.getGenericParameters(), false, null, buildConfiguration.isBrewPullActive(), buildConfiguration.getDefaultAlignmentParams(), AlignmentPreference.PREFER_TEMPORARY);
executor.startBuilding(buildExecutionConfiguration, onBuildExecutionStatusChangedEvent, "");
}
use of org.jboss.pnc.common.Configuration in project pnc by project-ncl.
the class BuildExecutionCancellationTest method testBuild.
@Test(timeout = 3000)
public void testBuild() throws ExecutorException, TimeoutException, InterruptedException, BuildDriverException, ConfigurationParseException {
BuildConfiguration buildConfiguration = configurationBuilder.build(1, "c1-java");
Set<BuildExecutionStatusChangedEvent> statusChangedEvents = new HashSet<>();
ObjectWrapper<BuildResult> buildExecutionResultWrapper = new ObjectWrapper<>();
DefaultBuildExecutor executor = new DefaultBuildExecutor(repositoryManagerFactory, buildDriverFactory, environmentDriverFactory, new Configuration(), null);
Consumer<BuildExecutionStatusChangedEvent> cancel = (e) -> {
if (BuildExecutionStatus.BUILD_WAITING.equals(e.getNewStatus())) {
try {
log.info("Cancelling build ...");
Thread.sleep(100);
executor.cancel(e.getBuildTaskId());
} catch (ExecutorException | InterruptedException e0) {
e0.printStackTrace();
}
}
};
runBuild(buildConfiguration, statusChangedEvents, buildExecutionResultWrapper, cancel, executor);
List<BuildExecutionStatus> expectedStatuses = getBuildExecutionStatusesBase();
expectedStatuses.add(BuildExecutionStatus.CANCELLED);
// check build statuses
checkBuildStatuses(statusChangedEvents, expectedStatuses);
// check results
BuildResult buildResult = buildExecutionResultWrapper.get();
BuildDriverResult buildDriverResult = buildResult.getBuildDriverResult().get();
Assert.assertEquals(BuildStatus.CANCELLED, buildDriverResult.getBuildStatus());
}
use of org.jboss.pnc.common.Configuration in project pnc by project-ncl.
the class IndyRepoDriverModuleConfigTest method checkDefaultValuesLoadedProperly.
@Test
public void checkDefaultValuesLoadedProperly() throws ConfigurationParseException {
String backupConfigPath = System.getProperty("pnc-config-file");
System.setProperty("pnc-config-file", "testConfigWithoutDefaults.json");
Configuration configuration = new Configuration();
IndyRepoDriverModuleConfig mavenConfig = configuration.getModuleConfig(new PncConfigProvider<>(IndyRepoDriverModuleConfig.class));
if (backupConfigPath != null) {
System.setProperty("pnc-config-file", backupConfigPath);
} else {
System.getProperties().remove("pnc-config-file");
}
assertNotNull(mavenConfig);
assertEquals(600, mavenConfig.getDefaultRequestTimeout().intValue());
assertFalse(mavenConfig.getBuildRepositoryAllowSnapshots().booleanValue());
}
Aggregations