use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.
the class PipelineTest method testAction.
@Test
public void testAction() throws Exception {
// Given
final RunnableAction mockAction = new RunnableAction() {
@Override
public DataSetRowAction getRowAction() {
return (r, context) -> {
context.get("ExecutedApply", p -> true);
return r;
};
}
};
final ActionContext actionContext = new ActionContext(new TransformationContext());
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
assertFalse(actionContext.has("ExecutedApply"));
node.exec().receive(row, rowMetadata);
// then
assertTrue(actionContext.has("ExecutedApply"));
assertTrue(actionContext.get("ExecutedApply"));
}
use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.
the class PipelineTest method testSourceNode.
@Test
public void testSourceNode() throws Exception {
// Given
final Node node = NodeBuilder.source().to(output).build();
final RowMetadata rowMetadata = new RowMetadata();
final DataSetRow row1 = new DataSetRow(rowMetadata);
final DataSetRow row2 = row1.clone();
row1.setTdpId(1L);
row2.setTdpId(2L);
// when
node.exec().receive(row1, rowMetadata);
node.exec().receive(row2, rowMetadata);
// then
assertEquals(2, output.getCount());
assertEquals(row2, output.getRow());
assertEquals(rowMetadata, output.getMetadata());
}
use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.
the class PipelineTest method testPipeline.
@Test
public void testPipeline() throws Exception {
// given
final Pipeline pipeline = new Pipeline(NodeBuilder.source().to(output).build());
final RowMetadata rowMetadata = new RowMetadata();
final DataSetRow row1 = new DataSetRow(rowMetadata);
final DataSetRow row2 = new DataSetRow(rowMetadata);
final List<DataSetRow> records = new ArrayList<>();
records.add(row1);
records.add(row2);
final DataSet dataSet = new DataSet();
final DataSetMetadata metadata = new DataSetMetadata();
metadata.setRowMetadata(rowMetadata);
dataSet.setMetadata(metadata);
dataSet.setRecords(records.stream());
// when
pipeline.execute(dataSet);
// then
assertThat(output.getCount(), is(2));
assertThat(output.getRow(), is(row2));
assertThat(output.getMetadata(), is(rowMetadata));
assertThat(output.getSignal(), is(END_OF_STREAM));
}
use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.
the class PipelineTest method testCleanUp.
@Test
public void testCleanUp() throws Exception {
// Given
final TransformationContext transformationContext = new TransformationContext();
final ActionContext actionContext = transformationContext.create((r, ac) -> r, new RowMetadata());
final AtomicInteger wasDestroyed = new AtomicInteger(0);
Destroyable destroyable = new Destroyable() {
@Override
public void destroy() {
wasDestroyed.incrementAndGet();
}
};
actionContext.get("test1", p -> destroyable);
actionContext.get("test2", p -> destroyable);
final Node node = //
NodeBuilder.source().to(//
new BasicNode()).to(//
new CleanUpNode(transformationContext)).to(//
output).build();
// when
node.exec().signal(END_OF_STREAM);
// then
assertEquals(2, wasDestroyed.get());
}
use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.
the class CloneLinkTest method should_emit_single_input_row_to_all_targets.
@Test
public void should_emit_single_input_row_to_all_targets() {
// given
final TestNode target1 = new TestNode();
final TestNode target2 = new TestNode();
final CloneLink link = new CloneLink(target1, target2);
final DataSetRow row = new DataSetRow(new HashMap<>());
final RowMetadata metadata = new RowMetadata(new ArrayList<>());
// when
link.emit(row, metadata);
// then
assertThat(target1.getReceivedRows(), hasSize(1));
assertThat(target1.getReceivedRows(), contains(row));
assertThat(target2.getReceivedRows(), hasSize(1));
assertThat(target2.getReceivedRows(), contains(row));
assertThat(target1.getReceivedMetadata(), hasSize(1));
assertThat(target1.getReceivedMetadata(), contains(metadata));
assertThat(target2.getReceivedMetadata(), hasSize(1));
assertThat(target2.getReceivedMetadata(), contains(metadata));
}
Aggregations