DATAGEODE-111 - Add ability to configure SecurityManager on CacheFactoryBean.
This commit is contained in:
@@ -53,6 +53,7 @@ import org.apache.geode.internal.datasource.ConfigProperty;
|
||||
import org.apache.geode.internal.jndi.JNDIInvoker;
|
||||
import org.apache.geode.pdx.PdxSerializable;
|
||||
import org.apache.geode.pdx.PdxSerializer;
|
||||
import org.apache.geode.security.SecurityManager;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
@@ -158,6 +159,8 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport<GemFireCache>
|
||||
private String cacheResolutionMessagePrefix;
|
||||
private String pdxDiskStoreName;
|
||||
|
||||
private org.apache.geode.security.SecurityManager securityManager;
|
||||
|
||||
private TransactionWriter transactionWriter;
|
||||
|
||||
/**
|
||||
@@ -298,7 +301,7 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport<GemFireCache>
|
||||
* @see #fetchCache()
|
||||
* @see #resolveProperties()
|
||||
* @see #createFactory(java.util.Properties)
|
||||
* @see #prepareFactory(Object)
|
||||
* @see #configureFactory(Object)
|
||||
* @see #createCache(Object)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -310,7 +313,7 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport<GemFireCache>
|
||||
catch (CacheClosedException ex) {
|
||||
this.cacheResolutionMessagePrefix = "Created new";
|
||||
initDynamicRegionFactory();
|
||||
return (T) createCache(prepareFactory(initializeFactory(createFactory(resolveProperties()))));
|
||||
return (T) createCache(configureFactory(initializeFactory(createFactory(resolveProperties()))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,20 +392,20 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport<GemFireCache>
|
||||
*
|
||||
* @param factory {@link CacheFactory} used to create the {@link Cache}.
|
||||
* @return the prepared and initialized {@link CacheFactory}.
|
||||
* @see #initializePdx(CacheFactory)
|
||||
* @see #configurePdx(CacheFactory)
|
||||
*/
|
||||
protected Object prepareFactory(Object factory) {
|
||||
return initializePdx((CacheFactory) factory);
|
||||
protected Object configureFactory(Object factory) {
|
||||
return configureSecurity(configurePdx((CacheFactory) factory));
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure PDX for the given {@link CacheFactory}.
|
||||
* Configures PDX for this peer {@link Cache} instance.
|
||||
*
|
||||
* @param cacheFactory {@link CacheFactory} used to configure PDX.
|
||||
* @param cacheFactory {@link CacheFactory} used to configure the peer {@link Cache} with PDX.
|
||||
* @return the given {@link CacheFactory}.
|
||||
* @see org.apache.geode.cache.CacheFactory
|
||||
*/
|
||||
private CacheFactory initializePdx(CacheFactory cacheFactory) {
|
||||
private CacheFactory configurePdx(CacheFactory cacheFactory) {
|
||||
|
||||
Optional.ofNullable(getPdxSerializer()).ifPresent(cacheFactory::setPdxSerializer);
|
||||
|
||||
@@ -419,7 +422,32 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport<GemFireCache>
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Cache} instance using the provided factory.
|
||||
* Configures security for this peer {@link Cache} instance.
|
||||
*
|
||||
* @param cacheFactory {@link CacheFactory} used to configure the peer {@link Cache} with security.
|
||||
* @return the given {@link CacheFactory}.
|
||||
* @see org.apache.geode.cache.CacheFactory
|
||||
*/
|
||||
private CacheFactory configureSecurity(CacheFactory cacheFactory) {
|
||||
|
||||
Optional.ofNullable(getSecurityManager()).ifPresent(cacheFactory::setSecurityManager);
|
||||
|
||||
return cacheFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post processes the {@link CacheFactory} used to create the {@link Cache}.
|
||||
*
|
||||
* @param factory {@link CacheFactory} used to create the {@link Cache}.
|
||||
* @return the post processed {@link CacheFactory}.
|
||||
* @see org.apache.geode.cache.CacheFactory
|
||||
*/
|
||||
protected Object postProcess(Object factory) {
|
||||
return factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Cache} instance using the provided {@link Object factory}.
|
||||
*
|
||||
* @param <T> parameterized {@link Class} type extension of {@link GemFireCache}.
|
||||
* @param factory instance of {@link CacheFactory}.
|
||||
@@ -716,9 +744,10 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport<GemFireCache>
|
||||
* @return boolean value indicating whether a {@link Resource cache.xml} {@link File} is present.
|
||||
* @see #getCacheXmlFile()
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
private boolean isCacheXmlAvailable() {
|
||||
try {
|
||||
return (getCacheXmlFile() != null);
|
||||
return getCacheXmlFile() != null;
|
||||
}
|
||||
catch (Throwable ignore) {
|
||||
return false;
|
||||
@@ -1183,6 +1212,26 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport<GemFireCache>
|
||||
return searchTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the {@link org.apache.geode.security.SecurityManager} used to secure this cache.
|
||||
*
|
||||
* @param securityManager {@link org.apache.geode.security.SecurityManager} used to secure this cache.
|
||||
* @see org.apache.geode.security.SecurityManager
|
||||
*/
|
||||
public void setSecurityManager(SecurityManager securityManager) {
|
||||
this.securityManager = securityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link org.apache.geode.security.SecurityManager} used to secure this cache.
|
||||
*
|
||||
* @return the {@link org.apache.geode.security.SecurityManager} used to secure this cache.
|
||||
* @see org.apache.geode.security.SecurityManager
|
||||
*/
|
||||
public SecurityManager getSecurityManager() {
|
||||
return securityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the list of TransactionListeners used to configure the Cache to receive transaction events after
|
||||
* the transaction is processed (committed, rolled back).
|
||||
|
||||
@@ -134,7 +134,6 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
|
||||
applyClientCacheConfigurers();
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private void applyClientCacheConfigurers() {
|
||||
applyClientCacheConfigurers(getCompositeClientCacheConfigurer());
|
||||
}
|
||||
@@ -244,7 +243,7 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
|
||||
* @see #initializePdx(ClientCacheFactory)
|
||||
*/
|
||||
@Override
|
||||
protected Object prepareFactory(Object factory) {
|
||||
protected Object configureFactory(Object factory) {
|
||||
return initializePool(initializePdx((ClientCacheFactory) factory));
|
||||
}
|
||||
|
||||
@@ -447,22 +446,18 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
|
||||
return Optional.ofNullable(getCache()).map(Object::getClass).orElse((Class) ClientCache.class);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void addLocators(ConnectionEndpoint... locators) {
|
||||
this.locators.add(locators);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void addLocators(Iterable<ConnectionEndpoint> locators) {
|
||||
this.locators.add(locators);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void addServers(ConnectionEndpoint... servers) {
|
||||
this.servers.add(servers);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void addServers(Iterable<ConnectionEndpoint> servers) {
|
||||
this.servers.add(servers);
|
||||
}
|
||||
@@ -544,34 +539,28 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
|
||||
return this.durableClientTimeout;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public final void setEnableAutoReconnect(Boolean enableAutoReconnect) {
|
||||
throw new UnsupportedOperationException("Auto-reconnect does not apply to clients");
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public final Boolean getEnableAutoReconnect() {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void setFreeConnectionTimeout(Integer freeConnectionTimeout) {
|
||||
this.freeConnectionTimeout = freeConnectionTimeout;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public Integer getFreeConnectionTimeout() {
|
||||
return freeConnectionTimeout;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void setIdleTimeout(Long idleTimeout) {
|
||||
this.idleTimeout = idleTimeout;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public Long getIdleTimeout() {
|
||||
return idleTimeout;
|
||||
}
|
||||
@@ -606,58 +595,47 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
|
||||
return Boolean.TRUE.equals(getKeepAlive());
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void setLoadConditioningInterval(Integer loadConditioningInterval) {
|
||||
this.loadConditioningInterval = loadConditioningInterval;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public Integer getLoadConditioningInterval() {
|
||||
return loadConditioningInterval;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void setLocators(ConnectionEndpoint[] locators) {
|
||||
setLocators(ConnectionEndpointList.from(locators));
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void setLocators(Iterable<ConnectionEndpoint> locators) {
|
||||
getLocators().clear();
|
||||
addLocators(locators);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected ConnectionEndpointList getLocators() {
|
||||
return locators;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void setMaxConnections(Integer maxConnections) {
|
||||
this.maxConnections = maxConnections;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public Integer getMaxConnections() {
|
||||
return maxConnections;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void setMinConnections(Integer minConnections) {
|
||||
this.minConnections = minConnections;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public Integer getMinConnections() {
|
||||
return minConnections;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void setMultiUserAuthentication(Boolean multiUserAuthentication) {
|
||||
this.multiUserAuthentication = multiUserAuthentication;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public Boolean getMultiUserAuthentication() {
|
||||
return multiUserAuthentication;
|
||||
}
|
||||
@@ -702,32 +680,26 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
|
||||
return poolName;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void setPingInterval(Long pingInterval) {
|
||||
this.pingInterval = pingInterval;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public Long getPingInterval() {
|
||||
return pingInterval;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void setPrSingleHopEnabled(Boolean prSingleHopEnabled) {
|
||||
this.prSingleHopEnabled = prSingleHopEnabled;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public Boolean getPrSingleHopEnabled() {
|
||||
return prSingleHopEnabled;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void setReadTimeout(Integer readTimeout) {
|
||||
this.readTimeout = readTimeout;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public Integer getReadTimeout() {
|
||||
return readTimeout;
|
||||
}
|
||||
@@ -778,119 +750,96 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void setRetryAttempts(Integer retryAttempts) {
|
||||
this.retryAttempts = retryAttempts;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public Integer getRetryAttempts() {
|
||||
return retryAttempts;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void setServerGroup(String serverGroup) {
|
||||
this.serverGroup = serverGroup;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public String getServerGroup() {
|
||||
return serverGroup;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void setServers(ConnectionEndpoint[] servers) {
|
||||
setServers(ConnectionEndpointList.from(servers));
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void setServers(Iterable<ConnectionEndpoint> servers) {
|
||||
getServers().clear();
|
||||
addServers(servers);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected ConnectionEndpointList getServers() {
|
||||
return servers;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void setSocketBufferSize(Integer socketBufferSize) {
|
||||
this.socketBufferSize = socketBufferSize;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public Integer getSocketBufferSize() {
|
||||
return socketBufferSize;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void setStatisticsInterval(Integer statisticsInterval) {
|
||||
this.statisticsInterval = statisticsInterval;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public Integer getStatisticsInterval() {
|
||||
return statisticsInterval;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void setSubscriptionAckInterval(Integer subscriptionAckInterval) {
|
||||
this.subscriptionAckInterval = subscriptionAckInterval;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public Integer getSubscriptionAckInterval() {
|
||||
return subscriptionAckInterval;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void setSubscriptionEnabled(Boolean subscriptionEnabled) {
|
||||
this.subscriptionEnabled = subscriptionEnabled;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public Boolean getSubscriptionEnabled() {
|
||||
return subscriptionEnabled;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void setSubscriptionMessageTrackingTimeout(Integer subscriptionMessageTrackingTimeout) {
|
||||
this.subscriptionMessageTrackingTimeout = subscriptionMessageTrackingTimeout;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public Integer getSubscriptionMessageTrackingTimeout() {
|
||||
return subscriptionMessageTrackingTimeout;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void setSubscriptionRedundancy(Integer subscriptionRedundancy) {
|
||||
this.subscriptionRedundancy = subscriptionRedundancy;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public Integer getSubscriptionRedundancy() {
|
||||
return subscriptionRedundancy;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public void setThreadLocalConnections(Boolean threadLocalConnections) {
|
||||
this.threadLocalConnections = threadLocalConnections;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public Boolean getThreadLocalConnections() {
|
||||
return threadLocalConnections;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public final void setUseClusterConfiguration(Boolean useClusterConfiguration) {
|
||||
throw new UnsupportedOperationException("Cluster-based Configuration is not applicable for clients");
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public final Boolean getUseClusterConfiguration() {
|
||||
return Boolean.FALSE;
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -99,8 +100,10 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
final AtomicBoolean postProcessBeforeCacheInitializationCalled = new AtomicBoolean(false);
|
||||
final Properties gemfireProperties = new Properties();
|
||||
|
||||
AtomicBoolean postProcessBeforeCacheInitializationCalled = new AtomicBoolean(false);
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
|
||||
@@ -119,6 +122,7 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void postProcessBeforeCacheInitializationUsingDefaults() {
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
new CacheFactoryBean().postProcessBeforeCacheInitialization(gemfireProperties);
|
||||
@@ -132,7 +136,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void postProcessBeforeCacheInitializationWithAutoReconnectAndClusterConfigurationDisabled() {
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setEnableAutoReconnect(false);
|
||||
@@ -148,7 +154,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void postProcessBeforeCacheInitializationWithAutoReconnectAndClusterConfigurationEnabled() {
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setEnableAutoReconnect(true);
|
||||
@@ -164,7 +172,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void postProcessBeforeCacheInitializationWithAutoReconnectDisabledAndClusterConfigurationEnabled() {
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setEnableAutoReconnect(false);
|
||||
@@ -180,9 +190,10 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void getObjectCallsInit() throws Exception {
|
||||
final Cache mockCache = mock(Cache.class);
|
||||
|
||||
final AtomicBoolean initCalled = new AtomicBoolean(false);
|
||||
AtomicBoolean initCalled = new AtomicBoolean(false);
|
||||
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
@Override Cache init() {
|
||||
@@ -199,7 +210,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void getObjectReturnsExistingCache() throws Exception {
|
||||
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setCache(mockCache);
|
||||
@@ -323,9 +336,11 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolveCacheCallsFetchCacheReturnsMock() {
|
||||
final Cache mockCache = mock(Cache.class);
|
||||
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
|
||||
@Override @SuppressWarnings("unchecked ")
|
||||
protected <T extends GemFireCache> T fetchCache() {
|
||||
return (T) mockCache;
|
||||
@@ -339,13 +354,17 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolveCacheCreatesCacheWhenFetchCacheThrowsCacheClosedException() {
|
||||
final Cache mockCache = mock(Cache.class);
|
||||
final CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
when(mockCacheFactory.create()).thenReturn(mockCache);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
@Override protected <T extends GemFireCache> T fetchCache() {
|
||||
|
||||
@Override
|
||||
protected <T extends GemFireCache> T fetchCache() {
|
||||
throw new CacheClosedException("test");
|
||||
}
|
||||
|
||||
@@ -364,7 +383,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void fetchExistingCache() throws Exception {
|
||||
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setCache(mockCache);
|
||||
@@ -378,7 +399,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolveProperties() {
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setProperties(gemfireProperties);
|
||||
@@ -388,6 +411,7 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolvePropertiesWhenNull() {
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setProperties(null);
|
||||
@@ -400,7 +424,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void createFactory() {
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
Object cacheFactoryReference = new CacheFactoryBean().createFactory(gemfireProperties);
|
||||
|
||||
assertThat(cacheFactoryReference, is(instanceOf(CacheFactory.class)));
|
||||
@@ -415,10 +441,45 @@ public class CacheFactoryBeanTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prepareFactoryWithUnspecifiedPdxOptions() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void initializesFactoryWitCacheFactoryInitializer() {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
assertThat(new CacheFactoryBean().prepareFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
|
||||
CacheFactoryBean.CacheFactoryInitializer<Object> mockCacheFactoryInitializer =
|
||||
mock(CacheFactoryBean.CacheFactoryInitializer.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setCacheFactoryInitializer(mockCacheFactoryInitializer);
|
||||
|
||||
assertThat(cacheFactoryBean.getCacheFactoryInitializer(), is(equalTo(mockCacheFactoryInitializer)));
|
||||
assertThat(cacheFactoryBean.initializeFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
|
||||
|
||||
verify(mockCacheFactoryInitializer, times(1)).initialize(eq(mockCacheFactory));
|
||||
verifyZeroInteractions(mockCacheFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initializeFactoryWhenNoCacheFactoryInitializerIsPresentIsNullSafe() {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
assertThat(cacheFactoryBean.getCacheFactoryInitializer(),
|
||||
is(nullValue(CacheFactoryBean.CacheFactoryInitializer.class)));
|
||||
assertThat(cacheFactoryBean.initializeFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
|
||||
|
||||
verifyZeroInteractions(mockCacheFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configureFactoryWithUnspecifiedPdxOptions() {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
assertThat(new CacheFactoryBean().configureFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
|
||||
|
||||
verify(mockCacheFactory, never()).setPdxDiskStore(any(String.class));
|
||||
verify(mockCacheFactory, never()).setPdxIgnoreUnreadFields(any(Boolean.class));
|
||||
@@ -428,7 +489,8 @@ public class CacheFactoryBeanTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prepareFactoryWithSpecificPdxOptions() {
|
||||
public void configureFactoryWithSpecificPdxOptions() {
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setPdxSerializer(mock(PdxSerializer.class));
|
||||
@@ -437,7 +499,7 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
assertThat(cacheFactoryBean.prepareFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
|
||||
assertThat(cacheFactoryBean.configureFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
|
||||
|
||||
verify(mockCacheFactory, never()).setPdxDiskStore(any(String.class));
|
||||
verify(mockCacheFactory, times(1)).setPdxIgnoreUnreadFields(eq(false));
|
||||
@@ -447,7 +509,8 @@ public class CacheFactoryBeanTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prepareFactoryWithAllPdxOptions() {
|
||||
public void configureFactoryWithAllPdxOptions() {
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setPdxDiskStoreName("testPdxDiskStoreName");
|
||||
@@ -458,7 +521,7 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
assertThat(cacheFactoryBean.prepareFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
|
||||
assertThat(cacheFactoryBean.configureFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
|
||||
|
||||
verify(mockCacheFactory, times(1)).setPdxDiskStore(eq("testPdxDiskStoreName"));
|
||||
verify(mockCacheFactory, times(1)).setPdxIgnoreUnreadFields(eq(false));
|
||||
@@ -468,24 +531,44 @@ public class CacheFactoryBeanTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createCacheWithExistingCache() throws Exception {
|
||||
public void configureFactoryWithSecurityManager() {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
org.apache.geode.security.SecurityManager mockSecurityManager =
|
||||
mock(org.apache.geode.security.SecurityManager.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setCache(mockCache);
|
||||
cacheFactoryBean.setSecurityManager(mockSecurityManager);
|
||||
|
||||
assertThat(cacheFactoryBean.getCache(), is(sameInstance(mockCache)));
|
||||
assertThat(cacheFactoryBean.getSecurityManager(), is(sameInstance(mockSecurityManager)));
|
||||
assertThat(cacheFactoryBean.configureFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
|
||||
|
||||
verify(mockCacheFactory, times(1)).setSecurityManager(eq(mockSecurityManager));
|
||||
verifyZeroInteractions(mockSecurityManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createCacheWithCacheFactory() {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
when(mockCacheFactory.create()).thenReturn(mockCache);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
Cache actualCache = cacheFactoryBean.createCache(mockCacheFactory);
|
||||
|
||||
assertThat(actualCache, is(sameInstance(mockCache)));
|
||||
assertThat(actualCache, is(equalTo(mockCache)));
|
||||
|
||||
verify(mockCacheFactory, never()).create();
|
||||
verify(mockCacheFactory, times(1)).create();
|
||||
verifyZeroInteractions(mockCache);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createCacheWithNoExistingCache() {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
when(mockCacheFactory.create()).thenReturn(mockCache);
|
||||
@@ -502,7 +585,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void postProcessCacheWithInvalidCriticalHeapPercentage() throws Exception {
|
||||
|
||||
try {
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setCriticalHeapPercentage(200.0f);
|
||||
@@ -521,7 +606,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void postProcessCacheWithInvalidCriticalOffHeapPercentage() throws Exception {
|
||||
|
||||
try {
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setCriticalOffHeapPercentage(200.0f);
|
||||
@@ -540,7 +627,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void postProcessCacheWithInvalidEvictionHeapPercentage() throws Exception {
|
||||
|
||||
try {
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setEvictionHeapPercentage(-75.0f);
|
||||
@@ -559,7 +648,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void postProcessCacheWithInvalidEvictionOffHeapPercentage() throws Exception {
|
||||
|
||||
try {
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setEvictionOffHeapPercentage(-75.0f);
|
||||
@@ -584,7 +675,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void getObjectTypeWithExistingCache() {
|
||||
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setCache(mockCache);
|
||||
@@ -600,8 +693,10 @@ public class CacheFactoryBeanTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void destroy() throws Exception {
|
||||
final AtomicBoolean fetchCacheCalled = new AtomicBoolean(false);
|
||||
final Cache mockCache = mock(Cache.class, "GemFireCache");
|
||||
|
||||
AtomicBoolean fetchCacheCalled = new AtomicBoolean(false);
|
||||
|
||||
Cache mockCache = mock(Cache.class, "GemFireCache");
|
||||
|
||||
GemfireBeanFactoryLocator mockGemfireBeanFactoryLocator = mock(GemfireBeanFactoryLocator.class);
|
||||
|
||||
@@ -631,7 +726,8 @@ public class CacheFactoryBeanTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void destroyWhenCacheIsNull() throws Exception {
|
||||
final AtomicBoolean fetchCacheCalled = new AtomicBoolean(false);
|
||||
|
||||
AtomicBoolean fetchCacheCalled = new AtomicBoolean(false);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
@Override protected <T extends GemFireCache> T fetchCache() {
|
||||
@@ -650,8 +746,10 @@ public class CacheFactoryBeanTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void destroyWhenCacheClosedIsTrue() throws Exception {
|
||||
final AtomicBoolean fetchCacheCalled = new AtomicBoolean(false);
|
||||
final Cache mockCache = mock(Cache.class, "GemFireCache");
|
||||
|
||||
AtomicBoolean fetchCacheCalled = new AtomicBoolean(false);
|
||||
|
||||
Cache mockCache = mock(Cache.class, "GemFireCache");
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
@Override @SuppressWarnings("unchecked") protected <T extends GemFireCache> T fetchCache() {
|
||||
@@ -672,6 +770,7 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void closeCache() {
|
||||
|
||||
GemFireCache mockCache = mock(GemFireCache.class, "testCloseCache.MockCache");
|
||||
|
||||
new CacheFactoryBean().close(mockCache);
|
||||
|
||||
@@ -273,7 +273,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(clientCacheFactoryBean.prepareFactory(mockClientCacheFactory),
|
||||
assertThat(clientCacheFactoryBean.configureFactory(mockClientCacheFactory),
|
||||
is(sameInstance(mockClientCacheFactory)));
|
||||
assertThat(initializePdxCalled.get(), is(true));
|
||||
assertThat(initializePoolCalled.get(), is(true));
|
||||
|
||||
Reference in New Issue
Block a user