use of org.jenkinsci.plugins.workflow.steps.StepContext in project selenium_java by sergueik.
the class Audit2DbStepTests method testStartWithStepContextReturnsAudit2DbExecution.
@Test
public void testStartWithStepContextReturnsAudit2DbExecution() throws Exception {
StepContext context = Mockito.mock(StepContext.class);
Audit2DbStep step = new Audit2DbStep();
StepExecution execution = step.start(context);
assertNotNull("Null StepExecution returned.", execution);
assertTrue("Expected Audit2DbExecution", Audit2DbExecution.class.isInstance(execution));
assertThat("StepContext should be injected into execution.", execution, hasProperty("context", sameInstance(context)));
assertThat("Step should be injected into execution.", execution, hasProperty("step", sameInstance(step)));
}
use of org.jenkinsci.plugins.workflow.steps.StepContext in project workflow-cps-plugin by jenkinsci.
the class CpsBodyExecution method launch.
/**
* Starts evaluating the body.
*
* If the body is a synchronous closure, this method evaluates the closure synchronously.
* Otherwise, the body is asynchronous and the method schedules another thread to evaluate the body.
*
* @param currentThread
* The thread whose context the new thread will inherit.
*/
@CpsVmThreadOnly
/*package*/
void launch(CpsBodyInvoker params, CpsThread currentThread, FlowHead head) {
if (isLaunched())
throw new IllegalStateException("Already launched");
StepStartNode sn = addBodyStartFlowNode(head);
for (Action a : params.startNodeActions) {
if (a != null)
sn.addAction(a);
}
head.setNewHead(sn);
CpsFlowExecution.maybeAutoPersistNode(sn);
StepContext sc = new CpsBodySubContext(context, sn);
for (BodyExecutionCallback c : callbacks) {
c.onStart(sc);
}
try {
// TODO: handle arguments to closure
Object x = params.body.getBody(currentThread).call();
// pointless synchronization to make findbugs happy. This is already done, so there's no cancelling this anyway.
synchronized (this) {
this.thread = currentThread;
}
onSuccess.receive(x);
} catch (CpsCallableInvocation e) {
// execute this closure asynchronously
// TODO: does it make sense that the new thread shares the same head?
CpsThread t = currentThread.group.addThread(createContinuable(currentThread, e), head, ContextVariableSet.from(currentThread.getContextVariables(), params.contextOverrides));
// due to earlier cancellation
synchronized (this) {
t.resume(new Outcome(null, stopped));
assert this.thread == null;
this.thread = t;
}
} catch (Throwable t) {
// body has completed synchronously and abnormally
synchronized (this) {
this.thread = currentThread;
}
onFailure.receive(t);
}
}
use of org.jenkinsci.plugins.workflow.steps.StepContext in project selenium_java by sergueik.
the class Audit2DbExecution method run.
@Override
protected Void run() throws Exception {
StepContext context = getContext();
Run<?, ?> run = context.get(Run.class);
LOGGER.fine("StepContext.Run: " + run);
Properties props = HibernateUtil.getExtraProperties(step.getJdbcDriver(), step.getJdbcUrl(), step.getJdbcUsername(), step.getJdbcPassword());
if (StringUtils.isNotBlank(step.getHibernateDialect())) {
props.put("hibernate.dialect", step.getHibernateDialect());
}
LOGGER.fine("props: " + props);
SessionFactory sessionFactory = HibernateUtil.getSessionFactory(props);
LOGGER.fine("sessionFactory: " + sessionFactory);
BuildDetailsRepository repository = new BuildDetailsHibernateRepository(sessionFactory);
BuildDetails details = BuildDetailsResolver.resolveBuildDetails(run, context.get(Computer.class));
Audit2DbGraphListener listener = new Audit2DbGraphListener(repository, details);
context.get(FlowExecution.class).addListener(listener);
return null;
}
Aggregations