From d29a295ec4761fc5b32f0d033204ef376aac76fc Mon Sep 17 00:00:00 2001 From: John Blum Date: Sat, 26 May 2018 23:34:29 -0700 Subject: [PATCH] Add a base ClientServerIntegrationTestsConfiguration class with support to configure the ClientCache Pool port and CacheServer port using SDG Configurers registered as bean definitions in the Spring context. Refactor SubscriptionEnabledClientServerIntegrationTestsConfiguration to extend ClientServerIntegrationTestsConfiguration. --- ...ntServerIntegrationTestsConfiguration.java | 63 +++++++++++++++++++ ...entServerIntegrationTestConfiguration.java | 5 +- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 spring-test-data-geode/src/main/java/org/springframework/data/gemfire/tests/integration/config/ClientServerIntegrationTestsConfiguration.java diff --git a/spring-test-data-geode/src/main/java/org/springframework/data/gemfire/tests/integration/config/ClientServerIntegrationTestsConfiguration.java b/spring-test-data-geode/src/main/java/org/springframework/data/gemfire/tests/integration/config/ClientServerIntegrationTestsConfiguration.java new file mode 100644 index 0000000..b7e49ac --- /dev/null +++ b/spring-test-data-geode/src/main/java/org/springframework/data/gemfire/tests/integration/config/ClientServerIntegrationTestsConfiguration.java @@ -0,0 +1,63 @@ +/* + * 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 + * + * 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.tests.integration.config; + +import static org.springframework.data.gemfire.tests.integration.ClientServerIntegrationTestsSupport.GEMFIRE_CACHE_SERVER_PORT_PROPERTY; + +import java.util.Collections; + +import org.apache.geode.cache.client.ClientCache; +import org.apache.geode.cache.client.Pool; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.gemfire.config.annotation.CacheServerConfigurer; +import org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer; +import org.springframework.data.gemfire.support.ConnectionEndpoint; + +/** + * The {@link ClientServerIntegrationTestsConfiguration} class is a Spring {@link @Configuration} class + * that registers a {@link ClientCacheConfigurer} used to configure the {@link ClientCache} {@link Pool} port + * to connect to the launched Apache Geode/Pivotal GemFire Server during integration testing. + * + * @author John Blum + * @see org.apache.geode.cache.client.ClientCache + * @see org.apache.geode.cache.client.Pool + * @see org.springframework.context.annotation.Bean + * @see org.springframework.context.annotation.Configuration + * @see org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer + * @since 1.0.0 + */ +@Configuration +@SuppressWarnings("unused") +public class ClientServerIntegrationTestsConfiguration { + + @Bean + ClientCacheConfigurer clientCachePoolPortConfigurer( + @Value("${" + GEMFIRE_CACHE_SERVER_PORT_PROPERTY + ":40404}") int port) { + + return (beanName, clientCacheFactoryBean) -> clientCacheFactoryBean.setServers( + Collections.singletonList(new ConnectionEndpoint("localhost", port))); + } + + @Bean + CacheServerConfigurer cacheServerPortConfigurer( + @Value("${" + GEMFIRE_CACHE_SERVER_PORT_PROPERTY + ":40404}") int port) { + + return (beanName, cacheServerFactoryBean) -> cacheServerFactoryBean.setPort(port); + } +} diff --git a/spring-test-data-geode/src/main/java/org/springframework/data/gemfire/tests/integration/config/SubscriptionEnabledClientServerIntegrationTestConfiguration.java b/spring-test-data-geode/src/main/java/org/springframework/data/gemfire/tests/integration/config/SubscriptionEnabledClientServerIntegrationTestConfiguration.java index 33a17d9..844bdb2 100644 --- a/spring-test-data-geode/src/main/java/org/springframework/data/gemfire/tests/integration/config/SubscriptionEnabledClientServerIntegrationTestConfiguration.java +++ b/spring-test-data-geode/src/main/java/org/springframework/data/gemfire/tests/integration/config/SubscriptionEnabledClientServerIntegrationTestConfiguration.java @@ -63,6 +63,7 @@ import org.springframework.util.StringUtils; * @see org.apache.geode.cache.client.ClientCache * @see org.apache.geode.cache.client.Pool * @see org.apache.geode.cache.client.PoolManager + * @see org.apache.geode.cache.client.internal.PoolImpl * @see org.apache.geode.management.membership.ClientMembership * @see org.apache.geode.management.membership.ClientMembershipListenerAdapter * @see org.springframework.beans.factory.ListableBeanFactory @@ -75,11 +76,13 @@ import org.springframework.util.StringUtils; * @see org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer * @see org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer * @see org.springframework.data.gemfire.tests.integration.ClientServerIntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.config.ClientServerIntegrationTestsConfiguration * @since 1.0.0 */ @Configuration @SuppressWarnings("unused") -public class SubscriptionEnabledClientServerIntegrationTestConfiguration { +public class SubscriptionEnabledClientServerIntegrationTestConfiguration + extends ClientServerIntegrationTestsConfiguration { private static final long DEFAULT_TIMEOUT = TimeUnit.SECONDS.toMillis(15);