Search in sources :

Example 6 with ObjectWrapper

use of org.jboss.pnc.common.util.ObjectWrapper 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 7 with ObjectWrapper

use of org.jboss.pnc.common.util.ObjectWrapper 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 8 with ObjectWrapper

use of org.jboss.pnc.common.util.ObjectWrapper in project pnc by project-ncl.

the class OpenshiftEnvironmentDriverRemoteTest method createAndDestroyEnvironment.

@Test
public void createAndDestroyEnvironment() throws EnvironmentDriverException, InterruptedException {
    final Semaphore mutex = new Semaphore(0);
    ObjectWrapper<Throwable> exceptionWrapper = new ObjectWrapper<>();
    String dummyImageId = "abcd1234";
    String dummyRepoUrl = "test.repo.url/repo";
    // Create container
    final StartedEnvironment startedEnv = environmentDriver.startEnvironment(dummyImageId, dummyRepoUrl, SystemImageType.DOCKER_IMAGE, DUMMY_REPOSITORY_CONFIGURATION, new DebugData(false), "put-access-token-here", false, Collections.emptyMap());
    Consumer<RunningEnvironment> onEnvironmentStarted = (runningEnvironment) -> {
        boolean containerDestroyed = false;
        try {
            assertThatContainerIsRunning(runningEnvironment);
            // Destroy container
            destroyEnvironment(runningEnvironment);
            containerDestroyed = true;
            assertThatContainerIsNotRunning(runningEnvironment);
            mutex.release();
        } catch (Throwable e) {
            exceptionWrapper.set(e);
        } finally {
            if (!containerDestroyed) {
                destroyEnvironmentWithReport(runningEnvironment);
            }
        }
        mutex.release();
    };
    Consumer<Exception> onError = (e) -> {
        try {
            logger.info("Trying to destroy environment due to an error:", e);
            startedEnv.destroyEnvironment();
            mutex.release();
        } catch (EnvironmentDriverException e1) {
            logger.error("Environment LEAK! The running environment was not destroyed. ID: " + startedEnv.getId(), e1);
        }
        fail("Failed to init builder. " + e.getMessage());
    };
    startedEnv.monitorInitialization(onEnvironmentStarted, onError);
    boolean completed = mutex.tryAcquire(TEST_EXECUTION_TIMEOUT, TimeUnit.SECONDS);
    Throwable exception = exceptionWrapper.get();
    if (exception != null) {
        logger.error("", exception);
        fail(exception.getMessage());
    }
    assertTrue("timeout reached, test has not complete.", completed);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) SystemImageType(org.jboss.pnc.enums.SystemImageType) RepositoryType(org.jboss.pnc.enums.RepositoryType) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) EnvironmentDriver(org.jboss.pnc.spi.environment.EnvironmentDriver) OpenshiftEnvironmentDriverModuleConfig(org.jboss.pnc.common.json.moduleconfig.OpenshiftEnvironmentDriverModuleConfig) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) Semaphore(java.util.concurrent.Semaphore) MethodHandles(java.lang.invoke.MethodHandles) Assert.assertTrue(org.junit.Assert.assertTrue) DebugTest(org.jboss.pnc.test.category.DebugTest) Test(org.junit.Test) IOException(java.io.IOException) Category(org.junit.experimental.categories.Category) PollingMonitor(org.jboss.pnc.common.monitor.PollingMonitor) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) RepositoryConnectionInfo(org.jboss.pnc.spi.repositorymanager.model.RepositoryConnectionInfo) Mockito(org.mockito.Mockito) RunningEnvironment(org.jboss.pnc.spi.environment.RunningEnvironment) StartedEnvironment(org.jboss.pnc.spi.environment.StartedEnvironment) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) DebugData(org.jboss.pnc.spi.builddriver.DebugData) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) Assert.assertFalse(org.junit.Assert.assertFalse) EnvironmentDriverException(org.jboss.pnc.spi.environment.exception.EnvironmentDriverException) SystemConfig(org.jboss.pnc.common.json.moduleconfig.SystemConfig) Collections(java.util.Collections) DebugData(org.jboss.pnc.spi.builddriver.DebugData) Semaphore(java.util.concurrent.Semaphore) StartedEnvironment(org.jboss.pnc.spi.environment.StartedEnvironment) RunningEnvironment(org.jboss.pnc.spi.environment.RunningEnvironment) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) IOException(java.io.IOException) EnvironmentDriverException(org.jboss.pnc.spi.environment.exception.EnvironmentDriverException) EnvironmentDriverException(org.jboss.pnc.spi.environment.exception.EnvironmentDriverException) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) DebugTest(org.jboss.pnc.test.category.DebugTest) Test(org.junit.Test)

Example 9 with ObjectWrapper

use of org.jboss.pnc.common.util.ObjectWrapper in project pnc by project-ncl.

the class DeploymentFactory method createDatastoreDeployment.

public static Archive<?> createDatastoreDeployment() {
    JavaArchive datastoreJar = ShrinkWrap.create(JavaArchive.class, "datastore.jar").addPackages(true, "org.jboss.pnc.datastore").addAsManifestResource("test-persistence.xml", "persistence.xml").addAsManifestResource("logback.xml");
    logger.info("Deployment datastoreJar: {}", datastoreJar.toString(true));
    File[] dependencies = Maven.resolver().loadPomFromFile("pom.xml").importDependencies(ScopeType.RUNTIME, ScopeType.COMPILE, ScopeType.TEST, ScopeType.IMPORT, ScopeType.SYSTEM).resolve().withTransitivity().asFile();
    // remove "model-<version>.jar" from the archive and add it as "model.jar" so we can reference it in the
    // test-persistence.xml
    ObjectWrapper<File> modelJarWrapper = new ObjectWrapper();
    List<File> dependenciesFiltered = Arrays.stream(dependencies).filter(jar -> extractModelJar(jar, modelJarWrapper)).filter(jar -> !mockJarMatches(jar)).collect(Collectors.toList());
    File modelJar = modelJarWrapper.get();
    if (modelJar == null) {
        throw new RuntimeException(new DeploymentException("Cannot find model*.jar"));
    }
    Optional<File> mockJarOptional = Arrays.stream(dependencies).filter(DeploymentFactory::mockJarMatches).findAny();
    if (!mockJarOptional.isPresent()) {
        throw new RuntimeException(new DeploymentException("Cannot find mock*.jar"));
    }
    JavaArchive mockJar = ShrinkWrap.createFromZipFile(JavaArchive.class, mockJarOptional.get());
    mockJar.addAsManifestResource("mock-beans.xml", "beans.xml");
    logger.info("Deployment mockJar: {}", mockJar.toString(true));
    EnterpriseArchive enterpriseArchive = ShrinkWrap.create(EnterpriseArchive.class, "datastore-test.ear").addAsModule(datastoreJar).addAsLibraries(dependenciesFiltered.toArray(new File[dependenciesFiltered.size()])).addAsLibrary(mockJar).addAsLibrary(modelJar, "model.jar");
    addManifestDependencies(enterpriseArchive, "com.google.guava  export meta-inf");
    logger.info("Deployment: {}", enterpriseArchive.toString(true));
    return enterpriseArchive;
}
Also used : ScopeType(org.jboss.shrinkwrap.resolver.api.maven.ScopeType) ShrinkWrap(org.jboss.shrinkwrap.api.ShrinkWrap) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) LoggerFactory(org.slf4j.LoggerFactory) Archive(org.jboss.shrinkwrap.api.Archive) ShrinkwrapDeployerUtils.addManifestDependencies(org.jboss.pnc.test.arquillian.ShrinkwrapDeployerUtils.addManifestDependencies) Collectors(java.util.stream.Collectors) File(java.io.File) Maven(org.jboss.shrinkwrap.resolver.api.maven.Maven) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) List(java.util.List) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Optional(java.util.Optional) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) File(java.io.File) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive)

Example 10 with ObjectWrapper

use of org.jboss.pnc.common.util.ObjectWrapper 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)

Aggregations

ObjectWrapper (org.jboss.pnc.common.util.ObjectWrapper)12 Test (org.junit.Test)10 HashSet (java.util.HashSet)9 BuildResult (org.jboss.pnc.spi.BuildResult)9 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)8 BuildExecutionStatusChangedEvent (org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent)8 LoggerFactory (org.slf4j.LoggerFactory)8 Consumer (java.util.function.Consumer)7 Logger (org.slf4j.Logger)7 Set (java.util.Set)6 Inject (javax.inject.Inject)6 BuildExecutionStatus (org.jboss.pnc.enums.BuildExecutionStatus)6 TestProjectConfigurationBuilder (org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder)6 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)6 Deployment (org.jboss.arquillian.container.test.api.Deployment)5 Arquillian (org.jboss.arquillian.junit.Arquillian)5 RunWith (org.junit.runner.RunWith)5 Arrays (java.util.Arrays)4 List (java.util.List)4 TimeoutException (java.util.concurrent.TimeoutException)4