@Override
  public boolean add(E e) {
    final int priorityLevel = e.getPriorityLevel();
    // try offering to all queues.
    if (!offerQueues(priorityLevel, e, true)) {

      CallQueueOverflowException ex;
      if (serverFailOverEnabled) {
        // Signal clients to failover and try a separate server.
        ex = CallQueueOverflowException.FAILOVER;
      } else if (priorityLevel == queues.size() - 1){
        // only disconnect the lowest priority users that overflow the queue.
        ex = CallQueueOverflowException.DISCONNECT;
      } else {
        ex = CallQueueOverflowException.KEEPALIVE;
      }
      throw ex;
    }
    return true;
  }
@SuppressWarnings("unchecked")
  @Test
  public void testInsertionWithFailover() {
    Configuration conf = new Configuration();
    // Config for server to throw StandbyException instead of the
    // regular RetriableException if call queue is full.

    // 3 queues, 2 slots each.
    fcq = Mockito.spy(new FairCallQueue<>(3, 6, "ns",
        true, conf));

    Schedulable p0 = mockCall("a", 0);
    Schedulable p1 = mockCall("b", 1);

    // add to first queue.
    addToQueueAndVerify(p0, 1, 0, 0);
    // 0:x- 1:-- 2:--

    // add to second queue.
    addToQueueAndVerify(p1, 0, 1, 0);
    // 0:x- 1:x- 2:--

    // add to first queue.
    addToQueueAndVerify(p0, 1, 0, 0);
    // 0:xx 1:x- 2:--

    // add to first full queue spills over to second.
    addToQueueAndVerify(p0, 1, 1, 0);
    // 0:xx 1:xx 2:--

    // add to second full queue spills over to third.
    addToQueueAndVerify(p1, 0, 1, 1);
    // 0:xx 1:xx 2:x-

    // add to first and second full queue spills over to third.
    addToQueueAndVerify(p0, 1, 1, 1);
    // 0:xx 1:xx 2:xx

    // adding non-lowest priority with all queues full throws a
    // standby exception for client to try another server.
    Mockito.reset(fcq);
    try {
      fcq.add(p0);
      fail("didn't fail");
    } catch (IllegalStateException ise) {
      checkOverflowException(ise, RpcStatusProto.FATAL, true);
    }
  }