KarmaGYZ commented on a change in pull request #11323: [FLINK-16439][k8s] Make KubernetesResourceManager starts workers using WorkerResourceSpec requested by SlotManager URL: https://github.com/apache/flink/pull/11323#discussion_r388749748
########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/ActiveResourceManagerTest.java ########## @@ -0,0 +1,75 @@ +/* + * 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.resourcemanager; + +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.fail; + +/** + * Tests for {@link ActiveResourceManager}. + */ +public class ActiveResourceManagerTest { + + @Test + public void testPendingWorkerCounter() { + final WorkerResourceSpec spec1 = new WorkerResourceSpec(1.0, 1, 1, 1, 1); + final WorkerResourceSpec spec2 = new WorkerResourceSpec(2.0, 1, 1, 1, 1); + + final ActiveResourceManager.PendingWorkerCounter counter = new ActiveResourceManager.PendingWorkerCounter(); + assertThat(counter.getTotalNum(), is(0)); + assertThat(counter.getNum(spec1), is(0)); + assertThat(counter.getNum(spec2), is(0)); + + assertThat(counter.increateAndGet(spec1), is(1)); + assertThat(counter.getTotalNum(), is(1)); + assertThat(counter.getNum(spec1), is(1)); + assertThat(counter.getNum(spec2), is(0)); + + assertThat(counter.increateAndGet(spec1), is(2)); + assertThat(counter.getTotalNum(), is(2)); + assertThat(counter.getNum(spec1), is(2)); + assertThat(counter.getNum(spec2), is(0)); + + assertThat(counter.increateAndGet(spec2), is(1)); + assertThat(counter.getTotalNum(), is(3)); + assertThat(counter.getNum(spec1), is(2)); + assertThat(counter.getNum(spec2), is(1)); + + assertThat(counter.decreaseAndGet(spec1), is(1)); + assertThat(counter.getTotalNum(), is(2)); + assertThat(counter.getNum(spec1), is(1)); + assertThat(counter.getNum(spec2), is(1)); + + assertThat(counter.decreaseAndGet(spec2), is(0)); + assertThat(counter.getTotalNum(), is(1)); + assertThat(counter.getNum(spec1), is(1)); + assertThat(counter.getNum(spec2), is(0)); + + try { + counter.decreaseAndGet(spec2); + fail("Should have failed calling `decreaseAndGet` on zero."); Review comment: We could move this to another test case and annotate it with @Test(expected = IllegalStateException.class). ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services