Search in sources :

Example 6 with StepIOMetaInterface

use of org.pentaho.di.trans.step.StepIOMetaInterface in project pentaho-kettle by pentaho.

the class TransExecutorMetaTest method mockStepIo.

@SuppressWarnings("unchecked")
private static StepIOMetaInterface mockStepIo(StreamInterface stream, int desiredIndex) {
    List<StreamInterface> list = mock(List.class);
    when(list.indexOf(stream)).thenReturn(desiredIndex);
    when(list.get(eq(desiredIndex))).thenReturn(stream);
    StepIOMetaInterface stepIo = mock(StepIOMetaInterface.class);
    when(stepIo.getTargetStreams()).thenReturn(list);
    return stepIo;
}
Also used : StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 7 with StepIOMetaInterface

use of org.pentaho.di.trans.step.StepIOMetaInterface in project pentaho-kettle by pentaho.

the class TransExecutorMetaTest method firstStreamIsExecutionStatistics.

@Test
public void firstStreamIsExecutionStatistics() throws Exception {
    StreamInterface stream = mockStream();
    StepIOMetaInterface stepIo = mockStepIo(stream, 0);
    TransExecutorMeta meta = new TransExecutorMeta();
    meta = spy(meta);
    when(meta.getStepIOMeta()).thenReturn(stepIo);
    doCallRealMethod().when(meta).handleStreamSelection(any(StreamInterface.class));
    meta.handleStreamSelection(stream);
    assertEquals(stream.getStepMeta(), meta.getExecutionResultTargetStepMeta());
}
Also used : StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface) Test(org.junit.Test)

Example 8 with StepIOMetaInterface

use of org.pentaho.di.trans.step.StepIOMetaInterface in project pentaho-kettle by pentaho.

the class TransExecutorMetaTest method forthStreamIsExecutorsInput.

@Test
public void forthStreamIsExecutorsInput() throws Exception {
    StreamInterface stream = mockStream();
    StepIOMetaInterface stepIo = mockStepIo(stream, 3);
    TransExecutorMeta meta = new TransExecutorMeta();
    meta = spy(meta);
    when(meta.getStepIOMeta()).thenReturn(stepIo);
    doCallRealMethod().when(meta).handleStreamSelection(any(StreamInterface.class));
    meta.handleStreamSelection(stream);
    assertEquals(stream.getStepMeta(), meta.getExecutorsOutputStepMeta());
}
Also used : StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface) Test(org.junit.Test)

Example 9 with StepIOMetaInterface

use of org.pentaho.di.trans.step.StepIOMetaInterface in project pentaho-kettle by pentaho.

the class MappingIT method testInfoStreams_with_main_data_path.

/**
 * Tests that an input step that is a main data path is not flagged as an info stream
 */
public void testInfoStreams_with_main_data_path() throws Exception {
    KettleEnvironment.init();
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // Create a new transformation with a row generator that feeds a Mapping (Sub-Transformation) Step
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("Mapping Info Test");
    StepMeta rowGenerator = buildRowGeneratorStep(registry, "Generate Rows");
    transMeta.addStep(rowGenerator);
    StepMeta rowGeneratorMain = buildRowGeneratorStep(registry, "Generate Rows Main");
    transMeta.addStep(rowGeneratorMain);
    String mappingName = "mapping";
    MappingMeta mappingMeta = new MappingMeta();
    mappingMeta.setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME);
    mappingMeta.setFileName("test/org/pentaho/di/trans/steps/mapping/subtrans.ktr");
    List<MappingIODefinition> inputMappings = new ArrayList<MappingIODefinition>();
    String mappingInputStepName = "input";
    inputMappings.add(createMappingDef(rowGenerator.getName(), mappingInputStepName, "string", "a"));
    // Create the main data path mapping
    MappingIODefinition mainMappingDef = createMappingDef(rowGeneratorMain.getName(), mappingInputStepName, "string", "a");
    mainMappingDef.setMainDataPath(true);
    inputMappings.add(mainMappingDef);
    mappingMeta.setInputMappings(inputMappings);
    String mappingPid = registry.getPluginId(StepPluginType.class, mappingMeta);
    StepMeta mapping = new StepMeta(mappingPid, mappingName, mappingMeta);
    transMeta.addStep(mapping);
    TransHopMeta hopGeneratorToMapping = new TransHopMeta(rowGenerator, mapping);
    transMeta.addTransHop(hopGeneratorToMapping);
    hopGeneratorToMapping = new TransHopMeta(rowGeneratorMain, mapping);
    transMeta.addTransHop(hopGeneratorToMapping);
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    // (Copied from TransMeta.loadXML())
    for (int i = 0; i < transMeta.nrSteps(); i++) {
        StepMeta stepMeta = transMeta.getStep(i);
        StepMetaInterface sii = stepMeta.getStepMetaInterface();
        if (sii != null) {
            sii.searchInfoAndTargetSteps(transMeta.getSteps());
        }
    }
    // Verify the transformation was configured properly
    assertEquals("Transformation not initialized properly", 3, transMeta.nrSteps());
    StepMeta meta = transMeta.getStep(2);
    assertTrue("Transformation not initialized properly", meta.getStepMetaInterface() instanceof MappingMeta);
    MappingMeta loadedMappingMeta = (MappingMeta) meta.getStepMetaInterface();
    assertEquals("Expected a two input mapping definition", 2, loadedMappingMeta.getInputMappings().size());
    StepIOMetaInterface ioMeta = loadedMappingMeta.getStepIOMeta();
    assertEquals("Expected a single Info Stream", 1, ioMeta.getInfoStreams().size());
    assertEquals("Expected a single Info Step", 1, loadedMappingMeta.getInfoSteps().length);
}
Also used : TransMeta(org.pentaho.di.trans.TransMeta) ArrayList(java.util.ArrayList) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Trans(org.pentaho.di.trans.Trans)

Example 10 with StepIOMetaInterface

use of org.pentaho.di.trans.step.StepIOMetaInterface in project pentaho-kettle by pentaho.

the class MappingIT method testInfoStreams_single.

/**
 * Tests that info steps are correctly identified via StepMetaInterface.getStepIOMeta()
 */
public void testInfoStreams_single() throws Exception {
    KettleEnvironment.init();
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // Create a new transformation with a row generator that feeds a Mapping (Sub-Transformation) Step
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("Mapping Info Test");
    StepMeta rowGenerator = buildRowGeneratorStep(registry, "Generate Rows");
    transMeta.addStep(rowGenerator);
    String mappingName = "mapping";
    MappingMeta mappingMeta = new MappingMeta();
    mappingMeta.setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME);
    mappingMeta.setFileName("test/org/pentaho/di/trans/steps/mapping/subtrans.ktr");
    String mappingInputStepName = "input";
    mappingMeta.setInputMappings(Collections.singletonList(createMappingDef(rowGenerator.getName(), mappingInputStepName, "string", "a")));
    String mappingPid = registry.getPluginId(StepPluginType.class, mappingMeta);
    StepMeta mapping = new StepMeta(mappingPid, mappingName, mappingMeta);
    transMeta.addStep(mapping);
    TransHopMeta hopGeneratorToMapping = new TransHopMeta(rowGenerator, mapping);
    transMeta.addTransHop(hopGeneratorToMapping);
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    // (Copied from TransMeta.loadXML())
    for (int i = 0; i < transMeta.nrSteps(); i++) {
        StepMeta stepMeta = transMeta.getStep(i);
        StepMetaInterface sii = stepMeta.getStepMetaInterface();
        if (sii != null) {
            sii.searchInfoAndTargetSteps(transMeta.getSteps());
        }
    }
    // Verify the transformation was configured properly
    assertEquals("Transformation not initialized properly", 2, transMeta.nrSteps());
    StepMeta meta = transMeta.getStep(1);
    assertTrue("Transformation not initialized properly", meta.getStepMetaInterface() instanceof MappingMeta);
    MappingMeta loadedMappingMeta = (MappingMeta) meta.getStepMetaInterface();
    assertEquals("Expected a single input mapping definition", 1, loadedMappingMeta.getInputMappings().size());
    StepIOMetaInterface ioMeta = loadedMappingMeta.getStepIOMeta();
    assertEquals("Expected a single Info Stream", 1, ioMeta.getInfoStreams().size());
    assertEquals("Expected a single Info Step", 1, loadedMappingMeta.getInfoSteps().length);
    // Verify the transformation can be executed
    StepInterface si = trans.getStepInterface(mappingName, 0);
    RowStepCollector rc = new RowStepCollector();
    si.addRowListener(rc);
    trans.startThreads();
    trans.waitUntilFinished();
    assertEquals(1, rc.getRowsRead().size());
    assertEquals(1, rc.getRowsWritten().size());
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Trans(org.pentaho.di.trans.Trans)

Aggregations

StepIOMetaInterface (org.pentaho.di.trans.step.StepIOMetaInterface)23 StreamInterface (org.pentaho.di.trans.step.errorhandling.StreamInterface)19 StepMeta (org.pentaho.di.trans.step.StepMeta)10 KettleException (org.pentaho.di.core.exception.KettleException)7 TransHopMeta (org.pentaho.di.trans.TransHopMeta)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)6 Point (org.pentaho.di.core.gui.Point)6 KettleStepException (org.pentaho.di.core.exception.KettleStepException)4 AreaOwner (org.pentaho.di.core.gui.AreaOwner)4 StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)4 RowSet (org.pentaho.di.core.RowSet)3 EImage (org.pentaho.di.core.gui.PrimitiveGCInterface.EImage)3 TransMeta (org.pentaho.di.trans.TransMeta)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 NotePadMeta (org.pentaho.di.core.NotePadMeta)2 KettleValueException (org.pentaho.di.core.exception.KettleValueException)2 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)2 KettleRepositoryLostException (org.pentaho.di.repository.KettleRepositoryLostException)2