@Test public void testPropagateExceptionsFromClose() { final ScheduledExecutorService timerService = Executors.newSingleThreadScheduledExecutor(); try { final CollectingOutput<Integer> out = new CollectingOutput<>(); final Object lock = new Object(); final StreamTask<?, ?> mockTask = createMockTaskWithTimer(timerService, lock); WindowFunction<Integer, Integer, Integer, TimeWindow> failingFunction = new FailingFunction(100); // the operator has a window time that is so long that it will not fire in this test final long hundredYears = 100L * 365 * 24 * 60 * 60 * 1000; AccumulatingProcessingTimeWindowOperator<Integer, Integer, Integer> op = new AccumulatingProcessingTimeWindowOperator<>( failingFunction, identitySelector, IntSerializer.INSTANCE, IntSerializer.INSTANCE, hundredYears, hundredYears); op.setup(mockTask, new StreamConfig(new Configuration()), out); op.open(); for (int i = 0; i < 150; i++) { synchronized (lock) { op.processElement(new StreamRecord<Integer>(i)); } } try { synchronized (lock) { op.close(); } fail("This should fail with an exception"); } catch (Exception e) { assertTrue( e.getMessage().contains("Artificial Test Exception") || (e.getCause() != null && e.getCause().getMessage().contains("Artificial Test Exception"))); } op.dispose(); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } finally { timerService.shutdown(); } }
@Test public void testFailWhenNoLocalStorageDir() throws Exception { File targetDir = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); try { assertTrue(targetDir.mkdirs()); if (!targetDir.setWritable(false, false)) { System.err.println( "Cannot execute 'testFailWhenNoLocalStorageDir' because cannot mark directory non-writable"); return; } RocksDBStateBackend rocksDbBackend = new RocksDBStateBackend(TEMP_URI); rocksDbBackend.setDbStoragePath(targetDir.getAbsolutePath()); try { rocksDbBackend.initializeForJob(getMockEnvironment(), "foobar", IntSerializer.INSTANCE); } catch (Exception e) { assertTrue(e.getMessage().contains("No local storage directories available")); assertTrue(e.getMessage().contains(targetDir.getAbsolutePath())); } } finally { //noinspection ResultOfMethodCallIgnored targetDir.setWritable(true, false); FileUtils.deleteDirectory(targetDir); } }
@Test public void testKeyValueStateInWindowFunction() { final ScheduledExecutorService timerService = Executors.newSingleThreadScheduledExecutor(); try { final CollectingOutput<Integer> out = new CollectingOutput<>(50); final Object lock = new Object(); final StreamTask<?, ?> mockTask = createMockTaskWithTimer(timerService, lock); StatefulFunction.globalCounts.clear(); // tumbling window that triggers every 20 milliseconds AccumulatingProcessingTimeWindowOperator<Integer, Integer, Integer> op = new AccumulatingProcessingTimeWindowOperator<>( new StatefulFunction(), identitySelector, IntSerializer.INSTANCE, IntSerializer.INSTANCE, 50, 50); op.setup(mockTask, createTaskConfig(identitySelector, IntSerializer.INSTANCE), out); op.open(); synchronized (lock) { op.processElement(new StreamRecord<Integer>(1)); op.processElement(new StreamRecord<Integer>(2)); } out.waitForNElements(2, 60000); synchronized (lock) { op.processElement(new StreamRecord<Integer>(1)); op.processElement(new StreamRecord<Integer>(2)); op.processElement(new StreamRecord<Integer>(1)); op.processElement(new StreamRecord<Integer>(1)); op.processElement(new StreamRecord<Integer>(2)); op.processElement(new StreamRecord<Integer>(2)); } out.waitForNElements(8, 60000); List<Integer> result = out.getElements(); assertEquals(8, result.size()); Collections.sort(result); assertEquals(Arrays.asList(1, 1, 1, 1, 2, 2, 2, 2), result); assertEquals(4, StatefulFunction.globalCounts.get(1).intValue()); assertEquals(4, StatefulFunction.globalCounts.get(2).intValue()); synchronized (lock) { op.close(); } op.dispose(); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } finally { timerService.shutdown(); } }
@Test public void shouldWireUpAtExitHook() { factory.registerExitHook(); try { Runtime.getRuntime().addShutdownHook(factory.exitHook()); } catch (Exception e) { assertThat(e.getMessage(), is("Hook previously registered")); } }
@SuppressWarnings("ThrowableResultOfMethodCallIgnored") private void checkException( final ArgumentCaptor<Exception> exceptionCaptor, final Class<? extends Exception> expectedException, final String expectedMessage) { final Exception exception = exceptionCaptor.getValue(); assertEquals(expectedException, exception.getClass()); assertEquals(expectedMessage, exception.getMessage()); }
@Test public void testDoesNotBombWhenDirectoryDoesNotExist() throws Exception { IPlatformImporter importer = mock(IPlatformImporter.class); ArchiveLoader loader = new ArchiveLoader(importer); try { loader.loadAll(new File("/fake/path/that/does/not/exist"), ArchiveLoader.ZIPS_FILTER); } catch (Exception e) { Assert.fail("Expected no exception but got " + e.getMessage()); } }
@Test(expected = Exception.class) public void runningCommandWithNonExistentAddressResultsInError() throws Exception { String[] args = {"-o", "-a", "user:pwd", "-c", "user:pwd:/FitNesse.NonExistentTestCase?test"}; Arguments arguments = new Arguments(args); try { Integer exitCode = new FitNesseMain().launchFitNesse(arguments); } catch (Exception e) { assertEquals("error loading page: 404", e.getMessage()); throw e; } }
@Test public void testTumblingWindow() { final ScheduledExecutorService timerService = Executors.newSingleThreadScheduledExecutor(); try { final int windowSize = 50; final CollectingOutput<Integer> out = new CollectingOutput<>(windowSize); final Object lock = new Object(); final StreamTask<?, ?> mockTask = createMockTaskWithTimer(timerService, lock); // tumbling window that triggers every 20 milliseconds AccumulatingProcessingTimeWindowOperator<Integer, Integer, Integer> op = new AccumulatingProcessingTimeWindowOperator<>( validatingIdentityFunction, identitySelector, IntSerializer.INSTANCE, IntSerializer.INSTANCE, windowSize, windowSize); op.setup(mockTask, new StreamConfig(new Configuration()), out); op.open(); final int numElements = 1000; for (int i = 0; i < numElements; i++) { synchronized (lock) { op.processElement(new StreamRecord<Integer>(i)); } Thread.sleep(1); } synchronized (lock) { op.close(); } op.dispose(); // get and verify the result List<Integer> result = out.getElements(); assertEquals(numElements, result.size()); Collections.sort(result); for (int i = 0; i < numElements; i++) { assertEquals(i, result.get(i).intValue()); } } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } finally { timerService.shutdown(); } }
@Test public void testInvalidParameters() { try { assertInvalidParameter(-1L, -1L); assertInvalidParameter(10000L, -1L); assertInvalidParameter(-1L, 1000L); assertInvalidParameter(1000L, 2000L); // actual internal slide is too low here: assertInvalidParameter(1000L, 999L); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void testSlidingWindowSingleElements() { final ScheduledExecutorService timerService = Executors.newSingleThreadScheduledExecutor(); try { final CollectingOutput<Integer> out = new CollectingOutput<>(50); final Object lock = new Object(); final StreamTask<?, ?> mockTask = createMockTaskWithTimer(timerService, lock); // tumbling window that triggers every 20 milliseconds AccumulatingProcessingTimeWindowOperator<Integer, Integer, Integer> op = new AccumulatingProcessingTimeWindowOperator<>( validatingIdentityFunction, identitySelector, IntSerializer.INSTANCE, IntSerializer.INSTANCE, 150, 50); op.setup(mockTask, new StreamConfig(new Configuration()), out); op.open(); synchronized (lock) { op.processElement(new StreamRecord<Integer>(1)); op.processElement(new StreamRecord<Integer>(2)); } // each element should end up in the output three times // wait until the elements have arrived 6 times in the output out.waitForNElements(6, 120000); List<Integer> result = out.getElements(); assertEquals(6, result.size()); Collections.sort(result); assertEquals(Arrays.asList(1, 1, 1, 2, 2, 2), result); synchronized (lock) { op.close(); } op.dispose(); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } finally { timerService.shutdown(); } }
@Test public void testUpdateStudent_passnull() { // Given StudentDirectoryServiceImpl studentDirectoryService = new StudentDirectoryServiceImpl(); try { // When studentDirectoryService.updateStudent(null); fail("An exception should have been thrown for a null value passed as a parameter."); } catch (Exception e) { // Then assertTrue(e instanceof NullPointerException); assertEquals("Unable to update a student. The student cannot be null.", e.getMessage()); } }
@Test public void test_wait_until_with_failure() { evaluator = mock(Evaluator.class); when(evaluator.existComponent(id)).thenReturn(true); when(evaluator.isVisible(any(Component.class))).thenReturn(false); when(evaluator.isEnabled(any(Component.class))).thenReturn(true); Component component = new Component(evaluator, id); try { waitUntil(component, is(visible())); fail(); } catch (Exception e) { assertThat(e.getMessage(), is("Unable to reach the condition in 5 SECONDS")); } }
@Test public void testEmitTrailingDataOnClose() { final ScheduledExecutorService timerService = Executors.newSingleThreadScheduledExecutor(); try { final CollectingOutput<Integer> out = new CollectingOutput<>(); final Object lock = new Object(); final StreamTask<?, ?> mockTask = createMockTaskWithTimer(timerService, lock); // the operator has a window time that is so long that it will not fire in this test final long oneYear = 365L * 24 * 60 * 60 * 1000; AccumulatingProcessingTimeWindowOperator<Integer, Integer, Integer> op = new AccumulatingProcessingTimeWindowOperator<>( validatingIdentityFunction, identitySelector, IntSerializer.INSTANCE, IntSerializer.INSTANCE, oneYear, oneYear); op.setup(mockTask, new StreamConfig(new Configuration()), out); op.open(); List<Integer> data = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); for (Integer i : data) { synchronized (lock) { op.processElement(new StreamRecord<Integer>(i)); } } synchronized (lock) { op.close(); } op.dispose(); // get and verify the result List<Integer> result = out.getElements(); Collections.sort(result); assertEquals(data, result); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } finally { timerService.shutdown(); } }
@Test public void shouldThrowExceptionWhenAgentWithNoCookieTriesToUpdateStatus() throws Exception { AgentRuntimeInfo runtimeInfo = new AgentRuntimeInfo( agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), null, null); try { agentService.updateRuntimeInfo(runtimeInfo); fail("should throw exception when no cookie is set"); } catch (Exception e) { assertThat(e, instanceOf(AgentNoCookieSetException.class)); assertThat( e.getMessage(), is(format("Agent [%s] has no cookie set", runtimeInfo.agentInfoDebugString()))); assertThat( Arrays.asList(logFixture.getMessages()), hasItem(format("Agent [%s] has no cookie set", runtimeInfo.agentInfoDebugString()))); } }
@Test public void shouldThrowExceptionWhenADuplicateAgentTriesToUpdateStatus() throws Exception { AgentRuntimeInfo runtimeInfo = new AgentRuntimeInfo( agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), null, null); runtimeInfo.setCookie("invalid_cookie"); AgentInstance original = AgentInstance.createFromLiveAgent( new AgentRuntimeInfo( agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), null, null), new SystemEnvironment()); try { when(agentService.findAgentAndRefreshStatus(runtimeInfo.getUUId())).thenReturn(original); agentService.updateRuntimeInfo(runtimeInfo); fail("should throw exception when cookie mismatched"); } catch (Exception e) { assertThat( e.getMessage(), is(format("Agent [%s] has invalid cookie", runtimeInfo.agentInfoDebugString()))); assertThat( Arrays.asList(logFixture.getMessages()), hasItem( format( "Found agent [%s] with duplicate uuid. Please check the agent installation.", runtimeInfo.agentInfoDebugString()))); verify(serverHealthService) .update( ServerHealthState.warning( format( "[%s] has duplicate unique identifier which conflicts with [%s]", runtimeInfo.agentInfoForDisplay(), original.agentInfoForDisplay()), "Please check the agent installation. Click <a href='http://www.go.cd/documentation/user/current/faq/agent_guid_issue.html' target='_blank'>here</a> for more info.", HealthStateType.duplicateAgent( HealthStateScope.forAgent(runtimeInfo.getCookie())), Timeout.THIRTY_SECONDS)); } verify(agentInstances).findAgentAndRefreshStatus(runtimeInfo.getUUId()); verifyNoMoreInteractions(agentInstances); }
public boolean tearDown() { /* List<MultiverseWorld> worlds = new ArrayList<MultiverseWorld>(core.getMVWorldManager() .getMVWorlds()); for (MultiverseWorld world : worlds) { core.getMVWorldManager().deleteWorld(world.getName()); } */ Server maybeNullServer = getServer(); PluginManager maybeNullPluginManager = maybeNullServer.getPluginManager(); Plugin plugin = maybeNullPluginManager.getPlugin("Multiverse-Inventories"); // Plugin plugin = getServer().getPluginManager().getPlugin("Multiverse-Inventories"); MultiverseInventories inventories = (MultiverseInventories) plugin; inventories.onDisable(); MockWorldFactory.clearWorlds(); plugin = getServer().getPluginManager().getPlugin("Multiverse-Core"); MultiverseCore core = (MultiverseCore) plugin; core.onDisable(); try { Field serverField = Bukkit.class.getDeclaredField("server"); serverField.setAccessible(true); serverField.set(Class.forName("org.bukkit.Bukkit"), null); } catch (Exception e) { Util.log( Level.SEVERE, "Error while trying to unregister the server from Bukkit. Has Bukkit changed?"); e.printStackTrace(); Assert.fail(e.getMessage()); return false; } return true; }
@Test public void testUnsubscribeAfterTake() { Subscription s = mock(Subscription.class); TestObservable w = new TestObservable(s, "one", "two", "three"); @SuppressWarnings("unchecked") Observer<String> aObserver = mock(Observer.class); Observable<String> take = Observable.create(take(w, 1)); take.subscribe(aObserver); // wait for the Observable to complete try { w.t.join(); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } System.out.println("TestObservable thread finished"); verify(aObserver, times(1)).onNext("one"); verify(aObserver, never()).onNext("two"); verify(aObserver, never()).onNext("three"); verify(s, times(1)).unsubscribe(); }
@Test public void testSlidingWindow() { final ScheduledExecutorService timerService = Executors.newSingleThreadScheduledExecutor(); try { final CollectingOutput<Integer> out = new CollectingOutput<>(50); final Object lock = new Object(); final StreamTask<?, ?> mockTask = createMockTaskWithTimer(timerService, lock); // tumbling window that triggers every 20 milliseconds AccumulatingProcessingTimeWindowOperator<Integer, Integer, Integer> op = new AccumulatingProcessingTimeWindowOperator<>( validatingIdentityFunction, identitySelector, IntSerializer.INSTANCE, IntSerializer.INSTANCE, 150, 50); op.setup(mockTask, new StreamConfig(new Configuration()), out); op.open(); final int numElements = 1000; for (int i = 0; i < numElements; i++) { synchronized (lock) { op.processElement(new StreamRecord<Integer>(i)); } Thread.sleep(1); } synchronized (lock) { op.close(); } op.dispose(); // get and verify the result List<Integer> result = out.getElements(); // if we kept this running, each element would be in the result three times (for each slide). // we are closing the window before the final panes are through three times, so we may have // less // elements. if (result.size() < numElements || result.size() > 3 * numElements) { fail("Wrong number of results: " + result.size()); } Collections.sort(result); int lastNum = -1; int lastCount = -1; for (int num : result) { if (num == lastNum) { lastCount++; assertTrue(lastCount <= 3); } else { lastNum = num; lastCount = 1; } } } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } finally { timerService.shutdown(); } }
@Test public void checkpointRestoreWithPendingWindowSliding() { final ScheduledExecutorService timerService = Executors.newSingleThreadScheduledExecutor(); try { final int factor = 4; final int windowSlide = 50; final int windowSize = factor * windowSlide; final CollectingOutput<Integer> out = new CollectingOutput<>(windowSlide); final Object lock = new Object(); final StreamTask<?, ?> mockTask = createMockTaskWithTimer(timerService, lock); // sliding window (200 msecs) every 50 msecs AccumulatingProcessingTimeWindowOperator<Integer, Integer, Integer> op = new AccumulatingProcessingTimeWindowOperator<>( validatingIdentityFunction, identitySelector, IntSerializer.INSTANCE, IntSerializer.INSTANCE, windowSize, windowSlide); op.setup(mockTask, new StreamConfig(new Configuration()), out); op.open(); // inject some elements final int numElements = 1000; final int numElementsFirst = 700; for (int i = 0; i < numElementsFirst; i++) { synchronized (lock) { op.processElement(new StreamRecord<Integer>(i)); } Thread.sleep(1); } // draw a snapshot StreamTaskState state; List<Integer> resultAtSnapshot; synchronized (lock) { int beforeSnapShot = out.getElements().size(); state = op.snapshotOperatorState(1L, System.currentTimeMillis()); resultAtSnapshot = new ArrayList<>(out.getElements()); int afterSnapShot = out.getElements().size(); assertEquals( "operator performed computation during snapshot", beforeSnapShot, afterSnapShot); } assertTrue(resultAtSnapshot.size() <= factor * numElementsFirst); // inject the remaining elements - these should not influence the snapshot for (int i = numElementsFirst; i < numElements; i++) { synchronized (lock) { op.processElement(new StreamRecord<Integer>(i)); } Thread.sleep(1); } op.dispose(); // re-create the operator and restore the state final CollectingOutput<Integer> out2 = new CollectingOutput<>(windowSlide); op = new AccumulatingProcessingTimeWindowOperator<>( validatingIdentityFunction, identitySelector, IntSerializer.INSTANCE, IntSerializer.INSTANCE, windowSize, windowSlide); op.setup(mockTask, new StreamConfig(new Configuration()), out2); op.restoreState(state, 1); op.open(); // inject again the remaining elements for (int i = numElementsFirst; i < numElements; i++) { synchronized (lock) { op.processElement(new StreamRecord<Integer>(i)); } Thread.sleep(1); } // for a deterministic result, we need to wait until all pending triggers // have fired and emitted their results long deadline = System.currentTimeMillis() + 120000; do { Thread.sleep(20); } while (resultAtSnapshot.size() + out2.getElements().size() < factor * numElements && System.currentTimeMillis() < deadline); synchronized (lock) { op.close(); } op.dispose(); // get and verify the result List<Integer> finalResult = new ArrayList<>(resultAtSnapshot); finalResult.addAll(out2.getElements()); assertEquals(factor * numElements, finalResult.size()); Collections.sort(finalResult); for (int i = 0; i < factor * numElements; i++) { assertEquals(i / factor, finalResult.get(i).intValue()); } } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } finally { timerService.shutdown(); } }
@Test public void checkpointRestoreWithPendingWindowTumbling() { final ScheduledExecutorService timerService = Executors.newSingleThreadScheduledExecutor(); try { final int windowSize = 200; final CollectingOutput<Integer> out = new CollectingOutput<>(windowSize); final Object lock = new Object(); final StreamTask<?, ?> mockTask = createMockTaskWithTimer(timerService, lock); // tumbling window that triggers every 50 milliseconds AccumulatingProcessingTimeWindowOperator<Integer, Integer, Integer> op = new AccumulatingProcessingTimeWindowOperator<>( validatingIdentityFunction, identitySelector, IntSerializer.INSTANCE, IntSerializer.INSTANCE, windowSize, windowSize); op.setup(mockTask, new StreamConfig(new Configuration()), out); op.open(); // inject some elements final int numElementsFirst = 700; final int numElements = 1000; for (int i = 0; i < numElementsFirst; i++) { synchronized (lock) { op.processElement(new StreamRecord<Integer>(i)); } Thread.sleep(1); } // draw a snapshot and dispose the window StreamTaskState state; List<Integer> resultAtSnapshot; synchronized (lock) { int beforeSnapShot = out.getElements().size(); state = op.snapshotOperatorState(1L, System.currentTimeMillis()); resultAtSnapshot = new ArrayList<>(out.getElements()); int afterSnapShot = out.getElements().size(); assertEquals( "operator performed computation during snapshot", beforeSnapShot, afterSnapShot); assertTrue(afterSnapShot <= numElementsFirst); } // inject some random elements, which should not show up in the state for (int i = 0; i < 300; i++) { synchronized (lock) { op.processElement(new StreamRecord<Integer>(i + numElementsFirst)); } Thread.sleep(1); } op.dispose(); // re-create the operator and restore the state final CollectingOutput<Integer> out2 = new CollectingOutput<>(windowSize); op = new AccumulatingProcessingTimeWindowOperator<>( validatingIdentityFunction, identitySelector, IntSerializer.INSTANCE, IntSerializer.INSTANCE, windowSize, windowSize); op.setup(mockTask, new StreamConfig(new Configuration()), out2); op.restoreState(state, 1); op.open(); // inject some more elements for (int i = numElementsFirst; i < numElements; i++) { synchronized (lock) { op.processElement(new StreamRecord<Integer>(i)); } Thread.sleep(1); } synchronized (lock) { op.close(); } op.dispose(); // get and verify the result List<Integer> finalResult = new ArrayList<>(resultAtSnapshot); finalResult.addAll(out2.getElements()); assertEquals(numElements, finalResult.size()); Collections.sort(finalResult); for (int i = 0; i < numElements; i++) { assertEquals(i, finalResult.get(i).intValue()); } } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } finally { timerService.shutdown(); } }
@Test public void testWindowSizeAndSlide() { try { AccumulatingProcessingTimeWindowOperator<String, String, String> op; op = new AccumulatingProcessingTimeWindowOperator<>( mockFunction, mockKeySelector, StringSerializer.INSTANCE, StringSerializer.INSTANCE, 5000, 1000); assertEquals(5000, op.getWindowSize()); assertEquals(1000, op.getWindowSlide()); assertEquals(1000, op.getPaneSize()); assertEquals(5, op.getNumPanesPerWindow()); op = new AccumulatingProcessingTimeWindowOperator<>( mockFunction, mockKeySelector, StringSerializer.INSTANCE, StringSerializer.INSTANCE, 1000, 1000); assertEquals(1000, op.getWindowSize()); assertEquals(1000, op.getWindowSlide()); assertEquals(1000, op.getPaneSize()); assertEquals(1, op.getNumPanesPerWindow()); op = new AccumulatingProcessingTimeWindowOperator<>( mockFunction, mockKeySelector, StringSerializer.INSTANCE, StringSerializer.INSTANCE, 1500, 1000); assertEquals(1500, op.getWindowSize()); assertEquals(1000, op.getWindowSlide()); assertEquals(500, op.getPaneSize()); assertEquals(3, op.getNumPanesPerWindow()); op = new AccumulatingProcessingTimeWindowOperator<>( mockFunction, mockKeySelector, StringSerializer.INSTANCE, StringSerializer.INSTANCE, 1200, 1100); assertEquals(1200, op.getWindowSize()); assertEquals(1100, op.getWindowSlide()); assertEquals(100, op.getPaneSize()); assertEquals(12, op.getNumPanesPerWindow()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
private void testGroupUserIDsGroupsException(Exception exception) throws SQLException, InstantiationException, IllegalAccessException, MalformedURLException { when(sql.sqlQuery(anyString())).thenThrow(exception); assertEquals(0, webGroupDao.getGroupUserIDs(group1).size()); verify(log).severe(SingleWebGroupDao.EXCEPTION_MESSAGE_GET_USERIDS + exception.getMessage()); }
@Test public void testWindowTriggerTimeAlignment() { try { @SuppressWarnings("unchecked") final Output<StreamRecord<String>> mockOut = mock(Output.class); final StreamTask<?, ?> mockTask = createMockTask(); AccumulatingProcessingTimeWindowOperator<String, String, String> op; op = new AccumulatingProcessingTimeWindowOperator<>( mockFunction, mockKeySelector, StringSerializer.INSTANCE, StringSerializer.INSTANCE, 5000, 1000); op.setup(mockTask, new StreamConfig(new Configuration()), mockOut); op.open(); assertTrue(op.getNextSlideTime() % 1000 == 0); assertTrue(op.getNextEvaluationTime() % 1000 == 0); op.dispose(); op = new AccumulatingProcessingTimeWindowOperator<>( mockFunction, mockKeySelector, StringSerializer.INSTANCE, StringSerializer.INSTANCE, 1000, 1000); op.setup(mockTask, new StreamConfig(new Configuration()), mockOut); op.open(); assertTrue(op.getNextSlideTime() % 1000 == 0); assertTrue(op.getNextEvaluationTime() % 1000 == 0); op.dispose(); op = new AccumulatingProcessingTimeWindowOperator<>( mockFunction, mockKeySelector, StringSerializer.INSTANCE, StringSerializer.INSTANCE, 1500, 1000); op.setup(mockTask, new StreamConfig(new Configuration()), mockOut); op.open(); assertTrue(op.getNextSlideTime() % 500 == 0); assertTrue(op.getNextEvaluationTime() % 1000 == 0); op.dispose(); op = new AccumulatingProcessingTimeWindowOperator<>( mockFunction, mockKeySelector, StringSerializer.INSTANCE, StringSerializer.INSTANCE, 1200, 1100); op.setup(mockTask, new StreamConfig(new Configuration()), mockOut); op.open(); assertTrue(op.getNextSlideTime() % 100 == 0); assertTrue(op.getNextEvaluationTime() % 1100 == 0); op.dispose(); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }