zentol commented on a change in pull request #13964:
URL: https://github.com/apache/flink/pull/13964#discussion_r544266554



##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/DeclarativeSlotPoolBridgeResourceDeclarationTest.java
##########
@@ -0,0 +1,183 @@
+/*
+ * 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.jobmaster.slotpool;
+
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.core.testutils.FlinkMatchers;
+import org.apache.flink.runtime.clusterframework.types.AllocationID;
+import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
+import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor;
+import 
org.apache.flink.runtime.concurrent.ComponentMainThreadExecutorServiceAdapter;
+import org.apache.flink.runtime.jobmaster.JobMasterId;
+import org.apache.flink.runtime.jobmaster.SlotRequestId;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.time.Duration;
+import java.util.Collections;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+
+import static 
org.apache.flink.runtime.jobmaster.slotpool.DeclarativeSlotPoolBridgeTest.createAllocatedSlot;
+import static 
org.apache.flink.runtime.jobmaster.slotpool.DeclarativeSlotPoolBridgeTest.createDeclarativeSlotPoolBridge;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Tests for the {@link DeclarativeSlotPoolBridge}.
+ */
+public class DeclarativeSlotPoolBridgeResourceDeclarationTest extends 
TestLogger {
+
+       private static final JobMasterId jobMasterId = JobMasterId.generate();
+       private final ComponentMainThreadExecutor mainThreadExecutor = 
ComponentMainThreadExecutorServiceAdapter.forMainThread();
+
+       private RequirementListener requirementListener;
+       private DeclarativeSlotPoolBridge declarativeSlotPoolBridge;
+
+       @Before
+       public void setup() throws Exception {
+               requirementListener = new RequirementListener();
+
+               final TestingDeclarativeSlotPoolBuilder slotPoolBuilder = 
TestingDeclarativeSlotPool.builder()
+                       
.setIncreaseResourceRequirementsByConsumer(requirementListener::increaseRequirements)
+                       
.setDecreaseResourceRequirementsByConsumer(requirementListener::decreaseRequirements)
+                       .setReserveFreeSlotFunction((allocationId, 
resourceProfile) -> createAllocatedSlot(allocationId))
+                       .setFreeReservedSlotFunction((allocationID, throwable, 
aLong) -> ResourceCounter.withResource(ResourceProfile.UNKNOWN, 1))
+                       .setReleaseSlotFunction((allocationID, e) -> 
ResourceCounter.withResource(ResourceProfile.UNKNOWN, 1));
+
+               final 
DeclarativeSlotPoolBridgeTest.TestingDeclarativeSlotPoolFactory 
declarativeSlotPoolFactory = new 
DeclarativeSlotPoolBridgeTest.TestingDeclarativeSlotPoolFactory(slotPoolBuilder);
+               declarativeSlotPoolBridge = 
createDeclarativeSlotPoolBridge(declarativeSlotPoolFactory);
+       }
+
+       @After
+       public void teardown() throws Exception {
+               if (declarativeSlotPoolBridge != null) {
+                       declarativeSlotPoolBridge.close();
+               }
+       }
+
+       @Test
+       public void testRequirementsIncreasedOnNewAllocation() throws Exception 
{
+               declarativeSlotPoolBridge.start(jobMasterId, "localhost", 
mainThreadExecutor);
+
+               // requesting the allocation of a new slot should increase the 
requirements
+               declarativeSlotPoolBridge.requestNewAllocatedSlot(new 
SlotRequestId(), ResourceProfile.UNKNOWN, Time.minutes(5));
+               
assertThat(requirementListener.getRequirements().getResourceCount(ResourceProfile.UNKNOWN),
 is(1));
+       }
+
+       @Test
+       public void testRequirementsDecreasedOnAllocationTimeout() throws 
Exception {

Review comment:
       x




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


Reply via email to