zentol commented on a change in pull request #8687: [FLINK-12612][coordination] 
Track stored partition on the TaskExecutor 
URL: https://github.com/apache/flink/pull/8687#discussion_r293282003
 
 

 ##########
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/partition/JobAwareShuffleEnvironmentImplTest.java
 ##########
 @@ -0,0 +1,357 @@
+/*
+ * 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.taskexecutor.partition;
+
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.metrics.MetricGroup;
+import org.apache.flink.metrics.groups.UnregisteredMetricsGroup;
+import org.apache.flink.runtime.deployment.InputGateDeploymentDescriptor;
+import org.apache.flink.runtime.deployment.ResultPartitionDeploymentDescriptor;
+import org.apache.flink.runtime.executiongraph.ExecutionAttemptID;
+import org.apache.flink.runtime.executiongraph.PartitionInfo;
+import org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter;
+import org.apache.flink.runtime.io.network.buffer.BufferBuilder;
+import org.apache.flink.runtime.io.network.buffer.BufferConsumer;
+import 
org.apache.flink.runtime.io.network.partition.PartitionProducerStateProvider;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionID;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.runtime.io.network.partition.consumer.InputGate;
+import org.apache.flink.runtime.jobgraph.IntermediateDataSetID;
+import org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID;
+import org.apache.flink.runtime.shuffle.PartitionDescriptor;
+import org.apache.flink.runtime.shuffle.ShuffleDescriptor;
+import org.apache.flink.runtime.shuffle.ShuffleEnvironment;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.annotation.Nullable;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+
+import static junit.framework.TestCase.assertTrue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.collection.IsEmptyCollection.empty;
+import static org.junit.Assert.assertFalse;
+
+/**
+ * Tests for the {@link JobAwareShuffleEnvironmentImpl}.
+ */
+public class JobAwareShuffleEnvironmentImplTest extends TestLogger {
+
+       private JobID jobId = new JobID();
+       private TestResultPartitionWriter externallyManagedWriter;
+       private TestResultPartitionWriter internallyManagedWriter;
+       private TestShuffleEnvironment wrappedEnvironment;
+       private JobAwareShuffleEnvironmentImpl<?> jobAwareEnvironment;
+       private Collection<ResultPartitionWriter> writers;
+
+       @Before
+       public void setup() {
+               final ExecutionAttemptID executionAttemptId = new 
ExecutionAttemptID();
+               externallyManagedWriter = new TestResultPartitionWriter(
+                       new ResultPartitionID(new 
IntermediateResultPartitionID(), executionAttemptId));
+               internallyManagedWriter = new TestResultPartitionWriter(
+                       new ResultPartitionID(new 
IntermediateResultPartitionID(), executionAttemptId));
+
+               wrappedEnvironment = new TestShuffleEnvironment(
+                       Arrays.asList(externallyManagedWriter, 
internallyManagedWriter));
+
+               jobAwareEnvironment = new 
JobAwareShuffleEnvironmentImpl<>(wrappedEnvironment);
+
+               ResultPartitionDeploymentDescriptor deploymentDescriptor1 = 
createResultPartitionDeploymentDescriptor(
+                       externallyManagedWriter.resultPartitionID, true);
+               ResultPartitionDeploymentDescriptor deploymentDescriptor2 = 
createResultPartitionDeploymentDescriptor(
+                       internallyManagedWriter.resultPartitionID, false);
+
+               writers = createResultPartitionWriters(
+                       jobAwareEnvironment,
+                       jobId,
+                       executionAttemptId,
+                       deploymentDescriptor1,
+                       deploymentDescriptor2
+               );
+       }
+
+       @Test
+       public void testInitialState() {
+               final JobID jobId = new JobID();
+               final TestResultPartitionWriter partitionWriter1 = new 
TestResultPartitionWriter(new ResultPartitionID());
+               final TestResultPartitionWriter partitionWriter2 = new 
TestResultPartitionWriter(new ResultPartitionID());
+
+               final TestShuffleEnvironment wrappedEnvironment = new 
TestShuffleEnvironment(
+                       Arrays.asList(partitionWriter1, partitionWriter2));
+
+               final JobAwareShuffleEnvironmentImpl jobAwareEnvironment = new 
JobAwareShuffleEnvironmentImpl(wrappedEnvironment);
+
+               
assertFalse(jobAwareEnvironment.hasPartitionsOccupyingLocalResources(jobId));
+       }
+
+       @Test
+       public void testReleaseAllPartitions() throws IOException {
+               jobAwareEnvironment.markJobActive(jobId);
+
+               for (ResultPartitionWriter writer : writers) {
+                       writer.setup();
+               }
+
+               for (ResultPartitionWriter writer : writers) {
+                       writer.finish();
+               }
+
+               
assertTrue(jobAwareEnvironment.hasPartitionsOccupyingLocalResources(jobId));
+
+               
jobAwareEnvironment.releaseAllFinishedPartitionsForJobAndMarkJobInactive(jobId);
+               assertThat(wrappedEnvironment.releasedPartitions, 
contains(externallyManagedWriter.resultPartitionID));
+       }
+
+       @Test
+       public void testReleasePartitions() throws IOException {
+               jobAwareEnvironment.markJobActive(jobId);
+
+               for (ResultPartitionWriter writer : writers) {
+                       writer.setup();
+               }
+
+               for (ResultPartitionWriter writer : writers) {
+                       writer.finish();
+               }
+
+               
assertTrue(jobAwareEnvironment.hasPartitionsOccupyingLocalResources(jobId));
+
+               jobAwareEnvironment.releaseFinishedPartitions(jobId, 
Collections.singleton(externallyManagedWriter.resultPartitionID));
+               assertThat(wrappedEnvironment.releasedPartitions, 
contains(externallyManagedWriter.resultPartitionID));
+       }
+
+       @Test
+       public void testPartitionFailure() throws IOException {
+               jobAwareEnvironment.markJobActive(jobId);
+
+               for (ResultPartitionWriter writer : writers) {
+                       writer.setup();
+               }
+
+               for (ResultPartitionWriter writer : writers) {
+                       writer.fail(null);
+               }
+
+               
assertFalse(jobAwareEnvironment.hasPartitionsOccupyingLocalResources(jobId));
+
+               
jobAwareEnvironment.releaseAllFinishedPartitionsForJobAndMarkJobInactive(jobId);
+               assertThat(wrappedEnvironment.releasedPartitions, empty());
+       }
+
+       @Test
+       public void testPartitionFinishWithoutActiveJob() throws IOException {
+               for (ResultPartitionWriter writer : writers) {
+                       writer.setup();
+               }
+
+               for (ResultPartitionWriter writer : writers) {
+                       writer.finish();
+               }
+
+               
assertFalse(jobAwareEnvironment.hasPartitionsOccupyingLocalResources(jobId));
+               assertThat(wrappedEnvironment.releasedPartitions, 
contains(externallyManagedWriter.resultPartitionID));
+       }
+
+       @Test
+       public void testPartitionFinishWithActiveJob() throws IOException {
+               jobAwareEnvironment.markJobActive(jobId);
+
+               for (ResultPartitionWriter writer : writers) {
+                       writer.setup();
+               }
+
+               for (ResultPartitionWriter writer : writers) {
+                       writer.finish();
+               }
+
+               
assertTrue(jobAwareEnvironment.hasPartitionsOccupyingLocalResources(jobId));
+               assertThat(wrappedEnvironment.releasedPartitions, empty());
+       }
+
+       @Test
+       public void testPartitionFinishWithPreviouslyActiveJob() throws 
IOException {
+               jobAwareEnvironment.markJobActive(jobId);
+
+               
jobAwareEnvironment.releaseAllFinishedPartitionsForJobAndMarkJobInactive(jobId);
+
+               for (ResultPartitionWriter writer : writers) {
+                       writer.setup();
+               }
+
+               for (ResultPartitionWriter writer : writers) {
+                       writer.finish();
+               }
+
+               
assertFalse(jobAwareEnvironment.hasPartitionsOccupyingLocalResources(jobId));
+               assertThat(wrappedEnvironment.releasedPartitions, 
contains(externallyManagedWriter.resultPartitionID));
+       }
+
+       private static Collection<ResultPartitionWriter> 
createResultPartitionWriters(
 
 Review comment:
   it is used twice though in that place.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to