diff --git a/samples/boot/gemfire/spring-session-sample-boot-gemfire.gradle b/samples/boot/gemfire/spring-session-sample-boot-gemfire.gradle index 6ea7414..1659ec5 100644 --- a/samples/boot/gemfire/spring-session-sample-boot-gemfire.gradle +++ b/samples/boot/gemfire/spring-session-sample-boot-gemfire.gradle @@ -9,12 +9,16 @@ repositories { dependencies { compile project(':spring-session-data-geode') + compile("org.springframework.boot:spring-boot-starter-thymeleaf") { exclude group: "org.springframework.boot", module: "spring-boot-starter-logging" } + compile("org.springframework.boot:spring-boot-starter-web") { exclude group: "org.springframework.boot", module: "spring-boot-starter-logging" } + + compile "org.springframework.data:spring-data-geode-test" compile "org.webjars:bootstrap" compile "org.webjars:webjars-locator" @@ -23,6 +27,7 @@ dependencies { testCompile("org.springframework.boot:spring-boot-starter-test") { exclude group: "org.springframework.boot", module: "spring-boot-starter-logging" } + testCompile seleniumDependencies integrationTestCompile seleniumDependencies @@ -58,7 +63,7 @@ task runGemFireServer() { 'java', '-server', '-ea', '-classpath', classpath, //"-Dgemfire.log-file=gemfire-server.log", //"-Dgemfire.log-level=config", - "-Dspring.session.data.geode.cache.server.port=$port", + "-Dspring.data.gemfire.cache.server.port=$port", 'sample.server.GemFireServer' ] @@ -83,11 +88,12 @@ integrationTest { systemProperties['server.port'] = port //systemProperties['gemfire.log-file'] = "gemfire-client.log" //systemProperties['gemfire.log-level'] = "config" - systemProperties['spring.session.data.geode.cache.server.port'] = runGemFireServer.port + systemProperties['spring.data.gemfire.cache.server.port'] = runGemFireServer.port } doLast { println 'Stopping Apache Geode Server...' - runGemFireServer.process?.destroyForcibly() + runGemFireServer.process?.destroy() +// runGemFireServer.process?.destroyForcibly() } } diff --git a/samples/boot/gemfire/src/main/java/sample/client/Application.java b/samples/boot/gemfire/src/main/java/sample/client/Application.java index 4f557a8..13919cf 100644 --- a/samples/boot/gemfire/src/main/java/sample/client/Application.java +++ b/samples/boot/gemfire/src/main/java/sample/client/Application.java @@ -26,14 +26,13 @@ import java.util.Optional; import javax.servlet.http.HttpSession; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.context.annotation.Import; import org.springframework.data.gemfire.config.annotation.ClientCacheApplication; -import org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer; +import org.springframework.data.gemfire.tests.integration.config.SubscriptionEnabledClientServerIntegrationTestsConfiguration; import org.springframework.data.gemfire.util.CollectionUtils; import org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession; import org.springframework.stereotype.Controller; @@ -78,26 +77,11 @@ public class Application { @ClientCacheApplication(name = "SpringSessionDataGeodeClientBootSample", logLevel = "error", pingInterval = 5000L, readTimeout = 15000, retryAttempts = 1, subscriptionEnabled = true) // <3> @EnableGemFireHttpSession(poolName = "DEFAULT") // <4> - static class ClientCacheConfiguration extends IntegrationTestConfiguration { - - // Required to resolve property placeholders in Spring @Value annotations. - @Bean - static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() { - return new PropertySourcesPlaceholderConfigurer(); - } - - @Bean - ClientCacheConfigurer clientCacheServerPortConfigurer( - @Value("${spring.session.data.geode.cache.server.port:40404}") int port) { // <5> - - return (beanName, clientCacheFactoryBean) -> - clientCacheFactoryBean.setServers(Collections.singletonList( - newConnectionEndpoint("localhost", port))); - } - } + @Import(SubscriptionEnabledClientServerIntegrationTestsConfiguration.class) + static class ClientCacheConfiguration { } @Configuration - static class SpringWebMvcConfiguration { // <6> + static class SpringWebMvcConfiguration { // <5> @Bean public WebMvcConfigurer webMvcConfig() { diff --git a/samples/boot/gemfire/src/main/java/sample/client/IntegrationTestConfiguration.java b/samples/boot/gemfire/src/main/java/sample/client/IntegrationTestConfiguration.java deleted file mode 100644 index 60736e2..0000000 --- a/samples/boot/gemfire/src/main/java/sample/client/IntegrationTestConfiguration.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright 2017 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 sample.client; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.geode.cache.Region; -import org.apache.geode.cache.client.ClientCache; -import org.apache.geode.cache.client.Pool; -import org.apache.geode.cache.client.PoolManager; -import org.apache.geode.cache.client.internal.PoolImpl; -import org.apache.geode.management.membership.ClientMembership; -import org.apache.geode.management.membership.ClientMembershipEvent; -import org.apache.geode.management.membership.ClientMembershipListenerAdapter; - -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.context.annotation.Bean; -import org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer; -import org.springframework.data.gemfire.config.xml.GemfireConstants; -import org.springframework.data.gemfire.support.ConnectionEndpoint; -import org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration; -import org.springframework.util.Assert; - -/** - * The IntegrationTestConfiguration class... - * - * @author John Blum - * @since 1.0.0 - */ -public class IntegrationTestConfiguration { - - static final long DEFAULT_TIMEOUT = TimeUnit.SECONDS.toMillis(60); - - static final CountDownLatch LATCH = new CountDownLatch(1); - - static final String GEMFIRE_DEFAULT_POOL_NAME = "DEFAULT"; - - @Bean - BeanPostProcessor clientServerReadyBeanPostProcessor( - @Value("${spring.session.data.geode.cache.server.port:40404}") int port) { // <5> - - return new BeanPostProcessor() { - - private final AtomicBoolean checkGemFireServerIsRunning = new AtomicBoolean(true); - private final AtomicReference defaultPool = new AtomicReference<>(null); - - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { - - if (shouldCheckWhetherGemFireServerIsRunning(bean, beanName)) { - try { - validateCacheClientNotified(); - validateCacheClientSubscriptionQueueConnectionEstablished(); - } - catch (InterruptedException cause) { - Thread.currentThread().interrupt(); - } - } - - return bean; - } - - private boolean shouldCheckWhetherGemFireServerIsRunning(Object bean, String beanName) { - - return (isGemFireRegion(bean, beanName) - ? checkGemFireServerIsRunning.compareAndSet(true, false) - : whenGemFireCache(bean, beanName)); - } - - private boolean isGemFireRegion(Object bean, String beanName) { - - return (GemFireHttpSessionConfiguration.DEFAULT_SESSION_REGION_NAME.equals(beanName) - || bean instanceof Region); - } - - private boolean whenGemFireCache(Object bean, String beanName) { - - if (bean instanceof ClientCache) { - defaultPool.compareAndSet(null, ((ClientCache) bean).getDefaultPool()); - } - - return false; - } - - private void validateCacheClientNotified() throws InterruptedException { - - boolean didNotTimeout = LATCH.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS); - - Assert.state(didNotTimeout, String.format( - "Apache Geode Cache Server failed to start on host [%s] and port [%d]", "localhost", port)); - } - - @SuppressWarnings("all") - private void validateCacheClientSubscriptionQueueConnectionEstablished() throws InterruptedException { - - boolean cacheClientSubscriptionQueueConnectionEstablished = false; - - Pool pool = defaultIfNull(this.defaultPool.get(), GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME, - GEMFIRE_DEFAULT_POOL_NAME); - - if (pool instanceof PoolImpl) { - - long timeout = (System.currentTimeMillis() + DEFAULT_TIMEOUT); - - while (System.currentTimeMillis() < timeout && !((PoolImpl) pool).isPrimaryUpdaterAlive()) { - synchronized (pool) { - TimeUnit.MILLISECONDS.timedWait(pool, 500L); - } - - } - - cacheClientSubscriptionQueueConnectionEstablished |= ((PoolImpl) pool).isPrimaryUpdaterAlive(); - } - - Assert.state(cacheClientSubscriptionQueueConnectionEstablished, - String.format("Cache client subscription queue connection not established; Apache Geode Pool was [%s];" - + " Apache Geode Pool configuration was [locators = %s, servers = %s]", - pool, pool.getLocators(), pool.getServers())); - } - - private Pool defaultIfNull(Pool pool, String... poolNames) { - - for (String poolName : poolNames) { - pool = (pool != null ? pool : PoolManager.find(poolName)); - } - - return pool; - } - }; - } - - ConnectionEndpoint newConnectionEndpoint(String host, int port) { - return new ConnectionEndpoint(host, port); - } - - @Bean - ClientCacheConfigurer registerClientMembershipListener() { - - return (beanName, bean) -> { - - ClientMembership.registerClientMembershipListener(new ClientMembershipListenerAdapter() { - - @Override - public void memberJoined(ClientMembershipEvent event) { - LATCH.countDown(); - } - }); - }; - } -} diff --git a/samples/boot/gemfire/src/main/java/sample/server/GemFireServer.java b/samples/boot/gemfire/src/main/java/sample/server/GemFireServer.java index 0596492..9ee6af1 100644 --- a/samples/boot/gemfire/src/main/java/sample/server/GemFireServer.java +++ b/samples/boot/gemfire/src/main/java/sample/server/GemFireServer.java @@ -16,14 +16,11 @@ package sample.server; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.SpringApplication; import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; +import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.data.gemfire.config.annotation.CacheServerApplication; -import org.springframework.data.gemfire.config.annotation.CacheServerConfigurer; -import org.springframework.data.gemfire.config.annotation.EnableManager; +import org.springframework.data.gemfire.tests.integration.config.ClientServerIntegrationTestsConfiguration; import org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession; /** @@ -42,21 +39,14 @@ import org.springframework.session.data.gemfire.config.annotation.web.http.Enabl @SpringBootApplication // <1> @CacheServerApplication(name = "SpringSessionDataGeodeServerBootSample", logLevel = "error") // <2> @EnableGemFireHttpSession(maxInactiveIntervalInSeconds = 20) // <3> -@EnableManager(start = true) // <4> -public class GemFireServer { +public class GemFireServer extends ClientServerIntegrationTestsConfiguration { public static void main(String[] args) { - SpringApplication springApplication = new SpringApplication(GemFireServer.class); - springApplication.setWebApplicationType(WebApplicationType.NONE); - springApplication.run(args); - } - @Bean - CacheServerConfigurer cacheServerPortConfigurer( - @Value("${spring.session.data.geode.cache.server.port:40404}") int port) { // <5> - - return (beanName, cacheServerFactoryBean) -> - cacheServerFactoryBean.setPort(port); + new SpringApplicationBuilder(GemFireServer.class) + .web(WebApplicationType.NONE) + .build() + .run(args); } } // end::class[]