Search in sources :

Example 11 with StepMetaDataCombi

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

the class StepLogTable method getLogRecord.

/**
 * This method calculates all the values that are required
 *
 * @param id
 *          the id to use or -1 if no id is needed
 * @param status
 *          the log status to use
 */
public RowMetaAndData getLogRecord(LogStatus status, Object subject, Object parent) {
    if (subject == null || subject instanceof StepMetaDataCombi) {
        StepMetaDataCombi combi = (StepMetaDataCombi) subject;
        RowMetaAndData row = new RowMetaAndData();
        for (LogTableField field : fields) {
            if (field.isEnabled()) {
                Object value = null;
                if (subject != null) {
                    switch(ID.valueOf(field.getId())) {
                        case ID_BATCH:
                            value = new Long(combi.step.getTrans().getBatchId());
                            break;
                        case CHANNEL_ID:
                            value = combi.step.getLogChannel().getLogChannelId();
                            break;
                        case LOG_DATE:
                            value = new Date();
                            break;
                        case TRANSNAME:
                            value = combi.step.getTrans().getName();
                            break;
                        case STEPNAME:
                            value = combi.stepname;
                            break;
                        case STEP_COPY:
                            value = new Long(combi.copy);
                            break;
                        case LINES_READ:
                            value = new Long(combi.step.getLinesRead());
                            break;
                        case LINES_WRITTEN:
                            value = new Long(combi.step.getLinesWritten());
                            break;
                        case LINES_UPDATED:
                            value = new Long(combi.step.getLinesUpdated());
                            break;
                        case LINES_INPUT:
                            value = new Long(combi.step.getLinesInput());
                            break;
                        case LINES_OUTPUT:
                            value = new Long(combi.step.getLinesOutput());
                            break;
                        case LINES_REJECTED:
                            value = new Long(combi.step.getLinesRejected());
                            break;
                        case ERRORS:
                            value = new Long(combi.step.getErrors());
                            break;
                        case LOG_FIELD:
                            value = getLogBuffer(combi.step, combi.step.getLogChannel().getLogChannelId(), status, null);
                            break;
                        default:
                            break;
                    }
                }
                row.addValue(field.getFieldName(), field.getDataType(), value);
                row.getRowMeta().getValueMeta(row.size() - 1).setLength(field.getLength());
            }
        }
        return row;
    } else {
        return null;
    }
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) Date(java.util.Date)

Example 12 with StepMetaDataCombi

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

the class MQTTProducerTest method testFeedbackSize.

@Test
public void testFeedbackSize() throws Exception {
    StepMetaDataCombi combi = trans.getSteps().get(1);
    MQTTProducer step = (MQTTProducer) combi.step;
    when(logChannel.isBasic()).thenReturn(true);
    step.getTransMeta().setFeedbackSize(1);
    trans.startThreads();
    trans.waitUntilFinished();
    verify(logChannel).logBasic(eq("Linenr1"));
}
Also used : StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with StepMetaDataCombi

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

the class MQTTProducerTest method testMQTTConnectException.

@Test
public void testMQTTConnectException() throws Exception {
    StepMetaDataCombi combi = trans.getSteps().get(1);
    MQTTProducer step = (MQTTProducer) combi.step;
    step.first = true;
    PowerMockito.mockStatic(MQTTClientBuilder.class);
    MQTTClientBuilder clientBuilder = spy(MQTTClientBuilder.class);
    MqttException mqttException = mock(MqttException.class);
    when(mqttException.toString()).thenReturn("There was an error connecting");
    doThrow(mqttException).when(clientBuilder).buildAndConnect();
    PowerMockito.when(MQTTClientBuilder.builder()).thenReturn(clientBuilder);
    trans.startThreads();
    trans.waitUntilFinished();
    verify(logChannel).logError("There was an error connecting");
}
Also used : MqttException(org.eclipse.paho.client.mqttv3.MqttException) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with StepMetaDataCombi

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

the class MQTTProducerTest method testInvalidQOS.

@Test
public void testInvalidQOS() throws Exception {
    trans.setVariable("qos", "hello");
    trans.prepareExecution(new String[] {});
    // Need to set first = false again since prepareExecution was called with the new variable.
    StepMetaDataCombi combi = trans.getSteps().get(1);
    MQTTProducer step = (MQTTProducer) combi.step;
    step.first = false;
    trans.startThreads();
    trans.waitUntilFinished();
    verify(logChannel).logError(eq("Unexpected error"), any(KettleStepException.class));
    verify(mqttClient, never()).publish(any(), any());
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with StepMetaDataCombi

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

the class MQTTProducerTest method testProcessFirstRow.

@Test
public void testProcessFirstRow() throws Exception {
    StepMetaDataCombi combi = trans.getSteps().get(1);
    MQTTProducer step = (MQTTProducer) combi.step;
    step.first = true;
    PowerMockito.mockStatic(MQTTClientBuilder.class);
    MQTTClientBuilder clientBuilder = spy(MQTTClientBuilder.class);
    MqttClient mqttClient = mock(MqttClient.class);
    doReturn(mqttClient).when(clientBuilder).buildAndConnect();
    PowerMockito.when(MQTTClientBuilder.builder()).thenReturn(clientBuilder);
    trans.startThreads();
    trans.waitUntilFinished();
    assertFalse(step.first);
}
Also used : MqttClient(org.eclipse.paho.client.mqttv3.MqttClient) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

StepMetaDataCombi (org.pentaho.di.trans.step.StepMetaDataCombi)55 StepInterface (org.pentaho.di.trans.step.StepInterface)21 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)18 Test (org.junit.Test)13 KettleException (org.pentaho.di.core.exception.KettleException)10 ArrayList (java.util.ArrayList)8 StepMeta (org.pentaho.di.trans.step.StepMeta)8 Trans (org.pentaho.di.trans.Trans)7 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)6 KettleValueException (org.pentaho.di.core.exception.KettleValueException)6 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)6 StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)6 RowSet (org.pentaho.di.core.RowSet)5 UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)5 TransMeta (org.pentaho.di.trans.TransMeta)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Before (org.junit.Before)4 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)4 KettleFileException (org.pentaho.di.core.exception.KettleFileException)4