DATAGEODE-197 - Prepare Region configuration using SDG FactoryBeans to accept AEQ and GatewaySender IDs for association.

This commit is contained in:
John Blum
2019-07-15 16:31:16 -07:00
parent 17a8156664
commit 8dc42601b7
10 changed files with 247 additions and 117 deletions

View File

@@ -13,31 +13,35 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import org.junit.Test;
import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionFactory;
import org.apache.geode.cache.RegionShortcut;
import org.junit.Test;
import org.springframework.data.gemfire.test.support.AbstractRegionFactoryBeanTests;
/**
* The PartitionedRegionFactoryBeanTest class is a test suite of test cases testing the component functionality
* and correct behavior of the PartitionedRegionFactoryBean class.
* Unit Tests for {@link LocalRegionFactoryBean}.
*
* @author David Turanski
* @author John Blum
* @see org.mockito.Mockito
* @see org.junit.Test
* @see org.apache.geode.cache.DataPolicy
* @see org.apache.geode.cache.Region
* @see org.apache.geode.cache.RegionFactory
* @see org.apache.geode.cache.RegionShortcut
* @see org.springframework.data.gemfire.LocalRegionFactoryBean
* @since 1.3.x
*/
@@ -133,7 +137,7 @@ public class LocalRegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
factoryBean.resolveDataPolicy(mockRegionFactory, null, " ");
}
catch (IllegalArgumentException e) {
assertEquals("Data Policy ' ' is invalid.", e.getMessage());
assertEquals("Data Policy [ ] is invalid", e.getMessage());
throw e;
}
finally {
@@ -153,7 +157,7 @@ public class LocalRegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
factoryBean.resolveDataPolicy(mockRegionFactory, null, "");
}
catch (IllegalArgumentException e) {
assertEquals("Data Policy '' is invalid.", e.getMessage());
assertEquals("Data Policy [] is invalid", e.getMessage());
throw e;
}
finally {
@@ -173,7 +177,7 @@ public class LocalRegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
factoryBean.resolveDataPolicy(mockRegionFactory, null, "INVALID_DATA_POLICY_NAME");
}
catch (IllegalArgumentException e) {
assertEquals("Data Policy 'INVALID_DATA_POLICY_NAME' is invalid.", e.getMessage());
assertEquals("Data Policy [INVALID_DATA_POLICY_NAME] is invalid", e.getMessage());
throw e;
}
finally {
@@ -193,7 +197,7 @@ public class LocalRegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
factoryBean.resolveDataPolicy(mockRegionFactory, null, "PARTITION");
}
catch (IllegalArgumentException e) {
assertEquals("Data Policy 'PARTITION' is not supported for Local Regions.", e.getMessage());
assertEquals("Data Policy [PARTITION] is not supported for Local Regions", e.getMessage());
throw e;
}
finally {
@@ -278,7 +282,7 @@ public class LocalRegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
factoryBean.resolveDataPolicy(mockRegionFactory, null, DataPolicy.PERSISTENT_REPLICATE);
}
catch (IllegalArgumentException expected) {
assertEquals("Data Policy 'PERSISTENT_REPLICATE' is not supported for Local Regions.",
assertEquals("Data Policy [PERSISTENT_REPLICATE] is not supported for Local Regions",
expected.getMessage());
throw expected;
}
@@ -300,7 +304,7 @@ public class LocalRegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
factoryBean.resolveDataPolicy(mockRegionFactory, true, DataPolicy.PERSISTENT_REPLICATE);
}
catch (IllegalArgumentException expected) {
assertEquals("Data Policy 'PERSISTENT_REPLICATE' is not supported for Local Regions.",
assertEquals("Data Policy [PERSISTENT_REPLICATE] is not supported for Local Regions",
expected.getMessage());
throw expected;
}

View File

@@ -13,29 +13,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.RegionFactory;
import org.junit.Test;
import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.RegionFactory;
/**
* The PartitionedRegionFactoryBeanTest class is a test suite of test cases testing the component functionality
* and correct behavior of the PartitionedRegionFactoryBean class.
* Unit Tests for {@link PartitionedRegionFactoryBean}.
*
* @author John Blum
* @see org.junit.Test
* @see org.mockito.Mockito
* @see org.springframework.data.gemfire.PartitionedRegionFactoryBean
* @see org.apache.geode.cache.DataPolicy
* @see org.apache.geode.cache.RegionFactory
* @see org.springframework.data.gemfire.PartitionedRegionFactoryBean
* @since 1.3.3
*/
@SuppressWarnings("unchecked")
@@ -78,7 +77,7 @@ public class PartitionedRegionFactoryBeanTest {
factoryBean.resolveDataPolicy(mockRegionFactory, null, " ");
}
catch (IllegalArgumentException e) {
assertEquals("Data Policy ' ' is invalid.", e.getMessage());
assertEquals("Data Policy [ ] is invalid.", e.getMessage());
throw e;
}
finally {
@@ -97,7 +96,7 @@ public class PartitionedRegionFactoryBeanTest {
factoryBean.resolveDataPolicy(mockRegionFactory, null, "");
}
catch (IllegalArgumentException e) {
assertEquals("Data Policy '' is invalid.", e.getMessage());
assertEquals("Data Policy [] is invalid.", e.getMessage());
throw e;
}
finally {
@@ -116,7 +115,7 @@ public class PartitionedRegionFactoryBeanTest {
factoryBean.resolveDataPolicy(mockRegionFactory, null, "INVALID_DATA_POLICY_NAME");
}
catch (IllegalArgumentException e) {
assertEquals("Data Policy 'INVALID_DATA_POLICY_NAME' is invalid.", e.getMessage());
assertEquals("Data Policy [INVALID_DATA_POLICY_NAME] is invalid.", e.getMessage());
throw e;
}
finally {
@@ -134,7 +133,7 @@ public class PartitionedRegionFactoryBeanTest {
factoryBean.resolveDataPolicy(mockRegionFactory, null, "REPLICATE");
}
catch (IllegalArgumentException e) {
assertEquals("Data Policy 'REPLICATE' is not supported in Partitioned Regions.", e.getMessage());
assertEquals("Data Policy [REPLICATE] is not supported in Partitioned Regions.", e.getMessage());
throw e;
}
finally {

View File

@@ -13,29 +13,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.RegionFactory;
import org.junit.Test;
import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.RegionFactory;
/**
* The ReplicatedRegionFactoryBeanTest class is a test suite of test cases testing the component functionality
* and correct behavior of the ReplicatedRegionFactoryBean class.
* Unit Tests for {@link ReplicatedRegionFactoryBean}.
*
* @author John Blum
* @see org.junit.Test
* @see org.mockito.Mockito
* @see org.springframework.data.gemfire.ReplicatedRegionFactoryBean
* @see org.apache.geode.cache.DataPolicy
* @see org.apache.geode.cache.RegionFactory
* @see org.springframework.data.gemfire.ReplicatedRegionFactoryBean
* @since 1.3.3
*/
@SuppressWarnings("unchecked")
@@ -78,7 +77,7 @@ public class ReplicatedRegionFactoryBeanTest {
factoryBean.resolveDataPolicy(mockRegionFactory, null, " ");
}
catch (IllegalArgumentException e) {
assertEquals("Data Policy ' ' is invalid.", e.getMessage());
assertEquals("Data Policy [ ] is invalid.", e.getMessage());
throw e;
}
finally {
@@ -97,7 +96,7 @@ public class ReplicatedRegionFactoryBeanTest {
factoryBean.resolveDataPolicy(mockRegionFactory, null, "");
}
catch (IllegalArgumentException e) {
assertEquals("Data Policy '' is invalid.", e.getMessage());
assertEquals("Data Policy [] is invalid.", e.getMessage());
throw e;
}
finally {
@@ -116,7 +115,7 @@ public class ReplicatedRegionFactoryBeanTest {
factoryBean.resolveDataPolicy(mockRegionFactory, null, "INVALID_DATA_POLICY_NAME");
}
catch (IllegalArgumentException e) {
assertEquals("Data Policy 'INVALID_DATA_POLICY_NAME' is invalid.", e.getMessage());
assertEquals("Data Policy [INVALID_DATA_POLICY_NAME] is invalid.", e.getMessage());
throw e;
}
finally {
@@ -135,7 +134,7 @@ public class ReplicatedRegionFactoryBeanTest {
factoryBean.resolveDataPolicy(mockRegionFactory, null, "PARTITION");
}
catch (IllegalArgumentException e) {
assertEquals("Data Policy 'PARTITION' is not supported in Replicated Regions.", e.getMessage());
assertEquals("Data Policy [PARTITION] is not supported in Replicated Regions.", e.getMessage());
throw e;
}
finally {

View File

@@ -17,9 +17,17 @@
package org.springframework.data.gemfire.util;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.junit.Test;
import org.apache.geode.cache.DataPolicy;
import org.junit.Test;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionService;
/**
* Unit tests for {@link RegionUtils}.
@@ -34,9 +42,9 @@ public class RegionUtilsUnitTests {
public void assertAllDataPoliciesWithNullPersistentPropertyIsCompatible() {
RegionUtils.assertDataPolicyAndPersistentAttributeAreCompatible(DataPolicy.PARTITION, null);
RegionUtils.assertDataPolicyAndPersistentAttributeAreCompatible(DataPolicy.REPLICATE, null);
RegionUtils.assertDataPolicyAndPersistentAttributeAreCompatible(DataPolicy.PERSISTENT_PARTITION, null);
RegionUtils.assertDataPolicyAndPersistentAttributeAreCompatible(DataPolicy.PERSISTENT_REPLICATE, null);
RegionUtils.assertDataPolicyAndPersistentAttributeAreCompatible(DataPolicy.REPLICATE, null);
}
@Test
@@ -54,7 +62,7 @@ public class RegionUtilsUnitTests {
}
@Test(expected = IllegalArgumentException.class)
public void testAssertNonPersistentDataPolicyWithPersistentAttribute() {
public void assertNonPersistentDataPolicyWithPersistentAttribute() {
try {
RegionUtils.assertDataPolicyAndPersistentAttributeAreCompatible(DataPolicy.REPLICATE, true);
@@ -69,7 +77,7 @@ public class RegionUtilsUnitTests {
}
@Test(expected = IllegalArgumentException.class)
public void testAssertPersistentDataPolicyWithNonPersistentAttribute() {
public void assertPersistentDataPolicyWithNonPersistentAttribute() {
try {
RegionUtils.assertDataPolicyAndPersistentAttributeAreCompatible(DataPolicy.PERSISTENT_PARTITION, false);
@@ -82,4 +90,78 @@ public class RegionUtilsUnitTests {
throw expected;
}
}
@Test
public void closeRegionHandlesNull() {
assertThat(RegionUtils.close((Region<?, ?>) null)).isFalse();
}
@Test
public void closeRegionSuccessfully() {
Region mockRegion = mock(Region.class);
assertThat(RegionUtils.close(mockRegion)).isTrue();
verify(mockRegion, times(1)).close();
}
@Test
public void closeRegionUnsuccessfully() {
Region mockRegion = mock(Region.class);
doThrow(new RuntimeException("TEST")).when(mockRegion).close();
assertThat(RegionUtils.close(mockRegion)).isFalse();
verify(mockRegion, times(1)).close();
}
@Test
public void nullRegionIsNotCloseable() {
assertThat(RegionUtils.isCloseable(null)).isFalse();
}
@Test
public void regionIsCloseable() {
Region mockRegion = mock(Region.class);
RegionService mockRegionService = mock(RegionService.class);
when(mockRegion.getRegionService()).thenReturn(mockRegionService);
when(mockRegionService.isClosed()).thenReturn(false);
assertThat(RegionUtils.isCloseable(mockRegion)).isTrue();
verify(mockRegion, times(1)).getRegionService();
verify(mockRegionService, times(1)).isClosed();
}
@Test
public void regionIsNotCloseable() {
Region mockRegion = mock(Region.class);
RegionService mockRegionService = mock(RegionService.class);
when(mockRegion.getRegionService()).thenReturn(mockRegionService);
when(mockRegionService.isClosed()).thenReturn(true);
assertThat(RegionUtils.isCloseable(mockRegion)).isFalse();
verify(mockRegion, times(1)).getRegionService();
verify(mockRegionService, times(1)).isClosed();
}
@Test
public void regionWithNoRegionServiceIsNotCloseable() {
Region mockRegion = mock(Region.class);
when(mockRegion.getRegionService()).thenReturn(null);
assertThat(RegionUtils.isCloseable(mockRegion)).isFalse();
verify(mockRegion, times(1)).getRegionService();
}
}