private void keysSetTester(Region pr) {
    assertEquals(Collections.EMPTY_SET, pr.keySet());
    pr.put(1, "won");
    pr.put(2, "to");
    pr.put(3, "free");
    pr.put(5, "hive");
    final Set ks = pr.keySet();
    assertEquals(4, ks.size());

    try {
      ks.clear();
      fail("Expected key set to be read only");
    } catch (Exception ignored) {
    }
    try {
      ks.add("foo");
      fail("Expected key set to be read only");
    } catch (Exception ignored) {
    }
    try {
      ks.addAll(Arrays.asList("one", "two", "three"));
      fail("Expected key set to be read only");
    } catch (Exception ignored) {
    }
    try {
      ks.remove("boom");
      fail("Expected key set to be read only");
    } catch (Exception ignored) {
    }
    try {
      ks.removeAll(Arrays.asList(1, 2));
      fail("Expected key set to be read only");
    } catch (Exception ignored) {
    }
    try {
      ks.retainAll(Arrays.asList(3, 5));
      fail("Expected key set to be read only");
    } catch (Exception ignored) {
    }

    final Iterator ksI = ks.iterator();
    for (int i = 0; i < 4; i++) {
      try {
        ksI.remove();
        fail("Expected key set iterator to be read only");
      } catch (Exception ignored) {
      }
      assertTrue(ksI.hasNext());
      Object key = ksI.next();
      assertEquals(Integer.class, key.getClass());
    }
    try {
      ksI.remove();
      fail("Expected key set iterator to be read only");
    } catch (Exception ignored) {
    }
    try {
      ksI.next();
      fail("Expected no such element exception");
    } catch (NoSuchElementException ignored) {
    }
  }
Test either the keySet() or keys() methods, which logically are expected to be the same
geode-core/src/integrationTest/java/org/apache/geode/internal/cache/PartitionedRegionSingleNodeOperationsJUnitTest.java