@Override public void waitForFinish() { this.waitForFinish(Duration.ofSeconds(0)); }
@Override public void waitForFinish() { this.waitForFinish(Duration.ofSeconds(0)); }
@Override public void waitForFinish() { this.waitForFinish(Duration.ofSeconds(0)); }
@Override public void waitForFinish() { this.waitForFinish(Duration.ofSeconds(0)); }
@Override public void waitForFinish() { this.waitForFinish(Duration.ofSeconds(0)); }
@Test public void testWaitForFinishTimesout() { long timeoutInMs = 100; boolean finished = runner.waitForFinish(Duration.ofMillis(timeoutInMs)); assertFalse("Application finished before the timeout.", finished); }
@Test public void testWaitForFinishReturnsBeforeTimeout() { long timeoutInMs = 1000; runner.getShutdownLatch().countDown(); boolean finished = runner.waitForFinish(Duration.ofMillis(timeoutInMs)); assertTrue("Application did not finish before the timeout.", finished); }
@Test public void testRunComplete() { Map<String, String> cfgs = new HashMap<>(); cfgs.put(ApplicationConfig.APP_PROCESSOR_ID_GENERATOR_CLASS, UUIDGenerator.class.getName()); config = new MapConfig(cfgs); ProcessorLifecycleListenerFactory mockFactory = (pContext, cfg) -> mock(ProcessorLifecycleListener.class); mockApp = (StreamApplication) appDesc -> { appDesc.withProcessorLifecycleListenerFactory(mockFactory); }; prepareTest(); // return the jobConfigs from the planner doReturn(Collections.singletonList(new JobConfig(new MapConfig(config)))).when(localPlanner).prepareJobs(); StreamProcessor sp = mock(StreamProcessor.class); ArgumentCaptor<StreamProcessor.StreamProcessorLifecycleListenerFactory> captor = ArgumentCaptor.forClass(StreamProcessor.StreamProcessorLifecycleListenerFactory.class); doAnswer(i -> { ProcessorLifecycleListener listener = captor.getValue().createInstance(sp); listener.afterStart(); listener.afterStop(); return null; }).when(sp).start(); ExternalContext externalContext = mock(ExternalContext.class); doReturn(sp).when(runner) .createStreamProcessor(anyObject(), anyObject(), captor.capture(), eq(Optional.of(externalContext))); runner.run(externalContext); runner.waitForFinish(); assertEquals(runner.status(), ApplicationStatus.SuccessfulFinish); }
@Test public void testRunFailure() { Map<String, String> cfgs = new HashMap<>(); cfgs.put(ApplicationConfig.PROCESSOR_ID, "0"); config = new MapConfig(cfgs); ProcessorLifecycleListenerFactory mockFactory = (pContext, cfg) -> mock(ProcessorLifecycleListener.class); mockApp = (StreamApplication) appDesc -> { appDesc.withProcessorLifecycleListenerFactory(mockFactory); }; prepareTest(); // return the jobConfigs from the planner doReturn(Collections.singletonList(new JobConfig(new MapConfig(config)))).when(localPlanner).prepareJobs(); StreamProcessor sp = mock(StreamProcessor.class); ArgumentCaptor<StreamProcessor.StreamProcessorLifecycleListenerFactory> captor = ArgumentCaptor.forClass(StreamProcessor.StreamProcessorLifecycleListenerFactory.class); doAnswer(i -> { throw new Exception("test failure"); }).when(sp).start(); ExternalContext externalContext = mock(ExternalContext.class); doReturn(sp).when(runner) .createStreamProcessor(anyObject(), anyObject(), captor.capture(), eq(Optional.of(externalContext))); try { runner.run(externalContext); runner.waitForFinish(); } catch (Throwable th) { assertNotNull(th); } assertEquals(runner.status(), ApplicationStatus.UnsuccessfulFinish); }