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);
}
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));
}
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);
}
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;
}
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));
}
Aggregations