@Before public void setUp() throws Exception { service = spy(new InternalConfigurationPersistenceService(CacheConfig.class, ElementOne.class, ElementTwo.class)); service2 = spy(new InternalConfigurationPersistenceService(CacheConfig.class)); configuration = new Configuration("cluster"); doReturn(configuration).when(service).getConfiguration(any()); doReturn(configuration).when(service2).getConfiguration(any()); doReturn(mock(Region.class)).when(service).getConfigurationRegion(); doReturn(mock(Region.class)).when(service2).getConfigurationRegion(); doReturn(true).when(service).lockSharedConfiguration(); doReturn(true).when(service2).lockSharedConfiguration(); doNothing().when(service).unlockSharedConfiguration(); doNothing().when(service2).unlockSharedConfiguration(); }
@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); }
@Override public void updateCacheConfig(String group, UnaryOperator<CacheConfig> mutator) { if (group == null) { group = CLUSTER_CONFIG; } lockSharedConfiguration(); try { CacheConfig cacheConfig = getCacheConfig(group, true); cacheConfig = mutator.apply(cacheConfig); if (cacheConfig == null) { // mutator returns a null config, indicating no change needs to be persisted return; } Configuration configuration = getConfiguration(group); if (configuration == null) { configuration = new Configuration(group); } configuration.setCacheXmlContent(jaxbService.marshall(cacheConfig)); getConfigurationRegion().put(group, configuration); } finally { unlockSharedConfiguration(); } } }
@Test public void invalidXml() throws IOException { String xmlContent = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><cache><region></cache>"; FileUtils.write(xmlFile, xmlContent, Charset.defaultCharset()); when(ccService.getConfiguration(any())).thenReturn(configuration); gfsh.executeAndAssertThat(command, commandWithFile).statusIsError() .containsOutput("Error while processing command "); }
@Before public void setUp() throws Exception { cache = mock(InternalCache.class); command = spy(DestroyJndiBindingCommand.class); doReturn(cache).when(command).getCache(); cacheConfig = mock(CacheConfig.class); ccService = mock(InternalConfigurationPersistenceService.class); doReturn(Collections.emptySet()).when(command).findMembers(any(), any()); doReturn(ccService).when(command).getConfigurationPersistenceService(); when(ccService.getCacheConfig(any())).thenReturn(cacheConfig); doAnswer(invocation -> { UnaryOperator<CacheConfig> mutator = invocation.getArgument(1); mutator.apply(cacheConfig); return null; }).when(ccService).updateCacheConfig(any(), any()); when(ccService.getConfigurationRegion()).thenReturn(mock(Region.class)); when(ccService.getConfiguration(any())).thenReturn(mock(Configuration.class)); }
@Test public void noMemberFound() throws IOException { String xmlContent = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><cache/>"; FileUtils.write(xmlFile, xmlContent, Charset.defaultCharset()); when(ccService.getConfiguration(any())).thenReturn(configuration); gfsh.executeAndAssertThat(command, commandWithFile).statusIsSuccess() .containsOutput("Successfully set the 'cluster' configuration to the content of"); assertThat(configuration.getCacheXmlContent()).isEqualTo(xmlContent); }
@Before public void setUp() { cache = mock(InternalCache.class); command = spy(DestroyDataSourceCommand.class); doReturn(cache).when(command).getCache(); cacheConfig = mock(CacheConfig.class); ccService = mock(InternalConfigurationPersistenceService.class); doReturn(Collections.emptySet()).when(command).findMembers(any(), any()); doReturn(ccService).when(command).getConfigurationPersistenceService(); when(ccService.getCacheConfig(any())).thenReturn(cacheConfig); doAnswer(invocation -> { UnaryOperator<CacheConfig> mutator = invocation.getArgument(1); mutator.apply(cacheConfig); return null; }).when(ccService).updateCacheConfig(any(), any()); when(ccService.getConfigurationRegion()).thenReturn(mock(Region.class)); when(ccService.getConfiguration(any())).thenReturn(mock(Configuration.class)); }
@Test public void getExistingGroupConfigShouldReturnNullIfNoXml() { Configuration groupConfig = new Configuration("some-new-group"); doReturn(groupConfig).when(service).getConfiguration("some-new-group"); CacheConfig groupCacheConfig = service.getCacheConfig("some-new-group"); assertThat(groupCacheConfig).isNull(); }
Configuration config = sc.getConfiguration(configGroup.name); assertThat(config.getJarNames()).isEqualTo(configGroup.getJars());
@Test public void existingMembersWithIgnore() { doReturn(Collections.singleton(mock(DistributedMember.class))).when(command).findMembers(any()); when(ccService.getConfiguration(any())).thenReturn(configuration); gfsh.executeAndAssertThat(command, commandWithFile + "--action=STAGE").statusIsSuccess() .containsOutput("Successfully set the 'cluster' configuration to the content of") .containsOutput("Existing servers are not affected with this configuration change"); } }
@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()); }
/** * Creates a ConfigurationResponse based on the configRequest, configuration response contains the * requested shared configuration This method locks the ConfigurationPersistenceService */ public ConfigurationResponse createConfigurationResponse(Set<String> groups) { ConfigurationResponse configResponse = null; boolean isLocked = lockSharedConfiguration(); try { if (isLocked) { configResponse = new ConfigurationResponse(); groups.add(ConfigurationPersistenceService.CLUSTER_CONFIG); logger.info("Building up configuration response with following configurations: {}", groups); for (String group : groups) { Configuration configuration = getConfiguration(group); configResponse.addConfiguration(configuration); if (configuration != null) { configResponse.addJar(group, configuration.getJarNames()); } } return configResponse; } } finally { unlockSharedConfiguration(); } return configResponse; }
@Test public void groupNotExist() { when(ccService.getConfiguration("groupA")).thenReturn(null); gfsh.executeAndAssertThat(command, EXPORT_SHARED_CONFIG + " --group=groupA").statusIsError() .containsOutput("No cluster configuration for 'groupA'."); }
} else { Configuration configuration = ccService.getConfiguration(group); if (configuration == null) { configuration = new Configuration(group);
@Test public void get() { when(ccService.getConfiguration(any())).thenReturn(configuration); configuration.setCacheXmlContent(CLUSTER_XML); Properties properties = new Properties(); properties.put("key1", "value1"); properties.put("key2", "value2"); configuration.setGemfireProperties(properties); configuration.addJarNames(new String[] {"jar1.jar", "jar2.jar"}); gfsh.executeAndAssertThat(command, EXPORT_SHARED_CONFIG).statusIsSuccess() .containsOutput("cluster.xml:").containsOutput("Properties:").containsOutput("Jars:") .containsOutput("jar1.jar, jar2.jar").containsOutput("<?xml version=\\\"1.0\\\"") .containsOutput("</cache>"); } }
Configuration configuration = configPersistenceService.getConfiguration(group); if (configuration == null) { return ResultModel.createError("No cluster configuration for '" + group + "'.");