@Test
  public void testModifyColocation() {
    // Create PRs where region3 is colocated with region1.
    createCacheAndColocatedPRs("region1");

    // Close everything
    cache.close();

    // Restart colocated with "region2"
    Throwable thrown = catchThrowable(() -> createCacheAndColocatedPRs("region2"));
    assertThat(thrown)
        .isInstanceOf(IllegalStateException.class)
        .hasMessageContaining("For partition region " + SEPARATOR + "region3")
        .hasMessageContaining("cannot change colocated-with to \"" + SEPARATOR + "region2\"")
        .hasMessageContaining("because there is persistent data with different colocation.")
        .hasMessageContaining("Previous configured value is \"" + SEPARATOR + "region1\"");

    // await cache close is complete
    awaitCacheClose();

    // Restart colocated with region1. Make sure we didn't screw anything up.
    createCacheAndColocatedPRs("region1");

    // Close everything
    cache.close();

    // await cache close is complete
    awaitCacheClose();

    // Restart uncolocated. We don't allow changing from colocated to uncolocated.
    thrown = catchThrowable(() -> createCacheAndColocatedPRs(null));

    assertThat(thrown)
        .isInstanceOf(IllegalStateException.class)
        .hasMessageContaining("For partition region " + SEPARATOR + "region3")
        .hasMessageContaining("cannot change colocated-with to \"\"")
        .hasMessageContaining("because there is persistent data with different colocation.")
        .hasMessageContaining("Previous configured value is \"" + SEPARATOR + "region1\"");

    awaitCacheClose();
  }
Test that a user is not allowed to change the colocation of a PR with persistent data.
geode-core/src/integrationTest/java/org/apache/geode/internal/cache/partitioned/colocation/ModifyColocationIntegrationTest.java