@SuppressWarnings({"unchecked", "deprecation", "rawtypes"}) void createRegion(String name, boolean accessor, int redundantCopies, CacheWriter<?, ?> cw) { AttributesFactory af = new AttributesFactory(); af.setPartitionAttributes( new PartitionAttributesFactory() .setLocalMaxMemory(accessor ? 0 : 12) .setRedundantCopies(redundantCopies) .create()); af.setCacheWriter(cw); getCache().createRegion(name, af.create()); }
/** * Tests that a local writer receives a modified version of the callback argument on an update. */ public void testLocalUpdateModifiedCallbackArgument() throws CacheException { final String name = this.getUniqueName(); final Object key = "KEY"; final Object value = "VALUE"; final Object one = "ONE"; final Object two = "TWO"; TestCacheLoader loader = new TestCacheLoader() { public Object load2(LoaderHelper helper) throws CacheLoaderException { Object[] array = (Object[]) helper.getArgument(); assertEquals(one, array[0]); array[0] = two; return value; } }; TestCacheWriter writer = new TestCacheWriter() { public void beforeCreate2(EntryEvent event) throws CacheWriterException {} public void beforeUpdate2(EntryEvent event) throws CacheWriterException { Object[] array = (Object[]) event.getCallbackArgument(); assertEquals(two, array[0]); } }; AttributesFactory factory = new AttributesFactory(getRegionAttributes()); factory.setCacheLoader(loader); factory.setCacheWriter(writer); Region region = createRegion(name, factory.create()); region.create(key, null); assertFalse(loader.wasInvoked()); assertTrue(writer.wasInvoked()); Object[] array = new Object[] {one}; assertEquals(value, region.get(key, array)); assertTrue(loader.wasInvoked()); assertTrue(writer.wasInvoked()); }