Search in sources :

Example 41 with SQL

use of org.pentaho.di.core.sql.SQL in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceExecutorTest method testStopWhenAlreadyStopped.

@Test
public void testStopWhenAlreadyStopped() throws KettleException {
    String sql = "SELECT * FROM " + DATA_SERVICE_NAME;
    when(serviceTrans.isRunning()).thenReturn(false);
    when(genTrans.isRunning()).thenReturn(false);
    DataServiceExecutor executor = new DataServiceExecutor.Builder(new SQL(sql), dataService, context).serviceTrans(serviceTrans).sqlTransGenerator(sqlTransGenerator).genTrans(genTrans).build();
    executor.stop();
    verify(serviceTrans, times(0)).stopAll();
    verify(genTrans, times(0)).stopAll();
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Matchers.anyString(org.mockito.Matchers.anyString) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 42 with SQL

use of org.pentaho.di.core.sql.SQL in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceExecutorTest method testWaitUntilFinished.

@Test
public void testWaitUntilFinished() throws Exception {
    SQL sql = new SQL("SELECT * FROM " + DATA_SERVICE_NAME);
    when(serviceTrans.getTransMeta().listParameters()).thenReturn(new String[0]);
    PushDownOptimizationMeta optimization = mock(PushDownOptimizationMeta.class);
    when(optimization.isEnabled()).thenReturn(true);
    dataService.getPushDownOptimizationMeta().add(optimization);
    IMetaStore metastore = mock(IMetaStore.class);
    DataServiceExecutor executor = new DataServiceExecutor.Builder(sql, dataService, context).serviceTrans(serviceTrans).sqlTransGenerator(sqlTransGenerator).genTrans(genTrans).metastore(metastore).build();
    executor.waitUntilFinished();
    verify(genTrans, times(0)).isFinishedOrStopped();
    verify(serviceTrans, times(1)).waitUntilFinished();
}
Also used : PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 43 with SQL

use of org.pentaho.di.core.sql.SQL in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceExecutorTest method testLogging.

@Test
public void testLogging() throws Exception {
    when(serviceTrans.getTransMeta()).thenReturn(transMeta);
    TransMeta genTransMeta = mock(TransMeta.class);
    when(genTrans.getTransMeta()).thenReturn(genTransMeta);
    new DataServiceExecutor.Builder(new SQL("SELECT * FROM " + DATA_SERVICE_NAME), dataService, context).serviceTrans(serviceTrans).genTrans(genTrans).prepareExecution(false).logLevel(LogLevel.DETAILED).build();
    verify(serviceTrans).setLogLevel(LogLevel.DETAILED);
    verify(transMeta).setLogLevel(LogLevel.DETAILED);
    verify(genTrans).setLogLevel(LogLevel.DETAILED);
    verify(genTransMeta).setLogLevel(LogLevel.DETAILED);
}
Also used : TransMeta(org.pentaho.di.trans.TransMeta) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 44 with SQL

use of org.pentaho.di.core.sql.SQL in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceExecutorTest method testBuilderBuildNullQueryServiceName.

@Test(expected = KettleException.class)
public void testBuilderBuildNullQueryServiceName() throws Exception {
    SQL sql = new SQL("SELECT * FROM " + DATA_SERVICE_NAME);
    dataService.setName(null);
    IMetaStore metastore = mock(IMetaStore.class);
    new DataServiceExecutor.Builder(sql, dataService, context).serviceTrans(serviceTrans).sqlTransGenerator(sqlTransGenerator).genTrans(genTrans).metastore(metastore).enableMetrics(false).normalizeConditions(false).rowLimit(50).build();
}
Also used : IMetaStore(org.pentaho.metastore.api.IMetaStore) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 45 with SQL

use of org.pentaho.di.core.sql.SQL in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceExecutorTest method testDynamicLimit.

@Test
public void testDynamicLimit() throws Exception {
    final String limitProp = "dataservice.dynamic.limit";
    boolean userDef = dataService.isUserDefined();
    try {
        System.setProperty(limitProp, "2");
        dataService.setUserDefined(false);
        DataServiceExecutor executor = new DataServiceExecutor.Builder(new SQL("SELECT * FROM " + DATA_SERVICE_NAME), dataService, context).serviceTrans(serviceTrans).genTrans(genTrans).build();
        assertEquals(2, executor.getServiceRowLimit());
        dataService.setUserDefined(true);
        System.setProperty(limitProp, "2");
        executor = new DataServiceExecutor.Builder(new SQL("SELECT * FROM " + DATA_SERVICE_NAME), dataService, context).serviceTrans(serviceTrans).genTrans(genTrans).build();
        assertEquals(0, executor.getServiceRowLimit());
        int serviceRowLimit = 1000;
        dataService.setRowLimit(serviceRowLimit);
        executor = new DataServiceExecutor.Builder(new SQL("SELECT * FROM " + DATA_SERVICE_NAME), dataService, context).serviceTrans(serviceTrans).genTrans(genTrans).build();
        assertEquals(serviceRowLimit, executor.getServiceRowLimit());
        serviceRowLimit = -3;
        dataService.setRowLimit(serviceRowLimit);
        executor = new DataServiceExecutor.Builder(new SQL("SELECT * FROM " + DATA_SERVICE_NAME), dataService, context).serviceTrans(serviceTrans).genTrans(genTrans).build();
        assertEquals(0, executor.getServiceRowLimit());
    } finally {
        dataService.setUserDefined(userDef);
        dataService.setRowLimit(0);
        System.getProperties().remove(limitProp);
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Matchers.anyString(org.mockito.Matchers.anyString) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Aggregations

SQL (org.pentaho.di.core.sql.SQL)58 Test (org.junit.Test)49 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)31 RowMeta (org.pentaho.di.core.row.RowMeta)18 Matchers.anyString (org.mockito.Matchers.anyString)17 IMetaStore (org.pentaho.metastore.api.IMetaStore)17 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)16 SelectValuesMeta (org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta)12 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)11 DataServiceExecutor (org.pentaho.di.trans.dataservice.DataServiceExecutor)7 PushDownOptimizationMeta (org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta)7 Condition (org.pentaho.di.core.Condition)6 KettleException (org.pentaho.di.core.exception.KettleException)4 SQLCondition (org.pentaho.di.core.sql.SQLCondition)4 TransMeta (org.pentaho.di.trans.TransMeta)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 DataOutputStream (java.io.DataOutputStream)3 RowProducer (org.pentaho.di.trans.RowProducer)3 Trans (org.pentaho.di.trans.Trans)3 ImmutableMap (com.google.common.collect.ImmutableMap)2