Github user tillrohrmann commented on a diff in the pull request:
https://github.com/apache/flink/pull/731#discussion_r31127537
--- Diff:
flink-runtime/src/test/java/org/apache/flink/runtime/instance/SharedSlotsTest.java
---
@@ -0,0 +1,665 @@
+/*
+ * 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.instance;
+
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.runtime.jobgraph.AbstractJobVertex;
+import org.apache.flink.runtime.jobgraph.JobVertexID;
+import org.apache.flink.runtime.jobmanager.scheduler.CoLocationConstraint;
+import org.apache.flink.runtime.jobmanager.scheduler.CoLocationGroup;
+import org.apache.flink.runtime.jobmanager.scheduler.Locality;
+import org.apache.flink.runtime.jobmanager.scheduler.SchedulerTestUtils;
+import org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup;
+import org.apache.flink.util.AbstractID;
+
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for the allocation, properties, and release of shared slots.
+ */
+public class SharedSlotsTest {
+
+ @Test
+ public void allocateAndReleaseEmptySlot() {
+ try {
+ JobID jobId = new JobID();
+ JobVertexID vertexId = new JobVertexID();
+
+ SlotSharingGroup sharingGroup = new
SlotSharingGroup(vertexId);
+ SlotSharingGroupAssignment assignment =
sharingGroup.getTaskAssignment();
+
+ assertEquals(0, assignment.getNumberOfSlots());
+ assertEquals(0,
assignment.getNumberOfAvailableSlotsForGroup(vertexId));
+
+ Instance instance =
SchedulerTestUtils.getRandomInstance(2);
+
+ assertEquals(2, instance.getTotalNumberOfSlots());
+ assertEquals(0, instance.getNumberOfAllocatedSlots());
+ assertEquals(2, instance.getNumberOfAvailableSlots());
+
+ // allocate a shared slot
+ SharedSlot slot = instance.allocateSharedSlot(jobId,
assignment);
+ assertEquals(2, instance.getTotalNumberOfSlots());
+ assertEquals(1, instance.getNumberOfAllocatedSlots());
+ assertEquals(1, instance.getNumberOfAvailableSlots());
+
+ // check that the new slot is fresh
+ assertTrue(slot.isAlive());
+ assertFalse(slot.isCanceled());
+ assertFalse(slot.isReleased());
+ assertEquals(0, slot.getNumberLeaves());
+ assertFalse(slot.hasChildren());
+ assertTrue(slot.isRootAndEmpty());
+ assertNotNull(slot.toString());
+ assertTrue(slot.getSubSlots().isEmpty());
+ assertEquals(0, slot.getSlotNumber());
+ assertEquals(0, slot.getRootSlotNumber());
+
+ // release the slot immediately.
+ slot.releaseSlot();
+
+ assertTrue(slot.isCanceled());
+ assertTrue(slot.isReleased());
+
+ // the slot sharing group and instance should not
+ assertEquals(2, instance.getTotalNumberOfSlots());
+ assertEquals(0, instance.getNumberOfAllocatedSlots());
+ assertEquals(2, instance.getNumberOfAvailableSlots());
+
+ assertEquals(0, assignment.getNumberOfSlots());
+ assertEquals(0,
assignment.getNumberOfAvailableSlotsForGroup(vertexId));
+
+ // we should not be able to allocate any children from
this released slot
+ assertNull(slot.allocateSharedSlot(new AbstractID()));
+ assertNull(slot.allocateSubSlot(new AbstractID()));
+
+ // we cannot add this slot to the assignment group
+ assignment.addSharedSlotAndAllocateSubSlot(slot,
Locality.NON_LOCAL, vertexId);
--- End diff --
Is an assertion which checks that the slot was not added missing here?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---