Search in sources :

Example 61 with RowMetadata

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"));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) CoreMatchers(org.hamcrest.CoreMatchers) BasicLink(org.talend.dataprep.transformation.pipeline.link.BasicLink) HashMap(java.util.HashMap) Test(org.junit.Test) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) ArrayList(java.util.ArrayList) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) org.talend.dataprep.transformation.pipeline.node(org.talend.dataprep.transformation.pipeline.node) END_OF_STREAM(org.talend.dataprep.transformation.pipeline.Signal.END_OF_STREAM) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) CloneLink(org.talend.dataprep.transformation.pipeline.link.CloneLink) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) DataSetRowAction(org.talend.dataprep.transformation.api.action.DataSetRowAction) Assert(org.junit.Assert) DataSet(org.talend.dataprep.api.dataset.DataSet) NodeBuilder(org.talend.dataprep.transformation.pipeline.builder.NodeBuilder) Before(org.junit.Before) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Example 62 with RowMetadata

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());
}
Also used : RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Example 63 with RowMetadata

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));
}
Also used : DataSet(org.talend.dataprep.api.dataset.DataSet) ArrayList(java.util.ArrayList) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test)

Example 64 with RowMetadata

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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) Test(org.junit.Test)

Example 65 with RowMetadata

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));
}
Also used : TestNode(org.talend.dataprep.transformation.pipeline.TestNode) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Aggregations

RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)199 Test (org.junit.Test)130 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)112 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)87 AbstractMetadataBaseTest (org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)68 HashMap (java.util.HashMap)48 ActionContext (org.talend.dataprep.transformation.api.action.context.ActionContext)21 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)20 RunnableAction (org.talend.dataprep.transformation.actions.common.RunnableAction)19 TransformationContext (org.talend.dataprep.transformation.api.action.context.TransformationContext)18 ArrayList (java.util.ArrayList)16 DataSet (org.talend.dataprep.api.dataset.DataSet)11 List (java.util.List)9 Statistics (org.talend.dataprep.api.dataset.statistics.Statistics)9 Before (org.junit.Before)7 SemanticDomain (org.talend.dataprep.api.dataset.statistics.SemanticDomain)6 Preparation (org.talend.dataprep.api.preparation.Preparation)6 Response (com.jayway.restassured.response.Response)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Logger (org.slf4j.Logger)5