@Override public void visit(Integer bucketId, Region r) { AttributesMutator mut = r.getAttributesMutator(); if (logger.isDebugEnabled()) { logger.debug("setting new cache loader in bucket region: {}", newLoader); } mut.setCacheLoader(newLoader); } });
@Override public void run2() throws CacheException { Region<Object, Object> region = createRegion(name); region.getAttributesMutator().setCacheLoader(new TestCacheLoader<Object, Object>() { @Override public Object load2(LoaderHelper<Object, Object> helper) throws CacheLoaderException { return value; } }); } });
@Override public void run2() throws CacheException { Region<Object, Object> region = createRegion(name); setLoader(new TestCacheLoader<Object, Object>() { @Override public Object load2(LoaderHelper<Object, Object> helper) throws CacheLoaderException { if (helper.getRegion().getAttributes().getPartitionAttributes() == null) { fail("Should not be invoked"); return null; } else { return value; } } }); region.getAttributesMutator().setCacheLoader(loader()); } };
@Test public void executeFunctionGivenARegionWithJdbcLoaderRemovesTheLoader() { when(regionAttributes.getCacheLoader()).thenReturn(mock(JdbcLoader.class)); when(service.getMappingForRegion(eq(regionName))).thenReturn(mapping); function.executeFunction(context); verify(regionMutator, times(1)).setCacheLoader(null); }
@Test public void executeFunctionGivenARegionWithNonJdbcLoaderDoesNotRemoveTheLoader() { when(regionAttributes.getCacheLoader()).thenReturn(mock(CacheLoader.class)); when(service.getMappingForRegion(eq(regionName))).thenReturn(mapping); function.executeFunction(context); verify(regionMutator, never()).setCacheLoader(null); }
@Test public void executeAlterRegionLoader() throws Exception { function.executeFunction(context); verify(service, times(1)).createRegionMapping(regionMapping); AttributesMutator mutator = region.getAttributesMutator(); verify(mutator, times(1)).setCacheLoader(any()); }
@Test public void updateWithNoCacheWriter() { regionAttributes.setCacheWriter(DeclarableType.EMPTY); function.alterRegion(cache, config); verify(mutator).setCacheWriter(null); verify(mutator, times(0)).setCacheLoader(any()); } }
@Test public void updateWithCacheWriter() { DeclarableType newCacheWriterDeclarable = mock(DeclarableType.class); when(newCacheWriterDeclarable.getClassName()).thenReturn(MyCacheWriter.class.getName()); regionAttributes.setCacheWriter(newCacheWriterDeclarable); function.alterRegion(cache, config); verify(mutator).setCacheWriter(notNull()); verify(mutator, times(0)).setCacheLoader(any()); }
@Override public void run2() throws CacheException { final Region<Object, Object> region = getRootRegion().getSubregion(name); if (region.getAttributes().getPartitionAttributes() != null) { setLoader(new TestCacheLoader<Object, Object>() { @Override public Object load2(LoaderHelper<Object, Object> helper) throws CacheLoaderException { Object[] array = (Object[]) helper.getArgument(); assertThat(array[0]).isEqualTo(one); array[0] = two; return value; } }); region.getAttributesMutator().setCacheLoader(loader()); } } });
/** * Change the existing region to have * the JdbcLoader as its cache-loader * and the given async-event-queue as one of its queues. */ private void alterRegion(Region<?, ?> region, String queueName, boolean synchronous) { region.getAttributesMutator().setCacheLoader(new JdbcLoader()); if (synchronous) { region.getAttributesMutator().setCacheWriter(new JdbcWriter()); } else { region.getAttributesMutator().addAsyncEventQueueId(queueName); } }
if (cacheLoader != null) { if (cacheLoader.equals(DeclarableType.EMPTY)) { mutator.setCacheLoader(null); } else { mutator.setCacheLoader(DeclarableTypeInstantiator.newInstance(cacheLoader, cache));
private void cleanupRegionAndQueue(Cache cache, String regionName) { String queueName = CreateMappingCommand.createAsyncEventQueueName(regionName); Region<?, ?> region = cache.getRegion(regionName); if (region != null) { CacheLoader<?, ?> loader = region.getAttributes().getCacheLoader(); if (loader instanceof JdbcLoader) { region.getAttributesMutator().setCacheLoader(null); } CacheWriter<?, ?> writer = region.getAttributes().getCacheWriter(); if (writer instanceof JdbcWriter) { region.getAttributesMutator().setCacheWriter(null); } Set<String> queueIds = region.getAttributes().getAsyncEventQueueIds(); if (queueIds.contains(queueName)) { region.getAttributesMutator().removeAsyncEventQueueId(queueName); } } InternalAsyncEventQueue queue = (InternalAsyncEventQueue) cache.getAsyncEventQueue(queueName); if (queue != null) { queue.stop(); queue.destroy(); } } }
mutator.setCacheLoader(attrs.getCacheLoader());
/** * Post-process the {@link Region} created by this {@link ClientRegionFactoryBean}. * * @param region {@link Region} to process. * @see org.apache.geode.cache.Region */ @Override protected Region<K, V> postProcess(Region<K, V> region) { super.postProcess(region); Optional.ofNullable(this.cacheLoader) .ifPresent(cacheLoader -> region.getAttributesMutator().setCacheLoader(cacheLoader)); Optional.ofNullable(this.cacheWriter) .ifPresent(cacheWriter -> region.getAttributesMutator().setCacheWriter(cacheWriter)); return region; }
/** * Post-process the {@link Region} created by this {@link ClientRegionFactoryBean}. * * @param region {@link Region} to process. * @see org.apache.geode.cache.Region */ @Override protected Region<K, V> postProcess(Region<K, V> region) { super.postProcess(region); Optional.ofNullable(this.cacheLoader) .ifPresent(cacheLoader -> region.getAttributesMutator().setCacheLoader(cacheLoader)); Optional.ofNullable(this.cacheWriter) .ifPresent(cacheWriter -> region.getAttributesMutator().setCacheWriter(cacheWriter)); return region; }
.when(mockAttributesMutator).setCacheLoader(any(CacheLoader.class));