Search in sources :

Example 31 with SQL

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

the class DataServiceRealTest method testServiceTransKeepsRunningWhenDataServiceIsNotUserDefined.

@Test
public void testServiceTransKeepsRunningWhenDataServiceIsNotUserDefined() throws Exception {
    TransMeta transMeta = new TransMeta(getClass().getResource("/GenerateOneMillion.ktr").getPath());
    DataServiceMeta dataServiceMeta = new DataServiceMeta(transMeta);
    dataServiceMeta.setName("table");
    dataServiceMeta.setStepname("Delay Row");
    dataServiceMeta.setUserDefined(false);
    PentahoCacheSystemConfiguration systemConfiguration = new PentahoCacheSystemConfiguration();
    systemConfiguration.setData(new HashMap<>());
    PentahoCacheManagerImpl pentahoCacheManager = new PentahoCacheManagerImpl(systemConfiguration, new HeapCacheProvidingService());
    ServiceCacheFactory cacheFactory = new ServiceCacheFactory(pentahoCacheManager, Executors.newSingleThreadExecutor());
    DataServiceContext dataServiceContext = new DataServiceContext(singletonList(cacheFactory), emptyList(), pentahoCacheManager, new UIFactory(), new LogChannel(""));
    SQL countSql = new SQL("select count(*) from table");
    DataServiceExecutor countExecutor = new DataServiceExecutor.Builder(countSql, dataServiceMeta, dataServiceContext).build();
    countExecutor.executeQuery();
    SQL limitSql = new SQL("select field1,field2 from table limit 5");
    DataServiceExecutor limitExecutor = new DataServiceExecutor.Builder(limitSql, dataServiceMeta, dataServiceContext).build();
    limitExecutor.executeQuery();
    limitExecutor.waitUntilFinished();
    assertTrue(countExecutor.getGenTrans().isRunning());
    assertTrue(countExecutor.getServiceTrans().isRunning());
    countExecutor.getServiceTrans().stopAll();
}
Also used : HeapCacheProvidingService(org.pentaho.caching.ri.HeapCacheProvidingService) UIFactory(org.pentaho.di.trans.dataservice.ui.UIFactory) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) TransMeta(org.pentaho.di.trans.TransMeta) LogChannel(org.pentaho.di.core.logging.LogChannel) ServiceCacheFactory(org.pentaho.di.trans.dataservice.optimization.cache.ServiceCacheFactory) SQL(org.pentaho.di.core.sql.SQL) DataServiceContext(org.pentaho.di.trans.dataservice.DataServiceContext) PentahoCacheManagerImpl(org.pentaho.caching.impl.PentahoCacheManagerImpl) PentahoCacheSystemConfiguration(org.pentaho.caching.api.PentahoCacheSystemConfiguration) Test(org.junit.Test)

Example 32 with SQL

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

the class DataServiceExecutorTest method testIsComplete.

@Test
public void testIsComplete() throws KettleException {
    String sql = "SELECT * FROM " + DATA_SERVICE_NAME;
    when(genTrans.isStopped()).thenReturn(true);
    DataServiceExecutor executor = new DataServiceExecutor.Builder(new SQL(sql), dataService, context).serviceTrans(serviceTrans).sqlTransGenerator(sqlTransGenerator).genTrans(genTrans).build();
    assertTrue(executor.isStopped());
}
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 33 with SQL

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

the class DataServiceExecutorTest method testMutatorGetsCalled.

@Test
public void testMutatorGetsCalled() throws Exception {
    when(serviceTransMeta.realClone(false)).thenReturn(serviceTransMeta);
    when(serviceTransMeta.listVariables()).thenReturn(new String[] {});
    when(serviceTransMeta.listParameters()).thenReturn(new String[] {});
    new DataServiceExecutor.Builder(new SQL("SELECT * FROM " + DATA_SERVICE_NAME), dataService, context).serviceTransMutator(mutator).serviceTrans(serviceTransMeta);
    Mockito.verify(mutator).accept(dataService.getStepname(), serviceTransMeta);
}
Also used : SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 34 with SQL

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

the class DataServiceExecutorTest method testWaitInterruptedException.

@Test(expected = RuntimeException.class)
public void testWaitInterruptedException() throws Exception {
    SQL sql = new SQL("SELECT * FROM " + DATA_SERVICE_NAME);
    when(serviceTrans.getTransMeta().listParameters()).thenReturn(new String[0]);
    when(sqlTransGenerator.getSql()).thenReturn(sql);
    PushDownOptimizationMeta optimization = mock(PushDownOptimizationMeta.class);
    when(optimization.isEnabled()).thenReturn(true);
    dataService.getPushDownOptimizationMeta().add(optimization);
    dataService.setStreaming(true);
    IMetaStore metastore = mock(IMetaStore.class);
    DataServiceExecutor executor = new DataServiceExecutor.Builder(sql, dataService, context).serviceTrans(serviceTrans).sqlTransGenerator(sqlTransGenerator).genTrans(genTrans).metastore(metastore).windowMode(IDataServiceClientService.StreamingMode.ROW_BASED).windowSize(1).windowEvery(0).windowLimit(0).build();
    doThrow(InterruptedException.class).when(genTrans).isFinishedOrStopped();
    executor.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 35 with SQL

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

the class DataServiceExecutorTest method testBuilderBuildServiceServiceTransNotNull.

@Test
public void testBuilderBuildServiceServiceTransNotNull() throws Exception {
    SQL sql = new SQL("SELECT * FROM " + DATA_SERVICE_NAME);
    RowMeta rowMeta = new RowMeta();
    ValueMetaInterface vm = new ValueMetaString("aBinaryStoredString");
    vm.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
    vm.setStorageMetadata(new ValueMetaString());
    rowMeta.addValueMeta(vm);
    when(serviceTrans.getTransMeta()).thenReturn(serviceTransMeta);
    when(serviceTransMeta.realClone(false)).thenReturn(serviceTransMeta);
    when(serviceTransMeta.listVariables()).thenReturn(new String[] {});
    when(serviceTransMeta.listParameters()).thenReturn(new String[] {});
    when(serviceTransMeta.getStepFields(DATA_SERVICE_STEP)).thenReturn(rowMeta);
    dataService.setServiceTrans(serviceTrans.getTransMeta());
    dataService.setStreaming(true);
    IMetaStore metastore = mock(IMetaStore.class);
    DataServiceExecutor executor = new DataServiceExecutor.Builder(sql, dataService, context).sqlTransGenerator(sqlTransGenerator).genTrans(genTrans).metastore(metastore).enableMetrics(false).normalizeConditions(false).rowLimit(50).build();
    assertSame(dataService.getServiceTrans(), serviceTrans.getTransMeta());
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) SQL(org.pentaho.di.core.sql.SQL) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) 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