StepOptimization implements PushDownType { public ListenableFuture<Boolean> activate( final DataServiceExecutor executor, final PushDownOptimizationMeta meta ) { ListenableFutureTask<Boolean> future = ListenableFutureTask.create( new Callable<Boolean>() { @Override public Boolean call() throws Exception { StepInterface stepInterface = executor.getServiceTrans().findRunThread( meta.getStepName() ); return activate( executor, stepInterface ); } } ); executor.getListenerMap().put( DataServiceExecutor.ExecutionPoint.OPTIMIZE, future ); return future; }  ListenableFuture<Boolean> activate( final DataServiceExecutor executor,
                                             final PushDownOptimizationMeta meta ); @Override OptimizationImpactInfo preview( DataServiceExecutor executor, PushDownOptimizationMeta meta );  }
@Test public void testActivate() throws Exception { final ArrayListMultimap<DataServiceExecutor.ExecutionPoint, Runnable> tasks = ArrayListMultimap.create(); doReturn( true ).when( stepOptimization ).activate( executor, stepInterface ); when( executor.getListenerMap() ).thenReturn( tasks ); final ListenableFuture<Boolean> activate = stepOptimization.activate( executor, meta ); assertThat( tasks.get( DataServiceExecutor.ExecutionPoint.OPTIMIZE ), hasSize( 1 ) ); assertThat( activate.isDone(), is( false ) ); verify( serviceTrans, never() ).findRunThread( anyString() ); tasks.get( DataServiceExecutor.ExecutionPoint.OPTIMIZE ).get( 0 ).run(); verify( stepOptimization ).activate( executor, stepInterface ); assertThat( activate.isDone(), is( true ) ); assertThat( activate.get(), is( true ) ); }