tillrohrmann 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_r295791892
 
 

 ##########
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TaskExecutorPartitionLifecycleTest.java
 ##########
 @@ -0,0 +1,454 @@
+/*
+ * 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;
+
+import org.apache.flink.api.common.ExecutionConfig;
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.api.common.time.Deadline;
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.core.testutils.BlockerSync;
+import org.apache.flink.metrics.MetricGroup;
+import org.apache.flink.runtime.blob.BlobCacheService;
+import org.apache.flink.runtime.blob.VoidBlobStore;
+import org.apache.flink.runtime.clusterframework.types.ResourceID;
+import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
+import org.apache.flink.runtime.concurrent.Executors;
+import org.apache.flink.runtime.deployment.InputGateDeploymentDescriptor;
+import org.apache.flink.runtime.deployment.ResultPartitionDeploymentDescriptor;
+import org.apache.flink.runtime.deployment.TaskDeploymentDescriptor;
+import org.apache.flink.runtime.execution.Environment;
+import org.apache.flink.runtime.execution.ExecutionState;
+import org.apache.flink.runtime.executiongraph.ExecutionAttemptID;
+import org.apache.flink.runtime.executiongraph.PartitionInfo;
+import org.apache.flink.runtime.heartbeat.HeartbeatServices;
+import 
org.apache.flink.runtime.highavailability.TestingHighAvailabilityServices;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder;
+import org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter;
+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.ResultPartitionTest;
+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.tasks.AbstractInvokable;
+import org.apache.flink.runtime.jobmaster.JMTMRegistrationSuccess;
+import org.apache.flink.runtime.jobmaster.JobMasterGateway;
+import org.apache.flink.runtime.jobmaster.utils.TestingJobMasterGateway;
+import org.apache.flink.runtime.jobmaster.utils.TestingJobMasterGatewayBuilder;
+import org.apache.flink.runtime.leaderretrieval.SettableLeaderRetrievalService;
+import org.apache.flink.runtime.messages.Acknowledge;
+import org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups;
+import org.apache.flink.runtime.rpc.RpcUtils;
+import org.apache.flink.runtime.rpc.TestingRpcService;
+import org.apache.flink.runtime.state.TaskExecutorLocalStateStoresManager;
+import 
org.apache.flink.runtime.taskexecutor.partition.JobAwareShuffleEnvironment;
+import 
org.apache.flink.runtime.taskexecutor.partition.JobAwareShuffleEnvironmentImpl;
+import org.apache.flink.runtime.taskexecutor.slot.TaskSlotTable;
+import org.apache.flink.runtime.taskexecutor.slot.TimerService;
+import org.apache.flink.runtime.taskmanager.NoOpTaskManagerActions;
+import org.apache.flink.runtime.testingUtils.TestingUtils;
+import org.apache.flink.runtime.util.TestingFatalErrorHandler;
+import org.apache.flink.util.SerializedValue;
+import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.function.TriConsumer;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.function.Function;
+
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * Tests for the partition-lifecycle logic in the {@link TaskExecutor}.
+ */
+public class TaskExecutorPartitionLifecycleTest extends TestLogger {
+
+       private static final Time timeout = Time.seconds(10L);
+
+       private static final TestingHighAvailabilityServices haServices = new 
TestingHighAvailabilityServices();
+       private static final SettableLeaderRetrievalService 
jobManagerLeaderRetriever = new SettableLeaderRetrievalService();
+       private static final JobID jobId = new JobID();
+
+       static {
+               haServices.setResourceManagerLeaderRetriever(new 
SettableLeaderRetrievalService());
+               haServices.setJobMasterLeaderRetriever(jobId, 
jobManagerLeaderRetriever);
+       }
+
+       @Rule
+       public final TemporaryFolder tmp = new TemporaryFolder();
+
+       private TestingRpcService rpc;
+
+       @Before
+       public void setup() {
+               rpc = new TestingRpcService();
+       }
+
+       @After
+       public void shutdown() throws ExecutionException, InterruptedException {
+               if (rpc != null) {
+                       rpc.stopService().get();
+               }
+       }
+
+       @Test
+       public void testConnectionTerminationAfterExternalRelease() throws 
IOException, InterruptedException, ExecutionException, TimeoutException {
+               final JobMasterGateway jobMasterGateway = new 
TestingJobMasterGatewayBuilder().build();
+
+               final JobManagerConnection jobManagerConnection = 
TaskSubmissionTestEnvironment.createJobManagerConnection(
+                       jobId, jobMasterGateway, rpc, new 
NoOpTaskManagerActions(), timeout);
+
+               final JobManagerTable jobManagerTable = new JobManagerTable();
+               jobManagerTable.put(jobId, jobManagerConnection);
+
+               final AtomicBoolean hasPartitionsOccupyingLocalResources = new 
AtomicBoolean(true);
+               final TestJobAwareShuffleEnvironment jobAwareShuffleEnvironment 
= new TestJobAwareShuffleEnvironment(jobId -> 
hasPartitionsOccupyingLocalResources.get());
+
+               final TaskManagerServices taskManagerServices = new 
TaskManagerServicesBuilder()
+                       .setJobManagerTable(jobManagerTable)
+                       .setShuffleEnvironment(jobAwareShuffleEnvironment)
+                       .setTaskSlotTable(createTaskSlotTable())
+                       .build();
+
+               final TestingTaskExecutor taskManager = 
createTestingTaskExecutor(taskManagerServices);
+
+               try {
+                       taskManager.start();
+                       taskManager.waitUntilStarted();
+
+                       assertTrue(jobManagerTable.contains(jobId));
+
+                       taskManager.releasePartitions(jobId, 
Collections.singletonList(new ResultPartitionID()));
+                       // connection should be kept alive since the 
environment still says we have local resources
+                       assertTrue(jobManagerTable.contains(jobId));
+
+                       hasPartitionsOccupyingLocalResources.set(false);
+
+                       // the TM should check whether partitions are still 
stored, and afterwards terminate the connection
+                       taskManager.releasePartitions(jobId, 
Collections.singletonList(new ResultPartitionID()));
+                       assertFalse(jobManagerTable.contains(jobId));
+               } finally {
+                       RpcUtils.terminateRpcEndpoint(taskManager, timeout);
+               }
+       }
+
+       @Test
+       public void testConnectionTerminationAfterInternalRelease() throws 
Exception {
+               final JobMasterGateway jobMasterGateway = new 
TestingJobMasterGatewayBuilder().build();
+
+               final JobManagerConnection jobManagerConnection = 
TaskSubmissionTestEnvironment.createJobManagerConnection(
+                       jobId, jobMasterGateway, rpc, new 
NoOpTaskManagerActions(), timeout);
+
+               final JobManagerTable jobManagerTable = new JobManagerTable();
+               jobManagerTable.put(jobId, jobManagerConnection);
+
+               final AtomicBoolean hasPartitionsOccupyingLocalResources = new 
AtomicBoolean(true);
+               final TestJobAwareShuffleEnvironment jobAwareShuffleEnvironment 
= new TestJobAwareShuffleEnvironment(jobId -> 
hasPartitionsOccupyingLocalResources.get());
 
 Review comment:
   So far the convention was to name testing classes with a `Testing` prefix.

----------------------------------------------------------------
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