SGF-865 - Refactor Gateway Sender/Receiver support and remove unnecessary configuration validations.

This commit is contained in:
John Blum
2019-07-23 10:52:55 -07:00
parent ac76726875
commit 094ea58a93
5 changed files with 96 additions and 139 deletions

View File

@@ -13,28 +13,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire.wan;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.Collections;
import org.junit.Test;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.wan.GatewayReceiverFactory;
import org.apache.geode.cache.wan.GatewayTransportFilter;
import org.junit.Test;
/**
* The GatewayReceiverFactoryBeanTest class is a test suite of test cases testing the contract and functionality
* of the GatewayReceiverFactoryBean class.
* Unit Tests for {@link GatewayReceiverFactoryBean}.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean
* @see org.apache.geode.cache.wan.GatewayReceiverFactory
* @since 1.5.0
@@ -42,9 +42,12 @@ import org.junit.Test;
public class GatewayReceiverFactoryBeanTest {
@Test
public void testDoInit() throws Exception {
public void doInitConfiguresGatewaySenderFactoryBean() throws Exception {
Cache mockCache = mock(Cache.class, "testDoInit.Cache");
GatewayReceiverFactory mockGatewayReceiverFactory = mock(GatewayReceiverFactory.class, "testDoInit.GatewayReceiverFactory");
GatewayTransportFilter mockGatewayTransportFilter = mock(GatewayTransportFilter.class, "testDoInit.GatewayTransportFilter");
when(mockCache.createGatewayReceiverFactory()).thenReturn(mockGatewayReceiverFactory);
@@ -59,7 +62,7 @@ public class GatewayReceiverFactoryBeanTest {
factoryBean.setMaximumTimeBetweenPings(5000);
factoryBean.setName("testDoInit");
factoryBean.setSocketBufferSize(16384);
factoryBean.setTransportFilters(Arrays.asList(mockGatewayTransportFilter));
factoryBean.setTransportFilters(Collections.singletonList(mockGatewayTransportFilter));
factoryBean.afterPropertiesSet();
verify(mockGatewayReceiverFactory).setBindAddress(eq("10.224.112.77"));
@@ -74,7 +77,7 @@ public class GatewayReceiverFactoryBeanTest {
}
@Test(expected = IllegalArgumentException.class)
public void testDoInitWithIllegalStartEndPorts() throws Exception {
public void doInitWithIllegalStartEndPorts() throws Exception {
try {
Cache mockCache = mock(Cache.class, "testDoInitWithIllegalStartEndPorts.Cache");
GatewayReceiverFactory mockGatewayReceiverFactory = mock(GatewayReceiverFactory.class,
@@ -90,9 +93,11 @@ public class GatewayReceiverFactoryBeanTest {
factoryBean.afterPropertiesSet();
}
catch (IllegalArgumentException expected) {
assertEquals("'startPort' must be less than or equal to 8192.", expected.getMessage());
assertThat(expected).hasMessageContaining("[startPort] must be less than or equal to [8192]");
assertThat(expected).hasNoCause();
throw expected;
}
}
}

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire.wan;
import static org.junit.Assert.assertEquals;
@@ -24,10 +23,12 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.junit.Test;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.wan.GatewaySender;
import org.apache.geode.cache.wan.GatewaySenderFactory;
import org.junit.Test;
import org.springframework.data.gemfire.TestUtils;
/**
@@ -181,29 +182,6 @@ public class GatewaySenderFactoryBeanTest {
assertEquals(69, gatewaySender.getRemoteDSId());
}
@Test(expected = IllegalArgumentException.class)
public void parallelGatewaySenderWithOrderPolicyCreation() {
GatewaySenderFactory mockGatewaySenderFactory =
mockGatewaySenderFactory("g2", 69);
GatewaySenderFactoryBean factoryBean = new GatewaySenderFactoryBean(
mockCacheWithGatewayInfrastructure(mockGatewaySenderFactory));
factoryBean.setName("g2");
factoryBean.setRemoteDistributedSystemId(69);
factoryBean.setParallel(true);
factoryBean.setOrderPolicy(GatewaySender.OrderPolicy.KEY);
try {
factoryBean.doInit();
}
catch (IllegalArgumentException expected) {
assertEquals("OrderPolicy cannot be used with a Parallel GatewaySender", expected.getMessage());
throw expected;
}
}
@Test
public void gatewaySenderCreationWithDiskSynchronousAndNoPersistence() throws Exception {