Search in sources :

Example 1 with TermdBuildDriverModuleConfig

use of org.jboss.pnc.common.json.moduleconfig.TermdBuildDriverModuleConfig in project pnc by project-ncl.

the class LivenessProbeTest method shouldFailTheBuildWhenAgentIsNotResponding.

@Test
public void shouldFailTheBuildWhenAgentIsNotResponding() throws InterruptedException, BuildDriverException {
    TermdBuildDriverModuleConfig buildDriverModuleConfig = mock(TermdBuildDriverModuleConfig.class);
    doReturn(200L).when(buildDriverModuleConfig).getLivenessProbeFrequencyMillis();
    doReturn(500L).when(buildDriverModuleConfig).getLivenessFailTimeoutMillis();
    ClientMockFactory buildAgentClientMockFactory = new ClientMockFactory();
    TermdBuildDriver driver = new TermdBuildDriver(systemConfig, buildDriverModuleConfig, buildAgentClientMockFactory);
    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(false)).when(runningEnvironment).getDebugData();
    doReturn("http://localhost/").when(runningEnvironment).getInternalBuildAgentUrl();
    doReturn(runningEnvironment).when(buildExecution).getRunningEnvironment();
    BlockingQueue<Throwable> result = new ArrayBlockingQueue(1);
    Consumer<CompletedBuild> onComplete = (completedBuild) -> Assert.fail("Build should complete with error.");
    Consumer<Throwable> onError = (throwable) -> {
        try {
            result.put(throwable);
        } catch (InterruptedException e) {
            Assert.fail("Error in the test. Unable to add the result to queue.");
        }
    };
    // when
    RunningBuild runningBuild = driver.startProjectBuild(buildExecution, runningEnvironment, onComplete, onError);
    // then
    Throwable throwable = result.poll(1, TimeUnit.SECONDS);
    Assert.assertNotNull("It should complete with an exception.", throwable);
    Assert.assertEquals("Build Agent has gone away.", throwable.getMessage());
}
Also used : BuildExecutionSession(org.jboss.pnc.spi.executor.BuildExecutionSession) CompletedBuild(org.jboss.pnc.spi.builddriver.CompletedBuild) Logger(org.slf4j.Logger) BuildDriverException(org.jboss.pnc.spi.builddriver.exception.BuildDriverException) RunningBuild(org.jboss.pnc.spi.builddriver.RunningBuild) LoggerFactory(org.slf4j.LoggerFactory) CompletedBuild(org.jboss.pnc.spi.builddriver.CompletedBuild) Test(org.junit.Test) BlockingQueue(java.util.concurrent.BlockingQueue) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) RunningEnvironment(org.jboss.pnc.spi.environment.RunningEnvironment) Paths(java.nio.file.Paths) DebugData(org.jboss.pnc.spi.builddriver.DebugData) TermdBuildDriverModuleConfig(org.jboss.pnc.common.json.moduleconfig.TermdBuildDriverModuleConfig) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) SystemConfig(org.jboss.pnc.common.json.moduleconfig.SystemConfig) Assert(org.junit.Assert) BuildExecutionSession(org.jboss.pnc.spi.executor.BuildExecutionSession) Mockito.doReturn(org.mockito.Mockito.doReturn) 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)

Example 2 with TermdBuildDriverModuleConfig

use of org.jboss.pnc.common.json.moduleconfig.TermdBuildDriverModuleConfig 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

Paths (java.nio.file.Paths)2 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)2 BlockingQueue (java.util.concurrent.BlockingQueue)2 TimeUnit (java.util.concurrent.TimeUnit)2 Consumer (java.util.function.Consumer)2 SystemConfig (org.jboss.pnc.common.json.moduleconfig.SystemConfig)2 TermdBuildDriverModuleConfig (org.jboss.pnc.common.json.moduleconfig.TermdBuildDriverModuleConfig)2 CompletedBuild (org.jboss.pnc.spi.builddriver.CompletedBuild)2 DebugData (org.jboss.pnc.spi.builddriver.DebugData)2 RunningBuild (org.jboss.pnc.spi.builddriver.RunningBuild)2 BuildDriverException (org.jboss.pnc.spi.builddriver.exception.BuildDriverException)2 RunningEnvironment (org.jboss.pnc.spi.environment.RunningEnvironment)2 BuildExecutionConfiguration (org.jboss.pnc.spi.executor.BuildExecutionConfiguration)2 BuildExecutionSession (org.jboss.pnc.spi.executor.BuildExecutionSession)2 Assert (org.junit.Assert)2 Test (org.junit.Test)2 Mockito.doReturn (org.mockito.Mockito.doReturn)2 Mockito.mock (org.mockito.Mockito.mock)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2