void installCacheListenerAndWriter() {
    AttributesMutator<String, String> mutator = region.getAttributesMutator();
    mutator.addCacheListener(new CacheListenerAdapter<String, String>() {
      @Override
      public void close() {
        cbCount++;
      }

      @Override
      public void afterCreate(EntryEvent<String, String> event) {
        cbCount++;
      }

      @Override
      public void afterUpdate(EntryEvent<String, String> event) {
        cbCount++;
      }

      @Override
      public void afterInvalidate(EntryEvent<String, String> event) {
        cbCount++;
      }

      @Override
      public void afterDestroy(EntryEvent<String, String> event) {
        cbCount++;
      }

      @Override
      public void afterRegionInvalidate(RegionEvent<String, String> event) {
        cbCount++;
      }

      @Override
      public void afterRegionDestroy(RegionEvent<String, String> event) {
        cbCount++;
      }
    });
    mutator.setCacheWriter(new CacheWriter<String, String>() {
      @Override
      public void close() {
        cbCount++;
      }

      @Override
      public void beforeUpdate(EntryEvent<String, String> event) throws CacheWriterException {
        cbCount++;
      }

      @Override
      public void beforeCreate(EntryEvent<String, String> event) throws CacheWriterException {
        cbCount++;
      }

      @Override
      public void beforeDestroy(EntryEvent<String, String> event) throws CacheWriterException {
        cbCount++;
      }

      @Override
      public void beforeRegionDestroy(RegionEvent<String, String> event)
          throws CacheWriterException {
        cbCount++;
      }

      @Override
      public void beforeRegionClear(RegionEvent<String, String> event) throws CacheWriterException {
        cbCount++;
      }
    });
  }
Extracted from TXWriterJUnitTest to share with TXWriterOOMEJUnitTest.
geode-junit/src/main/java/org/apache/geode/TXWriterTestCase.java