@Override
  public void put(SchedulerQueryContext query)
      throws OutOfCapacityException {
    Preconditions.checkNotNull(query);
    _queueLock.lock();
    String groupName = _groupSelector.getSchedulerGroupName(query);
    try {
      SchedulerGroup groupContext = getOrCreateGroupContext(groupName);
      checkGroupHasCapacity(groupContext);
      query.setSchedulerGroupContext(groupContext);
      groupContext.addLast(query);
      _queryReaderCondition.signal();
    } finally {
      _queueLock.unlock();
    }
  }
@Test
  public void testPutOutOfCapacity()
      throws OutOfCapacityException {
    Map<String, Object> properties = new HashMap<>();
    properties.put(MultiLevelPriorityQueue.MAX_PENDING_PER_GROUP_KEY, 2);

    PinotConfiguration configuration = new PinotConfiguration(properties);

    ResourceManager rm = new UnboundedResourceManager(configuration);
    MultiLevelPriorityQueue queue = createQueue(configuration, rm);
    queue.put(createQueryRequest(GROUP_ONE, METRICS));
    GROUP_FACTORY._groupMap.get(GROUP_ONE).addReservedThreads(rm.getTableThreadsHardLimit());
    // we should still be able to add one more waiting query
    queue.put(createQueryRequest(GROUP_ONE, METRICS));
    // this assert is to test that above call to put() is not the one
    // throwing exception
    assertTrue(true);
    // it should throw now
    try {
      queue.put(createQueryRequest(GROUP_ONE, METRICS));
    } catch (OutOfCapacityException e) {
      assertTrue(true);
      return;
    }
    assertTrue(false);
  }