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