SGF-328 - Add missing 'hostname-for-senders' attribute on the <gfe:gateway-receiver> element in the SDG XML namespace (XSD).

This commit is contained in:
John Blum
2014-09-23 17:19:14 -07:00
parent 6efb775c1e
commit 34ae38ef23
9 changed files with 166 additions and 12 deletions

View File

@@ -23,9 +23,12 @@ import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
* Spring BeanDefinitionParser for the &lt;gfe:gateway-receiver&gt; SDG (GFE) XML XSD namespace element.
*
* @author David Turanski
* @author John Blum
* @see org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser
* @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean
*/
class GatewayReceiverParser extends AbstractSimpleBeanDefinitionParser {
@@ -43,6 +46,7 @@ class GatewayReceiverParser extends AbstractSimpleBeanDefinitionParser {
builder.setLazyInit(false);
ParsingUtils.setPropertyValue(element, builder, "bind-address");
ParsingUtils.setPropertyValue(element, builder, "hostname-for-senders");
ParsingUtils.setPropertyValue(element, builder, "start-port");
ParsingUtils.setPropertyValue(element, builder, "end-port");
ParsingUtils.setPropertyValue(element, builder, "manual-start");

View File

@@ -26,18 +26,21 @@ import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
import com.gemstone.gemfire.cache.wan.GatewayReceiverFactory;
import com.gemstone.gemfire.cache.wan.GatewayTransportFilter;
import com.gemstone.gemfire.management.internal.cli.util.spring.StringUtils;
/**
* FactoryBean for creating a GemFire {@link GatewayReceiver}.
* Spring FactoryBean for creating a GemFire {@link GatewayReceiver}.
*
* @author David Turanski
* @author John Blum
* @see org.springframework.context.SmartLifecycle
* @see org.springframework.data.gemfire.wan.AbstractWANComponentFactoryBean
* @see com.gemstone.gemfire.cache.Cache
* @see com.gemstone.gemfire.cache.wan.GatewayReceiver
* @see com.gemstone.gemfire.cache.wan.GatewayReceiverFactory
* @since 1.2.2
*/
@SuppressWarnings("unused")
public class GatewayReceiverFactoryBean extends AbstractWANComponentFactoryBean<GatewayReceiver>
implements SmartLifecycle {
@@ -53,6 +56,7 @@ public class GatewayReceiverFactoryBean extends AbstractWANComponentFactoryBean<
private List<GatewayTransportFilter> transportFilters;
private String bindAddress;
private String hostnameForSenders;
/**
* Constructs an instance of the GatewayReceiverFactoryBean class for configuring an initializing
@@ -84,17 +88,22 @@ public class GatewayReceiverFactoryBean extends AbstractWANComponentFactoryBean<
}
}
if (bindAddress != null) {
if (StringUtils.hasText(bindAddress)) {
gatewayReceiverFactory.setBindAddress(bindAddress);
}
int minPort = (startPort != null ? startPort : GatewayReceiver.DEFAULT_START_PORT);
int maxPort = (endPort != null ? endPort : GatewayReceiver.DEFAULT_END_PORT);
if (StringUtils.hasText(hostnameForSenders)) {
gatewayReceiverFactory.setHostnameForSenders(hostnameForSenders);
}
Assert.isTrue(minPort <= maxPort, String.format("'startPort' must be less than or equal to %1$d.", maxPort));
int localStartPort = (startPort != null ? startPort : GatewayReceiver.DEFAULT_START_PORT);
int localEndPort = (endPort != null ? endPort : GatewayReceiver.DEFAULT_END_PORT);
gatewayReceiverFactory.setStartPort(minPort);
gatewayReceiverFactory.setEndPort(maxPort);
Assert.isTrue(localStartPort <= localEndPort, String.format("'startPort' must be less than or equal to %1$d.",
localEndPort));
gatewayReceiverFactory.setStartPort(localStartPort);
gatewayReceiverFactory.setEndPort(localEndPort);
if (maximumTimeBetweenPings != null) {
gatewayReceiverFactory.setMaximumTimeBetweenPings(maximumTimeBetweenPings);
@@ -115,6 +124,10 @@ public class GatewayReceiverFactoryBean extends AbstractWANComponentFactoryBean<
this.bindAddress = bindAddress;
}
public void setHostnameForSenders(String hostnameForSenders) {
this.hostnameForSenders = hostnameForSenders;
}
public void setStartPort(Integer startPort) {
this.startPort = startPort;
}

View File

@@ -2599,6 +2599,16 @@ Specifies the bind address (IP address or host name) for the gateway receiver
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="hostname-for-senders" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Attribute where you can specify an IP address or hostname for gateway sender connections.
If you configure hostname-for-senders, locators will use the provided hostname or IP address
when instructing gateway senders on how to connect to gateway receivers. If you provide ""
or null as the value, by default the gateway receiver's bind-address will be sent to clients.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="start-port" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[

View File

@@ -2689,6 +2689,16 @@ Specifies the bind address (IP address or host name) for the gateway receiver
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="hostname-for-senders" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Attribute where you can specify an IP address or hostname for gateway sender connections.
If you configure hostname-for-senders, locators will use the provided hostname or IP address
when instructing gateway senders on how to connect to gateway receivers. If you provide ""
or null as the value, by default the gateway receiver's bind-address will be sent to clients.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="start-port" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[

View File

@@ -2759,6 +2759,16 @@ Specifies the bind address (IP address or host name) for the gateway receiver
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="hostname-for-senders" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Attribute where you can specify an IP address or hostname for gateway sender connections.
If you configure hostname-for-senders, locators will use the provided hostname or IP address
when instructing gateway senders on how to connect to gateway receivers. If you provide ""
or null as the value, by default the gateway receiver's bind-address will be sent to clients.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="start-port" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[

View File

@@ -58,12 +58,13 @@ public class GatewayReceiverNamespaceTest {
// TODO test the default value for "manual-start" (true) without explicitly setting the attribute in Spring XML
public void testDefault() throws Exception {
assertNotNull("The 'Default' GatewayReceiverFactoryBean was not properly configured and initialized!", defaultFactoryBean);
assertFalse(defaultFactoryBean.isAutoStartup());
assertTrue(defaultFactoryBean.isAutoStartup());
GatewayReceiver defaultGatewayReceiver = defaultFactoryBean.getObject();
assertNotNull(defaultGatewayReceiver);
assertEquals("192.168.0.1", defaultGatewayReceiver.getBindAddress());
assertEquals("skullbox", defaultGatewayReceiver.getHost());
assertEquals(12345, defaultGatewayReceiver.getStartPort());
assertEquals(54321, defaultGatewayReceiver.getEndPort());
assertEquals(5000, defaultGatewayReceiver.getMaximumTimeBetweenPings());

View File

@@ -21,6 +21,7 @@ import java.util.List;
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
import com.gemstone.gemfire.cache.wan.GatewayReceiverFactory;
import com.gemstone.gemfire.cache.wan.GatewayTransportFilter;
import com.gemstone.gemfire.management.internal.cli.util.spring.StringUtils;
/**
* @author David Turanski
@@ -133,7 +134,8 @@ public class StubGatewayReceiverFactory implements GatewayReceiverFactory {
when(gatewayReceiver.getBindAddress()).thenReturn(this.bindAddress);
when(gatewayReceiver.getEndPort()).thenReturn(this.endPort);
when(gatewayReceiver.getGatewayTransportFilters()).thenReturn(this.gatewayTransportFilters);
when(gatewayReceiver.getHost()).thenReturn(this.hostnameForClients);
when(gatewayReceiver.getHost()).thenReturn(StringUtils.hasText(this.hostnameForSenders)
? this.hostnameForSenders : this.hostnameForClients);
when(gatewayReceiver.getMaximumTimeBetweenPings()).thenReturn(this.maximumTimeBetweenPings);
when(gatewayReceiver.getSocketBufferSize()).thenReturn(this.socketBufferSize);
when(gatewayReceiver.getStartPort()).thenReturn(this.startPort);

View File

@@ -0,0 +1,96 @@
/*
* 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.wan;
import static org.junit.Assert.assertEquals;
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 org.junit.Test;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.wan.GatewayReceiverFactory;
import com.gemstone.gemfire.cache.wan.GatewayTransportFilter;
/**
* The GatewayReceiverFactoryBeanTest class...
*
* @author John Blum
* @see org.springframework.data.gemfire.
* @since 1.5.0
*/
public class GatewayReceiverFactoryBeanTest {
@Test
public void testDoInit() 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);
GatewayReceiverFactoryBean factoryBean = new GatewayReceiverFactoryBean(mockCache);
factoryBean.setBindAddress("10.224.112.77");
factoryBean.setHostnameForSenders("skullbox");
factoryBean.setStartPort(2048);
factoryBean.setEndPort(4096);
factoryBean.setManualStart(true);
factoryBean.setMaximumTimeBetweenPings(5000);
factoryBean.setName("testDoInit");
factoryBean.setSocketBufferSize(16384);
factoryBean.setTransportFilters(Arrays.asList(mockGatewayTransportFilter));
factoryBean.afterPropertiesSet();
verify(mockGatewayReceiverFactory).setBindAddress(eq("10.224.112.77"));
verify(mockGatewayReceiverFactory).setHostnameForSenders(eq("skullbox"));
verify(mockGatewayReceiverFactory).setStartPort(eq(2048));
verify(mockGatewayReceiverFactory).setEndPort(eq(4096));
verify(mockGatewayReceiverFactory).setMaximumTimeBetweenPings(eq(5000));
verify(mockGatewayReceiverFactory).setSocketBufferSize(eq(16384));
verify(mockGatewayReceiverFactory).addGatewayTransportFilter(same(mockGatewayTransportFilter));
verify(mockGatewayReceiverFactory).create();
}
@Test(expected = IllegalArgumentException.class)
public void testDoInitWithIllegalStartEndPorts() throws Exception {
try {
Cache mockCache = mock(Cache.class, "testDoInitWithIllegalStartEndPorts.Cache");
GatewayReceiverFactory mockGatewayReceiverFactory = mock(GatewayReceiverFactory.class,
"testDoInitWithIllegalStartEndPorts.GatewayReceiverFactory");
when(mockCache.createGatewayReceiverFactory()).thenReturn(mockGatewayReceiverFactory);
GatewayReceiverFactoryBean factoryBean = new GatewayReceiverFactoryBean(mockCache);
factoryBean.setName("testDoInitWithIllegalStartEndPorts");
factoryBean.setStartPort(10240);
factoryBean.setEndPort(8192);
factoryBean.afterPropertiesSet();
}
catch (IllegalArgumentException expected) {
assertEquals("'startPort' must be less than or equal to 8192.", expected.getMessage());
throw expected;
}
}
}

View File

@@ -1,16 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:gfe="http://www.springframework.org/schema/gemfire"
xmlns:util="http://www.springframework.org/schema/util"
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/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
">
<gfe:cache/>
<util:properties id="gemfireProperties">
<prop key="name">GatewayReceiverNamespaceTest</prop>
<prop key="mcast-port">0</prop>
<prop key="log-level">config</prop>
</util:properties>
<gfe:gateway-receiver id="Default" bind-address="192.168.0.1" start-port="12345" end-port="54321"
manual-start="true" maximum-time-between-pings="5000" socket-buffer-size="32768"/>
<gfe:cache properties-ref="gemfireProperties"/>
<gfe:gateway-receiver id="Default" bind-address="192.168.0.1" hostname-for-senders="skullbox"
start-port="12345" end-port="54321" maximum-time-between-pings="5000" socket-buffer-size="32768"/>
<gfe:gateway-receiver id="Auto" manual-start="false"/>