From 636289aeef4ac8de330a43f65944c8cb04da6da4 Mon Sep 17 00:00:00 2001 From: John Blum Date: Mon, 4 Jun 2018 18:33:31 -0700 Subject: [PATCH] Improve configuration logic. Edit Javadoc. Rename memberNameIsCorrect() test case method to memberNameWasConfiguredCorrectly(). --- .../annotation/MemberNameConfiguration.java | 27 ++++++++++--------- .../config/annotation/UseMemberName.java | 9 ++++++- ...mberNameConfigurationIntegrationTests.java | 4 ++- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/geode-spring-boot/src/main/java/org/springframework/geode/config/annotation/MemberNameConfiguration.java b/geode-spring-boot/src/main/java/org/springframework/geode/config/annotation/MemberNameConfiguration.java index 6d06c566..7e32bbf2 100644 --- a/geode-spring-boot/src/main/java/org/springframework/geode/config/annotation/MemberNameConfiguration.java +++ b/geode-spring-boot/src/main/java/org/springframework/geode/config/annotation/MemberNameConfiguration.java @@ -33,10 +33,10 @@ import org.springframework.data.gemfire.config.annotation.support.AbstractAnnota import org.springframework.util.StringUtils; /** - * The {@link MemberNameConfiguration} class is a Spring {@link Configuration} class used to set - * an Apache Geode or Pivotal GemFire's name in the distributed system, whether the member - * is a {@link ClientCache client} in the client/server topology or a {@link Cache peer} member - * of the cluster. + * The {@link MemberNameConfiguration} class is a Spring {@link Configuration} class used to configure + * an Apache Geode or Pivotal GemFire's member name in the distributed system, whether the member + * is a {@link ClientCache client} in the client/server topology or a {@link Cache peer} in a cluster + * using the P2P topology. * * @author John Blum * @see org.apache.geode.cache.Cache @@ -44,6 +44,9 @@ import org.springframework.util.StringUtils; * @see org.springframework.context.annotation.Bean * @see org.springframework.context.annotation.Configuration * @see org.springframework.context.annotation.ImportAware + * @see org.springframework.core.annotation.AnnotationAttributes + * @see org.springframework.core.type.AnnotationMetadata + * @see org.springframework.data.gemfire.CacheFactoryBean * @see org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer * @see org.springframework.data.gemfire.config.annotation.PeerCacheConfigurer * @see org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport @@ -64,26 +67,26 @@ public class MemberNameConfiguration extends AbstractAnnotationConfigSupport imp } @Override + @SuppressWarnings("all") public void setImportMetadata(AnnotationMetadata importMetadata) { if (isAnnotationPresent(importMetadata)) { AnnotationAttributes memberNameAttributes = getAnnotationAttributes(importMetadata); - setMemberNameIfNotSet(memberNameAttributes.containsKey("name") - ? memberNameAttributes.getString("name") : null); - - setMemberNameIfNotSet(memberNameAttributes.containsKey("value") + setMemberName(memberNameAttributes.containsKey("value") ? memberNameAttributes.getString("value") : null); + + setMemberName(memberNameAttributes.containsKey("name") + ? memberNameAttributes.getString("name") : null); } } protected void setMemberName(String memberName) { - this.memberName = memberName; - } - protected void setMemberNameIfNotSet(String memberName) { - setMemberName(this.memberName != null ? this.memberName : memberName); + this.memberName = Optional.ofNullable(memberName) + .filter(StringUtils::hasText) + .orElse(this.memberName); } protected Optional getMemberName() { diff --git a/geode-spring-boot/src/main/java/org/springframework/geode/config/annotation/UseMemberName.java b/geode-spring-boot/src/main/java/org/springframework/geode/config/annotation/UseMemberName.java index bd985b03..907019c9 100644 --- a/geode-spring-boot/src/main/java/org/springframework/geode/config/annotation/UseMemberName.java +++ b/geode-spring-boot/src/main/java/org/springframework/geode/config/annotation/UseMemberName.java @@ -31,12 +31,17 @@ import org.springframework.core.annotation.AliasFor; /** * The {@link UseMemberName} annotation configures the {@literal name} of the member in the Apache Geode * or Pivotal GemFire distributed system, whether the member is a {@link ClientCache client} in - * the client/server topology or a {@link Cache peer} member of the cluster. + * the client/server topology or a {@link Cache peer Cache member} in the cluster using the P2P topology. * * @author John Blum + * @see java.lang.annotation.Documented + * @see java.lang.annotation.Inherited + * @see java.lang.annotation.Retention + * @see java.lang.annotation.Target * @see org.apache.geode.cache.Cache * @see org.apache.geode.cache.client.ClientCache * @see org.springframework.context.annotation.Import + * @see org.springframework.core.annotation.AliasFor * @see org.springframework.geode.config.annotation.MemberNameConfiguration * @since 1.0.0 */ @@ -49,6 +54,7 @@ public @interface UseMemberName { /** * {@link String Name} used for the Apache Geode/Pivotal GemFire distributed system member. + * * @see #name() */ @AliasFor("name") @@ -56,6 +62,7 @@ public @interface UseMemberName { /** * Alias for the {@link String name} of the Apache Geode/Pivotal GemFire distributed system member. + * * @see #value() */ @AliasFor("value") diff --git a/geode-spring-boot/src/test/java/org/springframework/geode/config/annotation/MemberNameConfigurationIntegrationTests.java b/geode-spring-boot/src/test/java/org/springframework/geode/config/annotation/MemberNameConfigurationIntegrationTests.java index fa510808..90c838bf 100644 --- a/geode-spring-boot/src/test/java/org/springframework/geode/config/annotation/MemberNameConfigurationIntegrationTests.java +++ b/geode-spring-boot/src/test/java/org/springframework/geode/config/annotation/MemberNameConfigurationIntegrationTests.java @@ -32,7 +32,9 @@ import org.springframework.test.context.junit4.SpringRunner; * Integration tests for {@link UseMemberName} and {@link MemberNameConfiguration}. * * @author John Blum + * @see org.apache.geode.cache.GemFireCache * @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner @@ -47,7 +49,7 @@ public class MemberNameConfigurationIntegrationTests extends IntegrationTestsSup private GemFireCache gemfireCache; @Test - public void memberNameIsCorrect() { + public void memberNameWasConfiguredCorrectly() { assertThat(this.gemfireCache).isNotNull(); assertThat(this.gemfireCache.getDistributedSystem()).isNotNull();