Replace the SSDG project build.GemFireServer Gradle Plugin with STDG means of launching and managing Apache Geode servers for client/server integration tests.
This commit is contained in:
@@ -3,12 +3,13 @@ plugins {
|
||||
id "io.spring.convention.spring-sample-war"
|
||||
}
|
||||
|
||||
apply plugin: "gemfire-server"
|
||||
// apply plugin: "gemfire-server"
|
||||
apply plugin: "application"
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation project(':spring-session-data-geode')
|
||||
implementation "io.github.classgraph:classgraph:4.8.149"
|
||||
implementation "org.springframework:spring-web"
|
||||
implementation "org.springframework.data:spring-data-geode-test"
|
||||
implementation jstlDependencies
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.data.gemfire.tests.integration.ClientServerIntegratio
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession;
|
||||
|
||||
// tag::class[]
|
||||
@ClientCacheApplication(name = "SpringSessionDataGeodeJavaConfigSampleClient", logLevel = "error",
|
||||
@ClientCacheApplication(name = "SpringSessionDataGeodeJavaConfigSampleClient",
|
||||
readTimeout = 15000, retryAttempts = 1, subscriptionEnabled = true) // <1>
|
||||
@EnableGemFireHttpSession(poolName = "DEFAULT") // <2>
|
||||
public class ClientConfig extends ClientServerIntegrationTestsSupport {
|
||||
|
||||
@@ -13,16 +13,104 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample.client;
|
||||
|
||||
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newRuntimeException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
|
||||
import org.springframework.data.gemfire.tests.process.ProcessWrapper;
|
||||
import org.springframework.data.gemfire.util.CollectionUtils;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.session.web.context.AbstractHttpSessionApplicationInitializer;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import io.github.classgraph.ClassGraph;
|
||||
import sample.server.GemFireServer;
|
||||
|
||||
// tag::class[]
|
||||
public class Initializer extends AbstractHttpSessionApplicationInitializer { // <1>
|
||||
|
||||
public Initializer() {
|
||||
super(ClientConfig.class); // <2>
|
||||
super(ApacheGeodeServerRunner.onStartup(ClientConfig.class)); // <2>
|
||||
}
|
||||
|
||||
static class ApacheGeodeServerRunner extends ForkingClientServerIntegrationTestsSupport {
|
||||
|
||||
static @NonNull Class<?> onStartup(@NonNull Class<?> clientConfigurationType) {
|
||||
|
||||
try {
|
||||
|
||||
//System.err.printf("JAVA CLASSPATH [%s]%n", javaSystemClasspath());
|
||||
//System.err.printf("THREAD CONTEXT CLASSLOADER CLASSPATH [%s]%n", contextClassLoaderClasspath());
|
||||
//System.err.printf("CLASS-GRAPH CLASSLOADER CLASSPATH [%s]%n", classGraphClassLoaderClasspath());
|
||||
|
||||
registerGeodeServerRuntimeShutdownHook(
|
||||
startGeodeServer(classGraphClasspath(), GemFireServer.class));
|
||||
|
||||
return clientConfigurationType;
|
||||
}
|
||||
catch(IOException cause) {
|
||||
throw newRuntimeException(cause, "Failed to start the Apache Geode Server");
|
||||
}
|
||||
}
|
||||
|
||||
static String classGraphClasspath() {
|
||||
|
||||
List<String> classpathElements = CollectionUtils.nullSafeList(new ClassGraph().getClasspathURLs()).stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(URL::getFile)
|
||||
.filter(StringUtils::hasText)
|
||||
.toList();
|
||||
|
||||
return StringUtils.collectionToDelimitedString(classpathElements, System.getProperty("path.separator"));
|
||||
}
|
||||
|
||||
static ProcessWrapper registerGeodeServerRuntimeShutdownHook(ProcessWrapper geodeServer) {
|
||||
|
||||
if (geodeServer != null) {
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
ForkingClientServerIntegrationTestsSupport.stop(geodeServer);
|
||||
}, "Apache Geode Server Runtime Shutdown Hook"));
|
||||
}
|
||||
|
||||
return geodeServer;
|
||||
}
|
||||
// end::class[]
|
||||
|
||||
static String javaSystemClasspath() {
|
||||
return System.getProperty("java.class.path");
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
static String threadContextClassLoaderClasspath() {
|
||||
|
||||
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
System.err.printf("THREAD CONTEXT CLASSLOADER TYPE [%s]%n", contextClassLoader != null
|
||||
? contextClassLoader.getClass().getName() : null);
|
||||
|
||||
List<String> classpathElements = Optional.ofNullable(Thread.currentThread())
|
||||
.map(Thread::getContextClassLoader)
|
||||
.filter(URLClassLoader.class::isInstance)
|
||||
.map(URLClassLoader.class::cast)
|
||||
.map(URLClassLoader::getURLs)
|
||||
.map(Stream::of)
|
||||
.orElseGet(Stream::empty)
|
||||
.filter(Objects::nonNull)
|
||||
.map(URL::getFile)
|
||||
.filter(StringUtils::hasText)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return StringUtils.collectionToDelimitedString(classpathElements, System.getProperty("path.separator"));
|
||||
}
|
||||
}
|
||||
}
|
||||
// end::class[]
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample.server;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
@@ -21,7 +20,7 @@ import org.springframework.data.gemfire.config.annotation.CacheServerApplication
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession;
|
||||
|
||||
// tag::class[]
|
||||
@CacheServerApplication(name = "SpringSessionDataGeodeJavaConfigSampleServer", logLevel = "error") // <1>
|
||||
@CacheServerApplication(name = "SpringSessionDataGeodeJavaConfigSampleServer") // <1>
|
||||
@EnableGemFireHttpSession(maxInactiveIntervalInSeconds = 30) // <2>
|
||||
public class GemFireServer {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user