@Test
  public void testTreeSetWithComparator() throws Exception {
    Random random = getRandom();
    int size = random.nextInt(50);
    TreeSet<Long> set = new TreeSet<>(new MyComparator(size));
    for (int i = 0; i < size; i++) {
      set.add(random.nextLong());
    }

    DataOutputStream out = getDataOutput();
    DataSerializer.writeTreeSet(new TreeSet<>(new MyComparator(0)), out);
    DataSerializer.writeTreeSet(set, out);
    out.flush();

    DataInput in = getDataInput();
    TreeSet<Long> emptySet = DataSerializer.readTreeSet(in);
    assertEquals(new TreeSet<>(new MyComparator(0)), emptySet);
    assertEquals(new MyComparator(0), emptySet.comparator());
    TreeSet<Long> set2 = DataSerializer.readTreeSet(in);
    assertEquals(set, set2);
    assertEquals(set.comparator(), set2.comparator());
  }
Tests data serializing an {@link TreeSet}
geode-core/src/test/java/org/apache/geode/internal/DataSerializableJUnitTest.java