Refactor the Spring Session Boot Sample with Scoped Proxies to use Spring Data for Apache Geode Test.

This commit is contained in:
John Blum
2018-08-13 16:48:27 -07:00
parent 6ad1813ddf
commit 55c19ca849
3 changed files with 16 additions and 50 deletions

View File

@@ -9,12 +9,16 @@ repositories {
dependencies { dependencies {
compile project(':spring-session-data-geode') compile project(':spring-session-data-geode')
compile("org.springframework.boot:spring-boot-starter-thymeleaf") { compile("org.springframework.boot:spring-boot-starter-thymeleaf") {
exclude group: "org.springframework.boot", module: "spring-boot-starter-logging" exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
} }
compile("org.springframework.boot:spring-boot-starter-web") { compile("org.springframework.boot:spring-boot-starter-web") {
exclude group: "org.springframework.boot", module: "spring-boot-starter-logging" 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:bootstrap"
compile "org.webjars:webjars-locator" compile "org.webjars:webjars-locator"
@@ -58,7 +62,7 @@ task runGemFireServer() {
'java', '-server', '-ea', '-classpath', classpath, 'java', '-server', '-ea', '-classpath', classpath,
//"-Dgemfire.log-file=gemfire-server.log", //"-Dgemfire.log-file=gemfire-server.log",
//"-Dgemfire.log-level=config", //"-Dgemfire.log-level=config",
"-Dspring.session.data.geode.cache.server.port=$port", "-Dspring.data.gemifre.cache.server.port=$port",
'sample.server.GemFireServer' 'sample.server.GemFireServer'
] ]
@@ -75,8 +79,7 @@ task runGemFireServer() {
} }
/* /*integrationTest {
integrationTest {
dependsOn runGemFireServer dependsOn runGemFireServer
doFirst { doFirst {
def port = reservePort() def port = reservePort()
@@ -84,11 +87,11 @@ integrationTest {
systemProperties['server.port'] = port systemProperties['server.port'] = port
//systemProperties['gemfire.log-file'] = "gemfire-client.log" //systemProperties['gemfire.log-file'] = "gemfire-client.log"
//systemProperties['gemfire.log-level'] = "config" //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 { doLast {
println 'Stopping Apache Geode Server...' println 'Stopping Apache Geode Server...'
runGemFireServer.process?.destroyForcibly() runGemFireServer.process?.destroy()
} }
} }
*/ */

View File

@@ -18,21 +18,18 @@ package sample.client;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.Collections;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; 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.ClientCacheApplication;
import org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer; import org.springframework.data.gemfire.tests.integration.config.ClientServerIntegrationTestsConfiguration;
import org.springframework.data.gemfire.support.ConnectionEndpoint;
import org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession; import org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
@@ -76,26 +73,11 @@ public class Application {
@ClientCacheApplication(name = "SpringSessionDataGeodeClientWithScopedProxiesBootSample", logLevel = "error", @ClientCacheApplication(name = "SpringSessionDataGeodeClientWithScopedProxiesBootSample", logLevel = "error",
pingInterval = 5000L, readTimeout = 15000, retryAttempts = 1, subscriptionEnabled = true) // <3> pingInterval = 5000L, readTimeout = 15000, retryAttempts = 1, subscriptionEnabled = true) // <3>
@EnableGemFireHttpSession(poolName = "DEFAULT") // <4> @EnableGemFireHttpSession(poolName = "DEFAULT") // <4>
static class ClientCacheConfiguration { @Import(ClientServerIntegrationTestsConfiguration.class)
static class ClientCacheConfiguration { }
// 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(
new ConnectionEndpoint("localhost", port)));
}
}
@Configuration @Configuration
static class SpringWebMvcConfiguration { // <6> static class SpringWebMvcConfiguration { // <5>
@Bean @Bean
public WebMvcConfigurer webMvcConfig() { public WebMvcConfigurer webMvcConfig() {
@@ -131,7 +113,7 @@ public class Application {
} }
@RequestMapping(method = RequestMethod.GET, path = "/counts") @RequestMapping(method = RequestMethod.GET, path = "/counts")
public String requestAndSessionInstanceCount(HttpServletRequest request, HttpSession session, Model model) { // <7> public String requestAndSessionInstanceCount(HttpServletRequest request, HttpSession session, Model model) { // <6>
model.addAttribute("sessionId", session.getId()); model.addAttribute("sessionId", session.getId());
model.addAttribute("requestCount", this.requestBean.getCount()); model.addAttribute("requestCount", this.requestBean.getCount());

View File

@@ -16,15 +16,11 @@
package sample.server; package sample.server;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.WebApplicationType; import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.data.gemfire.config.annotation.CacheServerApplication; import org.springframework.data.gemfire.config.annotation.CacheServerApplication;
import org.springframework.data.gemfire.config.annotation.CacheServerConfigurer; import org.springframework.data.gemfire.tests.integration.config.ClientServerIntegrationTestsConfiguration;
import org.springframework.data.gemfire.config.annotation.EnableManager;
import org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession; import org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession;
/** /**
@@ -43,8 +39,7 @@ import org.springframework.session.data.gemfire.config.annotation.web.http.Enabl
@SpringBootApplication // <1> @SpringBootApplication // <1>
@CacheServerApplication(name = "SpringSessionDataGeodeServerWithScopedProxiesBootSample", logLevel = "error") // <2> @CacheServerApplication(name = "SpringSessionDataGeodeServerWithScopedProxiesBootSample", logLevel = "error") // <2>
@EnableGemFireHttpSession(maxInactiveIntervalInSeconds = 10) // <3> @EnableGemFireHttpSession(maxInactiveIntervalInSeconds = 10) // <3>
@EnableManager(start = true) // <4> public class GemFireServer extends ClientServerIntegrationTestsConfiguration {
public class GemFireServer {
public static void main(String[] args) { public static void main(String[] args) {
@@ -53,19 +48,5 @@ public class GemFireServer {
.build() .build()
.run(args); .run(args);
} }
// Required to resolve property placeholders in Spring @Value annotations.
@Bean
static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
@Bean
CacheServerConfigurer cacheServerPortConfigurer(
@Value("${spring.session.data.geode.cache.server.port:40404}") int port) { // <5>
return (beanName, cacheServerFactoryBean) ->
cacheServerFactoryBean.setPort(port);
}
} }
// end::class[] // end::class[]