private void setupRequiredPreconditions() { ConfigurationPersistenceService configurationPersistenceService = mock(ConfigurationPersistenceService.class); doReturn(configurationPersistenceService).when(createRegionMappingCommand) .getConfigurationPersistenceService(); when(configurationPersistenceService.getCacheConfig(null)).thenReturn(cacheConfig); List<RegionConfig> list = new ArrayList<>(); list.add(matchingRegion); when(cacheConfig.getRegions()).thenReturn(list); }
@Test public void noMemberFound() throws Exception { regionConfig.setName("test"); when(persistenceService.getCacheConfig("cluster", true)).thenReturn(new CacheConfig()); doReturn(Collections.emptySet()).when(service).findMembers(any(), any()); result = service.create(regionConfig, "cluster"); assertThat(result.isSuccessful()).isFalse(); assertThat(result.isSuccessfullyAppliedOnMembers()).isFalse(); assertThat(result.getPersistenceStatus().getMessage()) .contains("no members found to create cache element"); }
@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"); }
@Test public void createsMappingReturnsStatusERRORWhenClusterConfigDoesNotContainRegion() { results.add(successFunctionResult); ConfigurationPersistenceService configurationPersistenceService = mock(ConfigurationPersistenceService.class); doReturn(configurationPersistenceService).when(createRegionMappingCommand) .getConfigurationPersistenceService(); when(configurationPersistenceService.getCacheConfig(null)).thenReturn(cacheConfig); when(cacheConfig.getRegions()).thenReturn(Collections.emptyList()); ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName, tableName, pdxClass, false, null, null, null); assertThat(result.getStatus()).isSameAs(Result.Status.ERROR); assertThat(result.toString()) .contains("A region named " + regionName + " must already exist."); }
@Test public void partialFailureOnMembers() throws Exception { List<CliFunctionResult> functionResults = new ArrayList<>(); functionResults.add(new CliFunctionResult("member1", true, "success")); functionResults.add(new CliFunctionResult("member2", false, "failed")); doReturn(functionResults).when(service).executeAndGetFunctionResult(any(), any(), any()); doReturn(Collections.singleton(mock(DistributedMember.class))).when(service).findMembers(any(), any()); when(persistenceService.getCacheConfig("cluster", true)).thenReturn(new CacheConfig()); regionConfig.setName("test"); result = service.create(regionConfig, "cluster"); assertThat(result.isSuccessful()).isFalse(); assertThat(result.isSuccessfullyAppliedOnMembers()).isFalse(); assertThat(result.isSuccessfullyPersisted()).isFalse(); assertThat(result.getPersistenceStatus().getMessage()) .contains("Failed to apply the update on all members"); } }
@Test public void createMappingWithSynchronousReturnsStatusOKWhenAsycnEventQueueAlreadyExists() { results.add(successFunctionResult); ConfigurationPersistenceService configurationPersistenceService = mock(ConfigurationPersistenceService.class); doReturn(configurationPersistenceService).when(createRegionMappingCommand) .getConfigurationPersistenceService(); when(configurationPersistenceService.getCacheConfig(null)).thenReturn(cacheConfig); List<RegionConfig> list = new ArrayList<>(); list.add(matchingRegion); when(cacheConfig.getRegions()).thenReturn(list); RegionAttributesType loaderAttribute = mock(RegionAttributesType.class); when(loaderAttribute.getCacheLoader()).thenReturn(null); when(matchingRegion.getRegionAttributes()).thenReturn(loaderAttribute); List<AsyncEventQueue> asyncEventQueues = new ArrayList<>(); AsyncEventQueue matchingQueue = mock(AsyncEventQueue.class); String queueName = createRegionMappingCommand.createAsyncEventQueueName(regionName); when(matchingQueue.getId()).thenReturn(queueName); asyncEventQueues.add(matchingQueue); when(cacheConfig.getAsyncEventQueues()).thenReturn(asyncEventQueues); ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName, tableName, pdxClass, true, null, null, null); assertThat(result.getStatus()).isSameAs(Result.Status.OK); }
@Test public void createMappingWithSynchronousReturnsStatusERRORWhenClusterConfigRegionHasWriter() { results.add(successFunctionResult); ConfigurationPersistenceService configurationPersistenceService = mock(ConfigurationPersistenceService.class); doReturn(configurationPersistenceService).when(createRegionMappingCommand) .getConfigurationPersistenceService(); when(configurationPersistenceService.getCacheConfig(null)).thenReturn(cacheConfig); List<RegionConfig> list = new ArrayList<>(); list.add(matchingRegion); when(cacheConfig.getRegions()).thenReturn(list); RegionAttributesType writerAttribute = mock(RegionAttributesType.class); DeclarableType writerDeclarable = mock(DeclarableType.class); when(writerDeclarable.getClassName()).thenReturn("MyCacheWriterClass"); when(writerAttribute.getCacheWriter()).thenReturn(writerDeclarable); when(matchingRegion.getRegionAttributes()).thenReturn(writerAttribute); ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName, tableName, pdxClass, true, null, null, null); assertThat(result.getStatus()).isSameAs(Result.Status.ERROR); assertThat(result.toString()).contains("The existing region " + regionName + " must not already have a cache-writer, but it has MyCacheWriterClass"); }
@Test public void createsMappingReturnsStatusERRORWhenRegionMappingExists() { results.add(successFunctionResult); ConfigurationPersistenceService configurationPersistenceService = mock(ConfigurationPersistenceService.class); doReturn(configurationPersistenceService).when(createRegionMappingCommand) .getConfigurationPersistenceService(); when(configurationPersistenceService.getCacheConfig(null)).thenReturn(cacheConfig); List<RegionConfig> list = new ArrayList<>(); list.add(matchingRegion); when(cacheConfig.getRegions()).thenReturn(list); RegionAttributesType loaderAttribute = mock(RegionAttributesType.class); DeclarableType loaderDeclarable = mock(DeclarableType.class); when(loaderDeclarable.getClassName()).thenReturn(null); when(loaderAttribute.getCacheLoader()).thenReturn(loaderDeclarable); when(matchingRegion.getRegionAttributes()).thenReturn(loaderAttribute); List<CacheElement> customList = new ArrayList<>(); RegionMapping existingMapping = mock(RegionMapping.class); customList.add(existingMapping); when(matchingRegion.getCustomRegionElements()).thenReturn(customList); ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName, tableName, pdxClass, false, null, null, null); assertThat(result.getStatus()).isSameAs(Result.Status.ERROR); assertThat(result.toString()).contains("A JDBC mapping for " + regionName + " already exists."); }
@Test public void createsMappingReturnsStatusERRORWhenClusterConfigRegionHasLoader() { results.add(successFunctionResult); ConfigurationPersistenceService configurationPersistenceService = mock(ConfigurationPersistenceService.class); doReturn(configurationPersistenceService).when(createRegionMappingCommand) .getConfigurationPersistenceService(); when(configurationPersistenceService.getCacheConfig(null)).thenReturn(cacheConfig); List<RegionConfig> list = new ArrayList<>(); list.add(matchingRegion); when(cacheConfig.getRegions()).thenReturn(list); RegionAttributesType loaderAttribute = mock(RegionAttributesType.class); DeclarableType loaderDeclarable = mock(DeclarableType.class); when(loaderDeclarable.getClassName()).thenReturn("MyCacheLoaderClass"); when(loaderAttribute.getCacheLoader()).thenReturn(loaderDeclarable); when(matchingRegion.getRegionAttributes()).thenReturn(loaderAttribute); ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName, tableName, pdxClass, false, null, null, null); assertThat(result.getStatus()).isSameAs(Result.Status.ERROR); assertThat(result.toString()).contains("The existing region " + regionName + " must not already have a cache-loader, but it has MyCacheLoaderClass"); }
@Test public void createsMappingReturnsStatusERRORWhenAsycnEventQueueAlreadyExists() { results.add(successFunctionResult); ConfigurationPersistenceService configurationPersistenceService = mock(ConfigurationPersistenceService.class); doReturn(configurationPersistenceService).when(createRegionMappingCommand) .getConfigurationPersistenceService(); when(configurationPersistenceService.getCacheConfig(null)).thenReturn(cacheConfig); List<RegionConfig> list = new ArrayList<>(); list.add(matchingRegion); when(cacheConfig.getRegions()).thenReturn(list); RegionAttributesType loaderAttribute = mock(RegionAttributesType.class); when(loaderAttribute.getCacheLoader()).thenReturn(null); when(matchingRegion.getRegionAttributes()).thenReturn(loaderAttribute); List<AsyncEventQueue> asyncEventQueues = new ArrayList<>(); AsyncEventQueue matchingQueue = mock(AsyncEventQueue.class); String queueName = createRegionMappingCommand.createAsyncEventQueueName(regionName); when(matchingQueue.getId()).thenReturn(queueName); asyncEventQueues.add(matchingQueue); when(cacheConfig.getAsyncEventQueues()).thenReturn(asyncEventQueues); ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName, tableName, pdxClass, false, null, null, null); assertThat(result.getStatus()).isSameAs(Result.Status.ERROR); assertThat(result.toString()) .contains("An async-event-queue named " + queueName + " must not already exist."); }
@CliCommand(value = LIST_DATA_SOURCE, help = LIST_DATA_SOURCE__HELP) @CliMetaData @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, operation = ResourcePermission.Operation.READ) public ResultModel listDataSources() { ResultModel resultModel = new ResultModel(); resultModel.setHeader(EXPERIMENTAL); TabularResultModel tabularData = resultModel.addTable(DATA_SOURCE_PROPERTIES_SECTION); tabularData.setColumnHeader("name", "pooled", "in use", "url"); ConfigurationPersistenceService ccService = getConfigurationPersistenceService(); if (ccService == null) { return ResultModel.createError("Cluster configuration service must be enabled."); } CacheConfig cacheConfig = ccService.getCacheConfig(null); if (cacheConfig == null) { return ResultModel.createInfo("No data sources found"); } cacheConfig.getJndiBindings().stream() .forEach(dataSource -> addDataSourceToResult(dataSource, cacheConfig, tabularData)); return resultModel; }
CacheConfig currentPersistedConfig = persistenceService.getCacheConfig(group, true); if (configurationMutator.exists(config, currentPersistedConfig)) { throw new EntityExistsException("cache element " + config.getId() + " already exists.");
CacheConfig cacheConfig = ccService.getCacheConfig("cluster"); if (cacheConfig == null) { return ResultModel.createError(String.format("JNDI binding : %s not found", bindingName));
ConfigurationPersistenceService configurationPersistenceService = checkForClusterConfiguration(); CacheConfig cacheConfig = configurationPersistenceService.getCacheConfig(null); RegionConfig regionConfig = checkForRegion(regionName, cacheConfig); checkForExistingMapping(regionName, regionConfig);
CacheConfig clusterConfig = ccService.getCacheConfig(group); RegionConfig regionConfig = null; if (clusterConfig != null) {