From 0820482818dde2cf6e5404268be5bc4136d95691 Mon Sep 17 00:00:00 2001 From: John Blum Date: Wed, 23 Mar 2016 16:52:47 -0700 Subject: [PATCH] SGF-416 - Remove deprecated code associated with syncing GemFire properties between the ClientCache and Pool. (cherry picked from commit a0c5ecad62917ccb71e856dae8e3743641f7d76e) Signed-off-by: John Blum --- .../data/gemfire/config/CacheParser.java | 2 +- ...ertiesSyncingBeanFactoryPostProcessor.java | 82 --------- ...rRegisteringBeanFactoryPostProcessor.java} | 16 +- .../ContinuousQueryListenerContainer.java | 10 +- ...esSyncingBeanFactoryPostProcessorTest.java | 159 ------------------ ...isteringBeanFactoryPostProcessorTest.java} | 14 +- .../ContinuousQueryListenerContainerTest.java | 84 ++++++++- .../data/gemfire/listener/container.xml | 5 +- 8 files changed, 111 insertions(+), 261 deletions(-) delete mode 100644 src/main/java/org/springframework/data/gemfire/config/ClientCachePoolGemfirePropertiesSyncingBeanFactoryPostProcessor.java rename src/main/java/org/springframework/data/gemfire/config/{CustomEditorRegistrationBeanFactoryPostProcessor.java => CustomEditorRegisteringBeanFactoryPostProcessor.java} (82%) delete mode 100644 src/test/java/org/springframework/data/gemfire/config/ClientCachePoolGemfirePropertiesSyncingBeanFactoryPostProcessorTest.java rename src/test/java/org/springframework/data/gemfire/config/{CustomEditorRegistrationBeanFactoryPostProcessorTest.java => CustomEditorRegisteringBeanFactoryPostProcessorTest.java} (89%) diff --git a/src/main/java/org/springframework/data/gemfire/config/CacheParser.java b/src/main/java/org/springframework/data/gemfire/config/CacheParser.java index b44b122c..d21abb95 100644 --- a/src/main/java/org/springframework/data/gemfire/config/CacheParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/CacheParser.java @@ -119,7 +119,7 @@ class CacheParser extends AbstractSingleBeanDefinitionParser { /* (non-Javadoc) */ void registerGemFireBeanFactoryPostProcessors(BeanDefinitionRegistry registry) { BeanDefinitionReaderUtils.registerWithGeneratedName(BeanDefinitionBuilder.genericBeanDefinition( - CustomEditorRegistrationBeanFactoryPostProcessor.class).getBeanDefinition(), registry); + CustomEditorRegisteringBeanFactoryPostProcessor.class).getBeanDefinition(), registry); } private void parsePdxDiskStore(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { diff --git a/src/main/java/org/springframework/data/gemfire/config/ClientCachePoolGemfirePropertiesSyncingBeanFactoryPostProcessor.java b/src/main/java/org/springframework/data/gemfire/config/ClientCachePoolGemfirePropertiesSyncingBeanFactoryPostProcessor.java deleted file mode 100644 index b89e36c0..00000000 --- a/src/main/java/org/springframework/data/gemfire/config/ClientCachePoolGemfirePropertiesSyncingBeanFactoryPostProcessor.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2012 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.springframework.data.gemfire.config; - -import org.springframework.beans.BeansException; -import org.springframework.beans.PropertyValue; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.config.BeanFactoryPostProcessor; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.beans.factory.config.RuntimeBeanReference; -import org.springframework.data.gemfire.client.ClientCacheFactoryBean; -import org.springframework.data.gemfire.client.PoolFactoryBean; -import org.springframework.util.StringUtils; - -/** - * The ClientCachePoolGemfirePropertiesSyncingBeanFactoryPostProcessor class is a Spring {@link BeanFactoryPostProcessor} - * implementation responsible for making sure the GemFire {@link java.util.Properties} between the GemFire ClientCache - * and GemFire Pool are identical. - * - * @author John Blum - * @see org.springframework.beans.factory.config.BeanDefinition - * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor - * @see org.springframework.beans.factory.config.ConfigurableListableBeanFactory - * @see org.springframework.data.gemfire.client.ClientCacheFactoryBean - * @see org.springframework.data.gemfire.client.PoolFactoryBean - * @since 1.8.0 - */ -@Deprecated -class ClientCachePoolGemfirePropertiesSyncingBeanFactoryPostProcessor implements BeanFactoryPostProcessor { - - protected static final String PROPERTIES_PROPERTY_NAME = "properties"; - - /** - * Post processes the given {@link ConfigurableListableBeanFactory} by syncing the gemfire.properties used - * to configure the GemFire Distributed System constructed by the {@link PoolFactoryBean} during Pool creation - * and resolved by the {@link ClientCacheFactoryBean} during ClientCache creation. - * - * @param beanFactory the {@link ConfigurableListableBeanFactory} to post process. - * @throws BeansException if errors occur during post processing. - * @see org.springframework.beans.factory.config.ConfigurableListableBeanFactory - */ - public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { - BeanDefinition poolFactoryBeanDefinition = null; - String gemfirePropertiesBeanName = null; - - for (String beanName : beanFactory.getBeanDefinitionNames()) { - BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName); - - if (ClientCacheFactoryBean.class.getName().equals(beanDefinition.getBeanClassName())) { - PropertyValue gemfirePropertiesPropertyValue = beanDefinition.getPropertyValues() - .getPropertyValue(PROPERTIES_PROPERTY_NAME); - - gemfirePropertiesBeanName = (gemfirePropertiesPropertyValue != null - ? ((RuntimeBeanReference) gemfirePropertiesPropertyValue.getValue()).getBeanName() : null); - } - else if (PoolFactoryBean.class.getName().equals(beanDefinition.getBeanClassName())) { - poolFactoryBeanDefinition = beanDefinition; - } - } - - if (poolFactoryBeanDefinition != null && StringUtils.hasText(gemfirePropertiesBeanName)) { - poolFactoryBeanDefinition.getPropertyValues().add(PROPERTIES_PROPERTY_NAME, - new RuntimeBeanReference(gemfirePropertiesBeanName)); - } - } - -} diff --git a/src/main/java/org/springframework/data/gemfire/config/CustomEditorRegistrationBeanFactoryPostProcessor.java b/src/main/java/org/springframework/data/gemfire/config/CustomEditorRegisteringBeanFactoryPostProcessor.java similarity index 82% rename from src/main/java/org/springframework/data/gemfire/config/CustomEditorRegistrationBeanFactoryPostProcessor.java rename to src/main/java/org/springframework/data/gemfire/config/CustomEditorRegisteringBeanFactoryPostProcessor.java index c2046140..553abaa4 100644 --- a/src/main/java/org/springframework/data/gemfire/config/CustomEditorRegistrationBeanFactoryPostProcessor.java +++ b/src/main/java/org/springframework/data/gemfire/config/CustomEditorRegisteringBeanFactoryPostProcessor.java @@ -47,20 +47,23 @@ import com.gemstone.gemfire.cache.Scope; import com.gemstone.gemfire.cache.wan.GatewaySender; /** - * The CustomEditorRegistrationBeanFactoryPostProcessor class is a Spring BeanFactoryPostProcessor used to register - * custom GemFire JavaBeans PropertyEditors and Spring Converters that are used to perform type conversions between - * String-based configuration meta-data and actual GemFire or SDG defined enumerated types. + * The CustomEditorRegisteringBeanFactoryPostProcessor class is a Spring {@link BeanFactoryPostProcessor} used + * to register custom GemFire-specific JavaBeans {@link java.beans.PropertyEditor}s and Spring {@link Converter}s + * that are used to perform type conversions between String-based configuration meta-data and actual GemFire + * or Spring Data GemFire defined enumerated types. * * @author John Blum * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor + * @see org.springframework.beans.factory.config.ConfigurableListableBeanFactory * @since 1.6.0 */ @SuppressWarnings({ "deprecation", "unused" }) -public class CustomEditorRegistrationBeanFactoryPostProcessor implements BeanFactoryPostProcessor { +class CustomEditorRegisteringBeanFactoryPostProcessor implements BeanFactoryPostProcessor { + /* (non-Javadoc) */ @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { - beanFactory.registerCustomEditor(ConnectionEndpoint[].class, ConnectionEndpointArrayToIterableConverter.class); + //beanFactory.registerCustomEditor(ConnectionEndpoint[].class, ConnectionEndpointArrayToIterableConverter.class); beanFactory.registerCustomEditor(EvictionAction.class, EvictionActionConverter.class); beanFactory.registerCustomEditor(EvictionPolicyType.class, EvictionPolicyConverter.class); beanFactory.registerCustomEditor(ExpirationAction.class, ExpirationActionConverter.class); @@ -73,7 +76,8 @@ public class CustomEditorRegistrationBeanFactoryPostProcessor implements BeanFac beanFactory.registerCustomEditor(SubscriptionEvictionPolicy.class, SubscriptionEvictionPolicyConverter.class); } - static final class ConnectionEndpointArrayToIterableConverter extends PropertyEditorSupport + /* (non-Javadoc) */ + public static class ConnectionEndpointArrayToIterableConverter extends PropertyEditorSupport implements Converter { @Override diff --git a/src/main/java/org/springframework/data/gemfire/listener/ContinuousQueryListenerContainer.java b/src/main/java/org/springframework/data/gemfire/listener/ContinuousQueryListenerContainer.java index 1619c832..6ccb5bc5 100644 --- a/src/main/java/org/springframework/data/gemfire/listener/ContinuousQueryListenerContainer.java +++ b/src/main/java/org/springframework/data/gemfire/listener/ContinuousQueryListenerContainer.java @@ -35,6 +35,8 @@ import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.core.task.TaskExecutor; import org.springframework.data.gemfire.GemfireQueryException; import org.springframework.data.gemfire.GemfireUtils; +import org.springframework.data.gemfire.client.support.DefaultableDelegatingPoolAdapter; +import org.springframework.data.gemfire.client.support.DelegatingPoolAdapter; import org.springframework.data.gemfire.config.GemfireConstants; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -108,6 +110,9 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN initQueryService(eagerlyInitializePool(resolvePoolName())); initExecutor(); initContinuousQueries(continuousQueryDefinitions); + + Assert.state(queryService != null, "QueryService was not properly initialized"); + initialized = true; if (isAutoStartup()) { @@ -145,8 +150,9 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN /* (non-Javadoc) */ QueryService initQueryService(String poolName) { - if (queryService == null) { - queryService = PoolManager.find(poolName).getQueryService(); + if (queryService == null || StringUtils.hasText(poolName)) { + queryService = DefaultableDelegatingPoolAdapter.from(DelegatingPoolAdapter.from( + PoolManager.find(poolName))).preferPool().getQueryService(queryService); } return queryService; diff --git a/src/test/java/org/springframework/data/gemfire/config/ClientCachePoolGemfirePropertiesSyncingBeanFactoryPostProcessorTest.java b/src/test/java/org/springframework/data/gemfire/config/ClientCachePoolGemfirePropertiesSyncingBeanFactoryPostProcessorTest.java deleted file mode 100644 index 5bc53096..00000000 --- a/src/test/java/org/springframework/data/gemfire/config/ClientCachePoolGemfirePropertiesSyncingBeanFactoryPostProcessorTest.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright 2012 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.springframework.data.gemfire.config; - -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.beans.factory.config.RuntimeBeanReference; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.data.gemfire.client.ClientCacheFactoryBean; -import org.springframework.data.gemfire.client.PoolFactoryBean; - -/** - * The ClientCachePoolGemfirePropertiesSyncingBeanFactoryPostProcessorTest class is a test suite of test cases testing - * the contract and functionality of the ClientCachePoolGemfirePropertiesSyncingBeanFactoryPostProcessor class. - * - * @author John Blum - * @see org.junit.Test - * @see org.junit.runner.RunWith - * @see org.mockito.Mock - * @see org.mockito.Mockito - * @see org.mockito.runners.MockitoJUnitRunner - * @see org.springframework.data.gemfire.config.ClientCachePoolGemfirePropertiesSyncingBeanFactoryPostProcessor - * @since 1.0.0 - */ -@RunWith(MockitoJUnitRunner.class) -@SuppressWarnings("deprecation") -public class ClientCachePoolGemfirePropertiesSyncingBeanFactoryPostProcessorTest { - - protected static final String PROPERTIES_PROPERTY_NAME_SHORTCUT = - ClientCachePoolGemfirePropertiesSyncingBeanFactoryPostProcessor.PROPERTIES_PROPERTY_NAME; - - private ClientCachePoolGemfirePropertiesSyncingBeanFactoryPostProcessor beanFactoryPostProcessor = - new ClientCachePoolGemfirePropertiesSyncingBeanFactoryPostProcessor(); - - @Mock - private ConfigurableListableBeanFactory mockBeanFactory; - - protected String getBeanReference(Object reference) { - return (reference instanceof RuntimeBeanReference ? ((RuntimeBeanReference) reference).getBeanName() : null); - } - - protected BeanDefinition newBeanDefinition(Class type) { - return BeanDefinitionBuilder.genericBeanDefinition(type).getBeanDefinition(); - } - - protected T[] toArray(T... array) { - return array; - } - - @Test - public void postProcessSyncsGemfireProperties() { - BeanDefinition objectBean = newBeanDefinition(Object.class); - BeanDefinition clientCacheBean = newBeanDefinition(ClientCacheFactoryBean.class); - - clientCacheBean.getPropertyValues().addPropertyValue(PROPERTIES_PROPERTY_NAME_SHORTCUT, - new RuntimeBeanReference("gemfireProperties")); - - BeanDefinition poolBean = newBeanDefinition(PoolFactoryBean.class); - - when(mockBeanFactory.getBeanDefinitionNames()).thenReturn(toArray("objectBean", "clientCacheBean", "poolBean")); - when(mockBeanFactory.getBeanDefinition(eq("objectBean"))).thenReturn(objectBean); - when(mockBeanFactory.getBeanDefinition(eq("clientCacheBean"))).thenReturn(clientCacheBean); - when(mockBeanFactory.getBeanDefinition(eq("poolBean"))).thenReturn(poolBean); - - assertThat(poolBean.getPropertyValues().getPropertyValue(PROPERTIES_PROPERTY_NAME_SHORTCUT), is(nullValue())); - - beanFactoryPostProcessor.postProcessBeanFactory(mockBeanFactory); - - assertThat(getBeanReference(poolBean.getPropertyValues().getPropertyValue(PROPERTIES_PROPERTY_NAME_SHORTCUT).getValue()), - is(equalTo("gemfireProperties"))); - - verify(mockBeanFactory, times(1)).getBeanDefinitionNames(); - verify(mockBeanFactory, times(1)).getBeanDefinition(eq("objectBean")); - verify(mockBeanFactory, times(1)).getBeanDefinition(eq("clientCacheBean")); - verify(mockBeanFactory, times(1)).getBeanDefinition(eq("poolBean")); - } - - @Test - public void postProcessDoesNotSyncGemfirePropertiesWhenNoClientCacheFactoryBeanIsDeclared() { - BeanDefinition poolBean = newBeanDefinition(PoolFactoryBean.class); - - when(mockBeanFactory.getBeanDefinitionNames()).thenReturn(toArray("poolBean")); - when(mockBeanFactory.getBeanDefinition(eq("poolBean"))).thenReturn(poolBean); - - assertThat(poolBean.getPropertyValues().getPropertyValue(PROPERTIES_PROPERTY_NAME_SHORTCUT), is(nullValue())); - - beanFactoryPostProcessor.postProcessBeanFactory(mockBeanFactory); - - assertThat(poolBean.getPropertyValues().getPropertyValue(PROPERTIES_PROPERTY_NAME_SHORTCUT), is(nullValue())); - - verify(mockBeanFactory, times(1)).getBeanDefinitionNames(); - verify(mockBeanFactory, times(1)).getBeanDefinition(eq("poolBean")); - } - - @Test - public void postProcessDoesNotSyncGemfirePropertiesWhenNoPoolFactoryBeanIsDeclared() { - BeanDefinition clientCacheBean = newBeanDefinition(ClientCacheFactoryBean.class); - - clientCacheBean.getPropertyValues().addPropertyValue(PROPERTIES_PROPERTY_NAME_SHORTCUT, - new RuntimeBeanReference("gemfireProperties")); - - when(mockBeanFactory.getBeanDefinitionNames()).thenReturn(toArray("clientCacheBean")); - when(mockBeanFactory.getBeanDefinition(eq("clientCacheBean"))).thenReturn(clientCacheBean); - - beanFactoryPostProcessor.postProcessBeanFactory(mockBeanFactory); - - verify(mockBeanFactory, times(1)).getBeanDefinitionNames(); - verify(mockBeanFactory, times(1)).getBeanDefinition(eq("clientCacheBean")); - } - - @Test - public void postProcessDoesNotSyncWhenGemfirePropertiesAreUnspecified() { - BeanDefinition clientCacheBean = newBeanDefinition(ClientCacheFactoryBean.class); - BeanDefinition poolBean = newBeanDefinition(PoolFactoryBean.class); - - when(mockBeanFactory.getBeanDefinitionNames()).thenReturn(toArray("clientCacheBean", "poolBean")); - when(mockBeanFactory.getBeanDefinition(eq("clientCacheBean"))).thenReturn(clientCacheBean); - when(mockBeanFactory.getBeanDefinition(eq("poolBean"))).thenReturn(poolBean); - - assertThat(poolBean.getPropertyValues().getPropertyValue(PROPERTIES_PROPERTY_NAME_SHORTCUT), is(nullValue())); - - beanFactoryPostProcessor.postProcessBeanFactory(mockBeanFactory); - - assertThat(poolBean.getPropertyValues().getPropertyValue(PROPERTIES_PROPERTY_NAME_SHORTCUT), is(nullValue())); - - verify(mockBeanFactory, times(1)).getBeanDefinitionNames(); - verify(mockBeanFactory, times(1)).getBeanDefinition(eq("clientCacheBean")); - verify(mockBeanFactory, times(1)).getBeanDefinition(eq("poolBean")); - } - -} diff --git a/src/test/java/org/springframework/data/gemfire/config/CustomEditorRegistrationBeanFactoryPostProcessorTest.java b/src/test/java/org/springframework/data/gemfire/config/CustomEditorRegisteringBeanFactoryPostProcessorTest.java similarity index 89% rename from src/test/java/org/springframework/data/gemfire/config/CustomEditorRegistrationBeanFactoryPostProcessorTest.java rename to src/test/java/org/springframework/data/gemfire/config/CustomEditorRegisteringBeanFactoryPostProcessorTest.java index 29b36c58..efb29869 100644 --- a/src/test/java/org/springframework/data/gemfire/config/CustomEditorRegistrationBeanFactoryPostProcessorTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/CustomEditorRegisteringBeanFactoryPostProcessorTest.java @@ -51,24 +51,24 @@ import com.gemstone.gemfire.cache.Scope; import com.gemstone.gemfire.cache.wan.GatewaySender; /** - * The CustomEditorRegistrationBeanFactoryPostProcessorTest class... + * The CustomEditorRegisteringBeanFactoryPostProcessorTest class... * * @author John Blum * @see org.junit.Test - * @see org.springframework.data.gemfire.config.CustomEditorRegistrationBeanFactoryPostProcessor + * @see CustomEditorRegisteringBeanFactoryPostProcessor * @since 1.6.0 */ @SuppressWarnings("deprecation") -public class CustomEditorRegistrationBeanFactoryPostProcessorTest { +public class CustomEditorRegisteringBeanFactoryPostProcessorTest { @Test public void customEditorRegistration() { ConfigurableListableBeanFactory mockBeanFactory = mock(ConfigurableListableBeanFactory.class); - new CustomEditorRegistrationBeanFactoryPostProcessor().postProcessBeanFactory(mockBeanFactory); + new CustomEditorRegisteringBeanFactoryPostProcessor().postProcessBeanFactory(mockBeanFactory); - verify(mockBeanFactory, times(1)).registerCustomEditor(eq(ConnectionEndpoint[].class), eq( - CustomEditorRegistrationBeanFactoryPostProcessor.ConnectionEndpointArrayToIterableConverter.class)); + //verify(mockBeanFactory, times(1)).registerCustomEditor(eq(ConnectionEndpoint[].class), + // eq(CustomEditorRegisteringBeanFactoryPostProcessor.ConnectionEndpointArrayToIterableConverter.class)); verify(mockBeanFactory, times(1)).registerCustomEditor(eq(EvictionAction.class), eq(EvictionActionConverter.class)); verify(mockBeanFactory, times(1)).registerCustomEditor(eq(EvictionPolicyType.class), @@ -103,7 +103,7 @@ public class CustomEditorRegistrationBeanFactoryPostProcessorTest { newConnectionEndpoint("localhost", 40404) }; - Iterable iterable = new CustomEditorRegistrationBeanFactoryPostProcessor + Iterable iterable = new CustomEditorRegisteringBeanFactoryPostProcessor .ConnectionEndpointArrayToIterableConverter().convert(array); assertThat(iterable, is(notNullValue())); diff --git a/src/test/java/org/springframework/data/gemfire/listener/ContinuousQueryListenerContainerTest.java b/src/test/java/org/springframework/data/gemfire/listener/ContinuousQueryListenerContainerTest.java index 3fd026d7..09015b06 100644 --- a/src/test/java/org/springframework/data/gemfire/listener/ContinuousQueryListenerContainerTest.java +++ b/src/test/java/org/springframework/data/gemfire/listener/ContinuousQueryListenerContainerTest.java @@ -45,6 +45,7 @@ import org.springframework.data.gemfire.GemfireUtils; import org.springframework.data.gemfire.TestUtils; import org.springframework.data.gemfire.config.GemfireConstants; +import com.gemstone.gemfire.cache.RegionService; import com.gemstone.gemfire.cache.client.Pool; import com.gemstone.gemfire.cache.query.QueryService; import com.gemstone.gemfire.internal.cache.PoolManagerImpl; @@ -136,6 +137,23 @@ public class ContinuousQueryListenerContainerTest { verifyZeroInteractions(mockQueryService); } + @Test + public void afterPropertiesSetThrowsIllegalStateExceptionWhenQueryServicesIsUninitialized() { + exception.expect(IllegalStateException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("QueryService was not properly initialized"); + + try { + listenerContainer.setPoolName("TestPool"); + listenerContainer.afterPropertiesSet(); + } + finally { + assertThat(listenerContainer.isActive(), is(false)); + assertThat(listenerContainer.isAutoStartup(), is(true)); + assertThat(listenerContainer.isRunning(), is(false)); + } + } + @Test public void resolvesToProvidedPoolName() { listenerContainer.setPoolName("TestPool"); @@ -222,7 +240,7 @@ public class ContinuousQueryListenerContainerTest { try { exception.expect(IllegalArgumentException.class); - exception.expectCause(nullValue(Throwable.class)); + exception.expectCause(is(nullValue(Throwable.class))); exception.expectMessage("No GemFire Pool with name [TestPool] was found"); listenerContainer.setBeanFactory(mockBeanFactory); @@ -245,6 +263,17 @@ public class ContinuousQueryListenerContainerTest { verifyZeroInteractions(mockQueryService); } + @Test + public void initializesQueryServiceFromContainer() { + QueryService mockQueryService = mock(QueryService.class); + + listenerContainer.setQueryService(mockQueryService); + + assertThat(listenerContainer.initQueryService("TestPool"), is(equalTo(mockQueryService))); + + verifyZeroInteractions(mockQueryService); + } + @Test public void initializesQueryServiceFromPool() { Pool mockPool = mock(Pool.class); @@ -255,6 +284,7 @@ public class ContinuousQueryListenerContainerTest { try { PoolManagerImpl.getPMI().register(mockPool); + listenerContainer.setQueryService(null); assertThat(listenerContainer.initQueryService("TestPool"), is(equalTo(mockQueryService))); } finally { @@ -265,6 +295,30 @@ public class ContinuousQueryListenerContainerTest { } } + @Test + public void initializesQueryServiceFromPoolInThePresenceOfAProvidedQueryService() { + Pool mockPool = mock(Pool.class); + + QueryService mockQueryServiceOne = mock(QueryService.class); + QueryService mockQueryServiceTwo = mock(QueryService.class); + + when(mockPool.getName()).thenReturn("TestPool"); + when(mockPool.getQueryService()).thenReturn(mockQueryServiceOne); + + try { + PoolManagerImpl.getPMI().register(mockPool); + listenerContainer.setQueryService(mockQueryServiceTwo); + assertThat(listenerContainer.initQueryService("TestPool"), is(equalTo(mockQueryServiceOne))); + } + finally { + assertThat(PoolManagerImpl.getPMI().unregister(mockPool), is(true)); + verify(mockPool, times(2)).getName(); + verify(mockPool, times(1)).getQueryService(); + verifyZeroInteractions(mockQueryServiceOne); + verifyZeroInteractions(mockQueryServiceTwo); + } + } + @Test public void initExecutorReturnsProvidedExecutor() { Executor mockExecutor = mock(Executor.class); @@ -281,4 +335,32 @@ public class ContinuousQueryListenerContainerTest { assertThat(listenerContainer.initExecutor(), is(instanceOf(Executor.class))); } + @Test + public void setCacheSetsQueryService() { + QueryService mockQueryService = mock(QueryService.class); + RegionService mockRegionService = mock(RegionService.class); + + when(mockRegionService.getQueryService()).thenReturn(mockQueryService); + + listenerContainer.setCache(mockRegionService); + + assertThat(listenerContainer.initQueryService(null), is(equalTo(mockQueryService))); + + verify(mockRegionService, times(1)).getQueryService(); + verifyZeroInteractions(mockQueryService); + } + + @Test + public void setAndGetAutoStartup() { + assertThat(listenerContainer.isAutoStartup(), is(true)); + + listenerContainer.setAutoStartup(false); + + assertThat(listenerContainer.isAutoStartup(), is(false)); + + listenerContainer.setAutoStartup(true); + + assertThat(listenerContainer.isAutoStartup(), is(true)); + } + } diff --git a/src/test/resources/org/springframework/data/gemfire/listener/container.xml b/src/test/resources/org/springframework/data/gemfire/listener/container.xml index 7e6a5f7b..5b38f9d5 100644 --- a/src/test/resources/org/springframework/data/gemfire/listener/container.xml +++ b/src/test/resources/org/springframework/data/gemfire/listener/container.xml @@ -15,7 +15,7 @@ warning - + @@ -23,7 +23,7 @@ - + @@ -32,7 +32,6 @@ -