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 <jblum@pivotal.io>
This commit is contained in:
John Blum
2016-03-23 16:52:47 -07:00
parent 9eb4ab24bf
commit 0820482818
8 changed files with 111 additions and 261 deletions

View File

@@ -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> 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"));
}
}

View File

@@ -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<ConnectionEndpoint> iterable = new CustomEditorRegistrationBeanFactoryPostProcessor
Iterable<ConnectionEndpoint> iterable = new CustomEditorRegisteringBeanFactoryPostProcessor
.ConnectionEndpointArrayToIterableConverter().convert(array);
assertThat(iterable, is(notNullValue()));

View File

@@ -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));
}
}