2020package org .apache .samza .runtime ;
2121
2222import com .google .common .collect .ImmutableList ;
23+
2324import java .time .Duration ;
2425import java .util .Collections ;
2526import java .util .HashMap ;
5657import static org .junit .Assert .assertTrue ;
5758import static org .mockito .Matchers .anyObject ;
5859import static org .mockito .Matchers .anyString ;
59- import static org .mockito .Mockito .*;
60+ import static org .mockito .Mockito .any ;
61+ import static org .mockito .Mockito .anyLong ;
62+ import static org .mockito .Mockito .doAnswer ;
63+ import static org .mockito .Mockito .mock ;
64+ import static org .mockito .Mockito .spy ;
65+ import static org .mockito .Mockito .verify ;
66+ import static org .mockito .Mockito .when ;
6067import static org .powermock .api .mockito .PowerMockito .doReturn ;
6168
6269
@@ -74,17 +81,18 @@ public class TestLocalApplicationRunner {
7481 @ Test
7582 public void testStreamCreation ()
7683 throws Exception {
77- Map < String , String > config = new HashMap <>();
78- LocalApplicationRunner runner = spy (new LocalApplicationRunner (new MapConfig ( config ) ));
84+ Config config = new MapConfig ( new HashMap <>() );
85+ LocalApplicationRunner runner = spy (new LocalApplicationRunner (config ));
7986 StreamApplication app = mock (StreamApplication .class );
8087
8188 StreamManager streamManager = mock (StreamManager .class );
82- doReturn (streamManager ).when (runner ).buildAndStartStreamManager ();
89+ doReturn (streamManager ).when (runner ).buildAndStartStreamManager (any ( Config . class ) );
8390
8491 ExecutionPlan plan = mock (ExecutionPlan .class );
8592 when (plan .getIntermediateStreams ()).thenReturn (Collections .singletonList (new StreamSpec ("test-stream" , "test-stream" , "test-system" )));
8693 when (plan .getPlanAsJson ()).thenReturn ("" );
87- doReturn (plan ).when (runner ).getExecutionPlan (any (), eq (streamManager ));
94+ when (plan .getJobConfigs ()).thenReturn (Collections .singletonList (new JobConfig (config )));
95+ doReturn (plan ).when (runner ).getExecutionPlan (any ());
8896
8997 CoordinationUtilsFactory coordinationUtilsFactory = mock (CoordinationUtilsFactory .class );
9098 JobCoordinatorConfig mockJcConfig = mock (JobCoordinatorConfig .class );
@@ -109,19 +117,19 @@ public void testStreamCreation()
109117 @ Test
110118 public void testStreamCreationWithCoordination ()
111119 throws Exception {
112- Map <String , String > config = new HashMap <>();
113- LocalApplicationRunner localRunner = new LocalApplicationRunner (new MapConfig (config ));
114- LocalApplicationRunner runner = spy (localRunner );
120+ Config config = new MapConfig (new HashMap <>());
121+ LocalApplicationRunner runner = spy (new LocalApplicationRunner (config ));
115122
116123 StreamApplication app = mock (StreamApplication .class );
117124
118125 StreamManager streamManager = mock (StreamManager .class );
119- doReturn (streamManager ).when (runner ).buildAndStartStreamManager ();
126+ doReturn (streamManager ).when (runner ).buildAndStartStreamManager (any ( Config . class ) );
120127
121128 ExecutionPlan plan = mock (ExecutionPlan .class );
122129 when (plan .getIntermediateStreams ()).thenReturn (Collections .singletonList (new StreamSpec ("test-stream" , "test-stream" , "test-system" )));
123130 when (plan .getPlanAsJson ()).thenReturn ("" );
124- doReturn (plan ).when (runner ).getExecutionPlan (any (), eq (streamManager ));
131+ when (plan .getJobConfigs ()).thenReturn (Collections .singletonList (new JobConfig (config )));
132+ doReturn (plan ).when (runner ).getExecutionPlan (any ());
125133
126134 CoordinationUtils coordinationUtils = mock (CoordinationUtils .class );
127135 CoordinationUtilsFactory coordinationUtilsFactory = mock (CoordinationUtilsFactory .class );
@@ -183,19 +191,20 @@ public void testRunStreamTask()
183191 @ Test
184192 public void testRunComplete ()
185193 throws Exception {
186- final Map <String , String > config = new HashMap <>();
187- config .put (ApplicationConfig .APP_PROCESSOR_ID_GENERATOR_CLASS , UUIDGenerator .class .getName ());
194+ HashMap <String , String > configMap = new HashMap <>();
195+ configMap .put (ApplicationConfig .APP_PROCESSOR_ID_GENERATOR_CLASS , UUIDGenerator .class .getName ());
196+ Config config = new MapConfig (configMap );
188197 LocalApplicationRunner runner = spy (new LocalApplicationRunner (new MapConfig (config )));
189198 StreamApplication app = mock (StreamApplication .class );
190199
191200 // buildAndStartStreamManager already includes start, so not going to verify it gets called
192201 StreamManager streamManager = mock (StreamManager .class );
193- when (runner .buildAndStartStreamManager ()).thenReturn (streamManager );
202+ when (runner .buildAndStartStreamManager (any ( Config . class ) )).thenReturn (streamManager );
194203 ExecutionPlan plan = mock (ExecutionPlan .class );
195204 when (plan .getIntermediateStreams ()).thenReturn (Collections .emptyList ());
196205 when (plan .getPlanAsJson ()).thenReturn ("" );
197206 when (plan .getJobConfigs ()).thenReturn (Collections .singletonList (new JobConfig (new MapConfig (config ))));
198- doReturn (plan ).when (runner ).getExecutionPlan (any (), eq ( streamManager ) );
207+ doReturn (plan ).when (runner ).getExecutionPlan (any ());
199208
200209 StreamProcessor sp = mock (StreamProcessor .class );
201210 ArgumentCaptor <StreamProcessorLifecycleListener > captor =
@@ -221,19 +230,20 @@ public void testRunComplete()
221230 @ Test
222231 public void testRunFailure ()
223232 throws Exception {
224- final Map <String , String > config = new HashMap <>();
225- config .put (ApplicationConfig .PROCESSOR_ID , "0" );
226- LocalApplicationRunner runner = spy (new LocalApplicationRunner (new MapConfig (config )));
233+ final Map <String , String > configMap = new HashMap <>();
234+ configMap .put (ApplicationConfig .PROCESSOR_ID , "0" );
235+ MapConfig config = new MapConfig (configMap );
236+ LocalApplicationRunner runner = spy (new LocalApplicationRunner (config ));
227237 StreamApplication app = mock (StreamApplication .class );
228238
229239 // buildAndStartStreamManager already includes start, so not going to verify it gets called
230240 StreamManager streamManager = mock (StreamManager .class );
231- when (runner .buildAndStartStreamManager ()).thenReturn (streamManager );
241+ when (runner .buildAndStartStreamManager (any ( Config . class ) )).thenReturn (streamManager );
232242 ExecutionPlan plan = mock (ExecutionPlan .class );
233243 when (plan .getIntermediateStreams ()).thenReturn (Collections .emptyList ());
234244 when (plan .getPlanAsJson ()).thenReturn ("" );
235- when (plan .getJobConfigs ()).thenReturn (Collections .singletonList (new JobConfig (new MapConfig ( config ) )));
236- doReturn (plan ).when (runner ).getExecutionPlan (any (), eq ( streamManager ) );
245+ when (plan .getJobConfigs ()).thenReturn (Collections .singletonList (new JobConfig (config )));
246+ doReturn (plan ).when (runner ).getExecutionPlan (any ());
237247
238248 StreamProcessor sp = mock (StreamProcessor .class );
239249 ArgumentCaptor <StreamProcessorLifecycleListener > captor =
0 commit comments