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);
}
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());
}
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);
}
Aggregations