use of org.jboss.pnc.spi.environment.exception.EnvironmentDriverException 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);
}
Aggregations