@Test
  public void testTreeMapWithComparator() throws Exception {
    Random random = getRandom();
    int size = random.nextInt(50);
    TreeMap<Long, String> map = new TreeMap<>(new MyComparator(size));
    for (int i = 0; i < size; i++) {
      Long key = random.nextLong();
      String value = String.valueOf(random.nextLong());
      map.put(key, value);
    }

    DataOutputStream out = getDataOutput();
    DataSerializer.writeTreeMap(new TreeMap<>(new MyComparator(0)), out);
    DataSerializer.writeTreeMap(map, out);
    out.flush();

    DataInput in = getDataInput();
    TreeMap<Long, String> emptyMap = DataSerializer.readTreeMap(in);
    assertEquals(new TreeMap<>(new MyComparator(0)), emptyMap);
    assertEquals(new MyComparator(0), emptyMap.comparator());
    TreeMap<Long, String> map2 = DataSerializer.readTreeMap(in);
    assertEquals(map, map2);
    assertEquals(map.comparator(), map2.comparator());
  }
Tests data serializing an {@link TreeMap}
geode-core/src/test/java/org/apache/geode/internal/DataSerializableJUnitTest.java