use of org.jboss.pnc.enums.BuildStatus.CANCELLED in project pnc by project-ncl.
the class TermdBuildDriverTest method shouldStartAndCancelTheExecutionImmediately.
@Test(timeout = 5_000)
public void shouldStartAndCancelTheExecutionImmediately() throws ConfigurationParseException, BuildDriverException, InterruptedException, IOException {
// given
String dirName = "test-workdir";
String logStart = "Running the command...";
String logEnd = "Command completed.";
TermdBuildDriver driver = new TermdBuildDriver(systemConfig, buildDriverModuleConfig, clientFactory);
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
CountDownLatch latch = new CountDownLatch(1);
Consumer<CompletedBuild> onComplete = (completedBuild) -> {
buildResult.set(completedBuild);
latch.countDown();
};
Consumer<Throwable> onError = (throwable) -> {
logger.error("Error received: ", throwable);
fail(throwable.getMessage());
};
RunningBuild runningBuild = driver.startProjectBuild(buildExecution, localEnvironmentPointer, onComplete, onError);
runningBuild.cancel();
latch.await();
// then
assertThat(buildResult.get().getBuildResult().getBuildLog()).doesNotContain(logEnd);
assertThat(buildResult.get().getBuildResult().getBuildStatus()).isEqualTo(CANCELLED);
}
use of org.jboss.pnc.enums.BuildStatus.CANCELLED 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