public void unregisterPartition(ResultPartitionID partitionId) {
        checkNotNull(partitionId);

        synchronized (registeredHandlers) {
            LOG.debug("unregistering {}", partitionId);
            // NOTE: tolerate un-registration of non-registered task (unregister is always called
            //       in the cleanup phase of a task even if it never came to the registration - see
            //       Task.java)
            registeredHandlers.remove(partitionId);
        }
    }
@Test
    void unregisterPartition() {
        ResultPartitionID partitionId1 = new ResultPartitionID();
        ResultPartitionID partitionId2 = new ResultPartitionID();
        TaskEventDispatcher ted = new TaskEventDispatcher();

        AllWorkersDoneEvent event = new AllWorkersDoneEvent();
        assertThat(ted.publish(partitionId1, event)).isFalse();

        ted.registerPartition(partitionId1);
        ted.registerPartition(partitionId2);

        OneShotEventListener eventListener1a = new OneShotEventListener(event);
        ZeroShotEventListener eventListener1b = new ZeroShotEventListener();
        OneShotEventListener eventListener2 = new OneShotEventListener(event);
        ted.subscribeToEvent(partitionId1, eventListener1a, AllWorkersDoneEvent.class);
        ted.subscribeToEvent(partitionId2, eventListener1b, AllWorkersDoneEvent.class);
        ted.subscribeToEvent(partitionId1, eventListener2, AllWorkersDoneEvent.class);

        ted.unregisterPartition(partitionId2);

        // publish something for partitionId1 triggering all according listeners
        assertThat(ted.publish(partitionId1, event)).isTrue();
        assertThat(eventListener1a.fired)
                .withFailMessage("listener should have fired for AllWorkersDoneEvent")
                .isTrue();
        assertThat(eventListener2.fired)
                .withFailMessage("listener should have fired for AllWorkersDoneEvent")
                .isTrue();

        // now publish something for partitionId2 which should not trigger any listeners
        assertThat(ted.publish(partitionId2, event)).isFalse();
    }