@Override public void add(RegionConfig configElement, CacheConfig existingConfig) { existingConfig.getRegions().add(configElement); }
@Override public boolean updateConfigForGroup(String group, CacheConfig config, Object configObject) { config.getAsyncEventQueues().add((CacheConfig.AsyncEventQueue) configObject); return true; } }
@Override public boolean updateConfigForGroup(String group, CacheConfig config, Object element) { config.getJndiBindings().add((JndiBindingsType.JndiBinding) element); return true; }
@Override public boolean updateConfigForGroup(String group, CacheConfig config, Object element) { if (config.getGatewayReceiver() != null) { config.setGatewayReceiver(null); return true; } return false; } }
@Test public void updateClusterConfigWithSynchronousAndOneMatchingRegionDoesNotCreateAsyncEventQueue() { arguments[1] = true; 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); assertThat(queueList).isEmpty(); }
@Test public void elementAlreadyExist() throws Exception { regionConfig.setName("test"); CacheConfig cacheConfig = new CacheConfig(); cacheConfig.getRegions().add(regionConfig); when(persistenceService.getCacheConfig("cluster", true)).thenReturn(cacheConfig); assertThatThrownBy(() -> service.create(regionConfig, "cluster")) .isInstanceOf(EntityExistsException.class) .hasMessageContaining("cache element test already exists"); }
assertThat(cacheConfig.getInitializer()).isEqualTo(declarableWithString); assertThat(cacheConfig.getFunctionService().getFunctions().get(0)) .isEqualTo(declarableWithString); assertThat(cacheConfig.getPdx().getPdxSerializer()).isEqualTo(declarableWithString); assertThat(cacheConfig.getCacheServers().get(0).getCustomLoadProbe()) .isEqualTo(declarableWithString); assertThat(cacheConfig.getGatewayConflictResolver()).isEqualTo(declarableWithString); assertThat(cacheConfig.getGatewayReceiver().getGatewayTransportFilters().get(0)) .isEqualTo(declarableWithString); assertThat(cacheConfig.getGatewayHubs().get(0).getGateway().get(0).getGatewayListeners().get(0)) .isEqualTo(declarableWithString); CacheConfig.AsyncEventQueue asyncEventQueue = cacheConfig.getAsyncEventQueues().get(0); assertThat(asyncEventQueue.getAsyncEventListener()).isEqualTo(declarableWithString); assertThat(asyncEventQueue.getGatewayEventFilters().get(0)).isEqualTo(declarableWithString); assertThat(asyncEventQueue.getGatewayEventSubstitutionFilter()).isEqualTo(declarableWithString); RegionAttributesType regionAttributes = cacheConfig.getRegionAttributes().get(0); assertThat(regionAttributes.getCacheListeners().get(0)).isEqualTo(declarableWithString); assertThat(regionAttributes.getCompressor().toString()).isEqualTo("my.className");
@Before public void setUp() { command = spy(DescribeDataSourceCommand.class); binding = new JndiBindingsType.JndiBinding(); binding.setJndiName(DATA_SOURCE_NAME); binding.setType(DATASOURCE_TYPE.POOLED.getType()); bindings = new ArrayList<>(); clusterConfigService = mock(InternalConfigurationPersistenceService.class); cacheConfig = mock(CacheConfig.class); when(cacheConfig.getJndiBindings()).thenReturn(bindings); bindings.add(binding); regionConfigs = new ArrayList<>(); when(cacheConfig.getRegions()).thenReturn(regionConfigs); doReturn(clusterConfigService).when(command).getConfigurationPersistenceService(); doReturn(cacheConfig).when(clusterConfigService).getCacheConfig(any()); }
public static void setBasicValues(CacheConfig cache) { cache.setCopyOnRead(true); CacheConfig.GatewayReceiver receiver = new CacheConfig.GatewayReceiver(); receiver.setBindAddress("localhost"); receiver.setEndPort("8080"); receiver.setManualStart(false); receiver.setStartPort("6000"); cache.setGatewayReceiver(receiver); cache.setVersion("1.0"); RegionConfig region = new RegionConfig(); region.setName("testRegion"); region.setType("REPLICATE"); cache.getRegions().add(region); }
@Override public boolean updateConfigForGroup(String group, CacheConfig config, Object element) { RegionConfig.Index indexFromCommand = (RegionConfig.Index) element; String indexName = indexFromCommand.getName(); String regionName = indexFromCommand.getFromClause(); if (regionName != null) { RegionConfig regionConfig = config.findRegionConfiguration(regionName); if (regionConfig == null) { String errorMessage = "Region " + regionName + " not found"; if (!ConfigurationPersistenceService.CLUSTER_CONFIG.equals(group)) { errorMessage += " in group " + group; } throw new EntityNotFoundException(errorMessage); } if (indexName.isEmpty()) { regionConfig.getIndexes().clear(); } else { CacheElement.removeElement(regionConfig.getIndexes(), indexName); } } else { // Need to search for the index name as region was not specified for (RegionConfig r : config.getRegions()) { CacheElement.removeElement(r.getIndexes(), indexName); } } return true; }
@Test public void testCacheOneMarshall() throws Exception { CacheConfig cache = new CacheConfig(); setBasicValues(cache); cache.getCustomCacheElements().add(new ElementOne("test")); xml = service.marshall(cache); System.out.println(xml); // cache has the default namespace assertThat(xml).contains("xmlns=\"http://geode.apache.org/schema/cache\""); assertThat(xml).contains("custom-one>"); }
String getValidRegionName(String regionPath, CacheConfig cacheConfig) { // Check to see if the region path contains an alias e.g "/region1 r1" // Then the first string will be the regionPath String[] regionPathTokens = regionPath.trim().split(" "); regionPath = regionPathTokens[0]; // check to see if the region path is in the form of "--region=region.entrySet() z" while (regionPath.contains(".") && cacheConfig.findRegionConfiguration(regionPath) == null) { regionPath = regionPath.substring(0, regionPath.lastIndexOf(".")); } return regionPath; }
@Before public void before() throws Exception { command = spy(AlterAsyncEventQueueCommand.class); service = spy(InternalConfigurationPersistenceService.class); configRegion = mock(AbstractRegion.class); doReturn(service).when(command).getConfigurationPersistenceService(); groupSet.add("group1"); groupSet.add("group2"); doReturn(groupSet).when(service).getGroups(); CacheConfig config = new CacheConfig(); CacheConfig.AsyncEventQueue aeq1 = new CacheConfig.AsyncEventQueue(); aeq1.setId("queue1"); config.getAsyncEventQueues().add(aeq1); doReturn(config).when(service).getCacheConfig("group1"); doReturn(new CacheConfig()).when(service).getCacheConfig("group2"); doReturn(config).when(service).getCacheConfig("group1", true); doReturn(new CacheConfig()).when(service).getCacheConfig("group2", true); doReturn(true).when(service).lockSharedConfiguration(); doNothing().when(service).unlockSharedConfiguration(); doReturn(null).when(service).getConfiguration(any()); doReturn(configRegion).when(service).getConfigurationRegion(); doCallRealMethod().when(service).updateCacheConfig(any(), any()); }
@Override public CacheConfig getCacheConfig(String group, boolean createNew) { if (group == null) { group = CLUSTER_CONFIG; } Configuration configuration = getConfiguration(group); if (configuration == null) { if (createNew) { return new CacheConfig(CACHE_CONFIG_VERSION); } return null; } String xmlContent = configuration.getCacheXmlContent(); // group existed, so we should create a blank one to start with if (xmlContent == null || xmlContent.isEmpty()) { if (createNew) { return new CacheConfig(CACHE_CONFIG_VERSION); } return null; } return jaxbService.unMarshall(xmlContent); }
public <T extends CacheElement> List<T> findCustomCacheElements(Class<T> classT) { List<T> newList = new ArrayList<>(); // streaming won't work here, because it's trying to cast element into CacheElement for (Object element : getCustomCacheElements()) { if (classT.isInstance(element)) { newList.add(classT.cast(element)); } } return newList; }
@Test // in case a locator in the cluster doesn't have the plugin installed public void xmlWithCustomElementsCanBeUnMarshalledByAnotherService() { service.updateCacheConfig("cluster", config -> { config.getCustomCacheElements().add(new ElementOne("one")); config.getCustomCacheElements().add(new ElementTwo("two")); return config; }); String prettyXml = configuration.getCacheXmlContent(); System.out.println(prettyXml); // the xml is sent to another locator with no such plugin installed, it can be parsed // but the element couldn't be recognized by the locator without the plugin service2.updateCacheConfig("cluster", cc -> cc); CacheConfig config = service2.getCacheConfig("cluster"); assertThat(config.findCustomCacheElement("one", ElementOne.class)).isNull(); String uglyXml = configuration.getCacheXmlContent(); System.out.println(uglyXml); assertThat(uglyXml).isNotEqualTo(prettyXml); // the xml can be unmarshalled correctly by the first locator CacheConfig cacheConfig = service.getCacheConfig("cluster"); service.updateCacheConfig("cluster", cc -> cc); assertThat(cacheConfig.getCustomCacheElements()).hasSize(2); assertThat(cacheConfig.getCustomCacheElements().get(0)).isInstanceOf(ElementOne.class); assertThat(cacheConfig.getCustomCacheElements().get(1)).isInstanceOf(ElementTwo.class); assertThat(configuration.getCacheXmlContent()).isEqualTo(prettyXml); }
@Override public boolean updateConfigForGroup(String group, CacheConfig config, Object configObject) { config.setGatewayReceiver((CacheConfig.GatewayReceiver) configObject); return true; }
@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 correctJsonAndXml() throws Exception { String json = "{\"name\":\"test\", \"type\":\"REPLICATE\"}"; ObjectMapper mapper = new ObjectMapper(); regionConfig = mapper.readValue(json, RegionConfig.class); assertThat(regionConfig.getName()).isEqualTo("test"); assertThat(regionConfig.getType()).isEqualTo("REPLICATE"); String json2 = mapper.writeValueAsString(regionConfig); assertThat(json2).contains("\"type\":\"REPLICATE\""); assertThat(json2).contains("\"id\":\"test\""); CacheConfig cacheConfig = new CacheConfig(); cacheConfig.getRegions().add(regionConfig); String xml = service.marshall(cacheConfig); assertThat(xml).contains("<region name=\"test\" refid=\"REPLICATE\""); } }
@Before public void setUp() { command = spy(ListDataSourceCommand.class); binding = new JndiBindingsType.JndiBinding(); binding.setJndiName(DATA_SOURCE_NAME); binding.setType(DATASOURCE_TYPE.POOLED.getType()); binding.setConnectionUrl("myURL"); bindings = new ArrayList<>(); clusterConfigService = mock(InternalConfigurationPersistenceService.class); cacheConfig = mock(CacheConfig.class); when(cacheConfig.getJndiBindings()).thenReturn(bindings); bindings.add(binding); regionConfigs = new ArrayList<>(); when(cacheConfig.getRegions()).thenReturn(regionConfigs); doReturn(clusterConfigService).when(command).getConfigurationPersistenceService(); doReturn(cacheConfig).when(clusterConfigService).getCacheConfig(any()); }