protected List<Span> sortTrace(List<Span> trace) {
    if (!returnsRawSpans()) trace = Trace.merge(trace);
    List<Span> result = new ArrayList<>(trace);
    // Sort so that tests aren't flakey. Spans are not required to be in any order by contract.
    // However, when writing tests, we shouldn't use data that can appear in random order.
    result.sort((l, r) -> {
      int traceId = l.traceId().compareTo(r.traceId());
      if (traceId != 0) return traceId;
      int id = l.id().compareTo(r.id());
      if (id != 0) return id;
      int shared = Boolean.compare(TRUE.equals(l.shared()), TRUE.equals(r.shared()));
      if (shared != 0) return shared;

      if (l.name() != null && r.name() != null) {
        int name = l.name().compareTo(r.name());
        if (name != 0) return name;
      }

      int timestamp = Long.compare(l.timestampAsLong(), r.timestampAsLong());
      if (timestamp != 0) return timestamp;

      int duration = Long.compare(l.durationAsLong(), r.durationAsLong());
      if (duration != 0) return duration;

      throw new AssertionError("Don't use test data that results in indeterministic ordering:\n" +
        "l=" + l + ", r=" + r);
    });
    return result;
  }
Used to help tests from colliding too much
zipkin-tests/src/main/java/zipkin2/storage/ITStorage.java