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;
}
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());
}
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());
}
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);
}
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());
}
Aggregations