You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by dawidwys <gi...@git.apache.org> on 2018/07/15 18:44:01 UTC

[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 <dw...@...>
Date:   2018-07-12T14:17:48Z

    [FLINK-8731] Replaced mockito with custom mock in TestInputChannel

----


---

[GitHub] flink pull request #6338: [FLINK-8731] Replaced mockito with custom mock in ...

Posted by zentol <gi...@git.apache.org>.
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<Optional<BufferAndAvailability>> answer = new Answer<Optional<BufferAndAvailability>>() {
    -			@Override
    -			public Optional<BufferAndAvailability> 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<BufferAndAvailability> 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 ...

Posted by asfgit <gi...@git.apache.org>.
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 ...

Posted by zentol <gi...@git.apache.org>.
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<BufferAndAvailability> 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<BufferAvailabilityProvider> buffers = new ConcurrentLinkedQueue<>();
    +
    +		private BufferAvailabilityProvider lastProvider = null;
    --- End diff --
    
    move fields above constructor


---

[GitHub] flink issue #6338: [FLINK-8731] Replaced mockito with custom mock in TestInp...

Posted by dawidwys <gi...@git.apache.org>.
Github user dawidwys commented on the issue:

    https://github.com/apache/flink/pull/6338
  
    merging


---