@Override public boolean updateConfigForGroup(String group, CacheConfig config, Object configObject) { config.getAsyncEventQueues().add((CacheConfig.AsyncEventQueue) configObject); return true; } }
private boolean removeJdbcQueueFromCache(CacheConfig cacheConfig, String regionName) { String queueName = CreateMappingCommand.createAsyncEventQueueName(regionName); Iterator<AsyncEventQueue> iterator = cacheConfig.getAsyncEventQueues().iterator(); while (iterator.hasNext()) { AsyncEventQueue queue = iterator.next(); if (queueName.equals(queue.getId())) { iterator.remove(); return true; } } return false; }
private void checkForAsyncQueue(String regionName, boolean synchronous, CacheConfig cacheConfig) throws PreconditionException { if (!synchronous) { String queueName = createAsyncEventQueueName(regionName); AsyncEventQueue asyncEventQueue = cacheConfig.getAsyncEventQueues().stream() .filter(queue -> queue.getId().equals(queueName)).findFirst().orElse(null); if (asyncEventQueue != null) { throw new PreconditionException( "An async-event-queue named " + queueName + " must not already exist."); } } }
@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 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 updateClusterConfigWithOneMatchingPartitionedRegionCreatesParallelAsyncEventQueue() { 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); when(matchingRegionAttributes.getDataPolicy()) .thenReturn(RegionAttributesDataPolicy.PARTITION); createRegionMappingCommand.updateConfigForGroup(null, cacheConfig, arguments); assertThat(queueList.get(0).isParallel()).isTrue(); }
CacheConfig.AsyncEventQueue findAEQ(String aeqId) { CacheConfig.AsyncEventQueue queue = null; InternalConfigurationPersistenceService ccService = (InternalConfigurationPersistenceService) this.getConfigurationPersistenceService(); if (ccService == null) { return null; } Set<String> groups = ccService.getGroups(); for (String group : groups) { queue = CacheElement.findElement(ccService.getCacheConfig(group).getAsyncEventQueues(), aeqId); if (queue != null) { return queue; } } return queue; }
@Test public void updateClusterConfigWithSynchronousAndOneMatchingRegionAndExistingQueuesDoesNotAddsAsyncEventQueueIdToRegion() { 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); when(matchingRegionAttributes.getAsyncEventQueueIds()).thenReturn("q1,q2"); createRegionMappingCommand.updateConfigForGroup(null, cacheConfig, arguments); verify(matchingRegionAttributes, never()).setAsyncEventQueueIds(any()); }
@Test public void updateClusterConfigWithOneMatchingRegionAndJdbcAsyncQueueRemovesTheQueue() { List<RegionConfig> list = new ArrayList<>(); List<CacheElement> listCacheElements = new ArrayList<>(); RegionMapping matchingMapping = mock(RegionMapping.class); listCacheElements.add(matchingMapping); when(matchingRegion.getCustomRegionElements()).thenReturn(listCacheElements); list.add(matchingRegion); when(cacheConfig.getRegions()).thenReturn(list); AsyncEventQueue queue = mock(AsyncEventQueue.class); String queueName = CreateMappingCommand.createAsyncEventQueueName(regionName); when(queue.getId()).thenReturn(queueName); List<AsyncEventQueue> queueList = new ArrayList<>(); queueList.add(queue); when(cacheConfig.getAsyncEventQueues()).thenReturn(queueList); boolean modified = destroyRegionMappingCommand.updateConfigForGroup(null, cacheConfig, regionName); assertThat(queueList).isEmpty(); assertThat(modified).isTrue(); }
@Test public void updateClusterConfigWithOneMatchingRegionAndNullQueuesAddsAsyncEventQueueIdToRegion() { 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); when(matchingRegionAttributes.getAsyncEventQueueIds()).thenReturn(null); createRegionMappingCommand.updateConfigForGroup(null, cacheConfig, arguments); ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class); verify(matchingRegionAttributes).setAsyncEventQueueIds(argument.capture()); String queueName = CreateMappingCommand.createAsyncEventQueueName(regionName); assertThat(argument.getValue()).isEqualTo(queueName); }
@Test public void updateClusterConfigWithOneMatchingRegionAndEmptyQueuesAddsAsyncEventQueueIdToRegion() { 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); when(matchingRegionAttributes.getAsyncEventQueueIds()).thenReturn(""); createRegionMappingCommand.updateConfigForGroup(null, cacheConfig, arguments); ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class); verify(matchingRegionAttributes).setAsyncEventQueueIds(argument.capture()); String queueName = CreateMappingCommand.createAsyncEventQueueName(regionName); assertThat(argument.getValue()).isEqualTo(queueName); }
@Test public void updateClusterConfigWithOneMatchingRegionAndExistingQueuesAddsAsyncEventQueueIdToRegion() { 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); when(matchingRegionAttributes.getAsyncEventQueueIds()).thenReturn("q1,q2"); createRegionMappingCommand.updateConfigForGroup(null, cacheConfig, arguments); ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class); verify(matchingRegionAttributes).setAsyncEventQueueIds(argument.capture()); String queueName = CreateMappingCommand.createAsyncEventQueueName(regionName); assertThat(argument.getValue()).isEqualTo("q1,q2," + queueName); }
@Test public void updateClusterConfigWithOneMatchingRegionAndQueuesContainingDuplicateDoesNotModifyAsyncEventQueueIdOnRegion() { 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); String queueName = CreateMappingCommand.createAsyncEventQueueName(regionName); String existingQueues = "q1," + queueName + ",q2"; when(matchingRegionAttributes.getAsyncEventQueueIds()).thenReturn(existingQueues); createRegionMappingCommand.updateConfigForGroup(null, cacheConfig, arguments); verify(matchingRegionAttributes, never()).setAsyncEventQueueIds(any()); }
@Test public void updateClusterConfigWithOneMatchingRegionCreatesAsyncEventQueue() { 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.size()).isEqualTo(1); String queueName = CreateMappingCommand.createAsyncEventQueueName(regionName); AsyncEventQueue createdQueue = queueList.get(0); assertThat(createdQueue.getId()).isEqualTo(queueName); assertThat(createdQueue.isParallel()).isFalse(); assertThat(createdQueue.getAsyncEventListener().getClassName()) .isEqualTo(JdbcAsyncWriter.class.getName()); }
private void createAsyncQueue(CacheConfig cacheConfig, RegionAttributesType attributes, String queueName) { AsyncEventQueue asyncEventQueue = new AsyncEventQueue(); asyncEventQueue.setId(queueName); boolean isPartitioned = attributes.getDataPolicy().equals(RegionAttributesDataPolicy.PARTITION) || attributes.getDataPolicy().equals(RegionAttributesDataPolicy.PERSISTENT_PARTITION); asyncEventQueue.setParallel(isPartitioned); DeclarableType listener = new DeclarableType(); listener.setClassName(JdbcAsyncWriter.class.getName()); asyncEventQueue.setAsyncEventListener(listener); cacheConfig.getAsyncEventQueues().add(asyncEventQueue); }
@Override public boolean updateConfigForGroup(String group, CacheConfig config, Object configObject) { boolean aeqConfigsHaveBeenUpdated = false; List<CacheConfig.AsyncEventQueue> queues = config.getAsyncEventQueues(); if (queues.isEmpty()) { return false; } CacheConfig.AsyncEventQueue aeqConfiguration = ((CacheConfig.AsyncEventQueue) configObject); String aeqId = aeqConfiguration.getId(); for (CacheConfig.AsyncEventQueue queue : queues) { if (aeqId.equals(queue.getId())) { if (StringUtils.isNotBlank(aeqConfiguration.getBatchSize())) { queue.setBatchSize(aeqConfiguration.getBatchSize()); } if (StringUtils.isNotBlank(aeqConfiguration.getBatchTimeInterval())) { queue.setBatchTimeInterval(aeqConfiguration.getBatchTimeInterval()); } if (StringUtils.isNotBlank(aeqConfiguration.getMaximumQueueMemory())) { queue.setMaximumQueueMemory(aeqConfiguration.getMaximumQueueMemory()); } aeqConfigsHaveBeenUpdated = true; } } return aeqConfigsHaveBeenUpdated; }
@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); }
@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()); }
@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."); }
.isEqualTo(declarableWithString); CacheConfig.AsyncEventQueue asyncEventQueue = cacheConfig.getAsyncEventQueues().get(0); assertThat(asyncEventQueue.getAsyncEventListener()).isEqualTo(declarableWithString); assertThat(asyncEventQueue.getGatewayEventFilters().get(0)).isEqualTo(declarableWithString);