Refactor and Simplify Interest Registration.
Resolves gh-6. Resolves gh-7.
This commit is contained in:
@@ -75,8 +75,8 @@ import org.springframework.session.Session;
|
||||
import org.springframework.session.SessionRepository;
|
||||
import org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepository.GemFireSession;
|
||||
import org.springframework.session.data.gemfire.GemFireOperationsSessionRepository;
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.support.GemFireCacheTypeAwareRegionFactoryBean;
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.support.SessionAttributesIndexFactoryBean;
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.support.SessionCacheTypeAwareRegionFactoryBean;
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.support.SpringSessionGemFireConfigurer;
|
||||
import org.springframework.session.data.gemfire.expiration.SessionExpirationPolicy;
|
||||
import org.springframework.session.data.gemfire.expiration.config.SessionExpirationTimeoutAwareBeanPostProcessor;
|
||||
@@ -127,7 +127,7 @@ import org.springframework.util.StringUtils;
|
||||
* @see org.springframework.session.data.gemfire.GemFireOperationsSessionRepository
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.AbstractGemFireHttpSessionConfiguration
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.support.GemFireCacheTypeAwareRegionFactoryBean
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.support.SessionCacheTypeAwareRegionFactoryBean
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.support.SessionAttributesIndexFactoryBean
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.support.SpringSessionGemFireConfigurer
|
||||
* @see org.springframework.session.data.gemfire.expiration.SessionExpirationPolicy
|
||||
@@ -982,7 +982,7 @@ public class GemFireHttpSessionConfiguration extends AbstractGemFireHttpSessionC
|
||||
*
|
||||
* @param gemfireCache reference to the {@link GemFireCache}.
|
||||
* @param sessionRegionAttributes {@link RegionAttributes} used to configure the {@link Region}.
|
||||
* @return a {@link GemFireCacheTypeAwareRegionFactoryBean} used to configure and initialize
|
||||
* @return a {@link SessionCacheTypeAwareRegionFactoryBean} used to configure and initialize
|
||||
* the cache {@link Region} used to store and manage {@link Session} state.
|
||||
* @see org.apache.geode.cache.GemFireCache
|
||||
* @see org.apache.geode.cache.RegionAttributes
|
||||
@@ -992,11 +992,11 @@ public class GemFireHttpSessionConfiguration extends AbstractGemFireHttpSessionC
|
||||
* @see #getSessionRegionName()
|
||||
*/
|
||||
@Bean(name = DEFAULT_SESSION_REGION_NAME)
|
||||
public GemFireCacheTypeAwareRegionFactoryBean<Object, Session> sessionRegion(GemFireCache gemfireCache,
|
||||
public SessionCacheTypeAwareRegionFactoryBean<Object, Session> sessionRegion(GemFireCache gemfireCache,
|
||||
@Qualifier("sessionRegionAttributes") RegionAttributes<Object, Session> sessionRegionAttributes) {
|
||||
|
||||
GemFireCacheTypeAwareRegionFactoryBean<Object, Session> sessionRegion =
|
||||
new GemFireCacheTypeAwareRegionFactoryBean<>();
|
||||
SessionCacheTypeAwareRegionFactoryBean<Object, Session> sessionRegion =
|
||||
new SessionCacheTypeAwareRegionFactoryBean<>();
|
||||
|
||||
sessionRegion.setAttributes(sessionRegionAttributes);
|
||||
sessionRegion.setCache(gemfireCache);
|
||||
|
||||
@@ -19,23 +19,20 @@ package org.springframework.session.data.gemfire.config.annotation.web.http.supp
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.geode.cache.Cache;
|
||||
import org.apache.geode.cache.InterestResultPolicy;
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.RegionAttributes;
|
||||
import org.apache.geode.cache.RegionShortcut;
|
||||
import org.apache.geode.cache.client.ClientCache;
|
||||
import org.apache.geode.cache.client.ClientRegionShortcut;
|
||||
import org.apache.geode.cache.client.Pool;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.data.gemfire.client.Interest;
|
||||
import org.springframework.data.gemfire.config.annotation.support.CacheTypeAwareRegionFactoryBean;
|
||||
import org.springframework.session.Session;
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration;
|
||||
import org.springframework.session.data.gemfire.support.GemFireUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* The {@link GemFireCacheTypeAwareRegionFactoryBean} class is a Spring {@link FactoryBean} used to construct,
|
||||
* The {@link SessionCacheTypeAwareRegionFactoryBean} class is a Spring {@link FactoryBean} used to construct,
|
||||
* configure and initialize the Apache Geode/Pivotal GemFire cache {@link Region} used to store and manage
|
||||
* Session state.
|
||||
*
|
||||
@@ -57,7 +54,7 @@ import org.springframework.util.StringUtils;
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration
|
||||
* @since 1.1.0
|
||||
*/
|
||||
public class GemFireCacheTypeAwareRegionFactoryBean<K, V> extends CacheTypeAwareRegionFactoryBean<K, V> {
|
||||
public class SessionCacheTypeAwareRegionFactoryBean<K, V> extends CacheTypeAwareRegionFactoryBean<K, V> {
|
||||
|
||||
protected static final ClientRegionShortcut DEFAULT_CLIENT_REGION_SHORTCUT =
|
||||
GemFireHttpSessionConfiguration.DEFAULT_CLIENT_REGION_SHORTCUT;
|
||||
@@ -73,39 +70,21 @@ public class GemFireCacheTypeAwareRegionFactoryBean<K, V> extends CacheTypeAware
|
||||
|
||||
private String regionName;
|
||||
|
||||
@Override
|
||||
public void setClientRegionShortcut(ClientRegionShortcut clientRegionShortcut) {
|
||||
super.setClientRegionShortcut(clientRegionShortcut != null ? clientRegionShortcut
|
||||
: DEFAULT_CLIENT_REGION_SHORTCUT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link Region} data management policy used by the Apache Geode/Pivotal GemFire {@link ClientCache}
|
||||
* to manage {@link Session} state.
|
||||
*
|
||||
* Defaults to {@link ClientRegionShortcut#PROXY}.
|
||||
*
|
||||
* @return a {@link ClientRegionShortcut} specifying the client {@link Region} data management policy
|
||||
* used to manage {@link Session} state.
|
||||
* @see org.apache.geode.cache.client.ClientRegionShortcut
|
||||
*/
|
||||
@Override
|
||||
public ClientRegionShortcut getClientRegionShortcut() {
|
||||
return super.getClientRegionShortcut();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Interest<K>[] getInterests() {
|
||||
|
||||
ClientRegionShortcut clientRegionShortcut = getClientRegionShortcut();
|
||||
|
||||
return registerInterests(!(clientRegionShortcut == null || GemFireUtils.isLocal(clientRegionShortcut)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Decides whether interests will be registered for all keys. Interests is only registered on
|
||||
* a client and typically only when the client is a (CACHING) PROXY to the server (i.e. non-LOCAL only).
|
||||
*
|
||||
* @param register a boolean value indicating whether interests should be registered.
|
||||
* @return an array of Interests KEY/VALUE registrations.
|
||||
* @see org.springframework.data.gemfire.client.Interest
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Interest<K>[] registerInterests(boolean register) {
|
||||
|
||||
return register
|
||||
? new Interest[] { new Interest<>("ALL_KEYS", InterestResultPolicy.KEYS) }
|
||||
: new Interest[0];
|
||||
return Optional.ofNullable(super.getClientRegionShortcut())
|
||||
.orElse(DEFAULT_CLIENT_REGION_SHORTCUT);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,34 +99,6 @@ public class GemFireCacheTypeAwareRegionFactoryBean<K, V> extends CacheTypeAware
|
||||
return Optional.of(super.getPoolName().orElse(DEFAULT_POOL_NAME));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Pivotal GemFire {@link RegionAttributes} used to configure the Pivotal GemFire cache
|
||||
* {@link Region} used to store and manage Session state.
|
||||
*
|
||||
* @param regionAttributes the Pivotal GemFire {@link RegionAttributes} used to configure the
|
||||
* Pivotal GemFire cache {@link Region}.
|
||||
* @see org.apache.geode.cache.RegionAttributes
|
||||
* @deprecated use {@link #setAttributes(RegionAttributes)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setRegionAttributes(RegionAttributes<K, V> regionAttributes) {
|
||||
setAttributes(regionAttributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Pivotal GemFire {@link RegionAttributes} used to configure the Pivotal GemFire cache
|
||||
* {@link Region} used to store and manage Session state.
|
||||
*
|
||||
* @return the Pivotal GemFire {@link RegionAttributes} used to configure the Pivotal GemFire cache
|
||||
* {@link Region}.
|
||||
* @see org.apache.geode.cache.RegionAttributes
|
||||
* @deprecated use {@link #getAttributes()}.
|
||||
*/
|
||||
@Deprecated
|
||||
protected RegionAttributes<K, V> getRegionAttributes() {
|
||||
return getAttributes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link String name} of the {@link Region} used to store and manage {@link Session} state.
|
||||
*
|
||||
@@ -168,25 +119,37 @@ public class GemFireCacheTypeAwareRegionFactoryBean<K, V> extends CacheTypeAware
|
||||
* @see org.apache.geode.cache.Region#getName()
|
||||
*/
|
||||
protected String getRegionName() {
|
||||
return Optional.ofNullable(this.regionName).filter(StringUtils::hasText).orElse(DEFAULT_SESSION_REGION_NAME);
|
||||
|
||||
return Optional.ofNullable(this.regionName)
|
||||
.filter(StringUtils::hasText)
|
||||
.orElse(DEFAULT_SESSION_REGION_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the {@link String name} of the {@link Region} used to manage {@link Session} state.
|
||||
*
|
||||
* @return the {@link String name} of the {@link Region} used to manage {@link Session} state.
|
||||
* @see #getRegionName()
|
||||
*/
|
||||
@Override
|
||||
public String resolveRegionName() {
|
||||
return getRegionName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link Region} data policy used by the Apache Geode/Pivotal GemFire peer {@link Cache}
|
||||
* Returns the {@link Region} data management policy used by the Apache Geode/Pivotal GemFire peer {@link Cache}
|
||||
* to manage {@link Session} state.
|
||||
*
|
||||
* Defaults to {@link RegionShortcut#PARTITION}.
|
||||
*
|
||||
* @return a {@link RegionShortcut} specifying the peer {@link Region} data management policy.
|
||||
* @return a {@link RegionShortcut} specifying the peer {@link Region} data management policy
|
||||
* to manage {@link Session} state.
|
||||
* @see org.apache.geode.cache.RegionShortcut
|
||||
*/
|
||||
@Override
|
||||
public RegionShortcut getServerRegionShortcut() {
|
||||
return Optional.ofNullable(super.getServerRegionShortcut()).orElse(DEFAULT_SERVER_REGION_SHORTCUT);
|
||||
|
||||
return Optional.ofNullable(super.getServerRegionShortcut())
|
||||
.orElse(DEFAULT_SERVER_REGION_SHORTCUT);
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,7 @@ import org.springframework.data.gemfire.RegionAttributesFactoryBean;
|
||||
import org.springframework.data.gemfire.util.ArrayUtils;
|
||||
import org.springframework.session.Session;
|
||||
import org.springframework.session.data.gemfire.GemFireOperationsSessionRepository;
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.support.GemFireCacheTypeAwareRegionFactoryBean;
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.support.SessionCacheTypeAwareRegionFactoryBean;
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.support.SpringSessionGemFireConfigurer;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
@@ -726,7 +726,7 @@ public class GemFireHttpSessionConfigurationTests {
|
||||
this.gemfireConfiguration.setServerRegionShortcut(RegionShortcut.PARTITION_REDUNDANT);
|
||||
this.gemfireConfiguration.setSessionRegionName("TestRegion");
|
||||
|
||||
GemFireCacheTypeAwareRegionFactoryBean<Object, Session> sessionRegionFactoryBean =
|
||||
SessionCacheTypeAwareRegionFactoryBean<Object, Session> sessionRegionFactoryBean =
|
||||
this.gemfireConfiguration.sessionRegion(mockGemFireCache, mockRegionAttributes);
|
||||
|
||||
assertThat(sessionRegionFactoryBean).isNotNull();
|
||||
|
||||
@@ -19,8 +19,6 @@ package org.springframework.session.data.gemfire.config.annotation.web.http.supp
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -29,41 +27,32 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.apache.geode.cache.Cache;
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.InterestResultPolicy;
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.RegionAttributes;
|
||||
import org.apache.geode.cache.RegionShortcut;
|
||||
import org.apache.geode.cache.client.ClientCache;
|
||||
import org.apache.geode.cache.client.ClientRegionShortcut;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.data.gemfire.client.ClientRegionShortcutWrapper;
|
||||
import org.springframework.data.gemfire.client.Interest;
|
||||
import org.springframework.session.Session;
|
||||
|
||||
/**
|
||||
* The GemFireCacheTypeAwareRegionFactoryBeanTests class is a test suite of test cases
|
||||
* testing the contract and functionality of the GemFireCacheTypeAwareRegionFactoryBean
|
||||
* class.
|
||||
* Unit tests for {@link SessionCacheTypeAwareRegionFactoryBean}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @since 1.1.0
|
||||
* @see org.junit.Rule
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.rules.ExpectedException
|
||||
* @see org.mockito.Mock
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.support.GemFireCacheTypeAwareRegionFactoryBean
|
||||
* @see org.apache.geode.cache.Cache
|
||||
* @see org.apache.geode.cache.GemFireCache
|
||||
* @see org.apache.geode.cache.InterestResultPolicy
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.apache.geode.cache.RegionAttributes
|
||||
* @see org.apache.geode.cache.RegionShortcut
|
||||
* @see org.apache.geode.cache.client.ClientCache
|
||||
* @see org.apache.geode.cache.client.ClientRegionShortcut
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.support.SessionCacheTypeAwareRegionFactoryBean
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class GemFireCacheTypeAwareRegionFactoryBeanTests {
|
||||
public class SessionCacheTypeAwareRegionFactoryBeanTests {
|
||||
|
||||
@Mock
|
||||
Cache mockCache;
|
||||
@@ -77,28 +66,28 @@ public class GemFireCacheTypeAwareRegionFactoryBeanTests {
|
||||
@Mock
|
||||
Region<Object, Session> mockServerRegion;
|
||||
|
||||
private GemFireCacheTypeAwareRegionFactoryBean<Object, Session> regionFactoryBean;
|
||||
private SessionCacheTypeAwareRegionFactoryBean<Object, Session> regionFactoryBean;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.regionFactoryBean = new GemFireCacheTypeAwareRegionFactoryBean<>();
|
||||
this.regionFactoryBean = new SessionCacheTypeAwareRegionFactoryBean<>();
|
||||
}
|
||||
|
||||
protected void afterPropertiesSetCreatesCorrectRegionForGemFireCacheType(GemFireCache expectedCache,
|
||||
private void testAfterPropertiesSetCreatesCorrectRegionForGemFireCacheType(GemFireCache expectedCache,
|
||||
Region<Object, Session> expectedRegion) throws Exception {
|
||||
|
||||
this.regionFactoryBean = new GemFireCacheTypeAwareRegionFactoryBean<Object, Session>() {
|
||||
this.regionFactoryBean = new SessionCacheTypeAwareRegionFactoryBean<Object, Session>() {
|
||||
|
||||
@Override
|
||||
protected Region<Object, Session> newClientRegion(GemFireCache gemfireCache, String name) throws Exception {
|
||||
assertThat(gemfireCache).isSameAs(expectedCache);
|
||||
return GemFireCacheTypeAwareRegionFactoryBeanTests.this.mockClientRegion;
|
||||
return SessionCacheTypeAwareRegionFactoryBeanTests.this.mockClientRegion;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Region<Object, Session> newServerRegion(GemFireCache gemfireCache, String name) throws Exception {
|
||||
assertThat(gemfireCache).isSameAs(expectedCache);
|
||||
return GemFireCacheTypeAwareRegionFactoryBeanTests.this.mockServerRegion;
|
||||
return SessionCacheTypeAwareRegionFactoryBeanTests.this.mockServerRegion;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -112,76 +101,12 @@ public class GemFireCacheTypeAwareRegionFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void afterPropertiesSetCreatesClientRegionForClientCache() throws Exception {
|
||||
afterPropertiesSetCreatesCorrectRegionForGemFireCacheType(this.mockClientCache, this.mockClientRegion);
|
||||
testAfterPropertiesSetCreatesCorrectRegionForGemFireCacheType(this.mockClientCache, this.mockClientRegion);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void afterPropertiesSetCreatesServerRegionForPeerCache() throws Exception {
|
||||
afterPropertiesSetCreatesCorrectRegionForGemFireCacheType(this.mockCache, this.mockServerRegion);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allKeysInterestsRegistration() {
|
||||
|
||||
Interest<Object>[] interests = this.regionFactoryBean.registerInterests(true);
|
||||
|
||||
assertThat(interests).isNotNull();
|
||||
assertThat(interests.length).isEqualTo(1);
|
||||
assertThat(interests[0].isDurable()).isFalse();
|
||||
assertThat(interests[0].getKey().toString()).isEqualTo("ALL_KEYS");
|
||||
assertThat(interests[0].getPolicy()).isEqualTo(InterestResultPolicy.KEYS);
|
||||
assertThat(interests[0].isReceiveValues()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyInterestsRegistration() {
|
||||
|
||||
Interest<Object>[] interests = this.regionFactoryBean.registerInterests(false);
|
||||
|
||||
assertThat(interests).isNotNull();
|
||||
assertThat(interests).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getInterestsWhenClientRegionShortcutIsNotLocalReturnsAllKeys() {
|
||||
|
||||
Arrays.stream(ClientRegionShortcut.values())
|
||||
.filter(clientRegionShortcut -> !clientRegionShortcut.name().contains("LOCAL"))
|
||||
.forEach(clientRegionShortcut -> {
|
||||
|
||||
this.regionFactoryBean.setClientRegionShortcut(clientRegionShortcut);
|
||||
|
||||
assertThat(this.regionFactoryBean.getClientRegionShortcut()).isEqualTo(clientRegionShortcut);
|
||||
assertThat(ClientRegionShortcutWrapper.valueOf(clientRegionShortcut).isLocal()).isFalse();
|
||||
|
||||
Interest<Object>[] interests = this.regionFactoryBean.getInterests();
|
||||
|
||||
assertThat(interests).isNotNull();
|
||||
assertThat(interests).hasSize(1);
|
||||
assertThat(interests[0].isDurable()).isFalse();
|
||||
assertThat(interests[0].getKey().toString()).isEqualTo("ALL_KEYS");
|
||||
assertThat(interests[0].getPolicy()).isEqualTo(InterestResultPolicy.KEYS);
|
||||
assertThat(interests[0].isReceiveValues()).isTrue();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getInterestsWhenClientRegionShortcutIsLocalReturnsNoKeys() {
|
||||
|
||||
Arrays.stream(ClientRegionShortcut.values())
|
||||
.filter(clientRegionShortcut -> clientRegionShortcut.name().contains("LOCAL"))
|
||||
.forEach(clientRegionShortcut -> {
|
||||
|
||||
this.regionFactoryBean.setClientRegionShortcut(clientRegionShortcut);
|
||||
|
||||
assertThat(this.regionFactoryBean.getClientRegionShortcut()).isEqualTo(clientRegionShortcut);
|
||||
assertThat(ClientRegionShortcutWrapper.valueOf(clientRegionShortcut).isLocal()).isTrue();
|
||||
|
||||
Interest<Object>[] interests = this.regionFactoryBean.getInterests();
|
||||
|
||||
assertThat(interests).isNotNull();
|
||||
assertThat(interests).isEmpty();
|
||||
});
|
||||
testAfterPropertiesSetCreatesCorrectRegionForGemFireCacheType(this.mockCache, this.mockServerRegion);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -194,11 +119,34 @@ public class GemFireCacheTypeAwareRegionFactoryBeanTests {
|
||||
assertThat(this.regionFactoryBean.isSingleton()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAndGetBeanClassLoader() {
|
||||
|
||||
ClassLoader mockClassLoader = mock(ClassLoader.class);
|
||||
|
||||
assertThat(this.regionFactoryBean.getBeanClassLoader()).isNull();
|
||||
|
||||
this.regionFactoryBean.setBeanClassLoader(Thread.currentThread().getContextClassLoader());
|
||||
|
||||
assertThat(this.regionFactoryBean.getBeanClassLoader())
|
||||
.isEqualTo(Thread.currentThread().getContextClassLoader());
|
||||
|
||||
this.regionFactoryBean.setBeanClassLoader(mockClassLoader);
|
||||
|
||||
assertThat(this.regionFactoryBean.getBeanClassLoader()).isEqualTo(mockClassLoader);
|
||||
|
||||
this.regionFactoryBean.setBeanClassLoader(ClassLoader.getSystemClassLoader());
|
||||
|
||||
assertThat(this.regionFactoryBean.getBeanClassLoader()).isEqualTo(ClassLoader.getSystemClassLoader());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAndGetBeanFactory() {
|
||||
|
||||
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||
|
||||
assertThat(this.regionFactoryBean.getBeanFactory()).isNull();
|
||||
|
||||
this.regionFactoryBean.setBeanFactory(mockBeanFactory);
|
||||
|
||||
assertThat(this.regionFactoryBean.getBeanFactory()).isEqualTo(mockBeanFactory);
|
||||
@@ -208,34 +156,42 @@ public class GemFireCacheTypeAwareRegionFactoryBeanTests {
|
||||
public void setAndGetClientRegionShortcut() {
|
||||
|
||||
assertThat(this.regionFactoryBean.getClientRegionShortcut())
|
||||
.isEqualTo(GemFireCacheTypeAwareRegionFactoryBean.DEFAULT_CLIENT_REGION_SHORTCUT);
|
||||
.isEqualTo(SessionCacheTypeAwareRegionFactoryBean.DEFAULT_CLIENT_REGION_SHORTCUT);
|
||||
|
||||
this.regionFactoryBean.setClientRegionShortcut(ClientRegionShortcut.LOCAL_PERSISTENT);
|
||||
|
||||
assertThat(this.regionFactoryBean.getClientRegionShortcut()).isEqualTo(
|
||||
ClientRegionShortcut.LOCAL_PERSISTENT);
|
||||
assertThat(this.regionFactoryBean.getClientRegionShortcut()).isEqualTo(ClientRegionShortcut.LOCAL_PERSISTENT);
|
||||
|
||||
this.regionFactoryBean.setClientRegionShortcut(null);
|
||||
|
||||
assertThat(this.regionFactoryBean.getClientRegionShortcut()).isEqualTo(
|
||||
GemFireCacheTypeAwareRegionFactoryBean.DEFAULT_CLIENT_REGION_SHORTCUT);
|
||||
assertThat(this.regionFactoryBean.getClientRegionShortcut())
|
||||
.isEqualTo(SessionCacheTypeAwareRegionFactoryBean.DEFAULT_CLIENT_REGION_SHORTCUT);
|
||||
|
||||
this.regionFactoryBean.setClientRegionShortcut(ClientRegionShortcut.CACHING_PROXY);
|
||||
|
||||
assertThat(this.regionFactoryBean.getClientRegionShortcut()).isEqualTo(ClientRegionShortcut.CACHING_PROXY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAndGetGemfireCache() {
|
||||
public void setAndGetGemFireCache() {
|
||||
|
||||
Cache mockCache = mock(Cache.class);
|
||||
ClientCache mockClientCache = mock(ClientCache.class);
|
||||
|
||||
this.regionFactoryBean.setCache(mockCache);
|
||||
|
||||
assertThat(this.regionFactoryBean.getCache()).isEqualTo(mockCache);
|
||||
|
||||
this.regionFactoryBean.setCache(mockClientCache);
|
||||
|
||||
assertThat(this.regionFactoryBean.getCache()).isEqualTo(mockClientCache);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAndGetPoolName() {
|
||||
|
||||
assertThat(this.regionFactoryBean.getPoolName().orElse(null))
|
||||
.isEqualTo(GemFireCacheTypeAwareRegionFactoryBean.DEFAULT_POOL_NAME);
|
||||
.isEqualTo(SessionCacheTypeAwareRegionFactoryBean.DEFAULT_POOL_NAME);
|
||||
|
||||
this.regionFactoryBean.setPoolName("TestPoolName");
|
||||
|
||||
@@ -244,41 +200,24 @@ public class GemFireCacheTypeAwareRegionFactoryBeanTests {
|
||||
this.regionFactoryBean.setPoolName(" ");
|
||||
|
||||
assertThat(this.regionFactoryBean.getPoolName().orElse(null))
|
||||
.isEqualTo(GemFireCacheTypeAwareRegionFactoryBean.DEFAULT_POOL_NAME);
|
||||
.isEqualTo(SessionCacheTypeAwareRegionFactoryBean.DEFAULT_POOL_NAME);
|
||||
|
||||
this.regionFactoryBean.setPoolName("");
|
||||
|
||||
assertThat(this.regionFactoryBean.getPoolName().orElse(null))
|
||||
.isEqualTo(GemFireCacheTypeAwareRegionFactoryBean.DEFAULT_POOL_NAME);
|
||||
.isEqualTo(SessionCacheTypeAwareRegionFactoryBean.DEFAULT_POOL_NAME);
|
||||
|
||||
this.regionFactoryBean.setPoolName(null);
|
||||
|
||||
assertThat(this.regionFactoryBean.getPoolName().orElse(null))
|
||||
.isEqualTo(GemFireCacheTypeAwareRegionFactoryBean.DEFAULT_POOL_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||
public void setAndGetRegionAttributes() {
|
||||
|
||||
RegionAttributes<Object, Session> mockRegionAttributes = mock(RegionAttributes.class);
|
||||
|
||||
assertThat(this.regionFactoryBean.getRegionAttributes()).isNull();
|
||||
|
||||
this.regionFactoryBean.setRegionAttributes(mockRegionAttributes);
|
||||
|
||||
assertThat(this.regionFactoryBean.getRegionAttributes()).isSameAs(mockRegionAttributes);
|
||||
|
||||
this.regionFactoryBean.setRegionAttributes(null);
|
||||
|
||||
assertThat(this.regionFactoryBean.getRegionAttributes()).isNull();
|
||||
.isEqualTo(SessionCacheTypeAwareRegionFactoryBean.DEFAULT_POOL_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAndGetRegionName() {
|
||||
|
||||
assertThat(this.regionFactoryBean.getRegionName())
|
||||
.isEqualTo(GemFireCacheTypeAwareRegionFactoryBean.DEFAULT_SESSION_REGION_NAME);
|
||||
.isEqualTo(SessionCacheTypeAwareRegionFactoryBean.DEFAULT_SESSION_REGION_NAME);
|
||||
|
||||
this.regionFactoryBean.setRegionName("Example");
|
||||
|
||||
@@ -287,24 +226,24 @@ public class GemFireCacheTypeAwareRegionFactoryBeanTests {
|
||||
this.regionFactoryBean.setRegionName(" ");
|
||||
|
||||
assertThat(this.regionFactoryBean.getRegionName())
|
||||
.isEqualTo(GemFireCacheTypeAwareRegionFactoryBean.DEFAULT_SESSION_REGION_NAME);
|
||||
.isEqualTo(SessionCacheTypeAwareRegionFactoryBean.DEFAULT_SESSION_REGION_NAME);
|
||||
|
||||
this.regionFactoryBean.setRegionName("");
|
||||
|
||||
assertThat(this.regionFactoryBean.getRegionName())
|
||||
.isEqualTo(GemFireCacheTypeAwareRegionFactoryBean.DEFAULT_SESSION_REGION_NAME);
|
||||
.isEqualTo(SessionCacheTypeAwareRegionFactoryBean.DEFAULT_SESSION_REGION_NAME);
|
||||
|
||||
this.regionFactoryBean.setRegionName(null);
|
||||
|
||||
assertThat(this.regionFactoryBean.getRegionName())
|
||||
.isEqualTo(GemFireCacheTypeAwareRegionFactoryBean.DEFAULT_SESSION_REGION_NAME);
|
||||
.isEqualTo(SessionCacheTypeAwareRegionFactoryBean.DEFAULT_SESSION_REGION_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAndGetServerRegionShortcut() {
|
||||
|
||||
assertThat(this.regionFactoryBean.getServerRegionShortcut())
|
||||
.isEqualTo(GemFireCacheTypeAwareRegionFactoryBean.DEFAULT_SERVER_REGION_SHORTCUT);
|
||||
.isEqualTo(SessionCacheTypeAwareRegionFactoryBean.DEFAULT_SERVER_REGION_SHORTCUT);
|
||||
|
||||
this.regionFactoryBean.setServerRegionShortcut(RegionShortcut.LOCAL_PERSISTENT);
|
||||
|
||||
@@ -313,6 +252,10 @@ public class GemFireCacheTypeAwareRegionFactoryBeanTests {
|
||||
this.regionFactoryBean.setServerRegionShortcut(null);
|
||||
|
||||
assertThat(this.regionFactoryBean.getServerRegionShortcut())
|
||||
.isEqualTo(GemFireCacheTypeAwareRegionFactoryBean.DEFAULT_SERVER_REGION_SHORTCUT);
|
||||
.isEqualTo(SessionCacheTypeAwareRegionFactoryBean.DEFAULT_SERVER_REGION_SHORTCUT);
|
||||
|
||||
this.regionFactoryBean.setServerRegionShortcut(RegionShortcut.PARTITION_REDUNDANT);
|
||||
|
||||
assertThat(this.regionFactoryBean.getServerRegionShortcut()).isEqualTo(RegionShortcut.PARTITION_REDUNDANT);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user