Skip to content

Commit

Permalink
[hotfix][network,tests] Add new unit tests for ResultPartitionManager…
Browse files Browse the repository at this point in the history
…#createSubpartitionView

It is necessary to make sure PartitionNotFoundException is thrown on producer side for flip1, so some new tests are added to cover the cases
of creating subpartition view via ResultPartitionManager for registered/unregistered partitions.
  • Loading branch information
zhijiangW authored and tillrohrmann committed May 23, 2019
1 parent 2f39736 commit 222f87f
Showing 1 changed file with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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:https://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.partition;

import org.apache.flink.util.TestLogger;

import org.hamcrest.Matchers;
import org.junit.Test;

import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

/**
* Tests for {@link ResultPartitionManager}.
*/
public class ResultPartitionManagerTest extends TestLogger {

/**
* Tests that {@link ResultPartitionManager#createSubpartitionView(ResultPartitionID, int, BufferAvailabilityListener)}
* would throw {@link PartitionNotFoundException} if this partition was not registered before.
*/
@Test
public void testThrowPartitionNotFoundException() throws Exception {
final ResultPartitionManager partitionManager = new ResultPartitionManager();
final ResultPartition partition = PartitionTestUtils.createPartition();
try {
partitionManager.createSubpartitionView(partition.getPartitionId(), 0, new NoOpBufferAvailablityListener());

fail("Should throw PartitionNotFoundException for unregistered partition.");
} catch (PartitionNotFoundException notFound) {
assertThat(partition.getPartitionId(), Matchers.is(notFound.getPartitionId()));
}
}

/**
* Tests {@link ResultPartitionManager#createSubpartitionView(ResultPartitionID, int, BufferAvailabilityListener)}
* successful if this partition was already registered before.
*/
@Test
public void testCreateViewForRegisteredPartition() throws Exception {
final ResultPartitionManager partitionManager = new ResultPartitionManager();
final ResultPartition partition = PartitionTestUtils.createPartition();

partitionManager.registerResultPartition(partition);
partitionManager.createSubpartitionView(partition.getPartitionId(), 0, new NoOpBufferAvailablityListener());
}
}

0 comments on commit 222f87f

Please sign in to comment.