diff --git a/gradle.properties b/gradle.properties index a5999a7d..c8902b6f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,7 +14,6 @@ jstlelVersion=1.2.5 junitVersion=4.12 lettuceVersion=5.0.0.Beta1 mockitoVersion=2.5.4 -reactorVersion=3.0.3.RELEASE seleniumVersion=2.52.0 servletApiVersion=3.0.1 springVersion=5.0.0.BUILD-SNAPSHOT diff --git a/samples/boot/gemfire/build.gradle b/samples/boot/gemfire/build.gradle index 1c989a93..72aff3ce 100644 --- a/samples/boot/gemfire/build.gradle +++ b/samples/boot/gemfire/build.gradle @@ -43,26 +43,34 @@ springBoot { task runGemFireServer() { doLast { - println 'STARTING GEMFIRE SERVER...' - ext.port = reservePort() + println "Starting GemFire 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.cache.server.port=$port", //"-Dgemfire.log-file=gemfire-server.log", - "-Dgemfire.log-level=" + System.getProperty('gemfire.log.level', 'config'), + //"-Dgemfire.log-level=config", + "-Dspring-session-data-gemfire.cache.server.port=$port", + "-Dspring-session-data-gemfire.log.level=" + + System.getProperty('spring-session-data-gemfire.log.level', 'config'), 'sample.server.GemFireServer' ] //println commandLine ext.process = commandLine.execute() - process.in.close() - process.out.close() - process.err.close() + //ext.process = new ProcessBuilder().command(commandLine).redirectErrorStream(true).start(); + + ext.process.consumeProcessOutput(out, err) + + //println 'OUT: ' + out + //println 'ERR: ' + err } } @@ -71,12 +79,15 @@ integrationTest { dependsOn runGemFireServer doFirst { def port = reservePort() - systemProperties['server.port'] = port systemProperties['management.port'] = 0 - systemProperties['gemfire.cache.server.port'] = runGemFireServer.port + systemProperties['server.port'] = port + //systemProperties['gemfire.log-file'] = "gemfire-client.log" + //systemProperties['gemfire.log-level'] = "config" + systemProperties['spring-session-data-gemfire.cache.server.port'] = runGemFireServer.port + systemProperties['spring-session-data-gemfire.log.level'] = System.getProperty("spring-session-data-gemfire.log.level", "warning") } doLast { - println 'STOPPING GEMFIRE SERVER...' + println 'Stopping GemFire Server...' 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 965f9029..c0c2e009 100644 --- a/samples/boot/gemfire/src/main/java/sample/client/Application.java +++ b/samples/boot/gemfire/src/main/java/sample/client/Application.java @@ -77,7 +77,7 @@ public class Application { static final CountDownLatch LATCH = new CountDownLatch(1); - static final String DEFAULT_GEMFIRE_LOG_LEVEL = "config"; + static final String DEFAULT_GEMFIRE_LOG_LEVEL = "warning"; static final String INDEX_TEMPLATE_VIEW_NAME = "index"; static final String PING_RESPONSE = "PONG"; static final String REQUEST_COUNT_ATTRIBUTE_NAME = "requestCount"; @@ -102,17 +102,17 @@ public class Application { } String applicationName() { - return "samples:httpsession-gemfire-boot:".concat(getClass().getSimpleName()); + return "spring-session-data-gemfire-boot-sample.".concat(getClass().getSimpleName()); } String logLevel() { - return System.getProperty("gemfire.log-level", DEFAULT_GEMFIRE_LOG_LEVEL); + return System.getProperty("spring-session-data-gemfire.log.level", DEFAULT_GEMFIRE_LOG_LEVEL); } @Bean ClientCacheFactoryBean gemfireCache( - @Value("${gemfire.cache.server.host:localhost}") String host, - @Value("${gemfire.cache.server.port:12480}") int port) { // <3> + @Value("${spring-session-data-gemfire.cache.server.host:localhost}") String host, + @Value("${spring-session-data-gemfire.cache.server.port:12480}") int port) { // <3> ClientCacheFactoryBean gemfireCache = new ClientCacheFactoryBean(); @@ -152,8 +152,8 @@ public class Application { @Bean BeanPostProcessor gemfireCacheServerReadyBeanPostProcessor( - @Value("${gemfire.cache.server.host:localhost}") final String host, - @Value("${gemfire.cache.server.port:12480}") final int port) { // <5> + @Value("${spring-session-data-gemfire.cache.server.host:localhost}") final String host, + @Value("${spring-session-data-gemfire.cache.server.port:12480}") final int port) { // <5> return new BeanPostProcessor() { 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 8291cf96..0f65756b 100644 --- a/samples/boot/gemfire/src/main/java/sample/server/GemFireServer.java +++ b/samples/boot/gemfire/src/main/java/sample/server/GemFireServer.java @@ -46,7 +46,7 @@ import org.springframework.session.data.gemfire.config.annotation.web.http.Enabl @EnableGemFireHttpSession(maxInactiveIntervalInSeconds = 20) // <1> public class GemFireServer { - static final String DEFAULT_GEMFIRE_LOG_LEVEL = "config"; + static final String DEFAULT_GEMFIRE_LOG_LEVEL = "warning"; public static void main(String[] args) { SpringApplication springApplication = new SpringApplication(GemFireServer.class); @@ -63,7 +63,6 @@ public class GemFireServer { Properties gemfireProperties = new Properties(); gemfireProperties.setProperty("name", applicationName()); - gemfireProperties.setProperty("mcast-port", "0"); //gemfireProperties.setProperty("log-file", "gemfire-server.log"); gemfireProperties.setProperty("log-level", logLevel()); //gemfireProperties.setProperty("jmx-manager", "true"); @@ -73,11 +72,11 @@ public class GemFireServer { } String applicationName() { - return "samples:httpsession-gemfire-boot:".concat(getClass().getSimpleName()); + return "spring-session-data-gemfire-boot-sample:".concat(getClass().getSimpleName()); } String logLevel() { - return System.getProperty("gemfire.log-level", DEFAULT_GEMFIRE_LOG_LEVEL); + return System.getProperty("spring-session-data-gemfire.log.level", DEFAULT_GEMFIRE_LOG_LEVEL); } @Bean @@ -92,9 +91,9 @@ public class GemFireServer { @Bean CacheServerFactoryBean gemfireCacheServer(Cache gemfireCache, - @Value("${gemfire.cache.server.bind-address:localhost}") String bindAddress, - @Value("${gemfire.cache.server.hostname-for-clients:localhost}") String hostnameForClients, - @Value("${gemfire.cache.server.port:12480}") int port) { // <4> + @Value("${spring-session-data-gemfire.cache.server.bind-address:localhost}") String bindAddress, + @Value("${spring-session-data-gemfire.cache.server.hostname-for-clients:localhost}") String hostnameForClients, + @Value("${spring-session-data-gemfire.cache.server.port:12480}") int port) { // <4> CacheServerFactoryBean gemfireCacheServer = new CacheServerFactoryBean(); diff --git a/samples/boot/gemfire/src/main/java/sample/server/NativeGemFireServer.java b/samples/boot/gemfire/src/main/java/sample/server/NativeGemFireServer.java new file mode 100644 index 00000000..80d11e34 --- /dev/null +++ b/samples/boot/gemfire/src/main/java/sample/server/NativeGemFireServer.java @@ -0,0 +1,186 @@ +/* + * Copyright 2014-2016 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.server; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Properties; + +import org.apache.geode.cache.Cache; +import org.apache.geode.cache.CacheFactory; +import org.apache.geode.cache.ExpirationAction; +import org.apache.geode.cache.ExpirationAttributes; +import org.apache.geode.cache.Region; +import org.apache.geode.cache.RegionFactory; +import org.apache.geode.cache.RegionShortcut; +import org.apache.geode.cache.server.CacheServer; + +import org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepository; +import org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration; +import org.springframework.util.StringUtils; + +/** + * The {@link NativeGemFireServer} class uses the GemFire API to create a GemFire (cache) instance. + * + * @author John Blum + * @see org.apache.geode.cache.Cache + * @see org.apache.geode.cache.Region + * @see org.apache.geode.cache.server.CacheServer + * @see org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration + * @since 1.3.0 + */ +@SuppressWarnings("unused") +public final class NativeGemFireServer implements Runnable { + + private static final int GEMFIRE_CACHE_SERVER_PORT = + Integer.getInteger("spring-session-data-gemfire.cache.server.port", 12480); + + private static final String GEMFIRE_CACHE_SERVER_HOST = "localhost"; + private static final String GEMFIRE_CACHE_SERVER_HOSTNAME_FOR_CLIENTS = GEMFIRE_CACHE_SERVER_HOST; + private static final String GEMFIRE_LOG_FILENAME_PATTERN = + String.format("%s", NativeGemFireServer.class.getSimpleName()).concat("-%s.log"); + + public static void main(String[] args) { + newNativeGemFireServer(args).run(); + } + + private final String[] args; + + private static File newGemFireLogFile(String suffix) { + return new File(String.format(GEMFIRE_LOG_FILENAME_PATTERN, suffix)); + } + + private static NativeGemFireServer newNativeGemFireServer(String[] args) { + return new NativeGemFireServer(args); + } + + private static String[] nullSafeStringArray(String[] array) { + return (array != null ? array.clone() : new String[0]); + } + + private static void writeStringTo(File file, String fileContents) { + PrintWriter fileWriter = null; + + try { + fileWriter = new PrintWriter(new BufferedWriter(new FileWriter(file, true)), true); + fileWriter.println(fileContents); + fileWriter.flush(); + } + catch (IOException e) { + throw new RuntimeException(String.format("Failed to write [%s] to file [%s]", fileContents, file), e); + } + finally { + if (fileWriter != null) { + fileWriter.close(); + } + } + } + private NativeGemFireServer(String[] args) { + this.args = nullSafeStringArray(args); + } + + /** + * @inheritDoc + */ + public void run() { + run(this.args); + } + + private void run(String[] args) { + try { + writeStringTo(newGemFireLogFile("stdout"), "Before"); + + registerShutdownHook(addCacheServer(createRegion(gemfireCache( + gemfireProperties(applicationName()))))); + + writeStringTo(newGemFireLogFile("stdout"), "After"); + } + catch (Throwable e) { + writeStringTo(newGemFireLogFile("stderr"), e.toString()); + } + } + + private String applicationName() { + return applicationName(null); + } + + private String applicationName(String applicationName) { + return StringUtils.hasText(applicationName) ? applicationName + : "spring-session-data-gemfire.boot.sample." + NativeGemFireServer.class.getSimpleName(); + } + + private Properties gemfireProperties(String applicationName) { + Properties gemfireProperties = new Properties(); + + gemfireProperties.setProperty("name", applicationName); + gemfireProperties.setProperty("log-file", "gemfire-server.log"); + gemfireProperties.setProperty("log-level", "config"); + //gemfireProperties.setProperty("jmx-manager", "true"); + //gemfireProperties.setProperty("jmx-manager-start", "true"); + + return gemfireProperties; + } + + private Cache gemfireCache(Properties gemfireProperties) { + return new CacheFactory(gemfireProperties).create(); + } + + private Cache createRegion(Cache gemfireCache) { + RegionFactory regionFactory = + gemfireCache.createRegionFactory(RegionShortcut.PARTITION); + + regionFactory.setKeyConstraint(Object.class); + regionFactory.setValueConstraint(AbstractGemFireOperationsSessionRepository.GemFireSession.class); + regionFactory.setStatisticsEnabled(true); + regionFactory.setEntryIdleTimeout(newExpirationAttributes(1800, ExpirationAction.INVALIDATE)); + + Region region = regionFactory.create( + GemFireHttpSessionConfiguration.DEFAULT_SPRING_SESSION_GEMFIRE_REGION_NAME); + + return gemfireCache; + } + + private ExpirationAttributes newExpirationAttributes(int expirationTime, ExpirationAction expirationAction) { + return new ExpirationAttributes(expirationTime, expirationAction); + } + + private Cache addCacheServer(Cache gemfireCache) throws IOException { + CacheServer cacheServer = gemfireCache.addCacheServer(); + + cacheServer.setBindAddress(GEMFIRE_CACHE_SERVER_HOST); + cacheServer.setHostnameForClients(GEMFIRE_CACHE_SERVER_HOSTNAME_FOR_CLIENTS); + cacheServer.setPort(GEMFIRE_CACHE_SERVER_PORT); + cacheServer.start(); + + return gemfireCache; + } + + private Cache registerShutdownHook(final Cache gemfireCache) { + Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { + public void run() { + if (gemfireCache != null) { + gemfireCache.close(); + } + } + })); + + return gemfireCache; + } +} diff --git a/samples/boot/redis-json/build.gradle b/samples/boot/redis-json/build.gradle index ed3da919..ac0be874 100644 --- a/samples/boot/redis-json/build.gradle +++ b/samples/boot/redis-json/build.gradle @@ -19,7 +19,6 @@ ext { assertjVersion = "2.4.0" } -ext['reactor.version'] = reactorVersion ext['spring-security.version'] = springSecurityVersion dependencies { diff --git a/samples/boot/websocket/build.gradle b/samples/boot/websocket/build.gradle index 9d3df68c..e4c97c8f 100644 --- a/samples/boot/websocket/build.gradle +++ b/samples/boot/websocket/build.gradle @@ -16,8 +16,6 @@ apply from: SAMPLE_GRADLE group = 'samples' -ext['reactor.version'] = reactorVersion - dependencies { compile(project(':spring-session-data-redis')) { exclude module: 'jedis' diff --git a/samples/javaconfig/gemfire-clientserver/build.gradle b/samples/javaconfig/gemfire-clientserver/build.gradle index fdb83e93..51913521 100644 --- a/samples/javaconfig/gemfire-clientserver/build.gradle +++ b/samples/javaconfig/gemfire-clientserver/build.gradle @@ -1,7 +1,7 @@ apply from: JAVA_GRADLE +apply from: SAMPLE_GRADLE apply from: TOMCAT_7_GRADLE apply plugin: "application" -apply from: SAMPLE_GRADLE dependencies { compile project(':spring-session-data-gemfire'), @@ -38,10 +38,13 @@ task availablePort() { task runGemFireServer(dependsOn: availablePort) { doLast { - println 'STARTING GEMFIRE SERVER...' + println "Starting GemFire Server on port [$port]..." + + def out = new StringBuilder() + def err = new StringBuilder() String classpath = sourceSets.main.runtimeClasspath.collect { it }.join(File.pathSeparator) - String gemfireLogLevel = System.getProperty('sample.httpsession.gemfire.log-level', 'warning') + String gemfireLogLevel = System.getProperty('sample.httpsession.gemfire.log-level', 'config') String[] commandLine = [ 'java', '-server', '-ea', '-classpath', classpath, @@ -53,14 +56,16 @@ task runGemFireServer(dependsOn: availablePort) { //println commandLine process = commandLine.execute() - process.in.close() - process.out.close() - process.err.close() + + process.consumeProcessOutput(out, err) + + //println 'OUT: ' + out + //println 'ERR: ' + err } } integrationTest.doLast { - println 'STOPPING GEMFIRE SERVER...' + println 'Stopping GemFire Server...' process?.destroyForcibly() } diff --git a/samples/javaconfig/gemfire-clientserver/src/main/java/sample/ClientConfig.java b/samples/javaconfig/gemfire-clientserver/src/main/java/sample/ClientConfig.java index 4524f7ea..0036e041 100644 --- a/samples/javaconfig/gemfire-clientserver/src/main/java/sample/ClientConfig.java +++ b/samples/javaconfig/gemfire-clientserver/src/main/java/sample/ClientConfig.java @@ -44,7 +44,9 @@ public class ClientConfig { static final CountDownLatch LATCH = new CountDownLatch(1); - static final String DEFAULT_GEMFIRE_LOG_LEVEL = "warning"; + static final String DEFAULT_GEMFIRE_LOG_LEVEL = "config"; + static final String PROXY_HOST = "dummy.example.com"; + static final String PROXY_PORT = "3128"; @Bean static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() { @@ -54,6 +56,7 @@ public class ClientConfig { Properties gemfireProperties() { // <2> Properties gemfireProperties = new Properties(); gemfireProperties.setProperty("name", applicationName()); + // gemfireProperties.setProperty("log-file", "gemfire-client.log"); gemfireProperties.setProperty("log-level", logLevel()); return gemfireProperties; } diff --git a/samples/javaconfig/gemfire-clientserver/src/main/java/sample/ServerConfig.java b/samples/javaconfig/gemfire-clientserver/src/main/java/sample/ServerConfig.java index 0c264b36..25229662 100644 --- a/samples/javaconfig/gemfire-clientserver/src/main/java/sample/ServerConfig.java +++ b/samples/javaconfig/gemfire-clientserver/src/main/java/sample/ServerConfig.java @@ -36,13 +36,12 @@ public class ServerConfig { static final int SERVER_PORT = 12480; - static final String DEFAULT_GEMFIRE_LOG_LEVEL = "warning"; + static final String DEFAULT_GEMFIRE_LOG_LEVEL = "config"; static final String SERVER_HOST = "localhost"; @SuppressWarnings("resource") public static void main(String[] args) throws IOException { // <5> - new AnnotationConfigApplicationContext(ServerConfig.class) - .registerShutdownHook(); + new AnnotationConfigApplicationContext(ServerConfig.class).registerShutdownHook(); } @Bean @@ -55,21 +54,20 @@ public class ServerConfig { gemfireProperties.setProperty("name", applicationName()); gemfireProperties.setProperty("mcast-port", "0"); + // gemfireProperties.setProperty("log-file", "gemfire-server.log"); gemfireProperties.setProperty("log-level", logLevel()); - gemfireProperties.setProperty("jmx-manager", "true"); - gemfireProperties.setProperty("jmx-manager-start", "true"); + // gemfireProperties.setProperty("jmx-manager", "true"); + // gemfireProperties.setProperty("jmx-manager-start", "true"); return gemfireProperties; } String applicationName() { - return "samples:httpsession-gemfire-clientserver:" - .concat(getClass().getSimpleName()); + return "samples:httpsession-gemfire-clientserver:".concat(getClass().getSimpleName()); } String logLevel() { - return System.getProperty("sample.httpsession.gemfire.log-level", - DEFAULT_GEMFIRE_LOG_LEVEL); + return System.getProperty("sample.httpsession.gemfire.log-level", DEFAULT_GEMFIRE_LOG_LEVEL); } @Bean diff --git a/samples/xml/gemfire-clientserver/build.gradle b/samples/xml/gemfire-clientserver/build.gradle index ad560249..16507e66 100644 --- a/samples/xml/gemfire-clientserver/build.gradle +++ b/samples/xml/gemfire-clientserver/build.gradle @@ -1,7 +1,7 @@ apply from: JAVA_GRADLE +apply from: SAMPLE_GRADLE apply from: TOMCAT_7_GRADLE apply plugin: "application" -apply from: SAMPLE_GRADLE dependencies { compile project(':spring-session-data-gemfire'), @@ -37,7 +37,10 @@ task availablePort() { task runGemFireServer(dependsOn: availablePort) { doLast { - println 'STARTING GEMFIRE SERVER...' + println "Starting GemFire Server on port [$port]..." + + def out = new StringBuilder() + def err = new StringBuilder() String classpath = sourceSets.main.runtimeClasspath.collect { it }.join(File.pathSeparator) String gemfireLogLevel = System.getProperty('sample.httpsession.gemfire.log-level', 'warning') @@ -52,14 +55,16 @@ task runGemFireServer(dependsOn: availablePort) { //println commandLine process = commandLine.execute() - process.in.close() - process.out.close() - process.err.close() + + process.consumeProcessOutput(out, err) + + //println 'OUT: ' + out + //println 'ERR: ' + err } } integrationTest.doLast { - println 'STOPPING GEMFIRE SERVER...' + println 'Stopping GemFire Server...' process?.destroyForcibly() } diff --git a/samples/xml/gemfire-clientserver/src/main/java/sample/Application.java b/samples/xml/gemfire-clientserver/src/main/java/sample/Application.java index 6e627c5d..9dfbceaf 100644 --- a/samples/xml/gemfire-clientserver/src/main/java/sample/Application.java +++ b/samples/xml/gemfire-clientserver/src/main/java/sample/Application.java @@ -27,8 +27,7 @@ import org.springframework.context.annotation.ImportResource; public class Application { public static void main(final String[] args) { - new AnnotationConfigApplicationContext(Application.class) - .registerShutdownHook(); + new AnnotationConfigApplicationContext(Application.class).registerShutdownHook(); } } // tag::end[] diff --git a/spring-session/build.gradle b/spring-session/build.gradle index e9b431e7..2770d365 100644 --- a/spring-session/build.gradle +++ b/spring-session/build.gradle @@ -17,7 +17,7 @@ configurations { dependencyManagement { springIoTestRuntime { imports { - mavenBom "io.spring.platform:platform-bom:${springIoVersion}" + mavenBom "io.spring.platform:platform-bom:$springIoVersion" } } }