Refactor all samples to use the build.GemFireServerPlugin Gradle Plugin.

This commit is contained in:
John Blum
2019-05-29 16:25:58 -07:00
parent b10ee66483
commit acd4d5b1a9
16 changed files with 46 additions and 152 deletions

View File

@@ -1,34 +1,30 @@
apply plugin: 'io.spring.convention.spring-sample-boot'
apply plugin: "application"
apply from: IDE_GRADLE
repositories {
mavenCentral()
}
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"
exclude group: "org.apache.logging.log4j", module: "log4j-to-slf4j"
}
compile("org.springframework.boot:spring-boot-starter-web") {
exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
exclude group: "org.apache.logging.log4j", module: "log4j-to-slf4j"
}
compile "org.springframework.data:spring-data-geode-test"
compile "org.webjars:bootstrap"
compile "org.webjars:webjars-locator"
runtime "org.springframework.shell:spring-shell"
testCompile("org.springframework.boot:spring-boot-starter-test") {
exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
exclude group: "org.apache.logging.log4j", module: "log4j-to-slf4j"
}
testCompile seleniumDependencies
// integrationTestCompile seleniumDependencies
// integrationTestRuntime "org.springframework.shell:spring-shell"
}
mainClassName = 'sample.client.Application'
@@ -42,61 +38,3 @@ run {
mainClassName = 'sample.server.GemFireServer'
}
}
task runGemFireServer() {
doLast {
ext.port = reservePort()
println "Starting Apache Geode Server on port [$port] ..."
def out = new StringBuilder()
def err = new StringBuilder()
String classpath = sourceSets.main.runtimeClasspath.collect { it }.join(File.pathSeparator)
String[] commandLine = [
'java', '-server', '-ea', '-classpath', classpath,
//"-Dgemfire.log-file=gemfire-server.log",
//"-Dgemfire.log-level=config",
"-Dspring.session.data.geode.cache.server.port=$port",
'sample.server.GemFireServer'
]
//println commandLine
ext.process = commandLine.execute()
//ext.process = new ProcessBuilder().command(commandLine).redirectErrorStream(true).start();
ext.process.consumeProcessOutput(out, err)
//println 'OUT: ' + out
//println 'ERR: ' + err
}
}
/*
integrationTest {
dependsOn runGemFireServer
doFirst {
def port = reservePort()
systemProperties['management.port'] = 0
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
}
doLast {
println 'Stopping Apache Geode Server...'
runGemFireServer.process?.destroyForcibly()
}
}
*/
def reservePort() {
def socket = new ServerSocket(0)
def result = socket.localPort
socket.close()
result
}

View File

@@ -86,7 +86,7 @@ public class Application {
@Bean
ClientCacheConfigurer clientCacheServerPortConfigurer(
@Value("${spring.session.data.geode.cache.server.port:40404}") int port) { // <5>
@Value("${spring.data.gemfire.cache.server.port:40404}") int port) { // <5>
return (beanName, clientCacheFactoryBean) ->
clientCacheFactoryBean.setServers(Collections.singletonList(

View File

@@ -62,7 +62,7 @@ public class GemFireServer {
@Bean
CacheServerConfigurer cacheServerPortConfigurer(
@Value("${spring.session.data.geode.cache.server.port:40404}") int port) { // <5>
@Value("${spring.data.gemfire.cache.server.port:40404}") int port) { // <5>
return (beanName, cacheServerFactoryBean) ->
cacheServerFactoryBean.setPort(port);

View File

@@ -1,29 +1,28 @@
apply plugin: 'io.spring.convention.spring-sample-boot'
apply plugin: "gemfire-server"
apply plugin: "application"
apply from: IDE_GRADLE
repositories {
mavenCentral()
}
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"
exclude group: "org.apache.logging.log4j", module: "log4j-to-slf4j"
}
compile("org.springframework.boot:spring-boot-starter-web") {
exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
exclude group: "org.apache.logging.log4j", module: "log4j-to-slf4j"
}
compile "org.springframework.data:spring-data-geode-test"
compile "org.webjars:bootstrap"
compile "org.webjars:webjars-locator"
runtime "org.springframework.shell:spring-shell"
testCompile("org.springframework.boot:spring-boot-starter-test") {
exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
exclude group: "org.apache.logging.log4j", module: "log4j-to-slf4j"
}
testCompile seleniumDependencies
integrationTestCompile seleniumDependencies
@@ -42,59 +41,3 @@ run {
mainClassName = 'sample.server.GemFireServer'
}
}
task runGemFireServer() {
doLast {
ext.port = reservePort()
println "Starting Apache Geode Server on port [$port] ..."
def out = new StringBuilder()
def err = new StringBuilder()
String classpath = project.sourceSets.main.runtimeClasspath.collect { it }.join(File.pathSeparator)
String[] commandLine = [
'java', '-server', '-ea', '-classpath', classpath,
//"-Dgemfire.log-file=gemfire-server.log",
//"-Dgemfire.log-level=config",
"-Dspring.session.data.geode.cache.server.port=$port",
'sample.server.GemFireServer'
]
//println commandLine
ext.process = commandLine.execute()
//ext.process = new ProcessBuilder().command(commandLine).redirectErrorStream(true).start();
ext.process.consumeProcessOutput(out, err)
//println 'OUT: ' + out
//println 'ERR: ' + err
}
}
integrationTest {
dependsOn runGemFireServer
doFirst {
def port = reservePort()
systemProperties['management.port'] = 0
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
}
doLast {
println 'Stopping Apache Geode Server...'
runGemFireServer.process?.destroyForcibly()
}
}
def reservePort() {
def socket = new ServerSocket(0)
def result = socket.localPort
socket.close()
result
}

View File

@@ -88,7 +88,7 @@ public class Application {
@Bean
ClientCacheConfigurer clientCacheServerPortConfigurer(
@Value("${spring.session.data.geode.cache.server.port:40404}") int port) { // <5>
@Value("${spring.data.gemfire.cache.server.port:40404}") int port) { // <5>
return (beanName, clientCacheFactoryBean) ->
clientCacheFactoryBean.setServers(Collections.singletonList(

View File

@@ -56,7 +56,7 @@ public class IntegrationTestConfiguration {
@Bean
BeanPostProcessor clientServerReadyBeanPostProcessor(
@Value("${spring.session.data.geode.cache.server.port:40404}") int port) { // <5>
@Value("${spring.data.gemfire.cache.server.port:40404}") int port) { // <5>
return new BeanPostProcessor() {

View File

@@ -53,7 +53,7 @@ public class GemFireServer {
@Bean
CacheServerConfigurer cacheServerPortConfigurer(
@Value("${spring.session.data.geode.cache.server.port:40404}") int port) { // <5>
@Value("${spring.data.gemfire.cache.server.port:40404}") int port) { // <5>
return (beanName, cacheServerFactoryBean) ->
cacheServerFactoryBean.setPort(port);

View File

@@ -26,4 +26,13 @@ dependencies {
}
mainClassName = "sample.ServerConfig"
mainClassName = 'sample.ServerConfig'
project.tasks.findByName("prepareAppServerForIntegrationTests")?.configure { task ->
//println('Task gemfireServer' + project.tasks.findByName("gemfireServer"))
project.tasks.findByName("gemfireServer")?.configure { gemfireServerTask ->
//println "Task 'mainClassName' Property Value [$gemfireServerTask.mainClassName]"
gemfireServerTask.mainClassName = this.mainClassName
//println "Task 'mainClassName' Property Value [$gemfireServerTask.mainClassName]"
}
}

View File

@@ -39,7 +39,7 @@ public class ClientConfig extends IntegrationTestConfig {
@Bean
ClientCacheConfigurer clientCacheServerPortConfigurer(
@Value("${spring.session.data.geode.cache.server.port:40404}") int port) { // <3>
@Value("${spring.data.gemfire.cache.server.port:40404}") int port) { // <3>
return (beanName, clientCacheFactoryBean) ->
clientCacheFactoryBean.setServers(Collections.singletonList(

View File

@@ -56,7 +56,7 @@ public abstract class IntegrationTestConfig {
@Bean
BeanPostProcessor clientServerReadyBeanPostProcessor(
@Value("${spring.session.data.geode.cache.server.port:40404}") int port) { // <5>
@Value("${spring.data.gemfire.cache.server.port:40404}") int port) { // <5>
return new BeanPostProcessor() {

View File

@@ -16,8 +16,6 @@
package sample;
import java.io.IOException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -34,7 +32,7 @@ import org.springframework.session.data.gemfire.config.annotation.web.http.Enabl
public class ServerConfig {
@SuppressWarnings("resource")
public static void main(String[] args) throws IOException {
public static void main(String[] args) {
new AnnotationConfigApplicationContext(ServerConfig.class).registerShutdownHook();
}
@@ -46,7 +44,7 @@ public class ServerConfig {
@Bean
CacheServerConfigurer cacheServerPortConfigurer(
@Value("${spring.session.data.geode.cache.server.port:40404}") int port) { // <4>
@Value("${spring.data.gemfire.cache.server.port:40404}") int port) { // <4>
return (beanName, cacheServerFactoryBean) -> {
cacheServerFactoryBean.setPort(port);

View File

@@ -27,3 +27,9 @@ dependencies {
}
mainClassName = "sample.ServerConfig"
project.tasks.findByName("prepareAppServerForIntegrationTests")?.configure { task ->
project.tasks.findByName("gemfireServer")?.configure { gemfireServerTask ->
gemfireServerTask.mainClassName = this.mainClassName
}
}

View File

@@ -55,7 +55,7 @@ public class ClientServerReadyBeanPostProcessor implements BeanPostProcessor {
);
}
@Value("${spring.session.data.geode.cache.server.port:${application.geode.client-server.port:40404}}")
@Value("${spring.data.gemfire.cache.server.port:${application.geode.client-server.port:40404}}")
private int port;
@Value("${application.geode.client-server.host:localhost}")

View File

@@ -32,7 +32,7 @@
<gfe:cache-server auto-startup="true"
bind-address="${application.geode.client-server.host:localhost}"
host-name-for-clients="${application.geode.client-server.host:localhost}"
port="${spring.session.data.geode.cache.server.port:${application.geode.client-server.port:40404}}"/>
port="${spring.data.gemfire.cache.server.port:${application.geode.client-server.port:40404}}"/>
<!--4-->
<bean class="org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration"

View File

@@ -21,7 +21,7 @@
<!--1-->
<util:properties id="gemfireProperties">
<prop key="log-level">${spring.session.data.geode.log-level:error}</prop>
<prop key="log-level">${spring.data.gemfire.cache.log-level:error}</prop>
</util:properties>
<!--2-->
@@ -30,7 +30,7 @@
<!--3-->
<gfe:pool ping-interval="5000" read-timeout="15000" retry-attempts="1" subscription-enabled="true">
<gfe:server host="${application.geode.client-server.host}"
port="${spring.session.data.geode.cache.server.port:${application.geode.client-server.port:40404}}"/>
port="${spring.data.gemfire.cache.server.port:${application.geode.client-server.port:40404}}"/>
</gfe:pool>
<!--4-->

View File

@@ -20,7 +20,7 @@
<!--1-->
<util:properties id="gemfireProperties">
<prop key="name">SpringSessionSampleXmlGemFireP2p</prop>
<prop key="log-level">${spring.session.data.geode.log-level:error}</prop>
<prop key="log-level">${spring.data.gemfire.cache.log-level:error}</prop>
<prop key="jmx-manager">true</prop>
<prop key="jmx-manager-start">true</prop>
</util:properties>