Search in sources :

Example 71 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore 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 72 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore 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 73 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceExecutorTest method testRowLimitAux.

private StreamingServiceTransExecutor testRowLimitAux(int userLimit, int metaLimit, String kettleLimit) throws Exception {
    when(genTrans.isFinishedOrStopped()).thenReturn(true);
    SQL sql = new SQL("SELECT * FROM " + DATA_SERVICE_NAME);
    when(serviceTrans.getTransMeta().listParameters()).thenReturn(new String[0]);
    when(sqlTransGenerator.getSql()).thenReturn(sql);
    System.setProperty(DataServiceConstants.ROW_LIMIT_PROPERTY, kettleLimit);
    dataService.setStreaming(true);
    dataService.setRowLimit(metaLimit);
    IMetaStore metastore = mock(IMetaStore.class);
    DataServiceExecutor executor = new DataServiceExecutor.Builder(sql, dataService, context).serviceTrans(serviceTrans).sqlTransGenerator(sqlTransGenerator).genTrans(genTrans).metastore(metastore).rowLimit(userLimit).windowMode(IDataServiceClientService.StreamingMode.ROW_BASED).windowSize(1).windowEvery(0).windowLimit(0).build();
    StreamingServiceTransExecutor exec = context.getServiceTransExecutor(dataService.getName());
    context.removeServiceTransExecutor(dataService.getName());
    return exec;
}
Also used : IMetaStore(org.pentaho.metastore.api.IMetaStore) StreamingServiceTransExecutor(org.pentaho.di.trans.dataservice.streaming.execution.StreamingServiceTransExecutor) SQL(org.pentaho.di.core.sql.SQL)

Example 74 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pdi-dataservice-server-plugin by pentaho.

the class ExecutorQueryServiceTest method testQueryBuildsWithMetastore.

@Test
public void testQueryBuildsWithMetastore() throws Exception {
    final DataServiceFactory factory = mock(DataServiceFactory.class);
    final DataServiceContext context = mock(DataServiceContext.class);
    final DataServiceResolver dataServiceResolver = mock(DataServiceResolver.class);
    final DataServiceExecutor dataServiceExecutor = mock(DataServiceExecutor.class);
    final Trans serviceTrans = mock(Trans.class);
    final Trans genTrans = mock(Trans.class);
    when(context.getMetaStoreUtil()).thenReturn(factory);
    DataServiceExecutor.Builder builder = mock(DataServiceExecutor.Builder.class);
    final IMetaStore metastore = mock(IMetaStore.class);
    final MetastoreLocator metastoreLocator = mock(MetastoreLocator.class);
    when(metastoreLocator.getMetastore()).thenReturn(metastore);
    SQL sql = new SQL("select field from table");
    HashMap<String, String> parameters = new HashMap<>();
    int rowLimit = 5432;
    ExecutorQueryService executorQueryService = new ExecutorQueryService(dataServiceResolver, metastoreLocator);
    when(dataServiceResolver.createBuilder(argThat(matchesSql(sql)))).thenReturn(builder);
    when(factory.getMetaStore()).thenReturn(metastore);
    when(builder.rowLimit(rowLimit)).thenReturn(builder);
    when(builder.parameters(parameters)).thenReturn(builder);
    when(builder.metastore(metastore)).thenReturn(builder);
    when(builder.windowMode(null)).thenReturn(builder);
    when(builder.windowSize(0)).thenReturn(builder);
    when(builder.windowEvery(0)).thenReturn(builder);
    when(builder.windowLimit(0)).thenReturn(builder);
    when(builder.build()).thenReturn(dataServiceExecutor);
    when(dataServiceExecutor.getServiceTrans()).thenReturn(serviceTrans);
    when(dataServiceExecutor.getGenTrans()).thenReturn(genTrans);
    Query result = executorQueryService.prepareQuery(sql.getSqlString(), rowLimit, parameters);
    assertEquals(ImmutableList.of(serviceTrans, genTrans), result.getTransList());
    verify(builder).rowLimit(rowLimit);
    verify(builder).parameters(parameters);
    verify(builder).metastore(metastore);
}
Also used : HashMap(java.util.HashMap) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) DataServiceResolver(org.pentaho.di.trans.dataservice.resolvers.DataServiceResolver) MetastoreLocator(org.pentaho.osgi.metastore.locator.api.MetastoreLocator) IMetaStore(org.pentaho.metastore.api.IMetaStore) SQL(org.pentaho.di.core.sql.SQL) DataServiceContext(org.pentaho.di.trans.dataservice.DataServiceContext) DataServiceFactory(org.pentaho.di.trans.dataservice.serialization.DataServiceFactory) Trans(org.pentaho.di.trans.Trans) Test(org.junit.Test)

Example 75 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pdi-dataservice-server-plugin by pentaho.

the class TransImportExtensionPointPluginTest method callExtensionPoint.

@Test
public void callExtensionPoint() throws Exception {
    DataServiceReferenceSynchronizer referenceSynchronizer = mock(DataServiceReferenceSynchronizer.class);
    TransMeta transMeta = mock(TransMeta.class);
    Repository transRepository = mock(Repository.class);
    IMetaStore transMetaStore = mock(IMetaStore.class);
    when(transRepository.getMetaStore()).thenReturn(transMetaStore);
    when(transMeta.getRepository()).thenReturn(transRepository);
    when(transMeta.getMetaStore()).thenReturn(transMetaStore);
    TransImportExtensionPointPlugin plugin = new TransImportExtensionPointPlugin(referenceSynchronizer);
    LogChannelInterface log = mock(LogChannelInterface.class);
    plugin.callExtensionPoint(log, null);
    verify(referenceSynchronizer, times(0)).sync(same(transMeta), any(Function.class), eq(true));
    plugin.callExtensionPoint(log, "Not TransMeta");
    verify(referenceSynchronizer, times(0)).sync(same(transMeta), any(Function.class), eq(true));
    plugin.callExtensionPoint(log, transMeta);
    ArgumentCaptor<Function> exceptionHandlerCaptor = ArgumentCaptor.forClass(Function.class);
    verify(referenceSynchronizer).sync(same(transMeta), exceptionHandlerCaptor.capture(), eq(true));
    Exception e = new Exception();
    exceptionHandlerCaptor.getValue().apply(e);
    verify(log).logError(anyString(), same(e));
    DataServiceMeta dsMeta = mock(DataServiceMeta.class);
    DataServiceAlreadyExistsException dsaee = new DataServiceAlreadyExistsException(dsMeta);
    exceptionHandlerCaptor.getValue().apply(dsaee);
    verify(log).logBasic(anyString());
}
Also used : Function(java.util.function.Function) Repository(org.pentaho.di.repository.Repository) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) TransMeta(org.pentaho.di.trans.TransMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Test(org.junit.Test)

Aggregations

IMetaStore (org.pentaho.metastore.api.IMetaStore)75 Test (org.junit.Test)55 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)20 SQL (org.pentaho.di.core.sql.SQL)17 Repository (org.pentaho.di.repository.Repository)17 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)11 TransMeta (org.pentaho.di.trans.TransMeta)11 Matchers.anyString (org.mockito.Matchers.anyString)10 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)10 StepMeta (org.pentaho.di.trans.step.StepMeta)10 KettleException (org.pentaho.di.core.exception.KettleException)9 IMetaStoreElementType (org.pentaho.metastore.api.IMetaStoreElementType)9 Node (org.w3c.dom.Node)8 ArrayList (java.util.ArrayList)7 Variables (org.pentaho.di.core.variables.Variables)7 PushDownOptimizationMeta (org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta)7 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)7 IMetaStoreElement (org.pentaho.metastore.api.IMetaStoreElement)6 CheckResultInterface (org.pentaho.di.core.CheckResultInterface)5 StringObjectId (org.pentaho.di.repository.StringObjectId)5