private boolean removeJdbcLoader(RegionAttributesType attributes) { DeclarableType cacheLoader = attributes.getCacheLoader(); if (cacheLoader != null) { if (JdbcLoader.class.getName().equals(cacheLoader.getClassName())) { attributes.setCacheLoader(null); return true; } } return false; }
private void setCacheLoader(RegionAttributesType attributes) { DeclarableType loader = new DeclarableType(); loader.setClassName(JdbcLoader.class.getName()); attributes.setCacheLoader(loader); }
@Test public void updateClusterConfigWithOneMatchingRegionCallsSetCacheLoader() { List<RegionConfig> list = new ArrayList<>(); List<CacheElement> listCacheElements = new ArrayList<>(); when(matchingRegion.getCustomRegionElements()).thenReturn(listCacheElements); list.add(matchingRegion); when(cacheConfig.getRegions()).thenReturn(list); List<CacheConfig.AsyncEventQueue> queueList = new ArrayList<>(); when(cacheConfig.getAsyncEventQueues()).thenReturn(queueList); createRegionMappingCommand.updateConfigForGroup(null, cacheConfig, arguments); verify(matchingRegionAttributes).setCacheLoader(any()); }
@Test public void alterWithNoCacheLoader() { RegionConfig deltaConfig = getDeltaRegionConfig("alter region --name=regionA --cache-loader=''"); RegionAttributesType deltaAttributes = deltaConfig.getRegionAttributes(); assertThat(deltaAttributes.getCacheLoader()).isEqualTo(DeclarableType.EMPTY); RegionAttributesType existingAttributes = new RegionAttributesType(); existingAttributes.setCacheLoader(new DeclarableType("def")); existingRegionConfig.setRegionAttributes(existingAttributes); command.updateConfigForGroup("cluster", cacheConfig, deltaConfig); // after the update the cache loader is null assertThat(existingAttributes.getCacheLoader()).isNull(); }
@Test public void alterWithCacheLoader() { RegionConfig deltaConfig = getDeltaRegionConfig("alter region --name=regionA --cache-loader=abc"); RegionAttributesType deltaAttributes = deltaConfig.getRegionAttributes(); assertThat(deltaAttributes.getCacheWriter()).isNull(); assertThat(deltaAttributes.getCacheLoader().getClassName()).isEqualTo("abc"); assertThat(deltaAttributes.getCacheListeners()).isNotNull().isEmpty(); RegionAttributesType existingAttributes = new RegionAttributesType(); existingAttributes.getCacheListeners().add(new DeclarableType("def")); existingAttributes.setCacheLoader(new DeclarableType("def")); existingAttributes.setCacheWriter(new DeclarableType("def")); existingRegionConfig.setRegionAttributes(existingAttributes); command.updateConfigForGroup("cluster", cacheConfig, deltaConfig); // after update, the cache listeners remains the same assertThat(existingAttributes.getCacheListeners()).hasSize(1); assertThat(existingAttributes.getCacheListeners().get(0).getClassName()).isEqualTo("def"); // after update the cache writer remains the same assertThat(existingAttributes.getCacheWriter().getClassName()).isEqualTo("def"); // after update the cache loader is changed assertThat(existingAttributes.getCacheLoader().getClassName()).isEqualTo("abc"); }
@Test public void regionConfig() { cacheConfig = new CacheConfig("1.0"); RegionConfig regionConfig = new RegionConfig(); regionConfig.setName("test"); regionConfig.setType("REPLICATE"); RegionAttributesType attributes = new RegionAttributesType(); attributes.setCacheLoader(new DeclarableType("abc.Foo")); regionConfig.setRegionAttributes(attributes); cacheConfig.getRegions().add(regionConfig); // make sure the xml marshed by this config can be validated with xsd String xml = service.marshall(cacheConfig); CacheConfig newCache = service.unMarshall(xml); assertThat(cacheConfig).isEqualToComparingFieldByFieldRecursively(newCache); }
getExpirationAttributes(regionExpirationTTL, regionExpirationTTLAction, null)); if (cacheLoader != null) { regionAttributesType.setCacheLoader( new DeclarableType(cacheLoader.getClassName(), cacheLoader.getInitProperties()));
existingAttributes.setCacheLoader(null); } else { existingAttributes.setCacheLoader(deltaAttributes.getCacheLoader());