DATAGEODE-197 - Add unit tests asserting the addition of AsyncEventQueues (AEQ) and GatewaySenders to Regions of various types (e.g. LOCAL, PARTITION, REPLICATE as well as Templates) using objects and identifiers.

This commit is contained in:
John Blum
2019-07-16 20:32:31 -07:00
parent 95ed811219
commit abc175d3c7
6 changed files with 277 additions and 13 deletions

View File

@@ -0,0 +1,135 @@
/*
* Copyright 2018 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
*
* https://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.wan;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionAttributes;
import org.apache.geode.cache.asyncqueue.AsyncEventListener;
import org.springframework.data.gemfire.support.AbstractFactoryBeanSupport;
import org.springframework.lang.Nullable;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
/**
* The RegionsWithAsyncEventQueuesAndGatewaySendersUnitTests class...
*
* @author John Blum
* @since 1.0.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration
@SuppressWarnings("unused")
public class RegionsWithAsyncEventQueuesAndGatewaySendersUnitTests {
@Resource(name = "TemplateBasedLocalRegion")
private Region<?, ?> templateBasedLocalRegion;
@Resource(name = "LocalRegion")
private Region<?, ?> localRegion;
@Resource(name = "PartitionRegion")
private Region<?, ?> partitionRegion;
@Resource(name = "ReplicateRegion")
private Region<?, ?> replicateRegion;
private void assertRegion(Region<?, ?> region, String name, DataPolicy dataPolicy) {
assertThat(region).isNotNull();
assertThat(region.getName()).isEqualTo(name);
RegionAttributes<?, ?> regionAttributes = region.getAttributes();
assertThat(regionAttributes).isNotNull();
assertThat(regionAttributes.getDataPolicy()).isEqualTo(dataPolicy);
}
@Test
public void templateBasedlocalRegionConfigurationIsCorrect() {
assertRegion(this.templateBasedLocalRegion, "TemplateBasedLocalRegion", DataPolicy.NORMAL);
assertThat(this.templateBasedLocalRegion.getAttributes().getAsyncEventQueueIds())
.containsExactlyInAnyOrder("X", "Y", "Z");
assertThat(this.templateBasedLocalRegion.getAttributes().getGatewaySenderIds())
.containsExactlyInAnyOrder("99", "100", "101");
}
@Test
public void localRegionConfigurationIsCorrect() {
assertRegion(this.localRegion, "LocalRegion", DataPolicy.NORMAL);
assertThat(this.localRegion.getAttributes().getAsyncEventQueueIds())
.containsExactlyInAnyOrder("A", "B", "C", "D", "E");
assertThat(this.localRegion.getAttributes().getGatewaySenderIds())
.containsExactlyInAnyOrder("1", "2", "3", "4", "5");
}
@Test
public void partitionRegionConfigurationIsCorrect() {
assertRegion(this.partitionRegion, "PartitionRegion", DataPolicy.PARTITION);
assertThat(this.partitionRegion.getAttributes().getAsyncEventQueueIds())
.containsExactlyInAnyOrder("E", "F", "G", "H", "I");
assertThat(this.partitionRegion.getAttributes().getGatewaySenderIds())
.containsExactlyInAnyOrder("5", "6", "7", "8", "9");
}
@Test
public void sreplicateRegionConfigurationIsCorrect() {
assertRegion(this.replicateRegion, "ReplicateRegion", DataPolicy.REPLICATE);
assertThat(this.replicateRegion.getAttributes().getAsyncEventQueueIds())
.containsExactlyInAnyOrder("E", "J", "K", "L", "M");
assertThat(this.replicateRegion.getAttributes().getGatewaySenderIds())
.containsExactlyInAnyOrder("5", "10", "11", "12", "13");
}
public static final class AsyncEventListenerFactoryBean extends AbstractFactoryBeanSupport<AsyncEventListener> {
private final AsyncEventListener mockAsyncEventListener = mock(AsyncEventListener.class);
@Nullable @Override
public AsyncEventListener getObject() {
return this.mockAsyncEventListener;
}
@Nullable @Override
public Class<?> getObjectType() {
return this.mockAsyncEventListener != null
? this.mockAsyncEventListener.getClass()
: AsyncEventListener.class;
}
}
}

View File

@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:gfe="http://www.springframework.org/schema/geode"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/geode http://www.springframework.org/schema/geode/spring-geode.xsd
">
<bean class="org.springframework.data.gemfire.test.mock.config.GemFireMockObjectsBeanPostProcessor"/>
<gfe:cache/>
<bean id="MockAsyncEventListener"
class="org.springframework.data.gemfire.wan.RegionsWithAsyncEventQueuesAndGatewaySendersUnitTests$AsyncEventListenerFactoryBean"/>
<gfe:async-event-queue id="E">
<gfe:async-event-listener ref="MockAsyncEventListener"/>
</gfe:async-event-queue>
<gfe:gateway-sender id="5" manual-start="true" remote-distributed-system-id="1"/>
<gfe:region-template id="BaseRegionTemplate" async-event-queue-ids="X, Y" gateway-sender-ids="99, 100">
<gfe:gateway-sender name="101" manual-start="true" remote-distributed-system-id="1"/>
<gfe:async-event-queue name="Z">
<gfe:async-event-listener ref="MockAsyncEventListener"/>
</gfe:async-event-queue>
</gfe:region-template>
<!-- Template Region AsyncEventQueues (AEQ) & GatewaySenders are used -->
<gfe:local-region id="TemplateBasedLocalRegion" template="BaseRegionTemplate"/>
<!-- Template Region AsyncEventQueues (AEQ) & GatewaySenders are overridden -->
<gfe:local-region id="LocalRegion"
async-event-queue-ids="A, B, C"
gateway-sender-ids="1, 2, 3"
template="BaseRegionTemplate">
<gfe:gateway-sender name="4" manual-start="true" remote-distributed-system-id="1"/>
<gfe:gateway-sender-ref bean="5"/>
<gfe:async-event-queue name="D">
<gfe:async-event-listener ref="MockAsyncEventListener"/>
</gfe:async-event-queue>
<gfe:async-event-queue-ref bean="E"/>
</gfe:local-region>
<!-- Template Region AsyncEventQueues (AEQ) & GatewaySenders are overridden -->
<gfe:partitioned-region id="PartitionRegion"
async-event-queue-ids="F, G, H"
gateway-sender-ids="6, 7, 8"
template="BaseRegionTemplate">
<gfe:gateway-sender name="9" manual-start="true" remote-distributed-system-id="1"/>
<gfe:gateway-sender-ref bean="5"/>
<gfe:async-event-queue name="I">
<gfe:async-event-listener ref="MockAsyncEventListener"/>
</gfe:async-event-queue>
<gfe:async-event-queue-ref bean="E"/>
</gfe:partitioned-region>
<!-- Template Region AsyncEventQueues (AEQ) & GatewaySenders are overridden -->
<gfe:replicated-region id="ReplicateRegion"
async-event-queue-ids="J, K, L"
gateway-sender-ids="10, 11, 12"
template="BaseRegionTemplate">
<gfe:gateway-sender name="13" manual-start="true" remote-distributed-system-id="1"/>
<gfe:gateway-sender-ref bean="5"/>
<gfe:async-event-queue name="M">
<gfe:async-event-listener ref="MockAsyncEventListener"/>
</gfe:async-event-queue>
<gfe:async-event-queue-ref bean="E"/>
</gfe:replicated-region>
</beans>