@Test
  public void testLocalAndRemoteCacheWriters() {
    assertThat(getRegionAttributes().getScope().isDistributed()).isTrue();

    final String name = getUniqueName();
    final Object key = "KEY";
    final Object oldValue = "OLD_VALUE";
    final Object newValue = "NEW_VALUE";

    vm0.invoke("Create \"Local\" Region", () -> {
      Region<Object, Object> region = createRegion(name);
      setWriter(new TestCacheWriter<Object, Object>() {
        @Override
        public void beforeUpdate2(EntryEvent<Object, Object> event) throws CacheWriterException {}

        @Override
        public void beforeCreate2(EntryEvent<Object, Object> event) throws CacheWriterException {}

        @Override
        public void beforeDestroy2(EntryEvent<Object, Object> event)
            throws CacheWriterException {}

        @Override
        public void beforeRegionDestroy2(RegionEvent<Object, Object> event)
            throws CacheWriterException {}
      });
      region.getAttributesMutator().setCacheWriter(writer());
    });

    vm1.invoke("Create \"Local\" Region", () -> {
      Region<Object, Object> region1 = createRegion(name);
      setWriter(new TestCacheWriter<Object, Object>() {});
      region1.getAttributesMutator().setCacheWriter(writer());
    });

    vm0.invoke("Create entry", () -> {
      Region<Object, Object> region = getRootRegion().getSubregion(name);
      region.put(key, oldValue);
      assertThat(writer().wasInvoked()).isTrue();
    });
    vm1.invoke("Verify no callback", () -> {
      assertThat(writer().wasInvoked()).isFalse();
    });

    vm0.invoke("Update entry", () -> {
      Region<Object, Object> region = getRootRegion().getSubregion(name);
      region.put(key, newValue);
      assertThat(writer().wasInvoked()).isTrue();
    });
    vm1.invoke("Verify no callback", () -> {
      assertThat(writer().wasInvoked()).isFalse();
    });

    vm0.invoke("Destroy entry", () -> {
      Region<Object, Object> region = getRootRegion().getSubregion(name);
      region.destroy(key);
      assertThat(writer().wasInvoked()).isTrue();
    });
    vm1.invoke("Verify no callback", () -> {
      assertThat(writer().wasInvoked()).isFalse();
    });

    vm0.invoke("Destroy region", () -> {
      Region<Object, Object> region = getRootRegion().getSubregion(name);
      region.destroyRegion();
      assertThat(writer().wasInvoked()).isTrue();
    });
    vm1.invoke("Verify no callback", () -> {
      assertThat(writer().wasInvoked()).isFalse();
    });
  }
Tests that, when given a choice, a local <code>CacheWriter</code> is invoked instead of a
remote one.
geode-dunit/src/main/java/org/apache/geode/cache30/MultiVMRegionTestCase.java