use of org.jboss.pnc.spi.builddriver.CompletedBuild in project pnc by project-ncl.
the class BlockedBuildDriverMock method complete.
protected void complete(BuildExecutionSession buildExecutionSession, final RunningEnvironment runningEnvironment, Consumer<CompletedBuild> onComplete) throws InterruptedException {
log.info("Running blocked build ...");
semaphore.acquire();
setBuildStatus(TestProjectConfigurationBuilder.CANCEL);
log.info("Blocked build canceled.");
onComplete.accept(new CompletedBuild() {
@Override
public BuildDriverResult getBuildResult() throws BuildDriverException {
return getBuildResultMock(runningEnvironment);
}
@Override
public RunningEnvironment getRunningEnvironment() {
return runningEnvironment;
}
});
}
use of org.jboss.pnc.spi.builddriver.CompletedBuild 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;
}
});
}
use of org.jboss.pnc.spi.builddriver.CompletedBuild 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"));
}
use of org.jboss.pnc.spi.builddriver.CompletedBuild in project pnc by project-ncl.
the class TermdBuildDriverTest method shouldFetchFromGitAndBuild.
@Test(timeout = 15_000)
public void shouldFetchFromGitAndBuild() throws Throwable {
// given
Path tmpRepo = Files.createTempDirectory("tmpRepo");
String repoPath = "file://" + tmpRepo.toAbsolutePath().toString() + "/test-repo";
ZipUtils.unzipToDir(tmpRepo, "/repo.zip");
String dirName = "test-repo-cloned";
TermdBuildDriver driver = new TermdBuildDriver(systemConfig, buildDriverModuleConfig, clientFactory);
BuildExecutionSession buildExecution = mock(BuildExecutionSession.class);
BuildExecutionConfiguration buildExecutionConfiguration = mock(BuildExecutionConfiguration.class);
doReturn(repoPath).when(buildExecutionConfiguration).getScmRepoURL();
doReturn("master").when(buildExecutionConfiguration).getScmRevision();
doReturn("mvn validate").when(buildExecutionConfiguration).getBuildScript();
doReturn(dirName).when(buildExecutionConfiguration).getName();
doReturn(buildExecutionConfiguration).when(buildExecution).getBuildExecutionConfiguration();
doReturn(mock(RunningEnvironment.class)).when(buildExecution).getRunningEnvironment();
AtomicReference<CompletedBuild> buildResult = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
Consumer<CompletedBuild> onComplete = (completedBuild) -> {
logger.info("Build completed.");
buildResult.set(completedBuild);
latch.countDown();
};
Consumer<Throwable> onError = (throwable) -> {
logger.error("Error received: ", throwable);
fail(throwable.getMessage());
};
// when
RunningBuild runningBuild = driver.startProjectBuild(buildExecution, localEnvironmentPointer, onComplete, // TODO set monitor
onError);
// before the build
// starts
logger.info("Waiting for build to complete...");
latch.await();
// then
assertThat(buildResult.get().getBuildResult()).isNotNull();
assertThat(buildResult.get().getBuildResult().getBuildLog()).isNotEmpty();
assertThat(Files.exists(localEnvironmentPointer.getWorkingDirectory())).isTrue();
assertThat(Files.exists(localEnvironmentPointer.getWorkingDirectory().resolve(dirName))).isTrue();
}
use of org.jboss.pnc.spi.builddriver.CompletedBuild in project pnc by project-ncl.
the class TermdBuildDriverTest method shouldStartAndCancelWhileExecutingCommand.
@Test(timeout = 5_000)
public void shouldStartAndCancelWhileExecutingCommand() throws ConfigurationParseException, BuildDriverException, InterruptedException {
// given
String dirName = "test-workdir";
String logStart = "Running the command...";
String logEnd = "Command completed.";
CountDownLatch latchCompleted = new CountDownLatch(1);
ClientMockFactory mockFactory = new ClientMockFactory();
TermdBuildDriver driver = new TermdBuildDriver(systemConfig, buildDriverModuleConfig, mockFactory);
BuildExecutionSession buildExecution = mock(BuildExecutionSession.class);
BuildExecutionConfiguration buildExecutionConfiguration = mock(BuildExecutionConfiguration.class);
doReturn("echo \"" + logStart + "\"; mvn validate; echo \"" + logEnd + "\";").when(buildExecutionConfiguration).getBuildScript();
doReturn(dirName).when(buildExecutionConfiguration).getName();
doReturn(buildExecutionConfiguration).when(buildExecution).getBuildExecutionConfiguration();
AtomicReference<CompletedBuild> buildResult = new AtomicReference<>();
// when
Consumer<CompletedBuild> onComplete = (completedBuild) -> {
buildResult.set(completedBuild);
latchCompleted.countDown();
};
Consumer<Throwable> onError = (throwable) -> {
logger.error("Error received: ", throwable);
fail(throwable.getMessage());
};
RunningBuild runningBuild = driver.startProjectBuild(buildExecution, localEnvironmentPointer, onComplete, onError);
runningBuild.cancel();
// simulate update for "CTRL+C" on a command, which results in the command failing
mockFactory.getOnStatusUpdate().accept(TaskStatusUpdateEvent.newBuilder().newStatus(Status.FAILED).build());
latchCompleted.await();
// then
assertThat(buildResult.get().getBuildResult()).isNotNull();
assertThat(buildResult.get().getBuildResult().getBuildStatus()).isEqualTo(CANCELLED);
}
Aggregations