public static int compare(SchedulerGroup lhs, SchedulerGroup rhs) {
    if (lhs == rhs) {
      return 0;
    }
    if (rhs == null) {
      return 1;
    }

    SchedulerQueryContext lhsFirst = lhs.peekFirst();
    SchedulerQueryContext rhsFirst = rhs.peekFirst();
    if (lhsFirst != null && rhsFirst != null) {
      return Long.compare(rhsFirst.getArrivalTimeMs(), lhsFirst.getArrivalTimeMs());
    } else if (lhsFirst != null) {
      return 1;
    } else if (rhsFirst != null) {
      return -1;
    } else {
      return 0;
    }
  }
@Test
  public void testCompare() {
    // Both groups are null
    assertEquals(FCFSSchedulerGroup.compare(null, null), 0);

    FCFSSchedulerGroup lhs = new FCFSSchedulerGroup("one");
    FCFSSchedulerGroup rhs = new FCFSSchedulerGroup("two");
    assertEquals(FCFSSchedulerGroup.compare(lhs, lhs), 0);

    // Both groups are empty
    assertNull(lhs.peekFirst());
    assertNull(rhs.peekFirst());
    assertEquals(lhs.compareTo(rhs), 0);
    assertEquals(rhs.compareTo(lhs), 0);

    SchedulerQueryContext firstRequest = createQueryRequest("groupOne", METRICS, 2000);
    lhs.addLast(firstRequest);
    assertEquals(lhs.compareTo(rhs), 1);
    assertEquals(rhs.compareTo(lhs), -1);

    SchedulerQueryContext secondRequest = createQueryRequest("groupTwo", METRICS, 3000);
    rhs.addLast(secondRequest);
    assertEquals(lhs.compareTo(rhs), 1);
    assertEquals(rhs.compareTo(lhs), -1);
  }