Search in sources :

Example 1 with BuildExecutionStatus

use of org.jboss.pnc.enums.BuildExecutionStatus in project pnc by project-ncl.

the class BuildExecutionBase method buildStatusesShouldNotContain.

protected void buildStatusesShouldNotContain(Set<BuildExecutionStatusChangedEvent> statusChangedEvents, List<BuildExecutionStatus> unexpectedStatuses) {
    List<BuildExecutionStatus> statusReceived = statusChangedEvents.stream().map(BuildExecutionStatusChangedEvent::getNewStatus).collect(Collectors.toList());
    for (BuildExecutionStatusChangedEvent statusChangedEvent : statusChangedEvents) {
        BuildExecutionStatus status = statusChangedEvent.getNewStatus();
        if (unexpectedStatuses.contains(status)) {
            log.info("Received statuses: {}", statusReceived);
            Assert.fail("Unexpected status [" + status + "] has been received.");
        }
    }
}
Also used : BuildExecutionStatus(org.jboss.pnc.enums.BuildExecutionStatus) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent)

Example 2 with BuildExecutionStatus

use of org.jboss.pnc.enums.BuildExecutionStatus 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 3 with BuildExecutionStatus

use of org.jboss.pnc.enums.BuildExecutionStatus in project pnc by project-ncl.

the class BuildExecutionTest method buildShouldFail.

@Test
public void buildShouldFail() throws ExecutorException, TimeoutException, InterruptedException, BuildDriverException {
    BuildConfiguration buildConfiguration = configurationBuilder.buildFailingConfiguration(2, "failed-build", null);
    Set<BuildExecutionStatusChangedEvent> statusChangedEvents = new HashSet<>();
    ObjectWrapper<BuildResult> buildExecutionResultWrapper = new ObjectWrapper<>();
    runBuild(buildConfiguration, statusChangedEvents, buildExecutionResultWrapper);
    List<BuildExecutionStatus> expectedStatuses = getBuildExecutionStatusesBase();
    expectedStatuses.add(DONE_WITH_ERRORS);
    // check build statuses
    checkBuildStatuses(statusChangedEvents, expectedStatuses);
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildResult(org.jboss.pnc.spi.BuildResult) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) BuildExecutionStatus(org.jboss.pnc.enums.BuildExecutionStatus) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with BuildExecutionStatus

use of org.jboss.pnc.enums.BuildExecutionStatus in project pnc by project-ncl.

the class BuildExecutionTest method testBuild.

@Test
public void testBuild() throws ExecutorException, TimeoutException, InterruptedException, BuildDriverException {
    BuildConfiguration buildConfiguration = configurationBuilder.build(1, "c1-java");
    Set<BuildExecutionStatusChangedEvent> statusChangedEvents = new HashSet<>();
    ObjectWrapper<BuildResult> buildExecutionResultWrapper = new ObjectWrapper<>();
    runBuild(buildConfiguration, statusChangedEvents, buildExecutionResultWrapper);
    List<BuildExecutionStatus> expectedStatuses = getBuildExecutionStatusesSuccess();
    // check build statuses
    checkBuildStatuses(statusChangedEvents, expectedStatuses);
    // check results
    BuildResult buildResult = buildExecutionResultWrapper.get();
    // check results: logs
    BuildDriverResult buildDriverResult = buildResult.getBuildDriverResult().get();
    String buildLog = buildDriverResult.getBuildLog();
    Assert.assertTrue("Invalid build log.", buildLog.contains("Finished: SUCCESS"));
    // check results: artifacts
    RepositoryManagerResult repositoryManagerResult = buildResult.getRepositoryManagerResult().get();
    Assert.assertTrue("Missing build artifacts.", repositoryManagerResult.getBuiltArtifacts().size() > 0);
    Assert.assertTrue("Missing build dependencies.", repositoryManagerResult.getDependencies().size() > 0);
    Artifact artifact = repositoryManagerResult.getBuiltArtifacts().iterator().next();
    Assert.assertTrue("Invalid built artifact in the result.", artifact.getIdentifier().startsWith(ArtifactBuilder.IDENTIFIER_PREFIX));
}
Also used : BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) BuildExecutionStatus(org.jboss.pnc.enums.BuildExecutionStatus) Artifact(org.jboss.pnc.model.Artifact) 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 BuildExecutionStatus

use of org.jboss.pnc.enums.BuildExecutionStatus in project pnc by project-ncl.

the class EarlyCancellationTest method cancelImmediately.

@Test(timeout = 3000)
public void cancelImmediately() throws InterruptedException, TimeoutException, ExecutorException, BuildDriverException {
    BuildExecutionStatus cancelAfter = BuildExecutionStatus.NEW;
    BuildExecutionStatus[] expectedStatuses = { BuildExecutionStatus.NEW, BuildExecutionStatus.FINALIZING_EXECUTION, BuildExecutionStatus.CANCELLED };
    BuildExecutionStatus[] unexpectedStatuses = { BuildExecutionStatus.BUILD_ENV_SETTING_UP, BuildExecutionStatus.BUILD_ENV_WAITING, BuildExecutionStatus.BUILD_ENV_SETUP_COMPLETE_SUCCESS, BuildExecutionStatus.REPO_SETTING_UP, BuildExecutionStatus.BUILD_SETTING_UP, BuildExecutionStatus.BUILD_WAITING, BuildExecutionStatus.COLLECTING_RESULTS_FROM_BUILD_DRIVER, BuildExecutionStatus.COLLECTING_RESULTS_FROM_REPOSITORY_MANAGER, BuildExecutionStatus.BUILD_ENV_DESTROYING, BuildExecutionStatus.BUILD_ENV_DESTROYED, BuildExecutionStatus.DONE, BuildExecutionStatus.DONE_WITH_ERRORS };
    try {
        testBuild(cancelAfter, expectedStatuses, unexpectedStatuses);
    } catch (ConfigurationParseException e) {
        log.error(e.toString());
    }
}
Also used : ConfigurationParseException(org.jboss.pnc.common.json.ConfigurationParseException) BuildExecutionStatus(org.jboss.pnc.enums.BuildExecutionStatus) Test(org.junit.Test)

Aggregations

BuildExecutionStatus (org.jboss.pnc.enums.BuildExecutionStatus)8 BuildExecutionStatusChangedEvent (org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent)6 Test (org.junit.Test)6 HashSet (java.util.HashSet)4 ConfigurationParseException (org.jboss.pnc.common.json.ConfigurationParseException)4 ObjectWrapper (org.jboss.pnc.common.util.ObjectWrapper)4 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)4 BuildResult (org.jboss.pnc.spi.BuildResult)4 Consumer (java.util.function.Consumer)3 TestProjectConfigurationBuilder (org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder)3 BuildDriverResult (org.jboss.pnc.spi.builddriver.BuildDriverResult)3 ExecutorException (org.jboss.pnc.spi.executor.exceptions.ExecutorException)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Set (java.util.Set)2 TimeoutException (java.util.concurrent.TimeoutException)2 Inject (javax.inject.Inject)2 Deployment (org.jboss.arquillian.container.test.api.Deployment)2 Arquillian (org.jboss.arquillian.junit.Arquillian)2 Configuration (org.jboss.pnc.common.Configuration)2