Search in sources :

Example 11 with RunningEnvironment

use of org.jboss.pnc.spi.environment.RunningEnvironment in project pnc by project-ncl.

the class BuildDriverMock method complete.

protected void complete(BuildExecutionSession buildExecutionSession, final RunningEnvironment runningEnvironment, Consumer<CompletedBuild> onComplete) throws InterruptedException {
    Thread.sleep(RandomUtils.randInt(100, 300));
    setBuildStatus(buildExecutionSession.getBuildExecutionConfiguration().getBuildScript());
    onComplete.accept(new CompletedBuild() {

        @Override
        public BuildDriverResult getBuildResult() throws BuildDriverException {
            return getBuildResultMock(runningEnvironment);
        }

        @Override
        public RunningEnvironment getRunningEnvironment() {
            return runningEnvironment;
        }
    });
}
Also used : CompletedBuild(org.jboss.pnc.spi.builddriver.CompletedBuild) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) BuildDriverException(org.jboss.pnc.spi.builddriver.exception.BuildDriverException) RunningEnvironment(org.jboss.pnc.spi.environment.RunningEnvironment)

Example 12 with RunningEnvironment

use of org.jboss.pnc.spi.environment.RunningEnvironment in project pnc by project-ncl.

the class DebugInContainerTest method shouldEnableSshWhenBuildFails.

@Test
public void shouldEnableSshWhenBuildFails() throws InterruptedException, BuildDriverException {
    TermdBuildDriverModuleConfig buildDriverModuleConfig = mock(TermdBuildDriverModuleConfig.class);
    doReturn(1000L).when(buildDriverModuleConfig).getLivenessProbeFrequencyMillis();
    doReturn(5000L).when(buildDriverModuleConfig).getLivenessFailTimeoutMillis();
    doReturn(5000).when(buildDriverModuleConfig).getFileTransferReadTimeout();
    ClientMockFactory buildAgentClientFactory = new ClientMockFactory();
    TermdBuildDriver driver = new TermdBuildDriver(systemConfig, buildDriverModuleConfig, buildAgentClientFactory);
    BuildExecutionSession buildExecution = mock(BuildExecutionSession.class);
    BuildExecutionConfiguration buildExecutionConfiguration = mock(BuildExecutionConfiguration.class);
    doReturn(buildExecutionConfiguration).when(buildExecution).getBuildExecutionConfiguration();
    RunningEnvironment runningEnvironment = mock(RunningEnvironment.class);
    doReturn(Paths.get("")).when(runningEnvironment).getWorkingDirectory();
    doReturn(new DebugData(true)).when(runningEnvironment).getDebugData();
    doReturn("http://localhost/").when(runningEnvironment).getInternalBuildAgentUrl();
    doReturn(runningEnvironment).when(buildExecution).getRunningEnvironment();
    BlockingQueue<CompletedBuild> result = new ArrayBlockingQueue(1);
    Consumer<CompletedBuild> onComplete = (completedBuild) -> {
        try {
            result.put(completedBuild);
        } catch (InterruptedException e) {
            Assert.fail("Unable to consume build result.");
        }
    };
    Consumer<Throwable> onError = (throwable) -> Assert.fail("Build should fail without system error.");
    // when
    RunningBuild runningBuild = driver.startProjectBuild(buildExecution, runningEnvironment, onComplete, onError);
    // wait to start waiting for completion and start liveness probe
    Thread.sleep(500);
    buildAgentClientFactory.getOnStatusUpdate().accept(TaskStatusUpdateEvent.newBuilder().newStatus(Status.FAILED).build());
    // then
    CompletedBuild completedBuild = result.poll(3, TimeUnit.SECONDS);
    Assert.assertNotNull("Missing build result.", completedBuild);
    Assert.assertEquals("The build should fail.", BuildStatus.FAILED, completedBuild.getBuildResult().getBuildStatus());
    List<Object> executedCommands = buildAgentClientFactory.getBuildAgentClient().getExecutedCommands();
    logger.info("Executed commands {}.", executedCommands);
    Assert.assertEquals(2, executedCommands.size());
    Assertions.assertThat(executedCommands).anySatisfy(c -> ((String) c).contains("startSshd.sh"));
}
Also used : BuildExecutionSession(org.jboss.pnc.spi.executor.BuildExecutionSession) CompletedBuild(org.jboss.pnc.spi.builddriver.CompletedBuild) BuildDriverException(org.jboss.pnc.spi.builddriver.exception.BuildDriverException) RunningBuild(org.jboss.pnc.spi.builddriver.RunningBuild) LoggerFactory(org.slf4j.LoggerFactory) Assertions(org.assertj.core.api.Assertions) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) Mockito.doReturn(org.mockito.Mockito.doReturn) Logger(org.slf4j.Logger) TaskStatusUpdateEvent(org.jboss.pnc.buildagent.api.TaskStatusUpdateEvent) CompletedBuild(org.jboss.pnc.spi.builddriver.CompletedBuild) Test(org.junit.Test) BlockingQueue(java.util.concurrent.BlockingQueue) BuildStatus(org.jboss.pnc.enums.BuildStatus) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) List(java.util.List) RunningEnvironment(org.jboss.pnc.spi.environment.RunningEnvironment) Paths(java.nio.file.Paths) DebugData(org.jboss.pnc.spi.builddriver.DebugData) Status(org.jboss.pnc.buildagent.api.Status) TermdBuildDriverModuleConfig(org.jboss.pnc.common.json.moduleconfig.TermdBuildDriverModuleConfig) SystemConfig(org.jboss.pnc.common.json.moduleconfig.SystemConfig) Assert(org.junit.Assert) BuildExecutionSession(org.jboss.pnc.spi.executor.BuildExecutionSession) Mockito.mock(org.mockito.Mockito.mock) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) DebugData(org.jboss.pnc.spi.builddriver.DebugData) RunningBuild(org.jboss.pnc.spi.builddriver.RunningBuild) RunningEnvironment(org.jboss.pnc.spi.environment.RunningEnvironment) TermdBuildDriverModuleConfig(org.jboss.pnc.common.json.moduleconfig.TermdBuildDriverModuleConfig) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Test(org.junit.Test)

Aggregations

RunningEnvironment (org.jboss.pnc.spi.environment.RunningEnvironment)12 Consumer (java.util.function.Consumer)6 CompletedBuild (org.jboss.pnc.spi.builddriver.CompletedBuild)6 DebugData (org.jboss.pnc.spi.builddriver.DebugData)6 RepositorySession (org.jboss.pnc.spi.repositorymanager.model.RepositorySession)6 LoggerFactory (org.slf4j.LoggerFactory)6 TimeUnit (java.util.concurrent.TimeUnit)5 SystemConfig (org.jboss.pnc.common.json.moduleconfig.SystemConfig)5 BuildDriverException (org.jboss.pnc.spi.builddriver.exception.BuildDriverException)5 Logger (org.slf4j.Logger)5 Paths (java.nio.file.Paths)4 BuildProcessException (org.jboss.pnc.executor.exceptions.BuildProcessException)4 RunningBuild (org.jboss.pnc.spi.builddriver.RunningBuild)4 BuildExecutionSession (org.jboss.pnc.spi.executor.BuildExecutionSession)4 Optional (java.util.Optional)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ExecutorService (java.util.concurrent.ExecutorService)3 TermdBuildDriverModuleConfig (org.jboss.pnc.common.json.moduleconfig.TermdBuildDriverModuleConfig)3 BuildStatus (org.jboss.pnc.enums.BuildStatus)3 StartedEnvironment (org.jboss.pnc.spi.environment.StartedEnvironment)3