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:
@@ -64,9 +64,15 @@ class SpringSampleWarPlugin extends SpringSamplePlugin {
|
||||
group = 'Verification'
|
||||
description = 'Prepares the Web application server for Integration Testing'
|
||||
doFirst {
|
||||
int cacheServerPort = getRandomPort();
|
||||
project.gretty {
|
||||
// classPath = project.sourceSets.integrationTest.runtimeClasspath.toSet()
|
||||
httpPort = getRandomPort()
|
||||
httpsPort = getRandomPort()
|
||||
jvmArgs = [
|
||||
"-Dspring.data.gemfire.cache.server.port=$cacheServerPort",
|
||||
"-Dspring.data.gemfire.pool.servers=localhost[$cacheServerPort]"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
apply plugin: 'io.spring.convention.spring-sample-boot'
|
||||
apply plugin: "gemfire-server"
|
||||
// apply plugin: "gemfire-server"
|
||||
apply plugin: "application"
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -17,8 +17,11 @@ package sample;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -26,6 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.htmlunit.webdriver.MockMvcHtmlUnitDriverBuilder;
|
||||
@@ -34,6 +38,7 @@ import org.openqa.selenium.WebDriver;
|
||||
|
||||
import sample.client.Application;
|
||||
import sample.pages.HomePage;
|
||||
import sample.server.GemFireServer;
|
||||
|
||||
/**
|
||||
* @author Eddú Meléndez
|
||||
@@ -41,13 +46,18 @@ import sample.pages.HomePage;
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.MOCK)
|
||||
@AutoConfigureMockMvc
|
||||
public class AttributeTests {
|
||||
public class AttributeTests extends ForkingClientServerIntegrationTestsSupport {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
private WebDriver driver;
|
||||
|
||||
@BeforeClass
|
||||
public static void startGeodeServer() throws IOException {
|
||||
startGeodeServer(GemFireServer.class);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.driver = MockMvcHtmlUnitDriverBuilder.mockMvcSetup(this.mockMvc).build();
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.session.data.gemfire.config.annotation.web.http.Enabl
|
||||
*/
|
||||
// tag::class[]
|
||||
@SpringBootApplication // <1>
|
||||
@CacheServerApplication(name = "SpringSessionDataGeodeBootSampleServer", logLevel = "error") // <2>
|
||||
@CacheServerApplication(name = "SpringSessionDataGeodeBootSampleServer") // <2>
|
||||
@EnableGemFireHttpSession(maxInactiveIntervalInSeconds = 20) // <3>
|
||||
public class GemFireServer {
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ plugins {
|
||||
id "io.spring.convention.spring-sample-war"
|
||||
}
|
||||
|
||||
apply plugin: "gemfire-server"
|
||||
// apply plugin: "gemfire-server"
|
||||
apply plugin: "application"
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2015-present 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
|
||||
*
|
||||
* https://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.client;
|
||||
|
||||
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newRuntimeException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import jakarta.servlet.ServletContext;
|
||||
|
||||
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.util.StringUtils;
|
||||
import org.springframework.web.WebApplicationInitializer;
|
||||
|
||||
import io.github.classgraph.ClassGraph;
|
||||
import sample.server.GemFireServer;
|
||||
|
||||
/**
|
||||
* Spring {@link WebApplicationInitializer} used to bootstrap an Apache Geode server process.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see sample.server.GemFireServer
|
||||
* @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.process.ProcessWrapper
|
||||
* @see org.springframework.web.WebApplicationInitializer
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class ApacheGeodeServerWebApplicationInitializer extends ForkingClientServerIntegrationTestsSupport
|
||||
implements WebApplicationInitializer {
|
||||
|
||||
@Override
|
||||
public void onStartup(ServletContext servletContext) {
|
||||
|
||||
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));
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample.client;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
<context:property-placeholder/>
|
||||
|
||||
<bean class="sample.client.ApacheGeodeServerWebApplicationInitializer"/>
|
||||
<bean class="sample.client.ClientServerReadyBeanPostProcessor"/>
|
||||
|
||||
<!--1-->
|
||||
|
||||
Reference in New Issue
Block a user