Update to Spring Data Hopper
Fixes gh-470
This commit is contained in:
@@ -65,24 +65,25 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public abstract class AbstractGemFireIntegrationTests {
|
||||
|
||||
protected static final boolean DEFAULT_ENABLE_QUERY_DEBUGGING = false;
|
||||
protected static final boolean GEMFIRE_QUERY_DEBUG = Boolean
|
||||
.getBoolean("spring.session.data.gemfire.query.debug");
|
||||
|
||||
protected static final boolean GEMFIRE_QUERY_DEBUG =
|
||||
Boolean.getBoolean("spring.session.data.gemfire.query.debug");
|
||||
|
||||
protected static final int DEFAULT_GEMFIRE_SERVER_PORT = CacheServer.DEFAULT_PORT;
|
||||
|
||||
protected static final long DEFAULT_WAIT_DURATION = TimeUnit.SECONDS.toMillis(20);
|
||||
protected static final long DEFAULT_WAIT_INTERVAL = 500L;
|
||||
|
||||
protected static final File WORKING_DIRECTORY = new File(
|
||||
System.getProperty("user.dir"));
|
||||
protected static final File WORKING_DIRECTORY =
|
||||
new File(System.getProperty("user.dir"));
|
||||
|
||||
protected static final String DEFAULT_PROCESS_CONTROL_FILENAME = "process.ctl";
|
||||
|
||||
protected static final String GEMFIRE_LOG_FILE_NAME = System
|
||||
.getProperty("spring.session.data.gemfire.log-file", "server.log");
|
||||
protected static final String GEMFIRE_LOG_FILE_NAME =
|
||||
System.getProperty("spring.session.data.gemfire.log-file", "server.log");
|
||||
|
||||
protected static final String GEMFIRE_LOG_LEVEL = System
|
||||
.getProperty("spring.session.data.gemfire.log-level", "warning");
|
||||
protected static final String GEMFIRE_LOG_LEVEL =
|
||||
System.getProperty("spring.session.data.gemfire.log-level", "warning");
|
||||
|
||||
@Autowired
|
||||
protected Cache gemfireCache;
|
||||
@@ -93,7 +94,7 @@ public abstract class AbstractGemFireIntegrationTests {
|
||||
@Before
|
||||
public void setup() {
|
||||
System.setProperty("gemfire.Query.VERBOSE",
|
||||
String.valueOf(isQueryDebuggingEnabled()));
|
||||
String.valueOf(isQueryDebuggingEnabled()));
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
|
||||
@@ -32,7 +32,6 @@ import com.gemstone.gemfire.cache.DataPolicy;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.RegionAttributes;
|
||||
import com.gemstone.gemfire.cache.client.ClientCache;
|
||||
import com.gemstone.gemfire.cache.client.Pool;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
@@ -49,7 +48,6 @@ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||
import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
|
||||
import org.springframework.data.gemfire.client.PoolFactoryBean;
|
||||
import org.springframework.data.gemfire.config.GemfireConstants;
|
||||
import org.springframework.data.gemfire.server.CacheServerFactoryBean;
|
||||
import org.springframework.data.gemfire.support.ConnectionEndpoint;
|
||||
import org.springframework.session.ExpiringSession;
|
||||
@@ -78,10 +76,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.springframework.session.data.gemfire.AbstractGemFireIntegrationTests
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.
|
||||
* EnableGemFireHttpSession
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.
|
||||
* GemFireHttpSessionConfiguration
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration
|
||||
* @see org.springframework.test.annotation.DirtiesContext
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
|
||||
@@ -159,17 +155,17 @@ public class ClientServerGemFireOperationsSessionRepositoryIntegrationTests
|
||||
public void setup() {
|
||||
assertThat(GemFireUtils.isClient(gemfireCache)).isTrue();
|
||||
|
||||
Region<Object, ExpiringSession> springSessionGemFireRegion = gemfireCache
|
||||
.getRegion(SPRING_SESSION_GEMFIRE_REGION_NAME);
|
||||
Region<Object, ExpiringSession> springSessionGemFireRegion =
|
||||
gemfireCache.getRegion(SPRING_SESSION_GEMFIRE_REGION_NAME);
|
||||
|
||||
assertThat(springSessionGemFireRegion).isNotNull();
|
||||
|
||||
RegionAttributes<Object, ExpiringSession> springSessionGemFireRegionAttributes = springSessionGemFireRegion
|
||||
.getAttributes();
|
||||
RegionAttributes<Object, ExpiringSession> springSessionGemFireRegionAttributes =
|
||||
springSessionGemFireRegion.getAttributes();
|
||||
|
||||
assertThat(springSessionGemFireRegionAttributes).isNotNull();
|
||||
assertThat(springSessionGemFireRegionAttributes.getDataPolicy())
|
||||
.isEqualTo(DataPolicy.EMPTY);
|
||||
.isEqualTo(DataPolicy.EMPTY);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -270,54 +266,40 @@ public class ClientServerGemFireOperationsSessionRepositoryIntegrationTests
|
||||
@Bean
|
||||
Properties gemfireProperties() {
|
||||
Properties gemfireProperties = new Properties();
|
||||
gemfireProperties.setProperty("name",
|
||||
ClientServerGemFireOperationsSessionRepositoryIntegrationTests.class
|
||||
.getName());
|
||||
gemfireProperties.setProperty("log-level", GEMFIRE_LOG_LEVEL);
|
||||
return gemfireProperties;
|
||||
}
|
||||
|
||||
@Bean(name = GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME)
|
||||
@Bean
|
||||
ClientCacheFactoryBean gemfireCache() {
|
||||
ClientCacheFactoryBean clientCacheFactory = new ClientCacheFactoryBean();
|
||||
|
||||
clientCacheFactory.setClose(true);
|
||||
clientCacheFactory.setProperties(gemfireProperties());
|
||||
|
||||
return clientCacheFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
PoolFactoryBean gemfirePool(@Value("${spring.session.data.gemfire.port:"
|
||||
+ DEFAULT_GEMFIRE_SERVER_PORT + "}") int port) {
|
||||
PoolFactoryBean poolFactory = new PoolFactoryBean() {
|
||||
@Override
|
||||
protected Properties resolveGemfireProperties() {
|
||||
return gemfireProperties();
|
||||
}
|
||||
};
|
||||
PoolFactoryBean poolFactory = new PoolFactoryBean();
|
||||
|
||||
poolFactory.setName(GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME);
|
||||
poolFactory.setFreeConnectionTimeout(5000); // 5 seconds
|
||||
poolFactory.setKeepAlive(false);
|
||||
poolFactory.setMaxConnections(
|
||||
SpringSessionGemFireServerConfiguration.MAX_CONNECTIONS);
|
||||
poolFactory.setMaxConnections(SpringSessionGemFireServerConfiguration.MAX_CONNECTIONS);
|
||||
poolFactory.setPingInterval(TimeUnit.SECONDS.toMillis(5));
|
||||
poolFactory.setReadTimeout(2000); // 2 seconds
|
||||
poolFactory.setRetryAttempts(2);
|
||||
poolFactory.setSubscriptionEnabled(true);
|
||||
poolFactory.setThreadLocalConnections(false);
|
||||
|
||||
poolFactory
|
||||
.setServerEndpoints(Collections.singletonList(new ConnectionEndpoint(
|
||||
SpringSessionGemFireServerConfiguration.SERVER_HOSTNAME,
|
||||
port)));
|
||||
poolFactory.setServers(Collections.singletonList(new ConnectionEndpoint(
|
||||
SpringSessionGemFireServerConfiguration.SERVER_HOSTNAME, port)));
|
||||
|
||||
return poolFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
ClientCacheFactoryBean gemfireCache(Pool gemfirePool) {
|
||||
ClientCacheFactoryBean clientCacheFactory = new ClientCacheFactoryBean();
|
||||
|
||||
clientCacheFactory.setClose(true);
|
||||
clientCacheFactory.setPool(gemfirePool);
|
||||
clientCacheFactory.setProperties(gemfireProperties());
|
||||
clientCacheFactory.setUseBeanFactoryLocator(false);
|
||||
|
||||
return clientCacheFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SessionEventListener sessionEventListener() {
|
||||
return new SessionEventListener();
|
||||
@@ -335,7 +317,7 @@ public class ClientServerGemFireOperationsSessionRepositoryIntegrationTests
|
||||
|
||||
for (InetSocketAddress server : clientCache.getCurrentServers()) {
|
||||
System.err.printf("GemFire Server [host: %1$s, port: %2$d]%n",
|
||||
server.getHostName(), server.getPort());
|
||||
server.getHostName(), server.getPort());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -366,12 +348,12 @@ public class ClientServerGemFireOperationsSessionRepositoryIntegrationTests
|
||||
|
||||
@Bean
|
||||
CacheFactoryBean gemfireCache() {
|
||||
CacheFactoryBean cacheFactory = new CacheFactoryBean();
|
||||
CacheFactoryBean gemfireCache = new CacheFactoryBean();
|
||||
|
||||
cacheFactory.setProperties(gemfireProperties());
|
||||
cacheFactory.setUseBeanFactoryLocator(false);
|
||||
gemfireCache.setClose(true);
|
||||
gemfireCache.setProperties(gemfireProperties());
|
||||
|
||||
return cacheFactory;
|
||||
return gemfireCache;
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -391,9 +391,7 @@ public class GemFireOperationsSessionRepositoryIntegrationTests
|
||||
CacheFactoryBean gemfireCache = new CacheFactoryBean();
|
||||
|
||||
gemfireCache.setClose(true);
|
||||
gemfireCache.setLazyInitialize(false);
|
||||
gemfireCache.setProperties(gemfireProperties());
|
||||
gemfireCache.setUseBeanFactoryLocator(false);
|
||||
|
||||
return gemfireCache;
|
||||
}
|
||||
|
||||
@@ -253,9 +253,8 @@ public class EnableGemFireHttpSessionEventsIntegrationTests
|
||||
CacheFactoryBean gemfireCache() {
|
||||
CacheFactoryBean gemfireCache = new CacheFactoryBean();
|
||||
|
||||
gemfireCache.setLazyInitialize(false);
|
||||
gemfireCache.setClose(true);
|
||||
gemfireCache.setProperties(gemfireProperties());
|
||||
gemfireCache.setUseBeanFactoryLocator(false);
|
||||
|
||||
return gemfireCache;
|
||||
}
|
||||
|
||||
@@ -135,7 +135,6 @@ public class GemFireHttpSessionJavaConfigurationTests
|
||||
|
||||
cacheFactory.setClose(true);
|
||||
cacheFactory.setProperties(gemfireProperties());
|
||||
cacheFactory.setUseBeanFactoryLocator(false);
|
||||
|
||||
return cacheFactory;
|
||||
}
|
||||
|
||||
@@ -65,8 +65,8 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
|
||||
* The default maximum interval in seconds in which a Session can remain inactive
|
||||
* before it is considered expired.
|
||||
*/
|
||||
public static final int DEFAULT_MAX_INACTIVE_INTERVAL_IN_SECONDS = (int) TimeUnit.MINUTES
|
||||
.toSeconds(30);
|
||||
public static final int DEFAULT_MAX_INACTIVE_INTERVAL_IN_SECONDS =
|
||||
(int) TimeUnit.MINUTES.toSeconds(30);
|
||||
|
||||
protected static final Class<Object> SPRING_SESSION_GEMFIRE_REGION_KEY_CONSTRAINT = Object.class;
|
||||
protected static final Class<GemFireSession> SPRING_SESSION_GEMFIRE_REGION_VALUE_CONSTRAINT = GemFireSession.class;
|
||||
@@ -152,7 +152,7 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
|
||||
*/
|
||||
protected ClientRegionShortcut getClientRegionShortcut() {
|
||||
return (this.clientRegionShortcut != null ? this.clientRegionShortcut
|
||||
: DEFAULT_CLIENT_REGION_SHORTCUT);
|
||||
: DEFAULT_CLIENT_REGION_SHORTCUT);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -175,7 +175,7 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
|
||||
*/
|
||||
protected String[] getIndexableSessionAttributes() {
|
||||
return (this.indexableSessionAttributes != null ? this.indexableSessionAttributes
|
||||
: DEFAULT_INDEXABLE_SESSION_ATTRIBUTES);
|
||||
: DEFAULT_INDEXABLE_SESSION_ATTRIBUTES);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,7 +245,7 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
|
||||
*/
|
||||
protected RegionShortcut getServerRegionShortcut() {
|
||||
return (this.serverRegionShortcut != null ? this.serverRegionShortcut
|
||||
: DEFAULT_SERVER_REGION_SHORTCUT);
|
||||
: DEFAULT_SERVER_REGION_SHORTCUT);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,8 +269,8 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
|
||||
*/
|
||||
protected String getSpringSessionGemFireRegionName() {
|
||||
return (StringUtils.hasText(this.springSessionGemFireRegionName)
|
||||
? this.springSessionGemFireRegionName
|
||||
: DEFAULT_SPRING_SESSION_GEMFIRE_REGION_NAME);
|
||||
? this.springSessionGemFireRegionName
|
||||
: DEFAULT_SPRING_SESSION_GEMFIRE_REGION_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -281,26 +281,24 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
|
||||
* this @Configuration class.
|
||||
*/
|
||||
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
||||
AnnotationAttributes enableGemFireHttpSessionAnnotationAttributes = AnnotationAttributes
|
||||
.fromMap(importMetadata.getAnnotationAttributes(
|
||||
EnableGemFireHttpSession.class.getName()));
|
||||
AnnotationAttributes enableGemFireHttpSessionAnnotationAttributes =
|
||||
AnnotationAttributes.fromMap(importMetadata.getAnnotationAttributes(
|
||||
EnableGemFireHttpSession.class.getName()));
|
||||
|
||||
setClientRegionShortcut(ClientRegionShortcut.class
|
||||
.cast(enableGemFireHttpSessionAnnotationAttributes
|
||||
.getEnum("clientRegionShortcut")));
|
||||
setClientRegionShortcut(ClientRegionShortcut.class.cast(
|
||||
enableGemFireHttpSessionAnnotationAttributes.getEnum("clientRegionShortcut")));
|
||||
|
||||
setIndexableSessionAttributes(enableGemFireHttpSessionAnnotationAttributes
|
||||
.getStringArray("indexableSessionAttributes"));
|
||||
.getStringArray("indexableSessionAttributes"));
|
||||
|
||||
setMaxInactiveIntervalInSeconds(enableGemFireHttpSessionAnnotationAttributes
|
||||
.getNumber("maxInactiveIntervalInSeconds").intValue());
|
||||
.getNumber("maxInactiveIntervalInSeconds").intValue());
|
||||
|
||||
setServerRegionShortcut(
|
||||
RegionShortcut.class.cast(enableGemFireHttpSessionAnnotationAttributes
|
||||
.getEnum("serverRegionShortcut")));
|
||||
setServerRegionShortcut(RegionShortcut.class.cast(
|
||||
enableGemFireHttpSessionAnnotationAttributes.getEnum("serverRegionShortcut")));
|
||||
|
||||
setSpringSessionGemFireRegionName(
|
||||
enableGemFireHttpSessionAnnotationAttributes.getString("regionName"));
|
||||
enableGemFireHttpSessionAnnotationAttributes.getString("regionName"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -316,11 +314,11 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
|
||||
public GemFireOperationsSessionRepository sessionRepository(
|
||||
@Qualifier("sessionRegionTemplate") GemfireOperations gemfireOperations) {
|
||||
|
||||
GemFireOperationsSessionRepository sessionRepository = new GemFireOperationsSessionRepository(
|
||||
gemfireOperations);
|
||||
GemFireOperationsSessionRepository sessionRepository =
|
||||
new GemFireOperationsSessionRepository(gemfireOperations);
|
||||
|
||||
sessionRepository
|
||||
.setMaxInactiveIntervalInSeconds(getMaxInactiveIntervalInSeconds());
|
||||
sessionRepository.setMaxInactiveIntervalInSeconds(
|
||||
getMaxInactiveIntervalInSeconds());
|
||||
|
||||
return sessionRepository;
|
||||
}
|
||||
@@ -339,8 +337,8 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
|
||||
@Bean
|
||||
@DependsOn(DEFAULT_SPRING_SESSION_GEMFIRE_REGION_NAME)
|
||||
public GemfireTemplate sessionRegionTemplate(GemFireCache gemFireCache) {
|
||||
return new GemfireTemplate(
|
||||
gemFireCache.getRegion(getSpringSessionGemFireRegionName()));
|
||||
return new GemfireTemplate(gemFireCache.getRegion(
|
||||
getSpringSessionGemFireRegionName()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -363,7 +361,8 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
|
||||
GemFireCache gemfireCache,
|
||||
RegionAttributes<Object, ExpiringSession> sessionRegionAttributes) {
|
||||
|
||||
GemFireCacheTypeAwareRegionFactoryBean<Object, ExpiringSession> serverRegion = new GemFireCacheTypeAwareRegionFactoryBean<Object, ExpiringSession>();
|
||||
GemFireCacheTypeAwareRegionFactoryBean<Object, ExpiringSession> serverRegion =
|
||||
new GemFireCacheTypeAwareRegionFactoryBean<Object, ExpiringSession>();
|
||||
|
||||
serverRegion.setGemfireCache(gemfireCache);
|
||||
serverRegion.setClientRegionShortcut(getClientRegionShortcut());
|
||||
@@ -390,19 +389,18 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
|
||||
*/
|
||||
@Bean
|
||||
@SuppressWarnings({ "unchecked", "deprecation" })
|
||||
public RegionAttributesFactoryBean sessionRegionAttributes(
|
||||
GemFireCache gemfireCache) {
|
||||
public RegionAttributesFactoryBean sessionRegionAttributes(GemFireCache gemfireCache) {
|
||||
|
||||
RegionAttributesFactoryBean regionAttributes = new RegionAttributesFactoryBean();
|
||||
|
||||
regionAttributes.setKeyConstraint(SPRING_SESSION_GEMFIRE_REGION_KEY_CONSTRAINT);
|
||||
regionAttributes
|
||||
.setValueConstraint(SPRING_SESSION_GEMFIRE_REGION_VALUE_CONSTRAINT);
|
||||
regionAttributes.setValueConstraint(SPRING_SESSION_GEMFIRE_REGION_VALUE_CONSTRAINT);
|
||||
|
||||
if (isExpirationAllowed(gemfireCache)) {
|
||||
regionAttributes.setStatisticsEnabled(true);
|
||||
regionAttributes.setEntryIdleTimeout(new ExpirationAttributes(
|
||||
Math.max(getMaxInactiveIntervalInSeconds(), 0),
|
||||
ExpirationAction.INVALIDATE));
|
||||
Math.max(getMaxInactiveIntervalInSeconds(), 0),
|
||||
ExpirationAction.INVALIDATE));
|
||||
}
|
||||
|
||||
return regionAttributes;
|
||||
@@ -421,8 +419,8 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
|
||||
*/
|
||||
boolean isExpirationAllowed(GemFireCache gemfireCache) {
|
||||
return !(GemFireUtils.isClient(gemfireCache)
|
||||
? GemFireUtils.isProxy(getClientRegionShortcut())
|
||||
: GemFireUtils.isProxy(getServerRegionShortcut()));
|
||||
? GemFireUtils.isProxy(getClientRegionShortcut())
|
||||
: GemFireUtils.isProxy(getServerRegionShortcut()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -486,9 +484,9 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
|
||||
index.setCache(gemfireCache);
|
||||
index.setName("sessionAttributesIndex");
|
||||
index.setExpression(String.format("s.attributes[%1$s]",
|
||||
getIndexableSessionAttributesAsGemFireIndexExpression()));
|
||||
getIndexableSessionAttributesAsGemFireIndexExpression()));
|
||||
index.setFrom(String.format("%1$s s",
|
||||
GemFireUtils.toRegionPath(getSpringSessionGemFireRegionName())));
|
||||
GemFireUtils.toRegionPath(getSpringSessionGemFireRegionName())));
|
||||
index.setOverride(true);
|
||||
|
||||
return index;
|
||||
|
||||
@@ -23,6 +23,8 @@ import com.gemstone.gemfire.cache.RegionAttributes;
|
||||
import com.gemstone.gemfire.cache.RegionShortcut;
|
||||
import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.data.gemfire.GenericRegionFactoryBean;
|
||||
@@ -43,9 +45,12 @@ import org.springframework.util.StringUtils;
|
||||
* @author John Blum
|
||||
* @since 1.1.0
|
||||
* @see org.springframework.data.gemfire.GenericRegionFactoryBean
|
||||
* @see org.springframework.beans.factory.BeanFactoryAware
|
||||
* @see org.springframework.beans.factory.FactoryBean
|
||||
* @see org.springframework.beans.factory.InitializingBean
|
||||
*/
|
||||
public class GemFireCacheTypeAwareRegionFactoryBean<K, V>
|
||||
implements FactoryBean<Region<K, V>>, InitializingBean {
|
||||
implements BeanFactoryAware, FactoryBean<Region<K, V>>, InitializingBean {
|
||||
|
||||
protected static final ClientRegionShortcut DEFAULT_CLIENT_REGION_SHORTCUT = GemFireHttpSessionConfiguration.DEFAULT_CLIENT_REGION_SHORTCUT;
|
||||
|
||||
@@ -53,6 +58,8 @@ public class GemFireCacheTypeAwareRegionFactoryBean<K, V>
|
||||
|
||||
protected static final String DEFAULT_SPRING_SESSION_GEMFIRE_REGION_NAME = GemFireHttpSessionConfiguration.DEFAULT_SPRING_SESSION_GEMFIRE_REGION_NAME;
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
private ClientRegionShortcut clientRegionShortcut;
|
||||
|
||||
private GemFireCache gemfireCache;
|
||||
@@ -138,6 +145,7 @@ public class GemFireCacheTypeAwareRegionFactoryBean<K, V>
|
||||
|
||||
ClientRegionShortcut shortcut = getClientRegionShortcut();
|
||||
|
||||
clientRegion.setBeanFactory(getBeanFactory());
|
||||
clientRegion.setCache(gemfireCache);
|
||||
clientRegion.setAttributes(getRegionAttributes());
|
||||
clientRegion.setInterests(registerInterests(!GemFireUtils.isLocal(shortcut)));
|
||||
@@ -206,6 +214,36 @@ public class GemFireCacheTypeAwareRegionFactoryBean<K, V>
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a reference to the Spring {@link BeanFactory} responsible for
|
||||
* creating GemFire components.
|
||||
*
|
||||
* @param beanFactory reference to the Spring {@link BeanFactory}
|
||||
* @see org.springframework.beans.factory.BeanFactory
|
||||
* @throws IllegalArgumentException if the {@link BeanFactory} reference
|
||||
* is null.
|
||||
*/
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
Assert.notNull(beanFactory, "BeanFactory must not be null");
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a reference to the Spring {@link BeanFactory} responsible for
|
||||
* creating GemFire components.
|
||||
*
|
||||
* @return a reference to the Spring {@link BeanFactory}
|
||||
* @throws IllegalStateException if the {@link BeanFactory} reference
|
||||
* is null.
|
||||
* @see org.springframework.beans.factory.BeanFactory
|
||||
*/
|
||||
protected BeanFactory getBeanFactory() {
|
||||
Assert.state(this.beanFactory != null,
|
||||
"A reference to the BeanFactory was not properly configured");
|
||||
return this.beanFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link Region} data policy used by the GemFire cache client to manage
|
||||
* Session state.
|
||||
@@ -240,7 +278,7 @@ public class GemFireCacheTypeAwareRegionFactoryBean<K, V>
|
||||
* @throws IllegalArgumentException if the {@link GemFireCache} reference is null.
|
||||
*/
|
||||
public void setGemfireCache(GemFireCache gemfireCache) {
|
||||
Assert.notNull(gemfireCache, "The GemFireCache reference must not be null");
|
||||
Assert.notNull(gemfireCache, "GemFireCache must not be null");
|
||||
this.gemfireCache = gemfireCache;
|
||||
}
|
||||
|
||||
@@ -253,7 +291,7 @@ public class GemFireCacheTypeAwareRegionFactoryBean<K, V>
|
||||
*/
|
||||
protected GemFireCache getGemfireCache() {
|
||||
Assert.state(this.gemfireCache != null,
|
||||
"A reference to a GemFireCache was not properly configured");
|
||||
"A reference to the GemFireCache was not properly configured");
|
||||
return this.gemfireCache;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.data.gemfire.client.Interest;
|
||||
import org.springframework.session.ExpiringSession;
|
||||
|
||||
@@ -47,6 +48,7 @@ import static org.mockito.Mockito.mock;
|
||||
* @since 1.1.0
|
||||
* @see org.junit.Rule
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.rules.ExpectedException
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.support.
|
||||
* GemFireCacheTypeAwareRegionFactoryBean
|
||||
@@ -63,14 +65,16 @@ import static org.mockito.Mockito.mock;
|
||||
public class GemFireCacheTypeAwareRegionFactoryBeanTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Mock
|
||||
ClientCache mockClientCache;
|
||||
|
||||
@Mock
|
||||
Region<Object, ExpiringSession> mockClientRegion;
|
||||
|
||||
@Mock
|
||||
Region<Object, ExpiringSession> mockServerRegion;
|
||||
@Mock
|
||||
ClientCache mockClientCache;
|
||||
|
||||
private GemFireCacheTypeAwareRegionFactoryBean<Object, ExpiringSession> regionFactoryBean;
|
||||
|
||||
@@ -164,13 +168,37 @@ public class GemFireCacheTypeAwareRegionFactoryBeanTest {
|
||||
assertThat(this.regionFactoryBean.isSingleton()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAndGetBeanFactory() {
|
||||
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||
|
||||
this.regionFactoryBean.setBeanFactory(mockBeanFactory);
|
||||
|
||||
assertThat(this.regionFactoryBean.getBeanFactory()).isEqualTo(mockBeanFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBeanFactoryToNullThrowsIllegalArgumentException() {
|
||||
this.exception.expect(IllegalArgumentException.class);
|
||||
this.exception.expectMessage("BeanFactory must not be null");
|
||||
this.regionFactoryBean.setBeanFactory(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanFactoryWhenNullThrowsIllegalStateException() {
|
||||
this.exception.expect(IllegalStateException.class);
|
||||
this.exception.expectMessage(
|
||||
"A reference to the BeanFactory was not properly configured");
|
||||
this.regionFactoryBean.getBeanFactory();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAndGetClientRegionShortcut() {
|
||||
assertThat(this.regionFactoryBean.getClientRegionShortcut()).isEqualTo(
|
||||
GemFireCacheTypeAwareRegionFactoryBean.DEFAULT_CLIENT_REGION_SHORTCUT);
|
||||
|
||||
this.regionFactoryBean
|
||||
.setClientRegionShortcut(ClientRegionShortcut.LOCAL_PERSISTENT);
|
||||
this.regionFactoryBean.setClientRegionShortcut(
|
||||
ClientRegionShortcut.LOCAL_PERSISTENT);
|
||||
|
||||
assertThat(this.regionFactoryBean.getClientRegionShortcut())
|
||||
.isEqualTo(ClientRegionShortcut.LOCAL_PERSISTENT);
|
||||
@@ -192,17 +220,16 @@ public class GemFireCacheTypeAwareRegionFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void setGemfireCacheToNullThrowsIllegalArgumentException() {
|
||||
this.expectedException.expect(IllegalArgumentException.class);
|
||||
this.expectedException
|
||||
.expectMessage("The GemFireCache reference must not be null");
|
||||
this.exception.expect(IllegalArgumentException.class);
|
||||
this.exception.expectMessage("GemFireCache must not be null");
|
||||
this.regionFactoryBean.setGemfireCache(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getGemfireCacheWhenNullThrowsIllegalStateException() {
|
||||
this.expectedException.expect(IllegalStateException.class);
|
||||
this.expectedException.expectMessage(
|
||||
"A reference to a GemFireCache was not properly configured");
|
||||
this.exception.expect(IllegalStateException.class);
|
||||
this.exception.expectMessage(
|
||||
"A reference to the GemFireCache was not properly configured");
|
||||
this.regionFactoryBean.getGemfireCache();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user