@Override
    public AllocatedSlot reserveFreeSlot(AllocationID allocationId) {
        LOG.debug("Reserve free slot with allocation id {}.", allocationId);
        AllocatedSlot slot = registeredSlots.get(allocationId);
        Preconditions.checkNotNull(slot, "The slot with id %s was not exists.", allocationId);
        Preconditions.checkState(
                freeSlots.removeFreeSlot(allocationId, slot.getTaskManagerId()) != null,
                "The slot with id %s was not free.",
                allocationId);
        return registeredSlots.get(allocationId);
    }
@Test
    void testReserveFreeSlot() {
        final DefaultAllocatedSlotPool slotPool = new DefaultAllocatedSlotPool();
        final Collection<AllocatedSlot> allSlots = createAllocatedSlots();
        final Collection<AllocatedSlot> freeSlots = new ArrayList<>(allSlots);
        final Iterator<AllocatedSlot> iterator = freeSlots.iterator();
        final AllocatedSlot allocatedSlot = iterator.next();
        iterator.remove();

        slotPool.addSlots(allSlots, 0);

        assertThat(slotPool.reserveFreeSlot(allocatedSlot.getAllocationId()))
                .isEqualTo(allocatedSlot);

        assertSlotPoolContainsFreeSlots(slotPool, freeSlots);
        assertSlotPoolContainsSlots(slotPool, allSlots);
    }