@Test
  public void testStageSorting() throws Exception {
    List<SortRequestProperty> sortProperties = new ArrayList<>();
    SortRequest sortRequest = new SortRequestImpl(sortProperties);

    Predicate predicate = new PredicateBuilder().property(
        StageResourceProvider.STAGE_CLUSTER_NAME).equals("c1").toPredicate();


    sortProperties.add(new SortRequestProperty(
        StageResourceProvider.STAGE_LOG_INFO, SortRequest.Order.ASC));

    Request request = PropertyHelper.getReadRequest(new HashSet<>(Arrays.asList()),
        null, null, null, sortRequest);

    // get back all 5
    List<StageEntity> entities = stageDao.findAll(request, predicate);
    assertEquals(5, entities.size());

    // assert sorting ASC
    String lastInfo = null;
    for (StageEntity entity : entities) {
      if (lastInfo == null) {
        lastInfo = entity.getLogInfo();
        continue;
      }

      String currentInfo = entity.getLogInfo();
      assertTrue(lastInfo.compareTo(currentInfo) <= 0);
      lastInfo = currentInfo;
    }

    // clear and do DESC
    sortProperties.clear();
    sortProperties.add(new SortRequestProperty(
        StageResourceProvider.STAGE_LOG_INFO, SortRequest.Order.DESC));

    // get back all 5
    entities = stageDao.findAll(request, predicate);
    assertEquals(5, entities.size());

    // assert sorting DESC
    lastInfo = null;
    for (StageEntity entity : entities) {
      if (null == lastInfo) {
        lastInfo = entity.getLogInfo();
        continue;
      }

      String currentInfo = entity.getLogInfo();
      assertTrue(lastInfo.compareTo(currentInfo) >= 0);
      lastInfo = currentInfo;
    }
  }
Tests that JPA does the sorting work for us.
ambari-server/src/test/java/org/apache/ambari/server/orm/dao/StageDAOTest.java