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

    DataOutputStream out = getDataOutput();
    DataSerializer.writeHashSet(set, out);
    out.flush();

    DataInput in = getDataInput();
    HashSet<Long> set2 = DataSerializer.readHashSet(in);
    assertEquals(set, set2);
  }
Tests data serializing an {@link HashSet}
geode-core/src/test/java/org/apache/geode/internal/DataSerializableJUnitTest.java