Source:
private void test(OverWindowFrame[] frames, GenericRow[] expect) throws Exception { operator = new BufferDataOverWindowOperator(frames, comparator, true) { { output = new NonBufferOverWindowOperatorTest.ConsumerOutput(new Consumer<BaseRow>() { @Override public void accept(BaseRow r) { collect.add(GenericRow.of(r.getInt(0), r.getLong(1), r.getLong(2), r.getLong(3), r.getLong(4))); } }); } @Override public ClassLoader getUserCodeClassloader() { return Thread.currentThread().getContextClassLoader(); } @Override public StreamConfig getOperatorConfig() { StreamConfig conf = mock(StreamConfig.class); when(conf.<BaseRow>getTypeSerializerIn1(getUserCodeClassloader())) .thenReturn(inputSer); when(conf.getManagedMemoryFraction()) .thenReturn(0.99); return conf; } @Override public StreamTask<?, ?> getContainingTask() { class MockableStreamTask extends StreamTask<Object, StreamOperator<Object>> implements EnvironmentSupport { MockableStreamTask() throws Exception { super(new MockEnvironmentBuilder().build()); } @Override protected void init() { } } StreamTask<?, ?> task = mock(MockableStreamTask.class); Environment env = mock(Environment.class); when(task.getEnvironment()).thenReturn(new MockEnvironmentBuilder().build()); when(env.getMemoryManager()).thenReturn(memoryManager); when(env.getIOManager()).thenReturn(ioManager); return task; } @Override public StreamingRuntimeContext getRuntimeContext() { return mock(StreamingRuntimeContext.class); } }; operator.open(); addRow(0, 1L, 4L); addRow(0, 1L, 1L); addRow(0, 1L, 1L); addRow(0, 1L, 1L); addRow(1, 5L, 2L); addRow(2, 5L, 4L); addRow(2, 6L, 2L); addRow(2, 6L, 2L); addRow(2, 6L, 2L); operator.endInput(); GenericRow[] outputs = this.collect.toArray(new GenericRow[0]); Assert.assertArrayEquals(expect, outputs); operator.close(); }

Target:
private void test(OverWindowFrame[] frames, GenericRow[] expect) throws Exception { MockEnvironment env = new MockEnvironmentBuilder().setIOManager(ioManager).setMemoryManager(memoryManager).build(); StreamTask<Object, StreamOperator<Object>> task = new StreamTask<Object, StreamOperator<Object>>(env) { @Override protected void init() { } }; operator = new BufferDataOverWindowOperator(frames, comparator, true) { { output = new NonBufferOverWindowOperatorTest.ConsumerOutput(new Consumer<BaseRow>() { @Override public void accept(BaseRow r) { collect.add(GenericRow.of(r.getInt(0), r.getLong(1), r.getLong(2), r.getLong(3), r.getLong(4))); } }); } @Override public ClassLoader getUserCodeClassloader() { return Thread.currentThread().getContextClassLoader(); } @Override public StreamConfig getOperatorConfig() { StreamConfig conf = mock(StreamConfig.class); when(conf.<BaseRow>getTypeSerializerIn1(getUserCodeClassloader())) .thenReturn(inputSer); when(conf.getManagedMemoryFraction()) .thenReturn(0.99); return conf; } @Override public StreamTask<?, ?> getContainingTask() { return task; } @Override public StreamingRuntimeContext getRuntimeContext() { return mock(StreamingRuntimeContext.class); } }; operator.open(); addRow(0, 1L, 4L); addRow(0, 1L, 1L); addRow(0, 1L, 1L); addRow(0, 1L, 1L); addRow(1, 5L, 2L); addRow(2, 5L, 4L); addRow(2, 6L, 2L); addRow(2, 6L, 2L); addRow(2, 6L, 2L); operator.endInput(); GenericRow[] outputs = this.collect.toArray(new GenericRow[0]); Assert.assertArrayEquals(expect, outputs); operator.close(); }