Search in sources :

Example 1 with Configuration

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

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();
}
Also used : BuildDriver(org.jboss.pnc.spi.builddriver.BuildDriver) TestInstance(org.jboss.pnc.test.cdi.TestInstance) Configuration(org.jboss.pnc.common.Configuration) BuildDriverFactory(org.jboss.pnc.executor.servicefactories.BuildDriverFactory) Test(org.junit.Test)

Example 3 with Configuration

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, "");
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Arrays(java.util.Arrays) Arquillian(org.jboss.arquillian.junit.Arquillian) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) AlignmentPreference(org.jboss.pnc.api.enums.AlignmentPreference) RepositoryManagerFactory(org.jboss.pnc.executor.servicefactories.RepositoryManagerFactory) BUILD_ENV_SETUP_COMPLETE_SUCCESS(org.jboss.pnc.enums.BuildExecutionStatus.BUILD_ENV_SETUP_COMPLETE_SUCCESS) Inject(javax.inject.Inject) HashSet(java.util.HashSet) BUILD_SETTING_UP(org.jboss.pnc.enums.BuildExecutionStatus.BUILD_SETTING_UP) ConfigurationParseException(org.jboss.pnc.common.json.ConfigurationParseException) Assertions(org.assertj.core.api.Assertions) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) Logger(org.slf4j.Logger) DONE_WITH_ERRORS(org.jboss.pnc.enums.BuildExecutionStatus.DONE_WITH_ERRORS) BuildDriverFactory(org.jboss.pnc.executor.servicefactories.BuildDriverFactory) BUILD_ENV_SETUP_COMPLETE_WITH_ERROR(org.jboss.pnc.enums.BuildExecutionStatus.BUILD_ENV_SETUP_COMPLETE_WITH_ERROR) BuildResult(org.jboss.pnc.spi.BuildResult) Set(java.util.Set) BUILD_ENV_WAITING(org.jboss.pnc.enums.BuildExecutionStatus.BUILD_ENV_WAITING) Test(org.junit.Test) Configuration(org.jboss.pnc.common.Configuration) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) Consumer(java.util.function.Consumer) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) Deployment(org.jboss.arquillian.container.test.api.Deployment) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) BUILD_ENV_SETTING_UP(org.jboss.pnc.enums.BuildExecutionStatus.BUILD_ENV_SETTING_UP) Assert(org.junit.Assert) EnvironmentDriverFactory(org.jboss.pnc.executor.servicefactories.EnvironmentDriverFactory) BuildExecutionStatus(org.jboss.pnc.enums.BuildExecutionStatus) Wait(org.jboss.pnc.test.util.Wait) BuildResult(org.jboss.pnc.spi.BuildResult) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) Configuration(org.jboss.pnc.common.Configuration) ConfigurationParseException(org.jboss.pnc.common.json.ConfigurationParseException) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent)

Example 4 with Configuration

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());
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildDriverException(org.jboss.pnc.spi.builddriver.exception.BuildDriverException) Arquillian(org.jboss.arquillian.junit.Arquillian) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) RepositoryManagerFactory(org.jboss.pnc.executor.servicefactories.RepositoryManagerFactory) Inject(javax.inject.Inject) HashSet(java.util.HashSet) ConfigurationParseException(org.jboss.pnc.common.json.ConfigurationParseException) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) Logger(org.slf4j.Logger) BuildDriverFactory(org.jboss.pnc.executor.servicefactories.BuildDriverFactory) BuildResult(org.jboss.pnc.spi.BuildResult) Set(java.util.Set) Test(org.junit.Test) Configuration(org.jboss.pnc.common.Configuration) BuildStatus(org.jboss.pnc.enums.BuildStatus) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) Consumer(java.util.function.Consumer) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) List(java.util.List) Deployment(org.jboss.arquillian.container.test.api.Deployment) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Assert(org.junit.Assert) EnvironmentDriverFactory(org.jboss.pnc.executor.servicefactories.EnvironmentDriverFactory) BuildExecutionStatus(org.jboss.pnc.enums.BuildExecutionStatus) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Configuration(org.jboss.pnc.common.Configuration) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) BuildExecutionStatus(org.jboss.pnc.enums.BuildExecutionStatus) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildResult(org.jboss.pnc.spi.BuildResult) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with Configuration

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());
}
Also used : Configuration(org.jboss.pnc.common.Configuration) Test(org.junit.Test)

Aggregations

Configuration (org.jboss.pnc.common.Configuration)12 Test (org.junit.Test)10 BuildDriverFactory (org.jboss.pnc.executor.servicefactories.BuildDriverFactory)5 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)4 HashSet (java.util.HashSet)3 Set (java.util.Set)3 TimeoutException (java.util.concurrent.TimeoutException)3 Consumer (java.util.function.Consumer)3 Inject (javax.inject.Inject)3 Deployment (org.jboss.arquillian.container.test.api.Deployment)3 Arquillian (org.jboss.arquillian.junit.Arquillian)3 ConfigurationParseException (org.jboss.pnc.common.json.ConfigurationParseException)3 ObjectWrapper (org.jboss.pnc.common.util.ObjectWrapper)3 BuildExecutionStatus (org.jboss.pnc.enums.BuildExecutionStatus)3 EnvironmentDriverFactory (org.jboss.pnc.executor.servicefactories.EnvironmentDriverFactory)3 RepositoryManagerFactory (org.jboss.pnc.executor.servicefactories.RepositoryManagerFactory)3 TestProjectConfigurationBuilder (org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder)3 BuildResult (org.jboss.pnc.spi.BuildResult)3 BuildExecutionStatusChangedEvent (org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent)3 ExecutorException (org.jboss.pnc.spi.executor.exceptions.ExecutorException)3