use of org.talend.dataprep.transformation.actions.common.RunnableAction in project data-prep by Talend.
the class PipelineTest method testCompileNode.
@Test
public void testCompileNode() throws Exception {
final ActionContext actionContext = new ActionContext(new TransformationContext());
final RunnableAction mockAction = new RunnableAction();
CompileNode compileNode = new CompileNode(mockAction, actionContext);
assertEquals(actionContext, compileNode.getActionContext());
assertEquals(mockAction, compileNode.getAction());
}
use of org.talend.dataprep.transformation.actions.common.RunnableAction in project data-prep by Talend.
the class PipelineTest method testRecompileAction.
@Test
public void testRecompileAction() throws Exception {
// Given
AtomicInteger compileCount = new AtomicInteger();
final RunnableAction mockAction = new RunnableAction() {
@Override
public DataSetRowAction getRowAction() {
return new DataSetRowAction() {
@Override
public void compile(ActionContext actionContext) {
compileCount.incrementAndGet();
actionContext.setActionStatus(ActionContext.ActionStatus.OK);
}
@Override
public DataSetRow apply(DataSetRow dataSetRow, ActionContext context) {
return dataSetRow;
}
};
}
};
final ActionContext actionContext = new ActionContext(new TransformationContext());
final Node node = NodeBuilder.source().to(new CompileNode(mockAction, actionContext)).to(output).build();
final RowMetadata rowMetadata = new RowMetadata();
final DataSetRow row = new DataSetRow(rowMetadata);
// when
assertEquals(0, compileCount.get());
node.exec().receive(row, rowMetadata);
// Change row metadata in middle of the transformation (to trigger
rowMetadata.addColumn(new ColumnMetadata());
// new compile).
node.exec().receive(row, rowMetadata);
// then
assertEquals(2, compileCount.get());
}
use of org.talend.dataprep.transformation.actions.common.RunnableAction in project data-prep by Talend.
the class PipelineTest method testCanceledAction.
@Test
public void testCanceledAction() throws Exception {
// Given
final RunnableAction mockAction = new RunnableAction() {
@Override
public DataSetRowAction getRowAction() {
return (r, context) -> {
context.get("Executed", p -> true);
return r;
};
}
};
final ActionContext actionContext = new ActionContext(new TransformationContext());
actionContext.setActionStatus(ActionContext.ActionStatus.CANCELED);
final Node node = NodeBuilder.source().to(new ActionNode(mockAction, actionContext)).to(output).build();
final RowMetadata rowMetadata = new RowMetadata();
final DataSetRow row = new DataSetRow(rowMetadata);
// when
node.exec().receive(row, rowMetadata);
// then
assertFalse(actionContext.has("Executed"));
}
use of org.talend.dataprep.transformation.actions.common.RunnableAction in project data-prep by Talend.
the class PipelineTest method testVisitorAndToString.
@Test
public void testVisitorAndToString() throws Exception {
final Node node = //
NodeBuilder.source().to(//
new BasicNode()).dispatchTo(//
new BasicNode()).to(//
new ActionNode(new RunnableAction(), new ActionContext(new TransformationContext()))).to(//
output).build();
final Pipeline pipeline = new Pipeline(node);
final NodeClassVisitor visitor = new NodeClassVisitor();
// when
pipeline.accept(visitor);
// then
final Class[] expectedClasses = { Pipeline.class, SourceNode.class, BasicLink.class, BasicNode.class, CloneLink.class, ActionNode.class };
assertThat(visitor.traversedClasses, CoreMatchers.hasItems(expectedClasses));
assertNotNull(pipeline.toString());
}
use of org.talend.dataprep.transformation.actions.common.RunnableAction in project data-prep by Talend.
the class PipelineTest method testActionNode.
@Test
public void testActionNode() throws Exception {
final ActionContext actionContext = new ActionContext(new TransformationContext());
final RunnableAction mockAction = new RunnableAction();
ActionNode compileNode = new ActionNode(mockAction, actionContext);
assertEquals(actionContext, compileNode.getActionContext());
assertEquals(mockAction, compileNode.getAction());
}
Aggregations