@Test
  public void testCacheWriterBeforeCreate() throws CacheException {
    String name = getUniqueName();
    final Object key = getUniqueName();
    final Object value = 42;
    final Object arg = "ARG";
    final String exception = "EXCEPTION";

    TestCacheWriter writer = new TestCacheWriter() {
      @Override
      public void beforeCreate2(EntryEvent event) throws CacheWriterException {

        assertEquals(key, event.getKey());
        assertEquals(value, event.getNewValue());
        assertNull(event.getOldValue());
        assertTrue(event.getOperation().isCreate());
        assertFalse(event.getOperation().isLoad());
        assertFalse(event.getOperation().isLocalLoad());
        assertFalse(event.getOperation().isNetLoad());
        assertFalse(event.getOperation().isNetSearch());

        Object argument = event.getCallbackArgument();
        if (argument != null) {
          if (argument.equals(exception)) {
            String s = "Test CacheWriterException";
            throw new CacheWriterException(s);

          } else {
            assertEquals(arg, argument);
          }
        }
      }

      @Override
      public void beforeDestroy2(EntryEvent event) throws CacheWriterException {
        // This method will get invoked when the region is populated
      }
    };

    AttributesFactory factory = new AttributesFactory(getRegionAttributes());
    factory.setCacheWriter(writer);
    Region region = createRegion(name, factory.create());

    region.create(key, value);
    assertTrue(writer.wasInvoked());
    region.destroy(key);
    assertTrue(writer.wasInvoked());

    region.put(key, value);
    assertTrue(writer.wasInvoked());
    region.destroy(key);
    assertTrue(writer.wasInvoked());

    region.create(key, value, arg);
    assertTrue(writer.wasInvoked());
    region.destroy(key);
    assertTrue(writer.wasInvoked());

    region.put(key, value, arg);
    assertTrue(writer.wasInvoked());
    region.destroy(key);
    assertTrue(writer.wasInvoked());

    try {
      region.create(key, value, exception);
      fail("Should have thrown a CacheWriterException");

    } catch (CacheWriterException ex) {
      // pass...
      assertTrue(writer.wasInvoked());
    }

    try {
      region.put(key, value, exception);
      fail("Should have thrown a CacheWriterException");

    } catch (CacheWriterException ex) {
      // pass...
      assertTrue(writer.wasInvoked());
    }

  }
Tests that the <code>CacheWriter</code> is called before an entry is
{@linkplain CacheWriter#beforeCreate created}.
geode-core/src/distributedTest/java/org/apache/geode/cache30/CacheWriterTestCase.java