Search in sources :

Example 21 with DataServiceExecutor

use of org.pentaho.di.trans.dataservice.DataServiceExecutor in project pdi-dataservice-server-plugin by pentaho.

the class ServiceCacheTest method testReplayFromRunning.

@Test
public void testReplayFromRunning() throws Exception {
    DataServiceExecutor executor = dataServiceExecutor("SELECT * FROM MOCK_SERVICE WHERE A = 2");
    CachedService.CacheKey key = CachedService.CacheKey.create(executor);
    final CachedServiceLoader cachedServiceLoader = mock(CachedServiceLoader.class);
    when(cache.get(key)).thenReturn(null);
    when(cache.get(key.withoutCondition())).thenReturn(null);
    HashMap<CachedService.CacheKey, ServiceObserver> runningServices = new HashMap<>();
    ServiceObserver serviceObserver = new ServiceObserver(executor);
    runningServices.put(key, serviceObserver);
    when(factory.getRunningServices()).thenReturn(runningServices);
    // noinspection unchecked
    when(factory.createCachedServiceLoader(any(java.util.function.Supplier.class))).thenReturn(cachedServiceLoader);
    when(cachedServiceLoader.replay(executor)).thenReturn(Futures.immediateFuture(2000));
    assertThat(serviceCache.activate(executor, serviceStep), is(true));
    verify(cachedServiceLoader).replay(executor);
}
Also used : HashMap(java.util.HashMap) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) Test(org.junit.Test)

Example 22 with DataServiceExecutor

use of org.pentaho.di.trans.dataservice.DataServiceExecutor in project pdi-dataservice-server-plugin by pentaho.

the class ServiceCacheTest method testRunningServiceIsRemovedOnError.

@Test
public void testRunningServiceIsRemovedOnError() throws Exception {
    DataServiceExecutor executor = spy(dataServiceExecutor("SELECT * FROM MOCK_SERVICE ORDER BY ID"));
    CachedService cachedService = CachedService.complete(ImmutableList.<RowMetaAndData>of());
    doReturn(true).when(executor).hasErrors();
    ServiceObserver observer = mock(ServiceObserver.class);
    when(factory.createObserver(executor)).thenReturn(observer);
    Map<CachedService.CacheKey, ServiceObserver> runningServices = new HashMap<>();
    when(factory.getRunningServices()).thenReturn(runningServices);
    when(observer.install()).thenReturn(Futures.immediateFuture(cachedService));
    assertThat(serviceCache.activate(executor, serviceStep), is(false));
    assertTrue(runningServices.isEmpty());
}
Also used : HashMap(java.util.HashMap) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) Test(org.junit.Test)

Example 23 with DataServiceExecutor

use of org.pentaho.di.trans.dataservice.DataServiceExecutor in project pdi-dataservice-server-plugin by pentaho.

the class ServiceCacheTest method testReplayComplete.

@Test
public void testReplayComplete() throws Exception {
    DataServiceExecutor executor = dataServiceExecutor("SELECT * FROM MOCK_SERVICE WHERE A = 2");
    CachedService.CacheKey key = CachedService.CacheKey.create(executor);
    CachedService cachedService = mock(CachedService.class);
    final CachedServiceLoader cachedServiceLoader = mock(CachedServiceLoader.class);
    when(cache.get(key)).thenReturn(null);
    when(cache.get(key.withoutCondition())).thenReturn(cachedService);
    when(cachedService.isComplete()).thenReturn(true);
    when(factory.createCachedServiceLoader(cachedService)).thenReturn(cachedServiceLoader);
    when(cachedServiceLoader.replay(executor)).thenReturn(Futures.immediateFuture(2000));
    assertThat(serviceCache.activate(executor, serviceStep), is(true));
    verify(cachedServiceLoader).replay(executor);
}
Also used : DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) Test(org.junit.Test)

Aggregations

DataServiceExecutor (org.pentaho.di.trans.dataservice.DataServiceExecutor)23 Test (org.junit.Test)19 SQL (org.pentaho.di.core.sql.SQL)6 HashMap (java.util.HashMap)4 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)4 KettleException (org.pentaho.di.core.exception.KettleException)4 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)3 StepListener (org.pentaho.di.trans.step.StepListener)3 StepMeta (org.pentaho.di.trans.step.StepMeta)3 IMetaStore (org.pentaho.metastore.api.IMetaStore)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Executor (java.util.concurrent.Executor)2 TimeUnit (java.util.concurrent.TimeUnit)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)2 RowProducer (org.pentaho.di.trans.RowProducer)2 DataServiceContext (org.pentaho.di.trans.dataservice.DataServiceContext)2