SGF-521 - Polish.

This commit is contained in:
John Blum
2019-06-14 00:59:06 -07:00
parent 4456decd6e
commit aaea1e620b
9 changed files with 340 additions and 249 deletions

View File

@@ -1,4 +1,19 @@
package org.springframework.data.gemfire.wan.annotation;
/*
* Copyright 2019 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.config.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
@@ -7,85 +22,37 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.wan.GatewayReceiver;
import org.springframework.context.annotation.Import;
/**
* The EnableGatewayReceiver annotation creates a {@link org.apache.geode.cache.wan.GatewayReceiver}
* within GemFire/Geode {@link org.apache.geode.cache.Cache}
* The {@link EnableGatewayReceiver} annotation creates a {@link GatewayReceiver} within an Apache Geode
* or Pivotal GemFire peer {@link Cache}.
*
* @author Udo Kohlmeyer
* @see org.springframework.context.annotation.Configuration
* @see org.springframework.context.annotation.Import
* @see org.apache.geode.cache.wan.GatewayTransportFilter
* @see org.apache.geode.cache.wan.GatewayReceiver
* @see org.apache.geode.cache.Cache
* @see org.apache.geode.cache.wan.GatewayReceiver
* @see org.apache.geode.cache.wan.GatewayTransportFilter
* @see org.springframework.context.annotation.Import
* @since 2.2.0
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
@Import(EnableGatewayReceiverConfiguration.class)
@Import(GatewayReceiverConfiguration.class)
@SuppressWarnings("unused")
public @interface EnableGatewayReceiver {
/**
* A boolean to allow the GatewayReceiver to be created without being started after creation.
* If the manualStart is set to <b><i>true</i></b> then the system will create the GatewayReceiver but not start it.
* It then becomes the responsibility of the operator to start the GatewayReceiver at a later stage.
* If set to <b><i>false</i></b> the GatewayReceiver will start automatically after creation.<br>
* This property can also be configured using the <b><i>spring.data.gemfire.gateway.receiver.manual-start</i></b> property<br>
* Default is {@value EnableGatewayReceiverConfiguration#DEFAULT_MANUAL_START}
*/
boolean manualStart() default EnableGatewayReceiverConfiguration.DEFAULT_MANUAL_START;
/**
* The starting port that GatewayReceiver will use when selecting a port to run on. This range of port numbers
* is bounded by a <b><i>startPort</i></b> and <b><i>endPort</i></b>.<br>
* This property can also be configured using the <b><i>spring.data.gemfire.gateway.receiver.start-port</i></b> property<br>
* Default is {@value EnableGatewayReceiverConfiguration#DEFAULT_START_PORT}
*/
int startPort() default EnableGatewayReceiverConfiguration.DEFAULT_START_PORT;
/**
* The end port that GatewayReceiver will use when selecting a port to run on. This range of port numbers
* is bounded by a <b><i>startPort</i></b> and <b><i>endPort</i></b>.<br>
* This property can also be configured using the <b><i>spring.data.gemfire.gateway.receiver.end-port</i></b> property<br>
* Default is {@value EnableGatewayReceiverConfiguration#DEFAULT_END_PORT}
*/
int endPort() default EnableGatewayReceiverConfiguration.DEFAULT_END_PORT;
/**
* An integer value in milliseconds representing the maximum time which a {@link org.apache.geode.cache.wan.GatewayReceiver}
* will wait to receive a ping back from a {@link org.apache.geode.cache.wan.GatewaySender} before the {@link org.apache.geode.cache.wan.GatewayReceiver}
* believes the sender to be not available.<br>
* This property can also be configured using the <b><i>spring.data.gemfire.gateway.receiver.maximum-time-between-pings</i></b> property<br>
* Default value is {@value EnableGatewayReceiverConfiguration#DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS}
*/
int maximumTimeBetweenPings() default EnableGatewayReceiverConfiguration.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS;
/**
* The socket buffer size for the {@link org.apache.geode.cache.wan.GatewayReceiver}. This setting is in bytes.<br>
* This property can also be configured using the <b><i>spring.data.gemfire.gateway.receiver.socket-buffer-size</i></b> property<br>
* Default value is {@value EnableGatewayReceiverConfiguration#DEFAULT_SOCKET_BUFFER_SIZE}
*/
int socketBufferSize() default EnableGatewayReceiverConfiguration.DEFAULT_SOCKET_BUFFER_SIZE;
/**
* An in-order list of {@link org.apache.geode.cache.wan.GatewayTransportFilter} to be applied to
* {@link org.apache.geode.cache.wan.GatewayReceiver}<br>
* This property can also be configured using the <b><i>spring.data.gemfire.gateway.receiver.transport-filters</i></b> property<br>
* Default value is an empty String array
*/
String[] transportFilters() default {};
/**
* The IP address or hostname that the {@link org.apache.geode.cache.wan.GatewayReceiver} communication socket will be bound to.
* An empty String will cause the underlying socket to bind to 0.0.0.0<br>
* This property can also be configured using the <b><i>spring.data.gemfire.gateway.receiver.bind-address</i></b> property <br>
* Default value is {@value EnableGatewayReceiverConfiguration#DEFAULT_BIND_ADDRESS}
* Default value is {@value GatewayReceiverConfiguration#DEFAULT_BIND_ADDRESS}
*/
String bindAddress() default EnableGatewayReceiverConfiguration.DEFAULT_BIND_ADDRESS;
String bindAddress() default GatewayReceiverConfiguration.DEFAULT_BIND_ADDRESS;
/**
* The hostname or IP Address that the {@link org.apache.geode.cache.wan.GatewaySender} will use to connect and communicate with the
@@ -95,7 +62,58 @@ public @interface EnableGatewayReceiver {
* the notion of external and internal network interfaces exist and generally the "externally"/outwardly facing network
* interface is used.<br>
* This property can also be configured using the <b><i>spring.data.gemfire.gateway.receiver.hostname-for-senders</i></b> property<br>
* Default value is {@value EnableGatewayReceiverConfiguration#DEFAULT_HOSTNAME_FOR_SENDERS}
* Default value is {@value GatewayReceiverConfiguration#DEFAULT_HOSTNAME_FOR_SENDERS}
*/
String hostnameForSenders() default EnableGatewayReceiverConfiguration.DEFAULT_HOSTNAME_FOR_SENDERS;
String hostnameForSenders() default GatewayReceiverConfiguration.DEFAULT_HOSTNAME_FOR_SENDERS;
/**
* A boolean to allow the GatewayReceiver to be created without being started after creation.
* If the manualStart is set to <b><i>true</i></b> then the system will create the GatewayReceiver but not start it.
* It then becomes the responsibility of the operator to start the GatewayReceiver at a later stage.
* If set to <b><i>false</i></b> the GatewayReceiver will start automatically after creation.<br>
* This property can also be configured using the <b><i>spring.data.gemfire.gateway.receiver.manual-start</i></b> property<br>
* Default is {@value GatewayReceiverConfiguration#DEFAULT_MANUAL_START}
*/
boolean manualStart() default GatewayReceiverConfiguration.DEFAULT_MANUAL_START;
/**
* An integer value in milliseconds representing the maximum time which a {@link org.apache.geode.cache.wan.GatewayReceiver}
* will wait to receive a ping back from a {@link org.apache.geode.cache.wan.GatewaySender} before the {@link org.apache.geode.cache.wan.GatewayReceiver}
* believes the sender to be not available.<br>
* This property can also be configured using the <b><i>spring.data.gemfire.gateway.receiver.maximum-time-between-pings</i></b> property<br>
* Default value is {@value GatewayReceiverConfiguration#DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS}
*/
int maximumTimeBetweenPings() default GatewayReceiverConfiguration.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS;
/**
* The starting port that GatewayReceiver will use when selecting a port to run on. This range of port numbers
* is bounded by a <b><i>startPort</i></b> and <b><i>endPort</i></b>.<br>
* This property can also be configured using the <b><i>spring.data.gemfire.gateway.receiver.start-port</i></b> property<br>
* Default is {@value GatewayReceiverConfiguration#DEFAULT_START_PORT}
*/
int startPort() default GatewayReceiverConfiguration.DEFAULT_START_PORT;
/**
* The end port that GatewayReceiver will use when selecting a port to run on. This range of port numbers
* is bounded by a <b><i>startPort</i></b> and <b><i>endPort</i></b>.<br>
* This property can also be configured using the <b><i>spring.data.gemfire.gateway.receiver.end-port</i></b> property<br>
* Default is {@value GatewayReceiverConfiguration#DEFAULT_END_PORT}
*/
int endPort() default GatewayReceiverConfiguration.DEFAULT_END_PORT;
/**
* The socket buffer size for the {@link org.apache.geode.cache.wan.GatewayReceiver}. This setting is in bytes.<br>
* This property can also be configured using the <b><i>spring.data.gemfire.gateway.receiver.socket-buffer-size</i></b> property<br>
* Default value is {@value GatewayReceiverConfiguration#DEFAULT_SOCKET_BUFFER_SIZE}
*/
int socketBufferSize() default GatewayReceiverConfiguration.DEFAULT_SOCKET_BUFFER_SIZE;
/**
* An in-order list of {@link org.apache.geode.cache.wan.GatewayTransportFilter} to be applied to
* {@link org.apache.geode.cache.wan.GatewayReceiver}<br>
* This property can also be configured using the <b><i>spring.data.gemfire.gateway.receiver.transport-filters</i></b> property<br>
* Default value is an empty String array
*/
String[] transportFilters() default {};
}

View File

@@ -1,16 +1,33 @@
package org.springframework.data.gemfire.wan.annotation;
/*
* Copyright 2019 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.config.annotation;
import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.Optional;
import org.apache.geode.cache.wan.GatewayReceiver;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.BeanReference;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
@@ -23,20 +40,23 @@ import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean;
* in a Spring application context.
*
* @author Udo Kohlmeyer
* @author John Blum
* @see org.apache.geode.cache.wan.GatewayReceiver
* @see org.springframework.context.annotation.Bean
* @see org.springframework.context.annotation.Configuration
* @see org.springframework.data.gemfire.wan.annotation.EnableGatewayReceiver
* @see EnableGatewayReceiver
* @since 2.2.0
*/
public class EnableGatewayReceiverConfiguration extends AbstractAnnotationConfigSupport
implements ImportBeanDefinitionRegistrar {
public class GatewayReceiverConfiguration extends AbstractAnnotationConfigSupport
implements ImportBeanDefinitionRegistrar {
static final boolean DEFAULT_MANUAL_START = GatewayReceiver.DEFAULT_MANUAL_START;
static final int DEFAULT_START_PORT = GatewayReceiver.DEFAULT_START_PORT;
static final int DEFAULT_END_PORT = GatewayReceiver.DEFAULT_END_PORT;
static final int DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS = GatewayReceiver.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS;
static final int DEFAULT_SOCKET_BUFFER_SIZE = GatewayReceiver.DEFAULT_SOCKET_BUFFER_SIZE;
static final String DEFAULT_BIND_ADDRESS = GatewayReceiver.DEFAULT_BIND_ADDRESS;
static final String DEFAULT_HOSTNAME_FOR_SENDERS = GatewayReceiver.DEFAULT_HOSTNAME_FOR_SENDERS;
@@ -60,15 +80,15 @@ public class EnableGatewayReceiverConfiguration extends AbstractAnnotationConfig
@Override
protected Class<? extends Annotation> getAnnotationType() {
return org.springframework.data.gemfire.wan.annotation.EnableGatewayReceiver.class;
return EnableGatewayReceiver.class;
}
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
if (importingClassMetadata.hasAnnotation(getAnnotationTypeName())) {
AnnotationAttributes enableGatewayReceiverAttributes =
AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(getAnnotationTypeName()));
if (isAnnotationPresent(importingClassMetadata)) {
AnnotationAttributes enableGatewayReceiverAttributes = getAnnotationAttributes(importingClassMetadata);
registerGatewayReceiverBeanDefinition(enableGatewayReceiverAttributes, registry);
}
@@ -76,22 +96,23 @@ public class EnableGatewayReceiverConfiguration extends AbstractAnnotationConfig
/**
* Configures a {@link GatewayReceiver} from the {@link EnableGatewayReceiver} annotation, <b><i>spring.data.gemfire.gateway.receiver.*</i></b>
* properties or {@link EnableGatewayReceiverConfigurer}
* properties or {@link GatewayReceiverConfigurer}
*
* @param enableGatewayReceiverAttributes
* @param registry
*/
private void registerGatewayReceiverBeanDefinition(AnnotationAttributes enableGatewayReceiverAttributes,
BeanDefinitionRegistry registry) {
BeanDefinitionRegistry registry) {
BeanDefinitionBuilder gatewayReceiverBeanBuilder =
BeanDefinitionBuilder.genericBeanDefinition(GatewayReceiverFactoryBean.class);
String gatewayReceiverBeanName = "GatewayReceiver";
configureBeanFromAnnotatedProperties(enableGatewayReceiverAttributes, gatewayReceiverBeanBuilder,
configureBeanFromAnnotationAttributes(enableGatewayReceiverAttributes, gatewayReceiverBeanBuilder,
gatewayReceiverBeanName);
configureBeanBuilderFromPropertiesOrWithDefaultValues(gatewayReceiverBeanBuilder);
configureBeanFromPropertiesOrWithDefaultValues(gatewayReceiverBeanBuilder);
registerGatewayTransportFilterDependencies(enableGatewayReceiverAttributes, gatewayReceiverBeanBuilder);
@@ -106,8 +127,9 @@ public class EnableGatewayReceiverConfiguration extends AbstractAnnotationConfig
* @param gatewayReceiverBeanBuilder
* @param gatewayReceiverBeanName
*/
private void configureBeanFromAnnotatedProperties(AnnotationAttributes enableGatewayReceiverAttributes,
BeanDefinitionBuilder gatewayReceiverBeanBuilder, String gatewayReceiverBeanName) {
private void configureBeanFromAnnotationAttributes(AnnotationAttributes enableGatewayReceiverAttributes,
BeanDefinitionBuilder gatewayReceiverBeanBuilder, String gatewayReceiverBeanName) {
gatewayReceiverBeanBuilder.addConstructorArgReference(GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME);
gatewayReceiverBeanBuilder.addPropertyValue("beanName", gatewayReceiverBeanName);
@@ -137,7 +159,7 @@ public class EnableGatewayReceiverConfiguration extends AbstractAnnotationConfig
enableGatewayReceiverAttributes.getString(HOSTNAME_FOR_SENDERS_LITERAL), DEFAULT_HOSTNAME_FOR_SENDERS);
setPropertyValueIfNotDefault(gatewayReceiverBeanBuilder, TRANSPORT_FILTERS_LITERAL,
resolveTransportBeanReferences(enableGatewayReceiverAttributes.getStringArray(TRANSPORT_FILTERS_LITERAL)),
resolveGatewayTransportFilterBeanReferences(enableGatewayReceiverAttributes.getStringArray(TRANSPORT_FILTERS_LITERAL)),
new ManagedList<BeanReference>());
}
@@ -146,90 +168,80 @@ public class EnableGatewayReceiverConfiguration extends AbstractAnnotationConfig
*
* @param gatewayReceiverBeanBuilder
*/
private void configureBeanBuilderFromPropertiesOrWithDefaultValues(
BeanDefinitionBuilder gatewayReceiverBeanBuilder) {
MutablePropertyValues beanPropertyValues = gatewayReceiverBeanBuilder.getRawBeanDefinition()
.getPropertyValues();
private void configureBeanFromPropertiesOrWithDefaultValues(BeanDefinitionBuilder gatewayReceiverBeanBuilder) {
MutablePropertyValues beanPropertyValues =
gatewayReceiverBeanBuilder.getRawBeanDefinition().getPropertyValues();
configureFromProperties(gatewayReceiverBeanBuilder, START_PORT_LITERAL, START_PORT_PROPERTY_LITERAL,
(Integer) beanPropertyValues.getPropertyValue(START_PORT_LITERAL).getValue());
Integer.class, (Integer) beanPropertyValues.getPropertyValue(START_PORT_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder, END_PORT_LITERAL, END_PORT_PROPERTY_LITERAL,
(Integer) beanPropertyValues.getPropertyValue(END_PORT_LITERAL).getValue());
Integer.class, (Integer) beanPropertyValues.getPropertyValue(END_PORT_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder, MANUAL_START_LITERAL, MANUAL_START_PROPERTY_LITERAL,
(Boolean) beanPropertyValues.getPropertyValue(MANUAL_START_LITERAL).getValue());
Boolean.class, (Boolean) beanPropertyValues.getPropertyValue(MANUAL_START_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder, MAXIMUM_TIME_BETWEEN_PINGS_LITERAL,
MAXIMUM_TIME_BETWEEN_PINGS_PROPERTY_LITERAL,
(Integer) beanPropertyValues.getPropertyValue(MAXIMUM_TIME_BETWEEN_PINGS_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder,
MAXIMUM_TIME_BETWEEN_PINGS_LITERAL, MAXIMUM_TIME_BETWEEN_PINGS_PROPERTY_LITERAL,
Integer.class, (Integer) beanPropertyValues.getPropertyValue(MAXIMUM_TIME_BETWEEN_PINGS_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder, SOCKET_BUFFER_SIZE_LITERAL,
SOCKET_BUFFER_SIZE_PROPERTY_LITERAL,
(Integer) beanPropertyValues.getPropertyValue(SOCKET_BUFFER_SIZE_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder,
SOCKET_BUFFER_SIZE_LITERAL, SOCKET_BUFFER_SIZE_PROPERTY_LITERAL,
Integer.class, (Integer) beanPropertyValues.getPropertyValue(SOCKET_BUFFER_SIZE_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder, BIND_ADDRESS_LITERAL, BIND_ADDRESS_PROPERTY_LITERAL,
(String) beanPropertyValues.getPropertyValue(BIND_ADDRESS_LITERAL).getValue());
String.class, (String) beanPropertyValues.getPropertyValue(BIND_ADDRESS_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder, HOSTNAME_FOR_SENDERS_LITERAL,
HOSTNAME_FOR_SENDERS_PROPERTY_LITERAL,
(String) beanPropertyValues.getPropertyValue(HOSTNAME_FOR_SENDERS_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder,
HOSTNAME_FOR_SENDERS_LITERAL, HOSTNAME_FOR_SENDERS_PROPERTY_LITERAL,
String.class, (String) beanPropertyValues.getPropertyValue(HOSTNAME_FOR_SENDERS_LITERAL).getValue());
String[] filters = resolveProperty(gatewayReceiverProperty(TRANSPORT_FILTERS_PROPERTY_LITERAL), String[].class);
Optional.ofNullable(filters)
.ifPresent(transportFilters ->
{
ManagedList<BeanReference> beanReferences = resolveTransportBeanReferences(transportFilters);
gatewayReceiverBeanBuilder.addPropertyValue(TRANSPORT_FILTERS_LITERAL, beanReferences);
});
Optional.ofNullable(filters).ifPresent(transportFilters -> {
ManagedList<BeanReference> beanReferences = resolveGatewayTransportFilterBeanReferences(transportFilters);
gatewayReceiverBeanBuilder.addPropertyValue(TRANSPORT_FILTERS_LITERAL, beanReferences);
});
}
private void configureFromProperties(BeanDefinitionBuilder gatewayReceiverBeanBuilder, String beanPropertyName,
String propertyName,
Integer annotatedPropertyValue) {
Integer propertyValue = resolveProperty(gatewayReceiverProperty(propertyName), annotatedPropertyValue);
private <T> void configureFromProperties(BeanDefinitionBuilder gatewayReceiverBeanBuilder,
String beanPropertyName, String propertyName, Class<T> propertyType, T annotationAttributeValue) {
T propertyValue = resolveProperty(gatewayReceiverProperty(propertyName), propertyType, annotationAttributeValue);
gatewayReceiverBeanBuilder.addPropertyValue(beanPropertyName, propertyValue);
}
private ManagedList<BeanReference> resolveGatewayTransportFilterBeanReferences(
String[] gatewayTransportFilterBeanNames) {
private void configureFromProperties(BeanDefinitionBuilder gatewayReceiverBeanBuilder, String beanPropertyName,
String propertyName,
String annotatedPropertyValue) {
String propertyValue = resolveProperty(gatewayReceiverProperty(propertyName), annotatedPropertyValue);
gatewayReceiverBeanBuilder.addPropertyValue(beanPropertyName, propertyValue);
}
ManagedList<BeanReference> gatewayTransportFilterBeanReferences = new ManagedList<>();
private void configureFromProperties(BeanDefinitionBuilder gatewayReceiverBeanBuilder, String beanPropertyName,
String propertyName,
Boolean annotatedPropertyValue) {
Boolean propertyValue = resolveProperty(gatewayReceiverProperty(propertyName), annotatedPropertyValue);
gatewayReceiverBeanBuilder.addPropertyValue(beanPropertyName, propertyValue);
}
private ManagedList<BeanReference> resolveTransportBeanReferences(String[] transportFilters) {
ManagedList<BeanReference> transportFilterBeanReferences = new ManagedList<>();
Optional.ofNullable(transportFilters).ifPresent(transportFilterBeanNames ->
Arrays.stream(transportFilterBeanNames)
Optional.ofNullable(gatewayTransportFilterBeanNames).ifPresent(it ->
Arrays.stream(it)
.map(RuntimeBeanReference::new)
.forEach(transportFilterBeanReferences::add));
.forEach(gatewayTransportFilterBeanReferences::add));
return transportFilterBeanReferences;
return gatewayTransportFilterBeanReferences;
}
private void registerGatewayTransportFilterDependencies(AnnotationAttributes annotationAttributes,
BeanDefinitionBuilder gatewayReceiverBeanBuilder) {
String[] transportFilters = (String[]) annotationAttributes.get(TRANSPORT_FILTERS_LITERAL);
Optional.ofNullable(transportFilters).ifPresent(
transportFilerBeanNames -> Arrays.stream(transportFilerBeanNames)
.forEach(gatewayReceiverBeanBuilder::addDependsOn));
BeanDefinitionBuilder gatewayReceiverBeanBuilder) {
String[] transportFilters = annotationAttributes.getStringArray(TRANSPORT_FILTERS_LITERAL);
Optional.ofNullable(transportFilters).ifPresent(transportFilerBeanNames ->
Arrays.stream(transportFilerBeanNames).forEach(gatewayReceiverBeanBuilder::addDependsOn));
}
/* (non-Javadoc) */
private <T> BeanDefinitionBuilder setPropertyValueIfNotDefault(BeanDefinitionBuilder beanDefinitionBuilder,
String propertyName, T value, T defaultValue) {
String propertyName, T value, T defaultValue) {
return (value != null) ?
beanDefinitionBuilder.addPropertyValue(propertyName, value)
return value != null
? beanDefinitionBuilder.addPropertyValue(propertyName, value)
: beanDefinitionBuilder.addPropertyValue(propertyName, defaultValue);
}
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2019 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.config.annotation;
import org.springframework.data.gemfire.config.annotation.support.Configurer;
import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean;
/**
* {@link GatewayReceiverConfigurer} used to customize the configuration of a {@link GatewayReceiverFactoryBean}.
*
* @author Udo Kohlmeyer
* @author John Blum
* @see org.springframework.data.gemfire.config.annotation.support.Configurer
*/
@FunctionalInterface
public interface GatewayReceiverConfigurer extends Configurer<GatewayReceiverFactoryBean> {
}

View File

@@ -13,12 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire.wan;
import org.apache.geode.cache.Cache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
@@ -26,6 +24,9 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Abstract base class for WAN Gateway components.
*

View File

@@ -24,10 +24,11 @@ import org.apache.geode.cache.Cache;
import org.apache.geode.cache.wan.GatewayReceiver;
import org.apache.geode.cache.wan.GatewayReceiverFactory;
import org.apache.geode.cache.wan.GatewayTransportFilter;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.gemfire.config.annotation.GatewayReceiverConfigurer;
import org.springframework.data.gemfire.util.CollectionUtils;
import org.springframework.data.gemfire.wan.annotation.EnableGatewayReceiverConfigurer;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -37,11 +38,12 @@ import org.springframework.util.StringUtils;
* @author David Turanski
* @author John Blum
* @author Udo Kohlmeyer
* @see org.springframework.context.SmartLifecycle
* @see org.springframework.data.gemfire.wan.AbstractWANComponentFactoryBean
* @see org.apache.geode.cache.Cache
* @see org.apache.geode.cache.wan.GatewayReceiver
* @see org.apache.geode.cache.wan.GatewayReceiverFactory
* @see org.apache.geode.cache.wan.GatewayTransportFilter
* @see org.springframework.context.SmartLifecycle
* @see org.springframework.data.gemfire.wan.AbstractWANComponentFactoryBean
* @since 1.2.2
*/
@SuppressWarnings("unused")
@@ -56,15 +58,15 @@ public class GatewayReceiverFactoryBean extends AbstractWANComponentFactoryBean<
private Integer socketBufferSize;
private Integer startPort;
@Autowired
private GatewayReceiverConfigurer gatewayReceiverConfigurer;
@Autowired
private List<GatewayTransportFilter> transportFilters;
private String bindAddress;
private String hostnameForSenders;
@Autowired
private EnableGatewayReceiverConfigurer gatewayReceiverConfigurer;
/**
* Constructs an instance of the {@link GatewayReceiverFactoryBean} class initialized with a reference to
* the Pivotal GemFire {@link Cache} used to configure and initialize a Pivotal GemFire {@link GatewayReceiver}.
@@ -81,7 +83,7 @@ public class GatewayReceiverFactoryBean extends AbstractWANComponentFactoryBean<
*/
@Override
public GatewayReceiver getObject() throws Exception {
return gatewayReceiver;
return this.gatewayReceiver;
}
/**
@@ -89,60 +91,61 @@ public class GatewayReceiverFactoryBean extends AbstractWANComponentFactoryBean<
*/
@Override
public Class<?> getObjectType() {
return (gatewayReceiver != null ? gatewayReceiver.getClass() : GatewayReceiver.class);
return this.gatewayReceiver != null
? this.gatewayReceiver.getClass()
: GatewayReceiver.class;
}
/**
* @inheritDoc
*/
@Override
protected void doInit() throws Exception {
protected void doInit() {
GatewayReceiverFactory gatewayReceiverFactory = cache.createGatewayReceiverFactory();
Optional.of(gatewayReceiverConfigurer)
.ifPresent(gatewayReceiverConfigurer1 -> gatewayReceiverConfigurer1.configure("GatewayReceiver",this));
Optional.of(this.gatewayReceiverConfigurer)
.ifPresent(it -> it.configure(getName(),this));
if (StringUtils.hasText(bindAddress)) {
gatewayReceiverFactory.setBindAddress(bindAddress);
if (StringUtils.hasText(this.bindAddress)) {
gatewayReceiverFactory.setBindAddress(this.bindAddress);
}
if (StringUtils.hasText(hostnameForSenders)) {
gatewayReceiverFactory.setHostnameForSenders(hostnameForSenders);
if (StringUtils.hasText(this.hostnameForSenders)) {
gatewayReceiverFactory.setHostnameForSenders(this.hostnameForSenders);
}
int localStartPort = defaultPort(startPort, GatewayReceiver.DEFAULT_START_PORT);
int localEndPort = defaultPort(endPort, GatewayReceiver.DEFAULT_END_PORT);
int localStartPort = defaultPort(this.startPort, GatewayReceiver.DEFAULT_START_PORT);
int localEndPort = defaultPort(this.endPort, GatewayReceiver.DEFAULT_END_PORT);
Assert.isTrue(localStartPort <= localEndPort,
String.format("'startPort' must be less than or equal to %d.", localEndPort));
gatewayReceiverFactory.setStartPort(localStartPort);
gatewayReceiverFactory.setEndPort(localEndPort);
gatewayReceiverFactory.setManualStart(manualStart);
gatewayReceiverFactory.setManualStart(this.manualStart);
if (maximumTimeBetweenPings != null) {
gatewayReceiverFactory.setMaximumTimeBetweenPings(maximumTimeBetweenPings);
}
Optional.ofNullable(this.maximumTimeBetweenPings).ifPresent(gatewayReceiverFactory::setMaximumTimeBetweenPings);
Optional.ofNullable(this.socketBufferSize).ifPresent(gatewayReceiverFactory::setSocketBufferSize);
if (socketBufferSize != null) {
gatewayReceiverFactory.setSocketBufferSize(socketBufferSize);
}
CollectionUtils.nullSafeList(transportFilters).forEach(gatewayReceiverFactory::addGatewayTransportFilter);
for (GatewayTransportFilter transportFilter : CollectionUtils.nullSafeList(transportFilters)) {
gatewayReceiverFactory.addGatewayTransportFilter(transportFilter);
}
gatewayReceiver = gatewayReceiverFactory.create();
this.gatewayReceiver = gatewayReceiverFactory.create();
}
protected int defaultPort(Integer port, int defaultPort) {
return (port != null ? port : defaultPort);
return port != null ? port : defaultPort;
}
public void setGatewayReceiver(GatewayReceiver gatewayReceiver) {
this.gatewayReceiver = gatewayReceiver;
}
public void setGatewayReceiverConfigurer(GatewayReceiverConfigurer gatewayReceiverConfigurer) {
this.gatewayReceiverConfigurer = gatewayReceiverConfigurer;
}
public void setBindAddress(String bindAddress) {
this.bindAddress = bindAddress;
}
@@ -178,8 +181,4 @@ public class GatewayReceiverFactoryBean extends AbstractWANComponentFactoryBean<
public Collection<? extends GatewayTransportFilter> getTransportFilters() {
return Collections.unmodifiableList(transportFilters);
}
public void setGatewayReceiverConfigurer(EnableGatewayReceiverConfigurer gatewayReceiverConfigurer) {
this.gatewayReceiverConfigurer = gatewayReceiverConfigurer;
}
}

View File

@@ -1,16 +0,0 @@
package org.springframework.data.gemfire.wan.annotation;
import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean;
public interface EnableGatewayReceiverConfigurer {
/**
* Configuration callback method providing a reference to a {@link GatewayReceiverFactoryBean} used to construct,
* configure and initialize an instance of {@link org.apache.geode.cache.wan.GatewayReceiver}.
*
* @param beanName name of the {@link org.apache.geode.cache.wan.GatewayReceiver} bean declared in the Spring application context.
* @param bean reference to the {@link GatewayReceiverFactoryBean}.
* @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean
* @see org.apache.geode.cache.wan.GatewayReceiver
*/
void configure(String beanName, GatewayReceiverFactoryBean bean);
}

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2019 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.config.annotation;
import static org.assertj.core.api.Assertions.assertThat;
@@ -10,22 +25,21 @@ import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import org.apache.geode.cache.wan.GatewayReceiver;
import org.apache.geode.cache.wan.GatewayTransportFilter;
import org.junit.After;
import org.junit.Test;
import org.apache.geode.cache.wan.GatewayReceiver;
import org.apache.geode.cache.wan.GatewayTransportFilter;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean;
import org.springframework.data.gemfire.wan.annotation.EnableGatewayReceiver;
import org.springframework.data.gemfire.wan.annotation.EnableGatewayReceiverConfiguration;
import org.springframework.data.gemfire.wan.annotation.EnableGatewayReceiverConfigurer;
/**
* Tests for {@link org.springframework.data.gemfire.wan.annotation.EnableGatewayReceiver}.
* Tests for {@link EnableGatewayReceiver}.
*
* @author Udo Kohlmeyer
* @see org.junit.Test
@@ -35,8 +49,8 @@ import org.springframework.data.gemfire.wan.annotation.EnableGatewayReceiverConf
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringRunner
* @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean
* @see EnableGatewayReceiverConfigurer
* @see EnableGatewayReceiverConfiguration
* @see GatewayReceiverConfigurer
* @see GatewayReceiverConfiguration
* @since 2.2.0
*/
public class EnableGatewayReceiverConfigurationTests {
@@ -44,8 +58,7 @@ public class EnableGatewayReceiverConfigurationTests {
private ConfigurableApplicationContext applicationContext;
@After
public void shutdown()
{
public void shutdown() {
Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close);
}
@@ -69,7 +82,7 @@ public class EnableGatewayReceiverConfigurationTests {
}
@Bean("gatewayConfigurer")
EnableGatewayReceiverConfigurer gatewayReceiverConfigurer() {
GatewayReceiverConfigurer gatewayReceiverConfigurer() {
return new TestGatewayReceiverConfigurer();
}
}
@@ -92,16 +105,18 @@ public class EnableGatewayReceiverConfigurationTests {
}
@Bean("gatewayConfigurer")
EnableGatewayReceiverConfigurer gatewayReceiverConfigurer() {
GatewayReceiverConfigurer gatewayReceiverConfigurer() {
return new TestGatewayReceiverConfigurer();
}
}
@Test
public void annotationConfiguredGatewayTransportFiltersOrdered() {
this.applicationContext = newApplicationContext(TestConfigurationFromAnnotation.class);
TestGatewayReceiverConfigurer gatewayReceiverConfigurer = (TestGatewayReceiverConfigurer) this.applicationContext.getBean(
EnableGatewayReceiverConfigurer.class);
TestGatewayReceiverConfigurer gatewayReceiverConfigurer =
(TestGatewayReceiverConfigurer) this.applicationContext.getBean(GatewayReceiverConfigurer.class);
GatewayReceiver gatewayReceiver = this.applicationContext.getBean("GatewayReceiver",GatewayReceiver.class);
@@ -120,9 +135,11 @@ public class EnableGatewayReceiverConfigurationTests {
@Test
public void beanConfiguredGatewayTransportFiltersOrdered() {
this.applicationContext = newApplicationContext(TestConfigurationWithOrder.class);
TestGatewayReceiverConfigurer gatewayReceiverConfigurer = (TestGatewayReceiverConfigurer) this.applicationContext.getBean(
EnableGatewayReceiverConfigurer.class);
TestGatewayReceiverConfigurer gatewayReceiverConfigurer =
(TestGatewayReceiverConfigurer) this.applicationContext.getBean(GatewayReceiverConfigurer.class);
GatewayReceiver gatewayReceiver = this.applicationContext.getBean("GatewayReceiver",GatewayReceiver.class);
@@ -139,7 +156,7 @@ public class EnableGatewayReceiverConfigurationTests {
assertThat(gatewayReceiverConfigurer.beanNames.toArray()).isEqualTo(new String[]{"transportBean1", "transportBean2"});
}
private static class TestGatewayReceiverConfigurer implements EnableGatewayReceiverConfigurer, Iterable<String> {
private static class TestGatewayReceiverConfigurer implements GatewayReceiverConfigurer, Iterable<String> {
private final List<String> beanNames = new ArrayList<>();
@@ -155,6 +172,7 @@ public class EnableGatewayReceiverConfigurationTests {
}
private static class TestGatewayTransportFilter implements GatewayTransportFilter {
private String name;
public TestGatewayTransportFilter(String name) {

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2019 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.config.annotation;
import static org.assertj.core.api.Assertions.assertThat;
@@ -7,10 +22,12 @@ import java.io.OutputStream;
import java.util.Arrays;
import java.util.Optional;
import org.apache.geode.cache.wan.GatewayReceiver;
import org.apache.geode.cache.wan.GatewayTransportFilter;
import org.junit.After;
import org.junit.Test;
import org.apache.geode.cache.wan.GatewayReceiver;
import org.apache.geode.cache.wan.GatewayTransportFilter;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -18,13 +35,10 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean;
import org.springframework.data.gemfire.wan.annotation.EnableGatewayReceiver;
import org.springframework.data.gemfire.wan.annotation.EnableGatewayReceiverConfiguration;
import org.springframework.data.gemfire.wan.annotation.EnableGatewayReceiverConfigurer;
import org.springframework.mock.env.MockPropertySource;
/**
* Tests for {@link org.springframework.data.gemfire.wan.annotation.EnableGatewayReceiver}.
* Tests for {@link EnableGatewayReceiver}.
*
* @author Udo Kohlmeyer
* @see org.junit.Test
@@ -34,11 +48,11 @@ import org.springframework.mock.env.MockPropertySource;
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringRunner
* @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean
* @see EnableGatewayReceiverConfigurer
* @see EnableGatewayReceiverConfiguration
* @see GatewayReceiverConfigurer
* @see GatewayReceiverConfiguration
* @since 2.2.0
*/
public class EnableEnableGatewayReceiverConfigurerTests {
public class GatewayReceiverConfigurerTests {
private ConfigurableApplicationContext applicationContext;
@@ -48,7 +62,7 @@ public class EnableEnableGatewayReceiverConfigurerTests {
}
private ConfigurableApplicationContext newApplicationContext(PropertySource<?> testPropertySource,
Class<?>... annotatedClasses) {
Class<?>... annotatedClasses) {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
@@ -69,7 +83,7 @@ public class EnableEnableGatewayReceiverConfigurerTests {
MockPropertySource testPropertySource = new MockPropertySource();
this.applicationContext = newApplicationContext(testPropertySource,
EnableEnableGatewayReceiverConfigurerTests.TestConfigurationWithProperties.class);
GatewayReceiverConfigurerTests.TestConfigurationWithProperties.class);
assertThat(this.applicationContext).isNotNull();
assertThat(this.applicationContext.containsBean("GatewayReceiver")).isTrue();
@@ -103,7 +117,7 @@ public class EnableEnableGatewayReceiverConfigurerTests {
.withProperty("spring.data.gemfire.gateway.receiver.transport-filters", "transportBean1,transportBean2");
this.applicationContext = newApplicationContext(testPropertySource,
EnableEnableGatewayReceiverConfigurerTests.TestConfigurationWithProperties.class);
GatewayReceiverConfigurerTests.TestConfigurationWithProperties.class);
assertThat(this.applicationContext).isNotNull();
assertThat(this.applicationContext.containsBean("GatewayReceiver")).isTrue();
@@ -134,7 +148,7 @@ public class EnableEnableGatewayReceiverConfigurerTests {
.withProperty("spring.data.gemfire.gateway.receiver.transport-filters", "transportBean2,transportBean1");
this.applicationContext = newApplicationContext(testPropertySource,
EnableEnableGatewayReceiverConfigurerTests.TestConfiguration.class);
GatewayReceiverConfigurerTests.TestConfiguration.class);
assertThat(this.applicationContext).isNotNull();
assertThat(this.applicationContext.containsBean("GatewayReceiver")).isTrue();
@@ -164,16 +178,16 @@ public class EnableEnableGatewayReceiverConfigurerTests {
@Bean("transportBean1")
GatewayTransportFilter createGatewayTransportBean1() {
return new EnableEnableGatewayReceiverConfigurerTests.TestGatewayTransportFilter("transportBean1");
return new GatewayReceiverConfigurerTests.TestGatewayTransportFilter("transportBean1");
}
@Bean("transportBean2")
GatewayTransportFilter createGatewayTransportBean2() {
return new EnableEnableGatewayReceiverConfigurerTests.TestGatewayTransportFilter("transportBean2");
return new GatewayReceiverConfigurerTests.TestGatewayTransportFilter("transportBean2");
}
@Bean("gatewayConfigurer")
EnableGatewayReceiverConfigurer gatewayReceiverConfigurer() {
GatewayReceiverConfigurer gatewayReceiverConfigurer() {
return (String beanName, GatewayReceiverFactoryBean bean) -> {
bean.setBindAddress("127.0.0.1");
bean.setEndPort(25000);
@@ -196,16 +210,16 @@ public class EnableEnableGatewayReceiverConfigurerTests {
@Bean("transportBean1")
GatewayTransportFilter createGatewayTransportBean1() {
return new EnableEnableGatewayReceiverConfigurerTests.TestGatewayTransportFilter("transportBean1");
return new GatewayReceiverConfigurerTests.TestGatewayTransportFilter("transportBean1");
}
@Bean("transportBean2")
GatewayTransportFilter createGatewayTransportBean2() {
return new EnableEnableGatewayReceiverConfigurerTests.TestGatewayTransportFilter("transportBean2");
return new GatewayReceiverConfigurerTests.TestGatewayTransportFilter("transportBean2");
}
@Bean("gatewayConfigurer")
EnableGatewayReceiverConfigurer gatewayReceiverConfigurer() {
GatewayReceiverConfigurer gatewayReceiverConfigurer() {
return (String beanName, GatewayReceiverFactoryBean bean) -> {
bean.setBindAddress("127.0.0.1");
bean.setHostnameForSenders("testHostNameReceiverForSender");

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2019 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.config.annotation;
import static org.assertj.core.api.Assertions.assertThat;
@@ -10,24 +25,22 @@ import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import org.apache.geode.cache.wan.GatewayReceiver;
import org.apache.geode.cache.wan.GatewayTransportFilter;
import org.junit.After;
import org.junit.Test;
import org.apache.geode.cache.wan.GatewayReceiver;
import org.apache.geode.cache.wan.GatewayTransportFilter;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean;
import org.springframework.data.gemfire.wan.annotation.EnableGatewayReceiver;
import org.springframework.data.gemfire.wan.annotation.EnableGatewayReceiverConfiguration;
import org.springframework.data.gemfire.wan.annotation.EnableGatewayReceiverConfigurer;
import org.springframework.mock.env.MockPropertySource;
/**
* Tests for {@link org.springframework.data.gemfire.wan.annotation.EnableGatewayReceiver}.
* Tests for {@link EnableGatewayReceiver}.
*
* @author Udo Kohlmeyer
* @see org.junit.Test
@@ -37,11 +50,11 @@ import org.springframework.mock.env.MockPropertySource;
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringRunner
* @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean
* @see EnableGatewayReceiverConfigurer
* @see EnableGatewayReceiverConfiguration
* @see GatewayReceiverConfigurer
* @see GatewayReceiverConfiguration
* @since 2.2.0
*/
public class EnableGatewayReceiverPropertiesTests {
public class GatewayReceiverPropertiesTests {
private ConfigurableApplicationContext applicationContext;
@@ -51,7 +64,7 @@ public class EnableGatewayReceiverPropertiesTests {
}
private ConfigurableApplicationContext newApplicationContext(PropertySource<?> testPropertySource,
Class<?>... annotatedClasses) {
Class<?>... annotatedClasses) {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
@@ -70,16 +83,17 @@ public class EnableGatewayReceiverPropertiesTests {
public void gatewayReceiverPropertiesConfiguration() {
MockPropertySource testPropertySource = new MockPropertySource()
.withProperty("spring.data.gemfire.gateway.receiver.bindAddress", "123.123.123.123")
.withProperty("spring.data.gemfire.gateway.receiver.hostnameForSenders", "testHostName")
.withProperty("spring.data.gemfire.gateway.receiver.startPort", 16000)
.withProperty("spring.data.gemfire.gateway.receiver.endPort", 17000)
.withProperty("spring.data.gemfire.gateway.receiver.maximumTimeBetweenPings", 30000)
.withProperty("spring.data.gemfire.gateway.receiver.socketBufferSize", 32768)
.withProperty("spring.data.gemfire.gateway.receiver.manualStart", true)
.withProperty("spring.data.gemfire.gateway.receiver.transportFilters", "transportBean2,transportBean1");
.withProperty("spring.data.gemfire.gateway.receiver.bind-address", "123.123.123.123")
.withProperty("spring.data.gemfire.gateway.receiver.hostname-for-senders", "testHostName")
.withProperty("spring.data.gemfire.gateway.receiver.start-port", 16000)
.withProperty("spring.data.gemfire.gateway.receiver.end-port", 17000)
.withProperty("spring.data.gemfire.gateway.receiver.maximum-time-between-pings", 30000)
.withProperty("spring.data.gemfire.gateway.receiver.socket-buffer-size", 32768)
.withProperty("spring.data.gemfire.gateway.receiver.manual-start", true)
.withProperty("spring.data.gemfire.gateway.receiver.transport-filters", "transportBean2,transportBean1");
this.applicationContext = newApplicationContext(testPropertySource, EnableGatewayReceiverPropertiesTests.TestConfigurationWithProperties.class);
this.applicationContext = newApplicationContext(testPropertySource,
GatewayReceiverPropertiesTests.TestConfigurationWithProperties.class);
assertThat(this.applicationContext).isNotNull();
assertThat(this.applicationContext.containsBean("GatewayReceiver")).isTrue();
@@ -98,28 +112,28 @@ public class EnableGatewayReceiverPropertiesTests {
}
@Configuration
@CacheServerApplication
@EnableGatewayReceiver
static class TestConfigurationWithProperties{
@Bean("transportBean1")
GatewayTransportFilter createGatewayTransportBean1() {
return new EnableGatewayReceiverPropertiesTests.TestGatewayTransportFilter("transportBean1");
return new GatewayReceiverPropertiesTests.TestGatewayTransportFilter("transportBean1");
}
@Bean("transportBean2")
GatewayTransportFilter createGatewayTransportBean2() {
return new EnableGatewayReceiverPropertiesTests.TestGatewayTransportFilter("transportBean2");
return new GatewayReceiverPropertiesTests.TestGatewayTransportFilter("transportBean2");
}
@Bean("gatewayConfigurer")
EnableGatewayReceiverConfigurer gatewayReceiverConfigurer() {
return new EnableGatewayReceiverPropertiesTests.TestGatewayReceiverConfigurer();
GatewayReceiverConfigurer gatewayReceiverConfigurer() {
return new GatewayReceiverPropertiesTests.TestGatewayReceiverConfigurer();
}
}
private static class TestGatewayTransportFilter implements GatewayTransportFilter {
private String name;
public TestGatewayTransportFilter(String name) {
@@ -137,7 +151,7 @@ public class EnableGatewayReceiverPropertiesTests {
}
}
private static class TestGatewayReceiverConfigurer implements EnableGatewayReceiverConfigurer, Iterable<String> {
private static class TestGatewayReceiverConfigurer implements GatewayReceiverConfigurer, Iterable<String> {
private final List<String> beanNames = new ArrayList<>();
@@ -148,7 +162,7 @@ public class EnableGatewayReceiverPropertiesTests {
@Override
public void configure(String beanName, GatewayReceiverFactoryBean bean) {
bean.getTransportFilters().stream().forEach(o -> beanNames.add(((EnableGatewayReceiverPropertiesTests.TestGatewayTransportFilter) o).name));
bean.getTransportFilters().stream().forEach(o -> beanNames.add(((GatewayReceiverPropertiesTests.TestGatewayTransportFilter) o).name));
}
}
}