[GitHub] flink pull request #6338: [FLINK-8731] Replaced mockito with custom mock in ...
Github user asfgit closed the pull request at: https://github.com/apache/flink/pull/6338 ---
[GitHub] flink pull request #6338: [FLINK-8731] Replaced mockito with custom mock in ...
Github user zentol commented on a diff in the pull request: https://github.com/apache/flink/pull/6338#discussion_r202606214 --- Diff: flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/consumer/TestInputChannel.java --- @@ -81,26 +72,21 @@ public TestInputChannel readBuffer(boolean moreAvailable) throws IOException, In } public TestInputChannel readEndOfPartitionEvent() throws IOException, InterruptedException { - final Answer> answer = new Answer>() { - @Override - public Optional answer(InvocationOnMock invocationOnMock) throws Throwable { - // Return true after finishing - when(mock.isReleased()).thenReturn(true); - - return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(EndOfPartitionEvent.INSTANCE), false, 0)); + mock.addBufferAndAvailability( + new BufferAvailabilityProvider() { + @Override + public Optional getBufferAvailability() throws IOException, InterruptedException { + mock.setReleased(); + return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(EndOfPartitionEvent.INSTANCE), + false, + 0)); + } } - }; - - if (stubbing == null) { - stubbing = when(mock.getNextBuffer()).thenAnswer(answer); - } else { - stubbing = stubbing.thenAnswer(answer); - } - + ); return this; } - public InputChannel getInputChannel() { + public MockInputChannel getInputChannel() { --- End diff -- It would be good if we could get by without exposing the mock. As far as i can tell on GitHub the only usages of `MockInputChannel` methods outside of this class are in `StreamTestSingleInputGate`: ```inputChannels[channelIndex].getInputChannel().addBufferAndAvailability(answer);``` ```inputChannels[channelIndex].getInputChannel().setReleased();``` Since the `TestInputChannel` class is already accessed anyway we could move these methods to the TestChannel class. Note that currently this exposes a package-private class with a public method, which means that anyone without package-private access will get a compile error. Either make this method package private, or make the class public. ---
[GitHub] flink pull request #6338: [FLINK-8731] Replaced mockito with custom mock in ...
Github user zentol commented on a diff in the pull request: https://github.com/apache/flink/pull/6338#discussion_r202604951 --- Diff: flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/consumer/TestInputChannel.java --- @@ -125,4 +111,79 @@ public InputChannel getInputChannel() { return mocks; } + + interface BufferAvailabilityProvider { + Optional getBufferAvailability() throws IOException, InterruptedException; + } + + class MockInputChannel extends InputChannel { + + MockInputChannel( + SingleInputGate inputGate, + int channelIndex) { + super(inputGate, channelIndex, new ResultPartitionID(), 0, 0, new SimpleCounter()); + } + + private final Queue buffers = new ConcurrentLinkedQueue<>(); + + private BufferAvailabilityProvider lastProvider = null; --- End diff -- move fields above constructor ---
[GitHub] flink pull request #6338: [FLINK-8731] Replaced mockito with custom mock in ...
GitHub user dawidwys opened a pull request: https://github.com/apache/flink/pull/6338 [FLINK-8731] Replaced mockito with custom mock in TestInputChannel Replaced questionable usage if Mockito with custom written mock. You can merge this pull request into a Git repository by running: $ git pull https://github.com/dawidwys/flink test-mock-lock Alternatively you can review and apply these changes as the patch at: https://github.com/apache/flink/pull/6338.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #6338 commit a2c78e6193c57bb69fc6f7d7b629ef0ec47171bb Author: Dawid Wysakowicz Date: 2018-07-12T14:17:48Z [FLINK-8731] Replaced mockito with custom mock in TestInputChannel ---