Refactor the Spring Session Boot Sample with Scoped Proxies to use Spring Data for Apache Geode Test.
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -58,7 +62,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.gemifre.cache.server.port=$port",
|
||||
'sample.server.GemFireServer'
|
||||
]
|
||||
|
||||
@@ -75,8 +79,7 @@ task runGemFireServer() {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
integrationTest {
|
||||
/*integrationTest {
|
||||
dependsOn runGemFireServer
|
||||
doFirst {
|
||||
def port = reservePort()
|
||||
@@ -84,11 +87,11 @@ 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()
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -18,21 +18,18 @@ package sample.client;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.support.ConnectionEndpoint;
|
||||
import org.springframework.data.gemfire.tests.integration.config.ClientServerIntegrationTestsConfiguration;
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
@@ -76,26 +73,11 @@ public class Application {
|
||||
@ClientCacheApplication(name = "SpringSessionDataGeodeClientWithScopedProxiesBootSample", logLevel = "error",
|
||||
pingInterval = 5000L, readTimeout = 15000, retryAttempts = 1, subscriptionEnabled = true) // <3>
|
||||
@EnableGemFireHttpSession(poolName = "DEFAULT") // <4>
|
||||
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)));
|
||||
}
|
||||
}
|
||||
@Import(ClientServerIntegrationTestsConfiguration.class)
|
||||
static class ClientCacheConfiguration { }
|
||||
|
||||
@Configuration
|
||||
static class SpringWebMvcConfiguration { // <6>
|
||||
static class SpringWebMvcConfiguration { // <5>
|
||||
|
||||
@Bean
|
||||
public WebMvcConfigurer webMvcConfig() {
|
||||
@@ -131,7 +113,7 @@ public class Application {
|
||||
}
|
||||
|
||||
@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("requestCount", this.requestBean.getCount());
|
||||
|
||||
@@ -16,15 +16,11 @@
|
||||
|
||||
package sample.server;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
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.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;
|
||||
|
||||
/**
|
||||
@@ -43,8 +39,7 @@ import org.springframework.session.data.gemfire.config.annotation.web.http.Enabl
|
||||
@SpringBootApplication // <1>
|
||||
@CacheServerApplication(name = "SpringSessionDataGeodeServerWithScopedProxiesBootSample", logLevel = "error") // <2>
|
||||
@EnableGemFireHttpSession(maxInactiveIntervalInSeconds = 10) // <3>
|
||||
@EnableManager(start = true) // <4>
|
||||
public class GemFireServer {
|
||||
public class GemFireServer extends ClientServerIntegrationTestsConfiguration {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -53,19 +48,5 @@ public class GemFireServer {
|
||||
.build()
|
||||
.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[]
|
||||
|
||||
Reference in New Issue
Block a user