Search in sources :

Example 1 with BuildDriverFactory

use of org.jboss.pnc.executor.servicefactories.BuildDriverFactory 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 2 with BuildDriverFactory

use of org.jboss.pnc.executor.servicefactories.BuildDriverFactory 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 3 with BuildDriverFactory

use of org.jboss.pnc.executor.servicefactories.BuildDriverFactory 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 4 with BuildDriverFactory

use of org.jboss.pnc.executor.servicefactories.BuildDriverFactory in project pnc by project-ncl.

the class EarlyCancellationTest method testBuild.

private void testBuild(BuildExecutionStatus cancelAfter, BuildExecutionStatus[] expectedStatuses, BuildExecutionStatus[] unexpectedStatuses) 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 (cancelAfter.equals(e.getNewStatus())) {
            try {
                log.info("Cancelling build ...");
                executor.cancel("1");
            } catch (ExecutorException e0) {
                e0.printStackTrace();
            }
        }
    };
    runBuild(buildConfiguration, statusChangedEvents, buildExecutionResultWrapper, cancel, executor);
    // check build statuses
    checkBuildStatuses(statusChangedEvents, Arrays.asList(expectedStatuses));
    buildStatusesShouldNotContain(statusChangedEvents, Arrays.asList(unexpectedStatuses));
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Arrays(java.util.Arrays) 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) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) Consumer(java.util.function.Consumer) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) Deployment(org.jboss.arquillian.container.test.api.Deployment) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) EnvironmentDriverFactory(org.jboss.pnc.executor.servicefactories.EnvironmentDriverFactory) BuildExecutionStatus(org.jboss.pnc.enums.BuildExecutionStatus) BuildResult(org.jboss.pnc.spi.BuildResult) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Configuration(org.jboss.pnc.common.Configuration) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent) HashSet(java.util.HashSet)

Example 5 with BuildDriverFactory

use of org.jboss.pnc.executor.servicefactories.BuildDriverFactory in project pnc by project-ncl.

the class BuildDriverFactoryTest method shouldPickProperDriver.

@Test
public void shouldPickProperDriver() throws Exception {
    // given
    ProperDriver testedBuildDriver = new ProperDriver();
    TestInstance<BuildDriver> allDrivers = new TestInstance<>(testedBuildDriver);
    Configuration configuration = mock(Configuration.class);
    BuildDriverFactory factory = new BuildDriverFactory(allDrivers, configuration);
    // when
    BuildDriver buildDriver = factory.getBuildDriver();
    // then
    assertThat(buildDriver).isEqualTo(testedBuildDriver);
}
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)

Aggregations

Configuration (org.jboss.pnc.common.Configuration)5 BuildDriverFactory (org.jboss.pnc.executor.servicefactories.BuildDriverFactory)5 Test (org.junit.Test)5 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 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)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