Fix sample XML client-server integration tests ClassNotFoundException on the o.s.session.config.annotation.web.http.SpringHttpSessionConfiguration class.

This commit is contained in:
John Blum
2018-08-17 00:34:19 -07:00
parent c80536d11b
commit 26c7b583bf
5 changed files with 96 additions and 20 deletions

View File

@@ -6,7 +6,6 @@ dependencies {
compile project(':spring-session-data-geode')
compile "org.springframework:spring-web"
compile "org.springframework.data:spring-data-geode-test"
compile "org.webjars:bootstrap"
compile "org.webjars:webjars-taglib"
compile jstlDependencies

View File

@@ -16,28 +16,107 @@
package sample;
import java.io.IOException;
import java.net.Socket;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
import org.springframework.data.gemfire.tests.integration.ClientServerIntegrationTestsSupport;
import org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration;
@SuppressWarnings("unused")
public class ClientServerReadyBeanPostProcessor extends ClientServerIntegrationTestsSupport
implements BeanPostProcessor {
public class ClientServerReadyBeanPostProcessor implements BeanPostProcessor {
@Value("${spring.session.data.geode.cache.server.port:${spring.data.gemfire.cache.server.port:40404}}")
private static final long DEFAULT_TIMEOUT = TimeUnit.SECONDS.toMillis(20);
private final AtomicBoolean verifyGemFireServerIsRunning = new AtomicBoolean(true);
@Value("${spring.data.gemfire.cache.server.port:40404}")
private int port;
@Value("${spring.session.data.geode.cache.server.host:${spring.data.gemfire.cache.server.host:localhost}}")
private String host;
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof ClientCacheFactoryBean) {
waitForServerToStart(host, port);
if (isGemFireServerRunningVerificationEnabled(bean, beanName)) {
waitOn(getGemFireServerSocketCondition(this.port));
}
return bean;
}
private boolean isGemFireServerRunningVerificationEnabled(Object bean, String beanName) {
return isSessionGemFireRegion(bean, beanName)
&& this.verifyGemFireServerIsRunning.compareAndSet(true, false);
}
private boolean isSessionGemFireRegion(Object bean, String beanName) {
return GemFireHttpSessionConfiguration.DEFAULT_SESSION_REGION_NAME.equals(beanName);
}
private Condition getGemFireServerSocketCondition(int port) {
AtomicBoolean gemfireServerRunning = new AtomicBoolean(false);
return () -> {
Socket socket = null;
try {
if (!gemfireServerRunning.get()) {
socket = new Socket("localhost", port);
gemfireServerRunning.set(true);
}
}
catch (IOException ignore) { }
finally {
safeClose(socket);
}
return gemfireServerRunning.get();
};
}
private boolean safeClose(Socket socket) {
try {
if (socket != null) {
socket.close();
}
return true;
}
catch (IOException ignore) {
return false;
}
}
private boolean waitOn(Condition condition) {
long timeout = System.currentTimeMillis() + DEFAULT_TIMEOUT;
while (doWait(condition, timeout)) {
synchronized (this) {
try {
TimeUnit.MICROSECONDS.timedWait(this, 500L);
}
catch (InterruptedException cause) {
Thread.currentThread().interrupt();
}
}
}
return condition.evaluate();
}
private boolean doWait(Condition condition, long timeout) {
return !Thread.currentThread().isInterrupted() && System.currentTimeMillis() < timeout && !condition.evaluate();
}
@FunctionalInterface
interface Condition {
boolean evaluate();
}
}

View File

@@ -1,2 +0,0 @@
spring.data.gemfire.cache.server.host=localhost
spring.data.gemfire.cache.server.port=42424

View File

@@ -15,12 +15,12 @@
<!-- tag::beans[] -->
<context:annotation-config/>
<context:property-placeholder location="classpath:META-INF/spring/application.properties"/>
<context:property-placeholder/>
<!--1-->
<util:properties id="gemfireProperties">
<prop key="name">SpringSessionDataGeodeXmlSampleServer</prop>
<prop key="log-level">${spring.session.data.gemfire.log-level:error}</prop>
<prop key="name">SpringSessionDataGeodeSampleXmlServer</prop>
<prop key="log-level">${spring.session.data.geode.log-level:error}</prop>
</util:properties>
<!--2-->
@@ -28,8 +28,8 @@
<!--3-->
<gfe:cache-server auto-startup="true"
bind-address="${spring.session.data.geode.cache.server.host:${spring.data.gemfire.cache.server.host:localhost}}"
host-name-for-clients="${spring.session.data.geode.cache.server.host:${spring.data.gemfire.cache.server.host:localhost}}"
bind-address="${spring.session.data.geode.cache.server.host:localhost}"
host-name-for-clients="${spring.session.data.geode.cache.server.hostname-for-clients:${spring.data.gemfire.cache.server.hostname-for-clients:localhost}}"
port="${spring.session.data.geode.cache.server.port:${spring.data.gemfire.cache.server.port:40404}}"/>
<!--4-->

View File

@@ -15,7 +15,7 @@
<!-- tag::beans[] -->
<context:annotation-config/>
<context:property-placeholder location="classpath:META-INF/spring/application.properties"/>
<context:property-placeholder/>
<bean class="sample.ClientServerReadyBeanPostProcessor"/>
@@ -29,7 +29,7 @@
<!--3-->
<gfe:pool read-timeout="15000" retry-attempts="1" subscription-enabled="true">
<gfe:server host="${spring.session.data.geode.cache.server.host:${spring.data.gemfire.cache.server.host:localhost}}"
<gfe:server host="${spring.session.data.geode.cache.server.host:localhost}"
port="${spring.session.data.geode.cache.server.port:${spring.data.gemfire.cache.server.port:40404}}"/>
</gfe:pool>