Additional fixes for SGF-203 involving the persistent, data-policy and shortcut attributes of client Regions.
This commit is contained in:
@@ -15,12 +15,21 @@
|
||||
*/
|
||||
package org.springframework.data.gemfire.client;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.DataPolicy;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.client.ClientCache;
|
||||
import com.gemstone.gemfire.cache.client.ClientRegionFactory;
|
||||
@@ -29,36 +38,251 @@ import com.gemstone.gemfire.cache.client.Pool;
|
||||
|
||||
public class ClientRegionFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void testLookupFallbackFailingToUseProvidedShortcut()
|
||||
throws Exception {
|
||||
ClientRegionFactoryBean<Object, Object> fb = new ClientRegionFactoryBean<Object, Object>();
|
||||
fb.setShortcut(ClientRegionShortcut.CACHING_PROXY);
|
||||
|
||||
Pool pool = Mockito.mock(Pool.class);
|
||||
|
||||
BeanFactory beanFactory = Mockito.mock(BeanFactory.class);
|
||||
|
||||
Mockito.when(beanFactory.getBean(Pool.class)).thenReturn(pool);
|
||||
|
||||
fb.setBeanFactory(beanFactory);
|
||||
private ClientRegionFactoryBean<Object, Object> factoryBean;
|
||||
|
||||
String regionName = "regionName";
|
||||
ClientCache cache = Mockito.mock(ClientCache.class);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ClientRegionFactory<Object, Object> factory = Mockito
|
||||
.mock(ClientRegionFactory.class);
|
||||
Mockito.when(
|
||||
cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY))
|
||||
.thenReturn(factory);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Region<Object, Object> region = Mockito.mock(Region.class);
|
||||
Mockito.when(factory.create(regionName)).thenReturn(region);
|
||||
|
||||
Region<Object, Object> result = fb.lookupFallback(cache, regionName);
|
||||
|
||||
assertSame(region, result);
|
||||
@Before
|
||||
public void setup() {
|
||||
factoryBean = new ClientRegionFactoryBean<Object, Object>();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
factoryBean.destroy();
|
||||
factoryBean = null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testLookupFallbackFailingToUseProvidedShortcut() throws Exception {
|
||||
factoryBean.setShortcut(ClientRegionShortcut.CACHING_PROXY);
|
||||
|
||||
BeanFactory beanFactory = mock(BeanFactory.class);
|
||||
Pool pool = mock(Pool.class);
|
||||
|
||||
when(beanFactory.getBean(Pool.class)).thenReturn(pool);
|
||||
|
||||
factoryBean.setBeanFactory(beanFactory);
|
||||
|
||||
ClientCache cache = mock(ClientCache.class);
|
||||
ClientRegionFactory<Object, Object> clientRegionFactory = mock(ClientRegionFactory.class);
|
||||
Region<Object, Object> expectedRegion = mock(Region.class);
|
||||
|
||||
when(cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)).thenReturn(clientRegionFactory);
|
||||
when(clientRegionFactory.create("testRegion")).thenReturn(expectedRegion);
|
||||
|
||||
Region<Object, Object> actualRegion = factoryBean.lookupFallback(cache, "testRegion");
|
||||
|
||||
assertSame(expectedRegion, actualRegion);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetDataPolicyName() throws Exception {
|
||||
factoryBean.setDataPolicyName("NORMAL");
|
||||
assertEquals(DataPolicy.NORMAL, TestUtils.readField("dataPolicy", factoryBean));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetDataPolicyNameWithInvalidName() throws Exception {
|
||||
try {
|
||||
factoryBean.setDataPolicyName("INVALID");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("Data Policy 'INVALID' is invalid.", e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
assertNull(TestUtils.readField("dataPolicy", factoryBean));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsPersistent() {
|
||||
assertFalse(factoryBean.isPersistent());
|
||||
factoryBean.setPersistent(false);
|
||||
assertFalse(factoryBean.isPersistent());
|
||||
factoryBean.setPersistent(true);
|
||||
assertTrue(factoryBean.isPersistent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsNotPersistent() {
|
||||
assertFalse(factoryBean.isNotPersistent());
|
||||
factoryBean.setPersistent(true);
|
||||
assertFalse(factoryBean.isNotPersistent());
|
||||
factoryBean.setPersistent(false);
|
||||
assertTrue(factoryBean.isNotPersistent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveClientRegionShortcut() throws Exception {
|
||||
assertNull(TestUtils.readField("dataPolicy", factoryBean));
|
||||
assertNull(TestUtils.readField("persistent", factoryBean));
|
||||
assertNull(TestUtils.readField("shortcut", factoryBean));
|
||||
assertEquals(ClientRegionShortcut.LOCAL, factoryBean.resolveClientRegionShortcut());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveClientRegionShortcutWhenNotPersistent() throws Exception {
|
||||
factoryBean.setPersistent(false);
|
||||
|
||||
assertNull(TestUtils.readField("dataPolicy", factoryBean));
|
||||
assertTrue(factoryBean.isNotPersistent());
|
||||
assertNull(TestUtils.readField("shortcut", factoryBean));
|
||||
assertEquals(ClientRegionShortcut.LOCAL, factoryBean.resolveClientRegionShortcut());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveClientRegionShortcutWhenPersistent() throws Exception {
|
||||
factoryBean.setPersistent(true);
|
||||
|
||||
assertNull(TestUtils.readField("dataPolicy", factoryBean));
|
||||
assertTrue(factoryBean.isPersistent());
|
||||
assertNull(TestUtils.readField("shortcut", factoryBean));
|
||||
assertEquals(ClientRegionShortcut.LOCAL_PERSISTENT, factoryBean.resolveClientRegionShortcut());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveClientRegionShortcutUsingShortcut() throws Exception {
|
||||
factoryBean.setShortcut(ClientRegionShortcut.CACHING_PROXY_OVERFLOW);
|
||||
|
||||
assertNull(TestUtils.readField("dataPolicy", factoryBean));
|
||||
assertNull(TestUtils.readField("persistent", factoryBean));
|
||||
assertEquals(ClientRegionShortcut.CACHING_PROXY_OVERFLOW, factoryBean.resolveClientRegionShortcut());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveClientRegionShortcutUsingShortcutWhenNotPersistent() throws Exception {
|
||||
factoryBean.setPersistent(false);
|
||||
factoryBean.setShortcut(ClientRegionShortcut.CACHING_PROXY_HEAP_LRU);
|
||||
|
||||
assertNull(TestUtils.readField("dataPolicy", factoryBean));
|
||||
assertTrue(factoryBean.isNotPersistent());
|
||||
assertEquals(ClientRegionShortcut.CACHING_PROXY_HEAP_LRU, factoryBean.resolveClientRegionShortcut());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testResolveClientRegionShortcutUsingShortcutWhenPersistent() throws Exception {
|
||||
try {
|
||||
factoryBean.setPersistent(true);
|
||||
factoryBean.setShortcut(ClientRegionShortcut.CACHING_PROXY);
|
||||
|
||||
assertNull(TestUtils.readField("dataPolicy", factoryBean));
|
||||
assertTrue(factoryBean.isPersistent());
|
||||
|
||||
factoryBean.resolveClientRegionShortcut();
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("Client Region Shortcut 'CACHING_PROXY' is invalid when persistent is true.", e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveClientRegionShortcutUsingPersistentShortcut() throws Exception {
|
||||
factoryBean.setShortcut(ClientRegionShortcut.LOCAL_PERSISTENT);
|
||||
|
||||
assertNull(TestUtils.readField("dataPolicy", factoryBean));
|
||||
assertNull(TestUtils.readField("persistent", factoryBean));
|
||||
assertEquals(ClientRegionShortcut.LOCAL_PERSISTENT, factoryBean.resolveClientRegionShortcut());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testResolveClientRegionShortcutUsingPersistentShortcutWhenNotPersistent() throws Exception {
|
||||
try {
|
||||
factoryBean.setPersistent(false);
|
||||
factoryBean.setShortcut(ClientRegionShortcut.LOCAL_PERSISTENT);
|
||||
|
||||
assertNull(TestUtils.readField("dataPolicy", factoryBean));
|
||||
assertTrue(factoryBean.isNotPersistent());
|
||||
|
||||
factoryBean.resolveClientRegionShortcut();
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("Client Region Shortcut 'LOCAL_PERSISTENT' is invalid when persistent is false.", e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveClientRegionShortcutUsingPersistentShortcutWhenPersistent() throws Exception {
|
||||
factoryBean.setPersistent(true);
|
||||
factoryBean.setShortcut(ClientRegionShortcut.LOCAL_PERSISTENT_OVERFLOW);
|
||||
|
||||
assertNull(TestUtils.readField("dataPolicy", factoryBean));
|
||||
assertTrue(factoryBean.isPersistent());
|
||||
assertEquals(ClientRegionShortcut.LOCAL_PERSISTENT_OVERFLOW, factoryBean.resolveClientRegionShortcut());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveClientRegionShortcutUsingEmptyDataPolicy() throws Exception {
|
||||
factoryBean.setDataPolicy(DataPolicy.EMPTY);
|
||||
|
||||
assertNull(TestUtils.readField("persistent", factoryBean));
|
||||
assertNull(TestUtils.readField("shortcut", factoryBean));
|
||||
assertEquals(ClientRegionShortcut.PROXY, factoryBean.resolveClientRegionShortcut());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveClientRegionShortcutUsingNormalDataPolicyWhenNotPersistent() throws Exception {
|
||||
factoryBean.setDataPolicy(DataPolicy.NORMAL);
|
||||
factoryBean.setPersistent(false);
|
||||
|
||||
assertTrue(factoryBean.isNotPersistent());
|
||||
assertNull(TestUtils.readField("shortcut", factoryBean));
|
||||
assertEquals(ClientRegionShortcut.CACHING_PROXY, factoryBean.resolveClientRegionShortcut());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testResolveClientRegionShortcutUsingNormalDataPolicyWhenPersistent() throws Exception {
|
||||
try {
|
||||
factoryBean.setDataPolicy(DataPolicy.NORMAL);
|
||||
factoryBean.setPersistent(true);
|
||||
|
||||
assertTrue(factoryBean.isPersistent());
|
||||
assertNull(TestUtils.readField("shortcut", factoryBean));
|
||||
|
||||
factoryBean.resolveClientRegionShortcut();
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("Data Policy 'NORMAL' is invalid when persistent is true.", e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveClientRegionShortcutUsingPersistentReplicateDataPolicy() throws Exception {
|
||||
factoryBean.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
|
||||
|
||||
assertNull(TestUtils.readField("persistent", factoryBean));
|
||||
assertNull(TestUtils.readField("shortcut", factoryBean));
|
||||
assertEquals(ClientRegionShortcut.LOCAL_PERSISTENT, factoryBean.resolveClientRegionShortcut());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testResolveClientRegionShortcutUsingPersistentReplicateDataPolicyWhenNotPersistent() throws Exception {
|
||||
try {
|
||||
factoryBean.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
|
||||
factoryBean.setPersistent(false);
|
||||
|
||||
assertTrue(factoryBean.isNotPersistent());
|
||||
assertNull(TestUtils.readField("shortcut", factoryBean));
|
||||
|
||||
factoryBean.resolveClientRegionShortcut();
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("Data Policy 'PERSISTENT_REPLICATE' is invalid when persistent is false.", e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveClientRegionShortcutUsingPersistentReplicateDataPolicyWhenPersistent() throws Exception {
|
||||
factoryBean.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
|
||||
factoryBean.setPersistent(true);
|
||||
|
||||
assertNull(TestUtils.readField("shortcut", factoryBean));
|
||||
assertTrue(factoryBean.isPersistent());
|
||||
assertEquals(ClientRegionShortcut.LOCAL_PERSISTENT, factoryBean.resolveClientRegionShortcut());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -124,7 +124,6 @@ public class ClientRegionNamespaceTest {
|
||||
public void testOverflowToDisk() throws Exception {
|
||||
assertTrue(context.containsBean("overflow"));
|
||||
ClientRegionFactoryBean fb = context.getBean("&overflow", ClientRegionFactoryBean.class);
|
||||
assertEquals(DataPolicy.NORMAL, TestUtils.readField("dataPolicy", fb));
|
||||
RegionAttributes attrs = TestUtils.readField("attributes", fb);
|
||||
EvictionAttributes evicAttr = attrs.getEvictionAttributes();
|
||||
assertEquals(EvictionAction.OVERFLOW_TO_DISK, evicAttr.getAction());
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* The ClientRegionUsingDataPolicyAndShortcutTest class is a test suite of test case testing a client Region
|
||||
* bean definition with both data-policy and shortcut specified.
|
||||
* <p/>
|
||||
* @author John Blum
|
||||
* @see org.junit.Assert
|
||||
* @since 1.3.3
|
||||
*/
|
||||
public class ClientRegionUsingDataPolicyAndShortcutTest {
|
||||
|
||||
@Test(expected = BeanDefinitionParsingException.class)
|
||||
public void testClientRegionBeanDefinitionWithDataPolicyAndShortcut() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("/org/springframework/data/gemfire/config/client-region-using-datapolicy-and-shortcut.xml");
|
||||
}
|
||||
catch (BeanDefinitionParsingException e) {
|
||||
assertTrue(e.getMessage().contains("Only one of [data-policy, shortcut] may be specified with element"));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user