Search in sources :

Example 96 with TransHopMeta

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

the class SynchronizeAfterMergeIT method setUp.

@Before
public void setUp() throws KettleDatabaseException, SQLException {
    connection = DriverManager.getConnection("jdbc:h2:mem:PERSON;");
    connection.setAutoCommit(false);
    PreparedStatement stmt = connection.prepareStatement("CREATE TABLE PERSON (ID INT PRIMARY KEY, personName VARCHAR(64) )");
    stmt.execute();
    stmt.close();
    stmt = connection.prepareStatement("INSERT INTO PERSON (ID, personName) VALUES (?, ?)");
    for (int i = 0; i < ROW_FOR_UPDATE + ROW_FOR_DELETE; i++) {
        stmt.setInt(1, i);
        stmt.setString(2, "personName" + i);
        stmt.addBatch();
    }
    stmt.executeBatch();
    stmt.close();
    connection.commit();
    PluginRegistry pluginRegistry = PluginRegistry.getInstance();
    transMeta = new TransMeta();
    transMeta.setName("SynchronizeAfterMerge");
    InjectorMeta injectorMeta = new InjectorMeta();
    String injectorPid = pluginRegistry.getPluginId(StepPluginType.class, injectorMeta);
    StepMeta injectorStep = new StepMeta(injectorPid, injectorStepname, injectorMeta);
    transMeta.addStep(injectorStep);
    DatabaseMeta dbMeta = spy(new DatabaseMeta());
    dbMeta.setDatabaseType("H2");
    when(dbMeta.getURL()).thenReturn("jdbc:h2:mem:PERSON;");
    when(dbMeta.supportsErrorHandlingOnBatchUpdates()).thenReturn(false);
    SynchronizeAfterMergeMeta synchronizeAfterMergeMeta = new SynchronizeAfterMergeMeta();
    // set commit size
    synchronizeAfterMergeMeta.setCommitSize(COMMIT_SIZE);
    synchronizeAfterMergeMeta.setDatabaseMeta(dbMeta);
    synchronizeAfterMergeMeta.setKeyCondition(new String[] { "=" });
    synchronizeAfterMergeMeta.setKeyLookup(new String[] { "ID" });
    synchronizeAfterMergeMeta.setKeyStream(new String[] { "personName" });
    synchronizeAfterMergeMeta.setKeyStream2(new String[] { null });
    synchronizeAfterMergeMeta.setUpdate(new Boolean[] { Boolean.TRUE });
    synchronizeAfterMergeMeta.setOperationOrderField("flag");
    synchronizeAfterMergeMeta.setOrderDelete(DELETE_FLAG);
    synchronizeAfterMergeMeta.setOrderInsert(INSERT_FLAG);
    synchronizeAfterMergeMeta.setOrderUpdate(UPDATE_FLAG);
    synchronizeAfterMergeMeta.setPerformLookup(true);
    synchronizeAfterMergeMeta.setTableName("PERSON");
    synchronizeAfterMergeMeta.settablenameInField(false);
    synchronizeAfterMergeMeta.settablenameField(null);
    synchronizeAfterMergeMeta.setUseBatchUpdate(true);
    synchronizeAfterMergeMeta.setUpdateLookup(new String[] { "ID" });
    synchronizeAfterMergeMeta.setUpdateStream(new String[] { "personName" });
    String synchronizeAfterMergePid = pluginRegistry.getPluginId(StepPluginType.class, synchronizeAfterMergeStepname);
    StepMeta synchronizeAfterMerge = new StepMeta(synchronizeAfterMergePid, synchronizeAfterMergeStepname, synchronizeAfterMergeMeta);
    transMeta.addStep(synchronizeAfterMerge);
    String dummyResultStepName = "dummyResultStepName";
    DummyTransMeta dummyResultTransMeta = new DummyTransMeta();
    String dummyResultPid = pluginRegistry.getPluginId(StepPluginType.class, dummyResultTransMeta);
    StepMeta dummyResultStep = new StepMeta(dummyResultPid, dummyResultStepName, dummyResultTransMeta);
    transMeta.addStep(dummyResultStep);
    String dummyErrorStepName = "dummyErrorStepName";
    DummyTransMeta dummyErrorTransMeta = new DummyTransMeta();
    String dummyErrorPid = pluginRegistry.getPluginId(StepPluginType.class, dummyErrorTransMeta);
    StepMeta dummyErrorStep = new StepMeta(dummyErrorPid, dummyErrorStepName, dummyErrorTransMeta);
    transMeta.addStep(dummyErrorStep);
    StepErrorMeta stepErrorMeta = new StepErrorMeta(transMeta, synchronizeAfterMerge, dummyErrorStep);
    stepErrorMeta.setEnabled(true);
    synchronizeAfterMerge.setStepErrorMeta(stepErrorMeta);
    TransHopMeta injSynch = new TransHopMeta(injectorStep, synchronizeAfterMerge);
    transMeta.addTransHop(injSynch);
    TransHopMeta synchDummyResult = new TransHopMeta(synchronizeAfterMerge, dummyResultStep);
    transMeta.addTransHop(synchDummyResult);
    TransHopMeta synchDummyError = new TransHopMeta(synchronizeAfterMerge, dummyErrorStep);
    transMeta.addTransHop(synchDummyError);
}
Also used : PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) InjectorMeta(org.pentaho.di.trans.steps.injector.InjectorMeta) StepErrorMeta(org.pentaho.di.trans.step.StepErrorMeta) PreparedStatement(java.sql.PreparedStatement) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) Before(org.junit.Before)

Example 97 with TransHopMeta

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

the class TransMetaConverterTest method testResolveStepMetaResources.

@Test
public void testResolveStepMetaResources() throws KettleException, MetaStoreException {
    Variables variables = new Variables();
    TransMeta transMeta = spy(new TransMeta());
    transMeta.setParentVariableSpace(variables);
    doReturn(transMeta).when(transMeta).realClone(false);
    TestMetaResolvableResource testMetaResolvableResource = spy(new TestMetaResolvableResource());
    TestMetaResolvableResource testMetaResolvableResourceTwo = spy(new TestMetaResolvableResource());
    StepMeta testMeta = new StepMeta("TestMeta", testMetaResolvableResource);
    StepMeta testMetaTwo = new StepMeta("TestMeta2", testMetaResolvableResourceTwo);
    transMeta.addStep(testMeta);
    transMeta.addStep(testMetaTwo);
    transMeta.addTransHop(new TransHopMeta(testMeta, testMetaTwo));
    TransMetaConverter.convert(transMeta);
    verify(testMetaResolvableResource).resolve();
    verify(testMetaResolvableResourceTwo).resolve();
}
Also used : Variables(org.pentaho.di.core.variables.Variables) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Test(org.junit.Test)

Example 98 with TransHopMeta

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

the class TransMetaConverterTest method testRemovingDisabledInputSteps.

@Test
public void testRemovingDisabledInputSteps() {
    TransMeta trans = new TransMeta();
    StepMeta inputToBeRemoved = new StepMeta("InputToBeRemoved", stepMetaInterface);
    trans.addStep(inputToBeRemoved);
    StepMeta inputToStay = new StepMeta("InputToStay", stepMetaInterface);
    trans.addStep(inputToStay);
    StepMeta inputReceiver1 = new StepMeta("InputReceiver1", stepMetaInterface);
    trans.addStep(inputReceiver1);
    StepMeta inputReceiver2 = new StepMeta("InputReceiver2", stepMetaInterface);
    trans.addStep(inputReceiver2);
    TransHopMeta hop1 = new TransHopMeta(inputToBeRemoved, inputReceiver1, false);
    TransHopMeta hop2 = new TransHopMeta(inputToStay, inputReceiver1);
    TransHopMeta hop3 = new TransHopMeta(inputToBeRemoved, inputReceiver2, false);
    trans.addTransHop(hop1);
    trans.addTransHop(hop2);
    trans.addTransHop(hop3);
    Transformation transformation = TransMetaConverter.convert(trans);
    List<String> steps = transformation.getOperations().stream().map(op -> op.getId()).collect(Collectors.toList());
    assertThat("Only 2 ops should exist", steps.size(), is(2));
    assertThat(steps, hasItems("InputToStay", "InputReceiver1"));
    List<String> hops = transformation.getHops().stream().map(hop -> hop.getId()).collect(Collectors.toList());
    assertThat("Only 1 hop should exist", hops.size(), is(1));
    assertThat(hops, hasItems("InputToStay -> InputReceiver1"));
}
Also used : Transformation(org.pentaho.di.engine.api.model.Transformation) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Trans(org.pentaho.di.trans.Trans) StepDataInterface(org.pentaho.di.trans.step.StepDataInterface) StepPluginType(org.pentaho.di.core.plugins.StepPluginType) Hop(org.pentaho.di.engine.api.model.Hop) CoreMatchers.startsWith(org.hamcrest.CoreMatchers.startsWith) KettleClientEnvironment(org.pentaho.di.core.KettleClientEnvironment) Operation(org.pentaho.di.engine.api.model.Operation) TransMeta(org.pentaho.di.trans.TransMeta) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) Document(org.w3c.dom.Document) Matchers.eq(org.mockito.Matchers.eq) Spy(org.mockito.Spy) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) CsvInputMeta(org.pentaho.di.trans.steps.csvinput.CsvInputMeta) ClassRule(org.junit.ClassRule) Mockito.doReturn(org.mockito.Mockito.doReturn) StepInterface(org.pentaho.di.trans.step.StepInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) AfterClass(org.junit.AfterClass) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) Variables(org.pentaho.di.core.variables.Variables) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) Collectors(java.util.stream.Collectors) ResolvableResource(org.pentaho.di.workarounds.ResolvableResource) List(java.util.List) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Mockito.mock(org.mockito.Mockito.mock) RestorePDIEngineEnvironment(org.pentaho.di.junit.rules.RestorePDIEngineEnvironment) BeforeClass(org.junit.BeforeClass) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) KettleException(org.pentaho.di.core.exception.KettleException) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) Answer(org.mockito.stubbing.Answer) CoreMatchers.everyItem(org.hamcrest.CoreMatchers.everyItem) InvocationOnMock(org.mockito.invocation.InvocationOnMock) XMLHandler(org.pentaho.di.core.xml.XMLHandler) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) Node(org.w3c.dom.Node) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) Props(org.pentaho.di.core.Props) Repository(org.pentaho.di.repository.Repository) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) Assert.assertNotNull(org.junit.Assert.assertNotNull) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) KettleEnvironment(org.pentaho.di.core.KettleEnvironment) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) TransHopMeta(org.pentaho.di.trans.TransHopMeta) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) TableInputMeta(org.pentaho.di.trans.steps.tableinput.TableInputMeta) Assert.assertEquals(org.junit.Assert.assertEquals) Transformation(org.pentaho.di.engine.api.model.Transformation) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Test(org.junit.Test)

Example 99 with TransHopMeta

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

the class TransMetaConverterTest method transWithHops.

@Test
public void transWithHops() {
    TransMeta meta = new TransMeta();
    meta.setFilename("fileName");
    StepMeta from = new StepMeta("step1", stepMetaInterface);
    meta.addStep(from);
    StepMeta to = new StepMeta("step2", stepMetaInterface);
    meta.addStep(to);
    meta.addTransHop(new TransHopMeta(from, to));
    Transformation trans = TransMetaConverter.convert(meta);
    assertThat(trans.getId(), is(meta.getFilename()));
    assertThat(trans.getOperations().size(), is(2));
    assertThat(trans.getHops().size(), is(1));
    assertThat(trans.getHops().get(0).getFrom().getId(), is(from.getName()));
    assertThat(trans.getHops().get(0).getTo().getId(), is(to.getName()));
    assertThat(trans.getHops().stream().map(Hop::getType).collect(Collectors.toList()), everyItem(is(Hop.TYPE_NORMAL)));
}
Also used : Transformation(org.pentaho.di.engine.api.model.Transformation) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) Hop(org.pentaho.di.engine.api.model.Hop) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Test(org.junit.Test)

Example 100 with TransHopMeta

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

the class TransMetaConverterTest method testMultipleDisabledHops.

@Test
public void testMultipleDisabledHops() {
    TransMeta trans = new TransMeta();
    StepMeta input = new StepMeta("Input", stepMetaInterface);
    trans.addStep(input);
    StepMeta step1 = new StepMeta("Step1", stepMetaInterface);
    trans.addStep(step1);
    StepMeta step2 = new StepMeta("Step2", stepMetaInterface);
    trans.addStep(step2);
    StepMeta step3 = new StepMeta("Step3", stepMetaInterface);
    trans.addStep(step3);
    TransHopMeta hop1 = new TransHopMeta(input, step1, false);
    TransHopMeta hop2 = new TransHopMeta(step1, step2, false);
    TransHopMeta hop3 = new TransHopMeta(step2, step3, false);
    trans.addTransHop(hop1);
    trans.addTransHop(hop2);
    trans.addTransHop(hop3);
    Transformation transformation = TransMetaConverter.convert(trans);
    assertThat("Trans has steps though all of them should be removed", transformation.getOperations().size(), is(0));
    assertThat("Trans has hops though all of them should be removed", transformation.getHops().size(), is(0));
}
Also used : Transformation(org.pentaho.di.engine.api.model.Transformation) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Test(org.junit.Test)

Aggregations

TransHopMeta (org.pentaho.di.trans.TransHopMeta)153 StepMeta (org.pentaho.di.trans.step.StepMeta)127 TransMeta (org.pentaho.di.trans.TransMeta)114 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)80 Trans (org.pentaho.di.trans.Trans)78 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)71 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)71 StepInterface (org.pentaho.di.trans.step.StepInterface)70 RowStepCollector (org.pentaho.di.trans.RowStepCollector)66 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)63 RowProducer (org.pentaho.di.trans.RowProducer)49 InjectorMeta (org.pentaho.di.trans.steps.injector.InjectorMeta)49 Test (org.junit.Test)35 KettleException (org.pentaho.di.core.exception.KettleException)28 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)25 Point (org.pentaho.di.core.gui.Point)21 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)19 NotePadMeta (org.pentaho.di.core.NotePadMeta)15 StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)14 File (java.io.File)12