[ 
https://issues.apache.org/jira/browse/FLINK-7748?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16272450#comment-16272450
 ] 

ASF GitHub Bot commented on FLINK-7748:
---------------------------------------

Github user pnowojski commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4761#discussion_r154025597
  
    --- Diff: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/TaskEventDispatcherTest.java
 ---
    @@ -0,0 +1,168 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.flink.runtime.io.network;
    +
    +import org.apache.flink.runtime.event.TaskEvent;
    +import org.apache.flink.runtime.io.network.partition.ResultPartitionID;
    +import org.apache.flink.runtime.iterative.event.AllWorkersDoneEvent;
    +import org.apache.flink.runtime.iterative.event.TerminationEvent;
    +import org.apache.flink.runtime.util.event.EventListener;
    +import org.apache.flink.util.TestLogger;
    +
    +import org.junit.Rule;
    +import org.junit.Test;
    +import org.junit.rules.ExpectedException;
    +
    +import static junit.framework.TestCase.assertTrue;
    +import static org.junit.Assert.assertFalse;
    +import static org.mockito.Matchers.any;
    +import static org.mockito.Mockito.mock;
    +import static org.mockito.Mockito.times;
    +import static org.mockito.Mockito.verify;
    +
    +/**
    + * Basic tests for {@link TaskEventDispatcher}.
    + */
    +public class TaskEventDispatcherTest extends TestLogger {
    +
    +   @Rule
    +   public ExpectedException expectedException = ExpectedException.none();
    +
    +   @Test
    +   public void registerPartitionTwice() throws Exception {
    +           ResultPartitionID partitionId = new ResultPartitionID();
    +           TaskEventDispatcher ted = new TaskEventDispatcher();
    +           ted.registerPartition(partitionId);
    +
    +           expectedException.expect(IllegalStateException.class);
    +           expectedException.expectMessage("already registered at task 
event dispatcher");
    +
    +           ted.registerPartition(partitionId);
    +   }
    +
    +   @Test
    +   public void subscribeToEventNotRegistered() throws Exception {
    +           TaskEventDispatcher ted = new TaskEventDispatcher();
    +
    +           expectedException.expect(IllegalStateException.class);
    +           expectedException.expectMessage("not registered at task event 
dispatcher");
    +
    +           //noinspection unchecked
    +           ted.subscribeToEvent(new ResultPartitionID(), 
mock(EventListener.class), TaskEvent.class);
    +   }
    +
    +   /**
    +    * Tests {@link TaskEventDispatcher#publish(ResultPartitionID, 
TaskEvent)} and {@link TaskEventDispatcher#subscribeToEvent(ResultPartitionID, 
EventListener, Class)} methods.
    +    */
    +   @Test
    --- End diff --
    
    Guess what? :)
    
    ```
    private static OneShotEventListener extends EventListener<TaskEvent> {
      private final TaskEvent expected;
      private boolean fired = false;
      public OneShotEventListener(TaskEvent expected) {
        ...
      }
      
      public void onEvent(TaskEvent actual) {
         checkState(!fired);
         fired = true;
         checkArgument(actual == expected);
      }
    }
    
    private static ZeroShotEventListener extends EventListener<TaskEvent> {
      public void onEvent(TaskEvent actual) {
         throw new IllegalStateException();
      }
    }
    ```


> remove event listener behaviour from ResultPartitionWriter
> ----------------------------------------------------------
>
>                 Key: FLINK-7748
>                 URL: https://issues.apache.org/jira/browse/FLINK-7748
>             Project: Flink
>          Issue Type: Sub-task
>          Components: Network
>    Affects Versions: 1.4.0
>            Reporter: Nico Kruber
>            Assignee: Nico Kruber
>
> {{ResultPartitionWriter}} currently implements the {{EventListener}} 
> interface and is used for event registration, although event publishing is 
> already handled via the {{TaskEventDispatcher}}. This should be unified by 
> using {{TaskEventDispatcher}} only.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to