diff --git a/spring-data-geode/pom.xml b/spring-data-geode/pom.xml
index a76e9369..fdcdfbe5 100644
--- a/spring-data-geode/pom.xml
+++ b/spring-data-geode/pom.xml
@@ -272,7 +272,6 @@
true
${basedir}/src/test/resources/java-util-logging.properties
- ${basedir}/src/test/resources/trusted.keystore
true
error
apache-geode
diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractBasicCacheFactoryBean.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractBasicCacheFactoryBean.java
index 6799423f..b0dc1a69 100644
--- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractBasicCacheFactoryBean.java
+++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractBasicCacheFactoryBean.java
@@ -620,7 +620,7 @@ public abstract class AbstractBasicCacheFactoryBean extends AbstractFactoryBeanS
* @see org.apache.geode.cache.GemFireCache
*/
protected boolean isNotClosed(@Nullable GemFireCache cache) {
- return cache == null || !cache.isClosed();
+ return cache != null && !cache.isClosed();
}
/**
diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractConfigurableCacheFactoryBean.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractConfigurableCacheFactoryBean.java
index 8840116e..b1f1fd8e 100644
--- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractConfigurableCacheFactoryBean.java
+++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractConfigurableCacheFactoryBean.java
@@ -137,10 +137,7 @@ public abstract class AbstractConfigurableCacheFactoryBean extends AbstractBasic
*/
@SuppressWarnings("unused")
protected boolean isCacheXmlPresent() {
-
- Resource cacheXml = getCacheXml();
-
- return cacheXml != null && cacheXml.exists();
+ return getOptionalCacheXml().filter(Resource::exists).isPresent();
}
/**
@@ -154,10 +151,7 @@ public abstract class AbstractConfigurableCacheFactoryBean extends AbstractBasic
* @see java.io.File
*/
protected boolean isCacheXmlResolvableAsAFile() {
-
- Resource cacheXml = getCacheXml();
-
- return cacheXml != null && cacheXml.isFile();
+ return getOptionalCacheXml().filter(Resource::isFile).isPresent();
}
/**
@@ -234,6 +228,17 @@ public abstract class AbstractConfigurableCacheFactoryBean extends AbstractBasic
}
}
+ /**
+ * Determine whether to use the {@link GemfireBeanFactoryLocator}.
+ *
+ * This method really determines whether the {@link GemfireBeanFactoryLocator} is enabled and required to configure
+ * native Apache Geode configuration metadata ({@literal cache.xml}).
+ *
+ * @return a boolean value indicating whether to use the {@link GemfireBeanFactoryLocator}.
+ * @see org.springframework.data.gemfire.support.GemfireBeanFactoryLocator
+ * @see #getOptionalBeanFactoryLocator()
+ * @see #isUseBeanFactoryLocator()
+ */
private boolean useBeanFactoryLocator() {
return isUseBeanFactoryLocator() && !getOptionalBeanFactoryLocator().isPresent();
}
diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractResolvableCacheFactoryBean.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractResolvableCacheFactoryBean.java
index 9ce248dc..6b0948c0 100644
--- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractResolvableCacheFactoryBean.java
+++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractResolvableCacheFactoryBean.java
@@ -32,6 +32,7 @@ import org.springframework.lang.NonNull;
* Abstract base class encapsulating logic to resolve or create a {@link GemFireCache} instance.
*
* @author John Blum
+ * @see java.util.Optional
* @see java.util.Properties
* @see org.apache.geode.cache.GemFireCache
* @see org.apache.geode.distributed.DistributedMember
@@ -85,24 +86,25 @@ public abstract class AbstractResolvableCacheFactoryBean extends AbstractConfigu
@SuppressWarnings("deprecation")
private void logCacheInitialization() {
- getOptionalCache().ifPresent(cache -> {
+ getOptionalCache()
+ .filter(cache -> isInfoLoggingEnabled())
+ .ifPresent(cache -> {
- Optional.ofNullable(cache.getDistributedSystem())
- .map(DistributedSystem::getDistributedMember)
- .ifPresent(member -> {
+ logInfo(() -> String.format("%1$s %2$s version [%3$s] Cache [%4$s]", this.cacheResolutionMessagePrefix,
+ apacheGeodeProductName(), apacheGeodeVersion(), cache.getName()));
- String message = "Connected to Distributed System [%1$s] as Member [%2$s] in Group(s) [%3$s]"
- + " with Role(s) [%4$s] on Host [%5$s] having PID [%6$d]";
+ Optional.ofNullable(cache.getDistributedSystem())
+ .map(DistributedSystem::getDistributedMember)
+ .ifPresent(member -> {
- logInfo(() -> String.format(message,
- cache.getDistributedSystem().getName(), member.getId(), member.getGroups(),
- member.getRoles(), member.getHost(), member.getProcessId()));
- });
+ String message = "Connected to Distributed System [%1$s] as Member [%2$s] in Group(s) [%3$s]"
+ + " with Role(s) [%4$s] on Host [%5$s] having PID [%6$d]";
- logInfo(() -> String.format("%1$s %2$s version [%3$s] Cache [%4$s]", this.cacheResolutionMessagePrefix,
- apacheGeodeProductName(), apacheGeodeVersion(), cache.getName()));
-
- });
+ logInfo(() -> String.format(message,
+ cache.getDistributedSystem().getName(), member.getId(), member.getGroups(),
+ member.getRoles(), member.getHost(), member.getProcessId()));
+ });
+ });
}
/**
diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/cache/GemfireCache.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/cache/GemfireCache.java
index 3cc902d1..e408b077 100644
--- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/cache/GemfireCache.java
+++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/cache/GemfireCache.java
@@ -14,7 +14,6 @@
* limitations under the License.
*
*/
-
package org.springframework.data.gemfire.cache;
import java.util.concurrent.Callable;
@@ -35,6 +34,7 @@ import org.springframework.util.Assert;
* @see org.springframework.cache.Cache
* @see org.apache.geode.cache.Region
*/
+@SuppressWarnings("rawtypes")
public class GemfireCache implements Cache {
private final Region region;
@@ -115,9 +115,10 @@ public class GemfireCache implements Cache {
* @see org.apache.geode.cache.Region#get(Object)
*/
public ValueWrapper get(Object key) {
+
Object value = getNativeCache().get(key);
- return (value != null ? new SimpleValueWrapper(value) : null);
+ return value != null ? new SimpleValueWrapper(value) : null;
}
/**
@@ -132,6 +133,7 @@ public class GemfireCache implements Cache {
*/
@SuppressWarnings("unchecked")
public T get(Object key, Class type) {
+
Object value = getNativeCache().get(key);
if (value != null && type != null && !type.isInstance(value)) {
@@ -160,6 +162,7 @@ public class GemfireCache implements Cache {
*/
@SuppressWarnings("unchecked")
public T get(Object key, Callable valueLoader) {
+
T value = (T) get(key, Object.class);
if (value == null) {
@@ -191,6 +194,7 @@ public class GemfireCache implements Cache {
*/
@SuppressWarnings("unchecked")
public void put(Object key, Object value) {
+
if (value != null) {
getNativeCache().put(key, value);
}
@@ -207,6 +211,7 @@ public class GemfireCache implements Cache {
*/
@SuppressWarnings("unchecked")
public ValueWrapper putIfAbsent(Object key, Object value) {
+
Object existingValue = getNativeCache().putIfAbsent(key, value);
return (existingValue != null ? new SimpleValueWrapper(existingValue) : null);
diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/cache/config/GemfireCachingConfiguration.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/cache/config/GemfireCachingConfiguration.java
index 4c33afea..be8bab4b 100644
--- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/cache/config/GemfireCachingConfiguration.java
+++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/cache/config/GemfireCachingConfiguration.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.springframework.data.gemfire.cache.config;
import org.apache.geode.cache.GemFireCache;
diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/CacheServerParser.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/CacheServerParser.java
index a20f2b9b..90241333 100644
--- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/CacheServerParser.java
+++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/CacheServerParser.java
@@ -13,11 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.springframework.data.gemfire.config.xml;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
+import java.util.concurrent.atomic.AtomicInteger;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
@@ -29,6 +27,9 @@ import org.springframework.data.gemfire.util.SpringUtils;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+
/**
* Bean definition parser for the <gfe:cache-server< SDG XML namespace (XSD) element.
*
@@ -40,6 +41,8 @@ import org.springframework.util.xml.DomUtils;
*/
class CacheServerParser extends AbstractSimpleBeanDefinitionParser {
+ private final AtomicInteger cacheServerIdentifier = new AtomicInteger(0);
+
/**
* {@inheritDoc}
*/
@@ -53,8 +56,10 @@ class CacheServerParser extends AbstractSimpleBeanDefinitionParser {
*/
@Override
protected boolean isEligibleAttribute(Attr attribute, ParserContext parserContext) {
- return (super.isEligibleAttribute(attribute, parserContext) && !"groups".equals(attribute.getName())
- && !"cache-ref".equals(attribute.getName()));
+
+ return super.isEligibleAttribute(attribute, parserContext)
+ && !"groups".equals(attribute.getName())
+ && !"cache-ref".equals(attribute.getName());
}
/**
@@ -62,6 +67,7 @@ class CacheServerParser extends AbstractSimpleBeanDefinitionParser {
*/
@Override
protected void postProcess(BeanDefinitionBuilder builder, Element element) {
+
String cacheRefAttribute = element.getAttribute(ParsingUtils.CACHE_REF_ATTRIBUTE_NAME);
builder.addPropertyReference("cache", SpringUtils.defaultIfEmpty(
@@ -76,11 +82,12 @@ class CacheServerParser extends AbstractSimpleBeanDefinitionParser {
parseSubscription(element, builder);
}
- /* (non-Javadoc) */
private void parseSubscription(Element element, BeanDefinitionBuilder builder) {
+
Element subscriptionConfigElement = DomUtils.getChildElementByTagName(element, "subscription-config");
if (subscriptionConfigElement != null) {
+
ParsingUtils.setPropertyValue(subscriptionConfigElement, builder, "capacity", "subscriptionCapacity");
ParsingUtils.setPropertyValue(subscriptionConfigElement, builder, "disk-store", "subscriptionDiskStore");
@@ -92,14 +99,24 @@ class CacheServerParser extends AbstractSimpleBeanDefinitionParser {
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected boolean shouldGenerateIdAsFallback() {
+ return true;
+ }
+
/**
* {@inheritDoc}
*/
@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
- throws BeanDefinitionStoreException {
+ throws BeanDefinitionStoreException {
String name = super.resolveId(element, definition, parserContext);
- return (StringUtils.hasText(name) ? name : "gemfireServer");
+
+ return StringUtils.hasText(name) ? name
+ : String.format("gemfireServer%d", cacheServerIdentifier.incrementAndGet());
}
}
diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/expiration/AnnotationBasedExpiration.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/expiration/AnnotationBasedExpiration.java
index 113327b8..b8bdf583 100644
--- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/expiration/AnnotationBasedExpiration.java
+++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/expiration/AnnotationBasedExpiration.java
@@ -14,7 +14,6 @@
* limitations under the License.
*
*/
-
package org.springframework.data.gemfire.expiration;
import java.lang.annotation.Annotation;
diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/listener/adapter/ContinuousQueryListenerAdapter.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/listener/adapter/ContinuousQueryListenerAdapter.java
index 864dde3f..ad743f88 100644
--- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/listener/adapter/ContinuousQueryListenerAdapter.java
+++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/listener/adapter/ContinuousQueryListenerAdapter.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.springframework.data.gemfire.listener.adapter;
import java.lang.reflect.InvocationTargetException;
@@ -27,9 +26,6 @@ import org.apache.geode.cache.Operation;
import org.apache.geode.cache.query.CqEvent;
import org.apache.geode.cache.query.CqQuery;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import org.springframework.dao.DataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.gemfire.listener.ContinuousQueryListener;
@@ -38,6 +34,9 @@ import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* Event listener adapter that delegates the handling of messages to target listener methods via reflection,
* with flexible event type conversion.
@@ -182,10 +181,13 @@ public class ContinuousQueryListenerAdapter implements ContinuousQueryListener {
public void onEvent(CqEvent event) {
try {
+
+ Object delegate = getDelegate();
+
// Determine whether the delegate is a ContinuousQueryListener implementation;
// If so, this adapter will simply act as a pass-through
- if (this.delegate != this && this.delegate instanceof ContinuousQueryListener) {
- ((ContinuousQueryListener) this.delegate).onEvent(event);
+ if (delegate != this && delegate instanceof ContinuousQueryListener) {
+ ((ContinuousQueryListener) delegate).onEvent(event);
}
// Else, find the listener method handler reflectively
else {
@@ -224,6 +226,7 @@ public class ContinuousQueryListenerAdapter implements ContinuousQueryListener {
* @see #getListenerMethodName
*/
protected void invokeListenerMethod(CqEvent event, String methodName) {
+
try {
this.invoker.invoke(event);
}
@@ -233,7 +236,7 @@ public class ContinuousQueryListenerAdapter implements ContinuousQueryListener {
}
else {
throw new GemfireListenerExecutionFailedException(
- String.format("Listener method [%s] threw Exception...", methodName), cause.getTargetException());
+ String.format("Listener method [%s] threw Exception", methodName), cause.getTargetException());
}
}
catch (Throwable cause) {
@@ -242,7 +245,7 @@ public class ContinuousQueryListenerAdapter implements ContinuousQueryListener {
}
}
- private class MethodInvoker {
+ private static class MethodInvoker {
private final Object delegate;
@@ -258,56 +261,19 @@ public class ContinuousQueryListenerAdapter implements ContinuousQueryListener {
ReflectionUtils.doWithMethods(delegateType, method -> {
ReflectionUtils.makeAccessible(method);
this.methods.add(method);
- }, method -> isValidEventMethodSignature(method, methodName));
+ }, method -> isValidEventHandlerMethodSignature(method, methodName));
Assert.isTrue(!this.methods.isEmpty(), String.format("Cannot find a suitable method named [%1$s#%2$s];"
+ " Is the method public and does it have the proper arguments?",
delegateType.getName(), methodName));
}
- @SuppressWarnings("all")
- private boolean isValidEventMethodSignature(Method method, String methodName) {
-
- if (isEventHandlerMethod(method, methodName)) {
-
- Class>[] parameterTypes = method.getParameterTypes();
-
- int objects = 0;
- int operations = 0;
-
- if (parameterTypes.length > 0) {
- for (Class> parameterType : parameterTypes) {
- if (Object.class.equals(parameterType)) {
- if (++objects > 2) {
- return false;
- }
- }
- else if (Operation.class.equals(parameterType)) {
- if (++operations > 2) {
- return false;
- }
- }
- else if (byte[].class.equals(parameterType)) {
- }
- else if (CqEvent.class.equals(parameterType)) {
- }
- else if (CqQuery.class.equals(parameterType)) {
- }
- else if (Throwable.class.equals(parameterType)) {
- }
- else {
- return false;
- }
- }
-
- return true;
- }
- }
-
- return false;
+ private boolean isValidEventHandlerMethodSignature(Method method, String methodName) {
+ return isValidEventHandlerMethodWithName(method, methodName)
+ && isValidEventHandlerMethodWithSignature(method);
}
- private boolean isEventHandlerMethod(Method method, String methodName) {
+ private boolean isValidEventHandlerMethodWithName(Method method, String methodName) {
return Optional.ofNullable(method)
.filter(it -> Modifier.isPublic(it.getModifiers()))
@@ -315,6 +281,41 @@ public class ContinuousQueryListenerAdapter implements ContinuousQueryListener {
.isPresent();
}
+ @SuppressWarnings("all")
+ private boolean isValidEventHandlerMethodWithSignature(Method method) {
+
+ Class>[] parameterTypes = method.getParameterTypes();
+
+ int objects = 0;
+ int operations = 0;
+
+ if (parameterTypes.length > 0) {
+ for (Class> parameterType : parameterTypes) {
+ if (Object.class.equals(parameterType)) {
+ if (++objects > 2) {
+ return false;
+ }
+ }
+ else if (Operation.class.equals(parameterType)) {
+ if (++operations > 2) {
+ return false;
+ }
+ }
+ else if (byte[].class.equals(parameterType)) { }
+ else if (CqEvent.class.equals(parameterType)) { }
+ else if (CqQuery.class.equals(parameterType)) { }
+ else if (Throwable.class.equals(parameterType)) { }
+ else {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
void invoke(CqEvent event) throws IllegalAccessException, InvocationTargetException {
for (Method method : this.methods) {
@@ -336,11 +337,11 @@ public class ContinuousQueryListenerAdapter implements ContinuousQueryListener {
Class> parameterType = parameterTypes[index];
if (Object.class.equals(parameterType)) {
- args[index] = (value ? event.getNewValue() : event.getKey());
+ args[index] = value ? event.getNewValue() : event.getKey();
value = true;
}
else if (Operation.class.equals(parameterType)) {
- args[index] = (query ? event.getQueryOperation() : event.getBaseOperation());
+ args[index] = query ? event.getQueryOperation() : event.getBaseOperation();
query = true;
}
else if (byte[].class.equals(parameterType)) {
diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/support/AbstractFactoryBeanSupport.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/support/AbstractFactoryBeanSupport.java
index 05fcd95c..b3618e50 100644
--- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/support/AbstractFactoryBeanSupport.java
+++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/support/AbstractFactoryBeanSupport.java
@@ -158,6 +158,64 @@ public abstract class AbstractFactoryBeanSupport
return this.log;
}
+ /**
+ * Returns an {@link Optional} reference to the {@link Logger} used by this {@link FactoryBean}
+ * to log {@link String messages}.
+ *
+ * @return an {@link Optional} reference to the {@link Logger} used by this {@link FactoryBean}
+ * to log {@link String messages}.
+ * @see java.util.Optional
+ * @see org.slf4j.Logger
+ * @see #getLog()
+ */
+ protected Optional getOptionalLog() {
+ return Optional.ofNullable(getLog());
+ }
+
+ /**
+ * Determines whether {@literal DEBUG} logging is enabled.
+ *
+ * @return a boolean value indicating whether {@literal DEBUG} logging is enabled.
+ * @see org.slf4j.Logger#isDebugEnabled()
+ * @see #getOptionalLog()
+ */
+ public boolean isDebugLoggingEnabled() {
+ return getOptionalLog().filter(Logger::isInfoEnabled).isPresent();
+ }
+
+ /**
+ * Determines whether {@literal INFO} logging is enabled.
+ *
+ * @return a boolean value indicating whether {@literal INFO} logging is enabled.
+ * @see org.slf4j.Logger#isInfoEnabled()
+ * @see #getOptionalLog()
+ */
+ public boolean isInfoLoggingEnabled() {
+ return getOptionalLog().filter(Logger::isInfoEnabled).isPresent();
+ }
+
+ /**
+ * Determines whether {@literal ERROR} logging is enabled.
+ *
+ * @return a boolean value indicating whether {@literal ERROR} logging is enabled.
+ * @see org.slf4j.Logger#isErrorEnabled()
+ * @see #getOptionalLog()
+ */
+ public boolean isErrorLoggingEnabled() {
+ return getOptionalLog().filter(Logger::isInfoEnabled).isPresent();
+ }
+
+ /**
+ * Determines whether {@literal WARN} logging is enabled.
+ *
+ * @return a boolean value indicating whether {@literal WARN} logging is enabled.
+ * @see org.slf4j.Logger#isWarnEnabled()
+ * @see #getOptionalLog()
+ */
+ public boolean isWarnLoggingEnabled() {
+ return getOptionalLog().filter(Logger::isInfoEnabled).isPresent();
+ }
+
/**
* Indicates that this {@link FactoryBean} produces a single bean instance.
*
@@ -189,7 +247,7 @@ public abstract class AbstractFactoryBeanSupport
* @see #getLog()
*/
protected void logDebug(Supplier message) {
- Optional.ofNullable(getLog())
+ getOptionalLog()
.filter(Logger::isDebugEnabled)
.ifPresent(log -> log.debug(message.get()));
}
@@ -214,7 +272,7 @@ public abstract class AbstractFactoryBeanSupport
* @see #getLog()
*/
protected void logInfo(Supplier message) {
- Optional.ofNullable(getLog())
+ getOptionalLog()
.filter(Logger::isInfoEnabled)
.ifPresent(log -> log.info(message.get()));
}
@@ -239,7 +297,7 @@ public abstract class AbstractFactoryBeanSupport
* @see #getLog()
*/
protected void logWarning(Supplier message) {
- Optional.ofNullable(getLog())
+ getOptionalLog()
.filter(Logger::isWarnEnabled)
.ifPresent(log -> log.warn(message.get()));
}
@@ -264,7 +322,7 @@ public abstract class AbstractFactoryBeanSupport
* @see #getLog()
*/
protected void logError(Supplier message) {
- Optional.ofNullable(getLog())
+ getOptionalLog()
.filter(Logger::isErrorEnabled)
.ifPresent(log -> log.error(message.get()));
}
diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/support/ConnectionEndpoint.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/support/ConnectionEndpoint.java
index a115e0d7..75a219ad 100644
--- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/support/ConnectionEndpoint.java
+++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/support/ConnectionEndpoint.java
@@ -18,6 +18,7 @@ package org.springframework.data.gemfire.support;
import java.net.InetSocketAddress;
import org.springframework.data.gemfire.util.SpringUtils;
+import org.springframework.lang.NonNull;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@@ -45,13 +46,38 @@ public class ConnectionEndpoint implements Cloneable, Comparable {
+public class SpringContextBootstrappingInitializer implements ApplicationListener, Declarable {
public static final String BASE_PACKAGES_PARAMETER = "basePackages";
public static final String CONTEXT_CONFIG_LOCATIONS_PARAMETER = "contextConfigLocations";
@@ -123,6 +124,21 @@ public class SpringContextBootstrappingInitializer implements Declarable, Applic
}
}
+ /**
+ * Destroy the state of the {@link SpringContextBootstrappingInitializer}.
+ */
+ public static void destroy() {
+
+ beanClassLoaderReference.set(null);
+ applicationContext = null;
+ contextRefreshedEvent = null;
+ registeredAnnotatedClasses.clear();
+
+ synchronized (applicationEventNotifier) {
+ applicationEventNotifier.removeAllListeners();
+ }
+ }
+
/**
* Notifies any Spring ApplicationListeners of a current and existing ContextRefreshedEvent if the
* ApplicationContext had been previously created, initialized and refreshed before any ApplicationListeners
@@ -258,7 +274,7 @@ public class SpringContextBootstrappingInitializer implements Declarable, Applic
* before using the context.
* @throws IllegalArgumentException if both the basePackages and configLocation parameter arguments
* are null or empty.
- * @see #createApplicationContext(String[])
+ * @see #newApplicationContext(String[])
* @see org.springframework.context.annotation.AnnotationConfigApplicationContext
* @see org.springframework.context.annotation.AnnotationConfigApplicationContext#scan(String...)
* @see org.springframework.context.support.ClassPathXmlApplicationContext
@@ -272,12 +288,12 @@ public class SpringContextBootstrappingInitializer implements Declarable, Applic
Class>[] annotatedClasses = registeredAnnotatedClasses.toArray(new Class>[0]);
- ConfigurableApplicationContext applicationContext = createApplicationContext(configLocations);
+ ConfigurableApplicationContext applicationContext = newApplicationContext(configLocations);
return scanBasePackages(registerAnnotatedClasses(applicationContext, annotatedClasses), basePackages);
}
- ConfigurableApplicationContext createApplicationContext(String[] configLocations) {
+ ConfigurableApplicationContext newApplicationContext(String[] configLocations) {
return ObjectUtils.isEmpty(configLocations)
? new AnnotationConfigApplicationContext()
@@ -430,8 +446,9 @@ public class SpringContextBootstrappingInitializer implements Declarable, Applic
String[] contextConfigLocationsArray = StringUtils.delimitedListToStringArray(
StringUtils.trimWhitespace(contextConfigLocations), COMMA_DELIMITER, CHARS_TO_DELETE);
- ConfigurableApplicationContext localApplicationContext = refreshApplicationContext(
- initApplicationContext(createApplicationContext(basePackagesArray, contextConfigLocationsArray)));
+ ConfigurableApplicationContext localApplicationContext =
+ refreshApplicationContext(initApplicationContext(createApplicationContext(basePackagesArray,
+ contextConfigLocationsArray)));
Assert.state(localApplicationContext.isRunning(), String.format(
"The Spring ApplicationContext (%1$s) failed to be properly initialized with the context config files (%2$s) or base packages (%3$s)!",
@@ -461,10 +478,7 @@ public class SpringContextBootstrappingInitializer implements Declarable, Applic
* @see org.springframework.context.ApplicationContext#getId()
*/
String nullSafeGetApplicationContextId(ApplicationContext applicationContext) {
-
- return applicationContext != null
- ? applicationContext.getId()
- : null;
+ return applicationContext != null ? applicationContext.getId() : null;
}
/**
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheAutoReconnectIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheAutoReconnectIntegrationTests.java
index 9ecab89c..5b242f5a 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheAutoReconnectIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheAutoReconnectIntegrationTests.java
@@ -16,19 +16,16 @@
package org.springframework.data.gemfire;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assume.assumeNotNull;
import java.io.File;
-import org.junit.After;
import org.junit.Test;
import org.apache.geode.cache.Cache;
-import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.gemfire.config.xml.GemfireConstants;
-import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
+import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport;
/**
* Integration Tests testing SDG support of Apache Geode Auto-Reconnect functionality.
@@ -37,31 +34,25 @@ import org.springframework.data.gemfire.tests.integration.IntegrationTestsSuppor
* @see org.junit.Test
* @see org.apache.geode.cache.Cache
* @see org.springframework.data.gemfire.CacheFactoryBean
- * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
+ * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
* @since 1.5.0
*/
-public class CacheAutoReconnectIntegrationTests extends IntegrationTestsSupport {
-
- private ConfigurableApplicationContext applicationContext;
-
- @After
- public void tearDown() {
- assumeNotNull(applicationContext);
- applicationContext.close();
- }
+public class CacheAutoReconnectIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
protected Cache getCache(String configLocation) {
String baseConfigLocation =
File.separator.concat(getClass().getPackage().getName().replace('.', File.separatorChar));
- applicationContext = new ClassPathXmlApplicationContext(baseConfigLocation.concat(File.separator).concat(configLocation));
+ String resolvedConfigLocation = baseConfigLocation.concat(File.separator).concat(configLocation);
- return applicationContext.getBean(GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME, Cache.class);
+ setApplicationContext(new ClassPathXmlApplicationContext(resolvedConfigLocation));
+
+ return getBean(GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME, Cache.class);
}
@Test
- public void testAutoReconnectDisabled() {
+ public void autoReconnectIsDisabled() {
Cache cache = getCache("cacheAutoReconnectDisabledIntegrationTests.xml");
@@ -73,7 +64,7 @@ public class CacheAutoReconnectIntegrationTests extends IntegrationTestsSupport
}
@Test
- public void testAutoReconnectEnabled() {
+ public void autoReconnectIsEnabled() {
Cache cache = getCache("cacheAutoReconnectEnabledIntegrationTests.xml");
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheClusterConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheClusterConfigurationIntegrationTests.java
index 084083f5..8302567b 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheClusterConfigurationIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheClusterConfigurationIntegrationTests.java
@@ -48,13 +48,14 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.data.gemfire.fork.LocatorProcess;
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.process.ProcessWrapper;
+import org.springframework.data.gemfire.tests.util.FileSystemUtils;
import org.springframework.data.gemfire.tests.util.FileUtils;
import org.springframework.data.gemfire.tests.util.ThrowableUtils;
import org.springframework.data.gemfire.tests.util.ZipUtils;
import org.springframework.data.gemfire.util.ArrayUtils;
-import org.springframework.util.FileSystemUtils;
import org.springframework.util.StringUtils;
+import org.assertj.core.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -74,8 +75,11 @@ import org.slf4j.LoggerFactory;
@SuppressWarnings("unused")
public class CacheClusterConfigurationIntegrationTests extends ForkingClientServerIntegrationTestsSupport {
+ private static final int ASSERTJ_MAX_STACK_TRACE_ELEMENTS = 500;
+
private static File locatorWorkingDirectory;
+ // The List of Strings represents each line of the Locator process output (System.out).
private static final List locatorProcessOutput = Collections.synchronizedList(new ArrayList<>());
private static final Logger logger = LoggerFactory.getLogger(CacheClusterConfigurationIntegrationTests.class);
@@ -100,7 +104,7 @@ public class CacheClusterConfigurationIntegrationTests extends ForkingClientServ
@Override
protected void finished(Description description) {
- if (Boolean.parseBoolean(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) {
+ if (Arrays.asList("config", "debug", "info").contains(LOG_LEVEL.toLowerCase())) {
try {
FileUtils.write(new File(locatorWorkingDirectory.getParent(),
String.format("%s-clusterconfiglocator.log", description.getMethodName())),
@@ -117,13 +121,14 @@ public class CacheClusterConfigurationIntegrationTests extends ForkingClientServ
try {
String locatorProcessOutputString = StringUtils.collectionToDelimitedString(locatorProcessOutput,
- FileUtils.LINE_SEPARATOR, String.format("[%1$s] - ", description.getMethodName()), "");
+ FileUtils.LINE_SEPARATOR, String.format("[%s] - ", description.getMethodName()), "");
locatorProcessOutputString = StringUtils.hasText(locatorProcessOutputString)
? locatorProcessOutputString
: locatorProcess.readLogFile();
return locatorProcessOutputString;
+
}
catch (IOException cause) {
throw newRuntimeException(cause, "Failed to read the contents of the Locator process log file");
@@ -132,57 +137,57 @@ public class CacheClusterConfigurationIntegrationTests extends ForkingClientServ
};
@BeforeClass
- @SuppressWarnings("all")
+ public static void configureAssertJ() {
+ Assertions.setMaxStackTraceElementsDisplayed(ASSERTJ_MAX_STACK_TRACE_ELEMENTS);
+ }
+
+ @BeforeClass
public static void startLocator() throws IOException {
- int availablePort = findAvailablePort();
+ int locatorPort = findAndReserveAvailablePort();
- String locatorName = "ClusterConfigLocator";
+ String locatorName = String.format("ClusterConfigLocator-%d", System.currentTimeMillis());
- locatorWorkingDirectory =
- createDirectory(new File(System.getProperty("java.io.tmpdir"), locatorName.toLowerCase()));
+ locatorWorkingDirectory = createDirectory(new File(FileSystemUtils.WORKING_DIRECTORY, locatorName.toLowerCase()));
- ZipUtils.unzip(new ClassPathResource("/cluster_config.zip"), locatorWorkingDirectory);
+ ZipUtils.unzip(new ClassPathResource("cluster_config.zip"), locatorWorkingDirectory);
List arguments = new ArrayList<>();
- arguments.add("-Dgemfire.name=" + locatorName);
- arguments.add("-Dlog4j.geode.log.level=error");
- arguments.add("-Dlogback.log.level=error");
+ arguments.add(String.format("-Dgemfire.name=%s", locatorName));
+ arguments.add(String.format("-Dlog4j.geode.log.level=%s", LOG_LEVEL));
+ arguments.add(String.format("-Dlogback.log.level=%s", LOG_LEVEL));
arguments.add("-Dspring.data.gemfire.enable-cluster-configuration=true");
arguments.add("-Dspring.data.gemfire.load-cluster-configuration=true");
- arguments.add(String.format("-Dgemfire.log-level=%s", LOG_LEVEL));
arguments.add(String.format("-Dgemfire.log-file=%s", LOG_FILE));
- arguments.add(String.format("-Dspring.data.gemfire.locator.port=%d", availablePort));
-
- locatorProcess = run(locatorWorkingDirectory, LocatorProcess.class,
- arguments.toArray(new String[arguments.size()]));
+ arguments.add(String.format("-Dgemfire.log-level=%s", LOG_LEVEL));
+ arguments.add(String.format("-Dspring.data.gemfire.locator.port=%d", locatorPort));
+ locatorProcess = run(locatorWorkingDirectory, LocatorProcess.class, arguments.toArray(new String[0]));
locatorProcess.register(input -> locatorProcessOutput.add(input));
-
locatorProcess.registerShutdownHook();
- waitForServerToStart("localhost", availablePort);
+ waitForServerToStart("localhost", locatorPort);
- System.setProperty("spring.data.gemfire.locator.port", String.valueOf(availablePort));
+ System.setProperty("spring.data.gemfire.locator.port", String.valueOf(locatorPort));
}
@AfterClass
public static void stopLocator() {
- locatorProcess.shutdown();
+ stop(locatorProcess);
System.clearProperty("spring.data.gemfire.locator.port");
- if (Boolean.parseBoolean(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) {
- FileSystemUtils.deleteRecursively(locatorWorkingDirectory);
- }
-
FilenameFilter logFileFilter = (directory, name) -> name.endsWith(".log");
File[] logFiles = ArrayUtils.nullSafeArray(locatorWorkingDirectory.listFiles(logFileFilter), File.class);
Arrays.stream(logFiles).forEach(File::delete);
+
+ if (Boolean.parseBoolean(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) {
+ FileSystemUtils.deleteRecursive(locatorWorkingDirectory);
+ }
}
private Region, ?> assertRegion(Region, ?> actualRegion, String expectedRegionName) {
@@ -192,8 +197,10 @@ public class CacheClusterConfigurationIntegrationTests extends ForkingClientServ
private Region, ?> assertRegion(Region, ?> actualRegion, String expectedRegionName,
String expectedRegionFullPath) {
- assertThat(actualRegion).as(String.format("The [%s] was not properly configured and initialized!",
- expectedRegionName)).isNotNull();
+ assertThat(actualRegion)
+ .describedAs("The [%s] was not properly configured and initialized!", expectedRegionName)
+ .isNotNull();
+
assertThat(actualRegion.getName()).isEqualTo(expectedRegionName);
assertThat(actualRegion.getFullPath()).isEqualTo(expectedRegionFullPath);
@@ -254,12 +261,14 @@ public class CacheClusterConfigurationIntegrationTests extends ForkingClientServ
DataPolicy.NORMAL, Scope.LOCAL);
}
- @Test
+ @Test(expected = BeanCreationException.class)
public void localConfigurationTest() {
+ ConfigurableApplicationContext applicationContext = null;
+
try {
- newApplicationContext(getLocation("cacheUsingLocalConfigurationIntegrationTest.xml"));
+ applicationContext = newApplicationContext(getLocation("cacheUsingLocalConfigurationIntegrationTest.xml"));
fail("Loading the 'cacheUsingLocalOnlyConfigurationIntegrationTest.xml' Spring ApplicationContext"
+ " configuration file should have resulted in an Exception due to the Region lookup on"
@@ -272,6 +281,11 @@ public class CacheClusterConfigurationIntegrationTests extends ForkingClientServ
assertThat(expected.getCause().getMessage()
.matches("Region \\[ClusterConfigRegion\\] in Cache \\[.*\\] not found"))
.as(String.format("Message was [%s]", expected.getMessage())).isTrue();
+
+ throw expected;
+ }
+ finally {
+ closeApplicationContext(applicationContext);
}
}
}
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheFactoryBeanUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheFactoryBeanUnitTests.java
index 8115c040..391439a3 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheFactoryBeanUnitTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheFactoryBeanUnitTests.java
@@ -35,7 +35,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.withSettings;
import java.io.InputStream;
import java.util.Collections;
@@ -56,8 +55,6 @@ import org.apache.geode.cache.TransactionListener;
import org.apache.geode.cache.TransactionWriter;
import org.apache.geode.cache.control.ResourceManager;
import org.apache.geode.cache.util.GatewayConflictResolver;
-import org.apache.geode.distributed.DistributedMember;
-import org.apache.geode.distributed.DistributedSystem;
import org.apache.geode.pdx.PdxSerializer;
import org.springframework.beans.factory.BeanFactory;
@@ -244,7 +241,6 @@ public class CacheFactoryBeanUnitTests {
}
@Test
- @SuppressWarnings("deprecation")
public void init() throws Exception {
BeanFactory mockBeanFactory = mock(BeanFactory.class);
@@ -253,10 +249,6 @@ public class CacheFactoryBeanUnitTests {
CacheTransactionManager mockCacheTransactionManager = mock(CacheTransactionManager.class);
- DistributedMember mockDistributedMember = mock(DistributedMember.class, withSettings().lenient());
-
- DistributedSystem mockDistributedSystem = mock(DistributedSystem.class, withSettings().lenient());
-
GatewayConflictResolver mockGatewayConflictResolver = mock(GatewayConflictResolver.class);
PdxSerializer mockPdxSerializer = mock(PdxSerializer.class);
@@ -274,16 +266,8 @@ public class CacheFactoryBeanUnitTests {
when(mockBeanFactory.getAliases(anyString())).thenReturn(new String[0]);
when(mockCacheFactory.create()).thenReturn(mockCache);
when(mockCache.getCacheTransactionManager()).thenReturn(mockCacheTransactionManager);
- when(mockCache.getDistributedSystem()).thenReturn(mockDistributedSystem);
when(mockCache.getResourceManager()).thenReturn(mockResourceManager);
when(mockCacheXml.getInputStream()).thenReturn(mock(InputStream.class));
- when(mockDistributedSystem.getDistributedMember()).thenReturn(mockDistributedMember);
- when(mockDistributedSystem.getName()).thenReturn("MockDistributedSystem");
- when(mockDistributedMember.getId()).thenReturn("MockDistributedMember");
- when(mockDistributedMember.getGroups()).thenReturn(Collections.emptyList());
- when(mockDistributedMember.getRoles()).thenReturn(Collections.emptySet());
- when(mockDistributedMember.getHost()).thenReturn("skullbox");
- when(mockDistributedMember.getProcessId()).thenReturn(12345);
ClassLoader expectedThreadContextClassLoader = Thread.currentThread().getContextClassLoader();
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationTests.java
index ceead40b..9f3d4ef5 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationTests.java
@@ -38,7 +38,7 @@ import org.apache.geode.cache.client.Pool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
@@ -56,7 +56,8 @@ import org.springframework.data.gemfire.util.PropertiesBuilder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
-import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@@ -107,13 +108,23 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT
@BeforeClass
public static void runGemFireCluster() throws Exception {
- serverOne = run(createDirectory("serverOne"), GemFireCacheServerOneConfiguration.class);
+ int locatorPort = findAndReserveAvailablePort();
+ int cacheServerPortOne = findAndReserveAvailablePort();
+ int cacheServerPortTwo = findAndReserveAvailablePort();
- waitForServerToStart("localhost", 41414);
+ serverOne = run(GemFireCacheServerOneConfiguration.class,
+ String.format("-Dspring.data.gemfire.cache.server.port=%d", cacheServerPortOne),
+ String.format("-Dspring.data.gemfire.locator.port=%d", locatorPort));
- serverTwo = run(createDirectory("serverTwo"), GemFireCacheServerTwoConfiguration.class);
+ waitForServerToStart("localhost", cacheServerPortOne);
- waitForServerToStart("localhost", 42424);
+ serverTwo = run(GemFireCacheServerTwoConfiguration.class,
+ String.format("-Dspring.data.gemfire.cache.server.port=%d", cacheServerPortTwo),
+ String.format("-Dspring.data.gemfire.locator.port=%d", locatorPort));
+
+ waitForServerToStart("localhost", cacheServerPortTwo);
+
+ System.setProperty("spring.data.gemfire.locator.port", String.valueOf(locatorPort));
}
@AfterClass
@@ -142,18 +153,20 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT
assertThat(dogNames).containsAll(Arrays.asList("Spuds", "Maha"));
}
- @Data
+ @Getter
+ @EqualsAndHashCode
@Region("Cats")
@RequiredArgsConstructor(staticName = "newCat")
static class Cat {
- @Id @NonNull private String name;
+ @Id @NonNull private final String name;
}
- @Data
+ @Getter
+ @EqualsAndHashCode
@Region("Dogs")
@RequiredArgsConstructor(staticName = "newDog")
static class Dog {
- @Id @NonNull private String name;
+ @Id @NonNull private final String name;
}
@Configuration
@@ -188,7 +201,7 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT
}
@Bean(name = "ServerOnePool")
- PoolFactoryBean serverOnePool() {
+ PoolFactoryBean serverOnePool(@Value("${spring.data.gemfire.locator.port:11235}") int locatorPort) {
PoolFactoryBean serverOnePool = new PoolFactoryBean();
@@ -197,13 +210,13 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT
serverOnePool.setReadTimeout(Long.valueOf(TimeUnit.SECONDS.toMillis(30)).intValue());
serverOnePool.setRetryAttempts(1);
serverOnePool.setServerGroup("serverOne");
- serverOnePool.setLocators(ConnectionEndpointList.from(newConnectionEndpoint("localhost", 11235)));
+ serverOnePool.setLocators(ConnectionEndpointList.from(ConnectionEndpoint.from("localhost", locatorPort)));
return serverOnePool;
}
@Bean(name = "ServerTwoPool")
- PoolFactoryBean serverTwoPool() {
+ PoolFactoryBean serverTwoPool(@Value("${spring.data.gemfire.locator.port:11235}") int locatorPort) {
PoolFactoryBean serverOnePool = new PoolFactoryBean();
@@ -212,7 +225,7 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT
serverOnePool.setReadTimeout(Long.valueOf(TimeUnit.SECONDS.toMillis(30)).intValue());
serverOnePool.setRetryAttempts(1);
serverOnePool.setServerGroup("serverTwo");
- serverOnePool.setLocators(ConnectionEndpointList.from(newConnectionEndpoint("localhost", 11235)));
+ serverOnePool.setLocators(ConnectionEndpointList.from(ConnectionEndpoint.from("localhost", locatorPort)));
return serverOnePool;
}
@@ -254,22 +267,19 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT
GemfireTemplate dogsTemplate(GemFireCache gemfireCache) {
return new GemfireTemplate(gemfireCache.getRegion("Dogs"));
}
-
- ConnectionEndpoint newConnectionEndpoint(String host, int port) {
- return new ConnectionEndpoint(host, port);
- }
}
static abstract class AbstractGemFireCacheServerConfiguration {
- Properties gemfireProperties() {
+ @Bean
+ Properties gemfireProperties(@Value("${spring.data.gemfire.locator.port:11235}") int locatorPort) {
return PropertiesBuilder.create()
.setProperty("name", applicationName())
.setProperty("log-level", logLevel())
- .setProperty("locators", "localhost[11235]")
+ .setProperty("locators", String.format("localhost[%d]", locatorPort))
.setProperty("groups", groups())
- .setProperty("start-locator", startLocator())
+ .setProperty("start-locator", startLocator(locatorPort))
.build();
}
@@ -283,36 +293,34 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT
return System.getProperty("spring.data.gemfire.log.level", GEMFIRE_LOG_LEVEL);
}
- String startLocator() {
+ String startLocator(int locatorPort) {
return "";
}
@Bean
- CacheFactoryBean gemfireCache() {
+ CacheFactoryBean gemfireCache(@Qualifier("gemfireProperties") Properties gemfireProperties) {
CacheFactoryBean gemfireCache = new CacheFactoryBean();
gemfireCache.setClose(true);
- gemfireCache.setProperties(gemfireProperties());
+ gemfireCache.setProperties(gemfireProperties);
return gemfireCache;
}
@Bean
- CacheServerFactoryBean gemfireCacheServer(GemFireCache gemfireCache) {
+ CacheServerFactoryBean gemfireCacheServer(GemFireCache gemfireCache,
+ @Value("${spring.data.gemfire.cache.server.port:40404}") int cacheServerPort) {
CacheServerFactoryBean gemfireCacheServer = new CacheServerFactoryBean();
gemfireCacheServer.setAutoStartup(true);
gemfireCacheServer.setCache((Cache) gemfireCache);
gemfireCacheServer.setMaxTimeBetweenPings(Long.valueOf(TimeUnit.SECONDS.toMillis(60)).intValue());
- gemfireCacheServer.setPort(cacheServerPort());
+ gemfireCacheServer.setPort(cacheServerPort);
return gemfireCacheServer;
}
-
- abstract int cacheServerPort();
-
}
@Configuration
@@ -320,14 +328,13 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT
static class GemFireCacheServerOneConfiguration extends AbstractGemFireCacheServerConfiguration {
public static void main(String[] args) {
- new AnnotationConfigApplicationContext(GemFireCacheServerOneConfiguration.class)
- .registerShutdownHook();
+ runSpringApplication(GemFireCacheServerOneConfiguration.class, args);
}
@Resource(name = "Cats")
private org.apache.geode.cache.Region cats;
- Cat save(Cat cat) {
+ private Cat save(Cat cat) {
cats.put(cat.getName(), cat);
return cat;
}
@@ -341,19 +348,14 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT
save(Cat.newCat("Sammy"));
}
- @Override
- int cacheServerPort() {
- return 41414;
- }
-
@Override
String groups() {
return "serverOne";
}
@Override
- String startLocator() {
- return "localhost[11235]";
+ String startLocator(int locatorPort) {
+ return String.format("localhost[%d]", locatorPort);
}
@Bean(name = "Cats")
@@ -373,14 +375,13 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT
static class GemFireCacheServerTwoConfiguration extends AbstractGemFireCacheServerConfiguration {
public static void main(String[] args) {
- new AnnotationConfigApplicationContext(GemFireCacheServerTwoConfiguration.class)
- .registerShutdownHook();
+ runSpringApplication(GemFireCacheServerTwoConfiguration.class, args);
}
@Resource(name = "Dogs")
private org.apache.geode.cache.Region dogs;
- Dog save(Dog dog) {
+ private Dog save(Dog dog) {
dogs.put(dog.getName(), dog);
return dog;
}
@@ -391,11 +392,6 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT
save(Dog.newDog("Maha"));
}
- @Override
- int cacheServerPort() {
- return 42424;
- }
-
@Override
String groups() {
return "serverTwo";
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/IndexConflictsIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/IndexConflictsIntegrationTests.java
index d7a794cf..83b34e65 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/IndexConflictsIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/IndexConflictsIntegrationTests.java
@@ -32,13 +32,11 @@ import org.apache.geode.cache.query.IndexNameConflictException;
import org.apache.geode.cache.query.QueryService;
import org.springframework.beans.factory.BeanCreationException;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Import;
-import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
+import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport;
/**
* Integration Tests for numerous conflicting {@link Index} configurations.
@@ -57,17 +55,16 @@ import org.springframework.data.gemfire.tests.integration.IntegrationTestsSuppor
* @see org.springframework.context.annotation.Bean
* @see org.springframework.context.annotation.Configuration
* @see org.springframework.context.annotation.Import
+ * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
* @see IndexFactoryBean traps IndexExistsException instead of IndexNameConflictException
* @see Improve IndexFactoryBean's resilience and options for handling GemFire IndexExistsExceptions and IndexNameConflictExceptions
* @since 1.6.3
*/
-public class IndexConflictsIntegrationTests extends IntegrationTestsSupport {
+public class IndexConflictsIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
private static final AtomicBoolean IGNORE = new AtomicBoolean(false);
private static final AtomicBoolean OVERRIDE = new AtomicBoolean(false);
- private ConfigurableApplicationContext applicationContext;
-
private void assertIndex(Index index, String expectedName, String expectedExpression, String expectedFromClause,
IndexType expectedType) {
@@ -82,16 +79,6 @@ public class IndexConflictsIntegrationTests extends IntegrationTestsSupport {
assertThat(getIndexCount()).isEqualTo(count);
}
- private boolean close(ConfigurableApplicationContext applicationContext) {
-
- if (applicationContext != null) {
- applicationContext.close();
- return !(applicationContext.isActive() || applicationContext.isRunning());
- }
-
- return true;
- }
-
private Index getIndex(String indexName) {
for (Index index : nullSafeCollection(getQueryService().getIndexes())) {
@@ -108,19 +95,16 @@ public class IndexConflictsIntegrationTests extends IntegrationTestsSupport {
}
private QueryService getQueryService() {
- return this.applicationContext.getBean("gemfireCache", GemFireCache.class).getQueryService();
+ return getBean("gemfireCache", GemFireCache.class).getQueryService();
}
private boolean hasIndex(String indexName) {
- return (getIndex(indexName) != null);
- }
-
- private ConfigurableApplicationContext newApplicationContext(Class>... annotatedClasses) {
- return new AnnotationConfigApplicationContext(annotatedClasses);
+ return getIndex(indexName) != null;
}
@Before
public void setup() {
+
assertThat(IGNORE.get()).isFalse();
assertThat(OVERRIDE.get()).isFalse();
}
@@ -130,8 +114,6 @@ public class IndexConflictsIntegrationTests extends IntegrationTestsSupport {
OVERRIDE.set(false);
IGNORE.set(false);
-
- assertThat(close(this.applicationContext)).isTrue();
}
@Test
@@ -139,10 +121,10 @@ public class IndexConflictsIntegrationTests extends IntegrationTestsSupport {
assertThat(IGNORE.compareAndSet(false, true)).isTrue();
- this.applicationContext = newApplicationContext(IndexDefinitionConflictConfiguration.class);
+ newApplicationContext(IndexDefinitionConflictConfiguration.class);
- assertThat(this.applicationContext.containsBean("customerIdIndex")).isTrue();
- assertThat(this.applicationContext.containsBean("customerIdentifierIndex")).isTrue();
+ assertThat(requireApplicationContext().containsBean("customerIdIndex")).isTrue();
+ assertThat(requireApplicationContext().containsBean("customerIdentifierIndex")).isTrue();
assertIndexCount(1);
assertThat(hasIndex("customerIdIndex")).isTrue();
assertThat(hasIndex("customerIdentifierIndex")).isFalse();
@@ -158,10 +140,10 @@ public class IndexConflictsIntegrationTests extends IntegrationTestsSupport {
assertThat(OVERRIDE.compareAndSet(false, true)).isTrue();
- this.applicationContext = newApplicationContext(IndexDefinitionConflictConfiguration.class);
+ newApplicationContext(IndexDefinitionConflictConfiguration.class);
- assertThat(this.applicationContext.containsBean("customerIdIndex")).isTrue();
- assertThat(this.applicationContext.containsBean("customerIdentifierIndex")).isTrue();
+ assertThat(containsBean("customerIdIndex")).isTrue();
+ assertThat(containsBean("customerIdentifierIndex")).isTrue();
assertIndexCount(1);
assertThat(hasIndex("customerIdIndex")).isFalse();
assertThat(hasIndex("customerIdentifierIndex")).isTrue();
@@ -176,7 +158,7 @@ public class IndexConflictsIntegrationTests extends IntegrationTestsSupport {
public void indexDefinitionConflictThrowsIndexExistsException() throws Throwable {
try {
- this.applicationContext = newApplicationContext(IndexDefinitionConflictConfiguration.class);
+ newApplicationContext(IndexDefinitionConflictConfiguration.class);
}
catch (BeanCreationException expected) {
@@ -206,10 +188,10 @@ public class IndexConflictsIntegrationTests extends IntegrationTestsSupport {
assertThat(IGNORE.compareAndSet(false, true)).isTrue();
- this.applicationContext = newApplicationContext(IndexNameConflictConfiguration.class);
+ newApplicationContext(IndexNameConflictConfiguration.class);
- assertThat(this.applicationContext.containsBean("customerLastNameIndex")).isTrue();
- assertThat(this.applicationContext.containsBean("customerFirstNameIndex")).isTrue();
+ assertThat(containsBean("customerLastNameIndex")).isTrue();
+ assertThat(containsBean("customerFirstNameIndex")).isTrue();
assertIndexCount(1);
assertThat(hasIndex(IndexNameConflictConfiguration.INDEX_NAME)).isTrue();
@@ -224,11 +206,11 @@ public class IndexConflictsIntegrationTests extends IntegrationTestsSupport {
assertThat(OVERRIDE.compareAndSet(false, true)).isTrue();
- this.applicationContext = newApplicationContext(IndexNameConflictConfiguration.class);
+ newApplicationContext(IndexNameConflictConfiguration.class);
- assertThat(this.applicationContext.getBeansOfType(Index.class)).hasSize(2);
- assertThat(this.applicationContext.containsBean("customerLastNameIndex")).isTrue();
- assertThat(this.applicationContext.containsBean("customerFirstNameIndex")).isTrue();
+ assertThat(getBeansOfType(Index.class)).hasSize(2);
+ assertThat(containsBean("customerLastNameIndex")).isTrue();
+ assertThat(containsBean("customerFirstNameIndex")).isTrue();
assertIndexCount(1);
assertThat(hasIndex(IndexNameConflictConfiguration.INDEX_NAME)).isTrue();
@@ -242,7 +224,7 @@ public class IndexConflictsIntegrationTests extends IntegrationTestsSupport {
public void indexNameConflictThrowsIndexNameConflictException() throws Throwable {
try {
- this.applicationContext = newApplicationContext(IndexNameConflictConfiguration.class);
+ newApplicationContext(IndexNameConflictConfiguration.class);
}
catch (BeanCreationException expected) {
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/LookupPartitionRegionMutationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/LookupPartitionRegionMutationIntegrationTests.java
index e6cc5941..77a9a979 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/LookupPartitionRegionMutationIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/LookupPartitionRegionMutationIntegrationTests.java
@@ -51,6 +51,7 @@ import org.apache.geode.cache.asyncqueue.AsyncEventListener;
import org.apache.geode.cache.util.CacheListenerAdapter;
import org.springframework.beans.factory.BeanNameAware;
+import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.StringUtils;
@@ -63,6 +64,7 @@ import org.springframework.util.StringUtils;
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.LookupRegionFactoryBean
+ * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
* @since 1.7.0
@@ -70,7 +72,7 @@ import org.springframework.util.StringUtils;
@RunWith(SpringRunner.class)
@ContextConfiguration
@SuppressWarnings("unused")
-public class LookupPartitionRegionMutationIntegrationTests {
+public class LookupPartitionRegionMutationIntegrationTests extends IntegrationTestsSupport {
@Resource(name = "Example")
private Region, ?> example;
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/RecreatingSpringApplicationContextTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/RecreatingSpringApplicationContextTest.java
index 8ebbaf55..0afca550 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/RecreatingSpringApplicationContextTest.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/RecreatingSpringApplicationContextTest.java
@@ -15,12 +15,14 @@
*/
package org.springframework.data.gemfire;
+import java.io.File;
+
import org.junit.After;
import org.junit.Before;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
-import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
+import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport;
/**
* Abstract base test class that creates the Spring {@link ConfigurableApplicationContext} after each method (test case).
@@ -31,17 +33,18 @@ import org.springframework.data.gemfire.tests.integration.IntegrationTestsSuppor
* @see org.springframework.context.ConfigurableApplicationContext
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
*/
-public abstract class RecreatingSpringApplicationContextTest extends IntegrationTestsSupport {
-
- protected GenericXmlApplicationContext applicationContext;
+public abstract class RecreatingSpringApplicationContextTest extends SpringApplicationContextIntegrationTestsSupport {
@Before
public void createContext() {
- applicationContext = configureContext(new GenericXmlApplicationContext());
+ GenericXmlApplicationContext applicationContext = configureContext(new GenericXmlApplicationContext());
+
applicationContext.load(location());
applicationContext.registerShutdownHook();
applicationContext.refresh();
+
+ setApplicationContext(applicationContext);
}
protected abstract String location();
@@ -51,8 +54,12 @@ public abstract class RecreatingSpringApplicationContextTest extends Integration
}
@After
- public void closeContext() {
- closeApplicationContext(this.applicationContext);
+ public void cleanupAfterTests() {
+
destroyAllGemFireMockObjects();
+
+ for (String name : new File(".").list((file, filename) -> filename.startsWith("BACKUP"))) {
+ new File(name).delete();
+ }
}
}
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/RegionLookupIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/RegionLookupIntegrationTests.java
index e5bba639..623c7740 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/RegionLookupIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/RegionLookupIntegrationTests.java
@@ -18,8 +18,7 @@ package org.springframework.data.gemfire;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
-import java.util.Optional;
-
+import org.junit.After;
import org.junit.Test;
import org.apache.geode.cache.DataPolicy;
@@ -44,7 +43,6 @@ import org.springframework.data.gemfire.tests.integration.IntegrationTestsSuppor
* @since 1.4.0
* @link https://jira.spring.io/browse/SGF-204
*/
-// TODO: slow test; can this test use mocks?
public class RegionLookupIntegrationTests extends IntegrationTestsSupport {
private void assertNoRegionLookup(String configLocation) {
@@ -52,36 +50,41 @@ public class RegionLookupIntegrationTests extends IntegrationTestsSupport {
ConfigurableApplicationContext applicationContext = null;
try {
- applicationContext = createApplicationContext(configLocation);
+ applicationContext = newApplicationContext(configLocation);
fail("Spring ApplicationContext should have thrown a BeanCreationException caused by a RegionExistsException!");
}
catch (BeanCreationException expected) {
- assertThat(expected.getCause() instanceof RegionExistsException).as(expected.getMessage()).isTrue();
+ assertThat(expected.getCause() instanceof RegionExistsException)
+ .describedAs(expected.getMessage())
+ .isTrue();
throw (RegionExistsException) expected.getCause();
+
}
finally {
closeApplicationContext(applicationContext);
}
}
- private ConfigurableApplicationContext createApplicationContext(String configLocation) {
+ private ConfigurableApplicationContext newApplicationContext(String configLocation) {
return new ClassPathXmlApplicationContext(configLocation);
}
- private void closeApplicationContext(ConfigurableApplicationContext applicationContext) {
- Optional.ofNullable(applicationContext).ifPresent(ConfigurableApplicationContext::close);
+ @After
+ public void cleanupAfterTests() {
+ destroyAllGemFireMockObjects();
}
@Test
- public void testAllowRegionBeanDefinitionOverrides() {
+ public void allowRegionBeanDefinitionOverrides() {
ConfigurableApplicationContext applicationContext = null;
try {
- applicationContext = createApplicationContext(
- "/org/springframework/data/gemfire/allowRegionBeanDefinitionOverridesTest.xml");
+
+ applicationContext =
+ newApplicationContext("/org/springframework/data/gemfire/allowRegionBeanDefinitionOverridesTest.xml");
assertThat(applicationContext).isNotNull();
assertThat(applicationContext.containsBean("regionOne")).isTrue();
@@ -108,47 +111,88 @@ public class RegionLookupIntegrationTests extends IntegrationTestsSupport {
}
@Test(expected = RegionExistsException.class)
- public void testNoDuplicateRegionDefinitions() {
- assertNoRegionLookup("/org/springframework/data/gemfire/noDuplicateRegionDefinitionsTest.xml");
- }
-
- @Test(expected = RegionExistsException.class)
- public void testNoClientRegionLookups() {
+ public void noClientRegionLookups() {
assertNoRegionLookup("/org/springframework/data/gemfire/noClientRegionLookupTest.xml");
}
@Test(expected = RegionExistsException.class)
- public void testNoClientSubRegionLookups() {
+ public void noClientSubRegionLookups() {
assertNoRegionLookup("/org/springframework/data/gemfire/noClientSubRegionLookupTest.xml");
}
@Test(expected = RegionExistsException.class)
- public void testNoLocalRegionLookups() {
+ public void noDuplicateRegionDefinitions() {
+ assertNoRegionLookup("/org/springframework/data/gemfire/noDuplicateRegionDefinitionsTest.xml");
+ }
+
+ @Test(expected = RegionExistsException.class)
+ public void noLocalRegionLookups() {
assertNoRegionLookup("/org/springframework/data/gemfire/noLocalRegionLookupTest.xml");
}
@Test(expected = RegionExistsException.class)
- public void testNoPartitionRegionLookups() {
+ public void noPartitionRegionLookups() {
assertNoRegionLookup("/org/springframework/data/gemfire/noPartitionRegionLookupTest.xml");
}
@Test(expected = RegionExistsException.class)
- public void testNoReplicateRegionLookups() {
+ public void noReplicateRegionLookups() {
assertNoRegionLookup("/org/springframework/data/gemfire/noReplicateRegionLookupTest.xml");
}
@Test(expected = RegionExistsException.class)
- public void testNoSubRegionLookups() {
+ public void noSubRegionLookups() {
assertNoRegionLookup("/org/springframework/data/gemfire/noSubRegionLookupTest.xml");
}
@Test
- public void testEnableRegionLookups() {
+ public void withEnableClientRegionLookups() {
ConfigurableApplicationContext applicationContext = null;
try {
- applicationContext = createApplicationContext("/org/springframework/data/gemfire/enableRegionLookupsTest.xml");
+
+ applicationContext =
+ newApplicationContext("/org/springframework/data/gemfire/enableClientRegionLookupsTest.xml");
+
+ assertThat(applicationContext).isNotNull();
+ assertThat(applicationContext.containsBean("NativeClientRegion")).isTrue();
+ assertThat(applicationContext.containsBean("NativeClientParentRegion")).isTrue();
+ assertThat(applicationContext.containsBean("/NativeClientParentRegion/NativeClientChildRegion")).isTrue();
+
+ Region, ?> nativeClientRegion = applicationContext.getBean("NativeClientRegion", Region.class);
+
+ assertThat(nativeClientRegion).isNotNull();
+ assertThat(nativeClientRegion.getName()).isEqualTo("NativeClientRegion");
+ assertThat(nativeClientRegion.getFullPath()).isEqualTo("/NativeClientRegion");
+ assertThat(nativeClientRegion.getAttributes()).isNotNull();
+ assertThat(nativeClientRegion.getAttributes().getCloningEnabled()).isFalse();
+ assertThat(nativeClientRegion.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.NORMAL);
+
+ Region, ?> nativeClientChildRegion =
+ applicationContext.getBean("/NativeClientParentRegion/NativeClientChildRegion", Region.class);
+
+ assertThat(nativeClientChildRegion).isNotNull();
+ assertThat(nativeClientChildRegion.getName()).isEqualTo("NativeClientChildRegion");
+ assertThat(nativeClientChildRegion.getFullPath())
+ .isEqualTo("/NativeClientParentRegion/NativeClientChildRegion");
+ assertThat(nativeClientChildRegion.getAttributes()).isNotNull();
+ assertThat(nativeClientChildRegion.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.NORMAL);
+ }
+ finally {
+ closeApplicationContext(applicationContext);
+ }
+ }
+
+ @Test
+ public void withEnableRegionLookups() {
+
+ ConfigurableApplicationContext applicationContext = null;
+
+ try {
+
+ applicationContext =
+ newApplicationContext("/org/springframework/data/gemfire/enableRegionLookupsTest.xml");
assertThat(applicationContext).isNotNull();
assertThat(applicationContext.containsBean("NativeLocalRegion")).isTrue();
@@ -228,42 +272,4 @@ public class RegionLookupIntegrationTests extends IntegrationTestsSupport {
closeApplicationContext(applicationContext);
}
}
-
- @Test
- public void testEnableClientRegionLookups() {
-
- ConfigurableApplicationContext applicationContext = null;
-
- try {
-
- applicationContext = createApplicationContext("/org/springframework/data/gemfire/enableClientRegionLookupsTest.xml");
-
- assertThat(applicationContext).isNotNull();
- assertThat(applicationContext.containsBean("NativeClientRegion")).isTrue();
- assertThat(applicationContext.containsBean("NativeClientParentRegion")).isTrue();
- assertThat(applicationContext.containsBean("/NativeClientParentRegion/NativeClientChildRegion")).isTrue();
-
- Region, ?> nativeClientRegion = applicationContext.getBean("NativeClientRegion", Region.class);
-
- assertThat(nativeClientRegion).isNotNull();
- assertThat(nativeClientRegion.getName()).isEqualTo("NativeClientRegion");
- assertThat(nativeClientRegion.getFullPath()).isEqualTo("/NativeClientRegion");
- assertThat(nativeClientRegion.getAttributes()).isNotNull();
- assertThat(nativeClientRegion.getAttributes().getCloningEnabled()).isFalse();
- assertThat(nativeClientRegion.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.NORMAL);
-
- Region, ?> nativeClientChildRegion =
- applicationContext.getBean("/NativeClientParentRegion/NativeClientChildRegion", Region.class);
-
- assertThat(nativeClientChildRegion).isNotNull();
- assertThat(nativeClientChildRegion.getName()).isEqualTo("NativeClientChildRegion");
- assertThat(nativeClientChildRegion.getFullPath())
- .isEqualTo("/NativeClientParentRegion/NativeClientChildRegion");
- assertThat(nativeClientChildRegion.getAttributes()).isNotNull();
- assertThat(nativeClientChildRegion.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.NORMAL);
- }
- finally {
- closeApplicationContext(applicationContext);
- }
- }
}
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/ClientCacheManagerIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/ClientCacheManagerIntegrationTests.java
index 01d4e450..9572807b 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/ClientCacheManagerIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/ClientCacheManagerIntegrationTests.java
@@ -23,8 +23,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
-import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer;
-import org.springframework.test.context.ContextConfiguration;
+import org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
@@ -35,19 +34,22 @@ import org.springframework.test.context.junit4.SpringRunner;
* @see org.junit.Test
* @see org.springframework.data.gemfire.cache.GemfireCacheManager
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
+ * @see org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringRunner
*/
@RunWith(SpringRunner.class)
-@ContextConfiguration(value = "/org/springframework/data/gemfire/cache/cache-manager-client-cache.xml",
- initializers = GemFireMockObjectsApplicationContextInitializer.class)
+@GemFireUnitTest
+@SuppressWarnings("unused")
public class ClientCacheManagerIntegrationTests extends IntegrationTestsSupport {
@Autowired
- GemfireCacheManager cacheManager;
+ private GemfireCacheManager cacheManager;
@Test
public void cacheManagerUsesConfiguredGemFireRegionAsCache() {
- assertThat(cacheManager.getCache("Example")).isNotNull();
+
+ assertThat(this.cacheManager).isNotNull();
+ assertThat(this.cacheManager.getCache("Example")).isNotNull();
}
}
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/CompoundCachePutCacheEvictIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/CompoundCachePutCacheEvictIntegrationTests.java
index ef27db77..76f17fcb 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/CompoundCachePutCacheEvictIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/CompoundCachePutCacheEvictIntegrationTests.java
@@ -20,7 +20,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.io.Serializable;
import java.util.List;
-import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.Resource;
@@ -30,6 +29,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.apache.geode.cache.GemFireCache;
+import org.apache.geode.cache.client.ClientRegionShortcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
@@ -41,8 +41,10 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
-import org.springframework.data.gemfire.CacheFactoryBean;
-import org.springframework.data.gemfire.LocalRegionFactoryBean;
+import org.springframework.data.gemfire.cache.config.EnableGemfireCaching;
+import org.springframework.data.gemfire.config.annotation.ClientCacheApplication;
+import org.springframework.data.gemfire.config.annotation.EnableCachingDefinedRegions;
+import org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions;
import org.springframework.data.gemfire.mapping.GemfireMappingContext;
import org.springframework.data.gemfire.mapping.annotation.Region;
import org.springframework.data.gemfire.repository.support.GemfireRepositoryFactoryBean;
@@ -77,79 +79,89 @@ import lombok.RequiredArgsConstructor;
* @since 1.9.0
*/
@RunWith(SpringRunner.class)
-@ContextConfiguration(classes = CompoundCachePutCacheEvictIntegrationTests.ApplicationTestConfiguration.class)
+@ContextConfiguration(classes = CompoundCachePutCacheEvictIntegrationTests.TestConfiguration.class)
@SuppressWarnings("unused")
public class CompoundCachePutCacheEvictIntegrationTests extends IntegrationTestsSupport {
- private Person janeDoe;
- private Person jonDoe;
+ private Employee janeDoe;
+ private Employee jonDoe;
@Autowired
- private PeopleService peopleService;
+ private EmployeeRepository employeeRepository;
- @Resource(name = "People")
- private org.apache.geode.cache.Region peopleRegion;
+ @Autowired
+ private EmployeeService employeeService;
- protected void assertNoPeopleInDepartment(Department department) {
+ @Resource(name = "Employees")
+ private org.apache.geode.cache.Region employeesRegion;
+
+ private void assertNoEmployeeInDepartment(Department department) {
assertPeopleInDepartment(department);
}
- protected void assertPeopleInDepartment(Department department, Person... people) {
- List peopleInDepartment = peopleService.findByDepartment(department);
+ private void assertPeopleInDepartment(Department department, Employee... people) {
+
+ List peopleInDepartment = employeeService.findByDepartment(department);
assertThat(peopleInDepartment).isNotNull();
assertThat(peopleInDepartment.size()).isEqualTo(people.length);
assertThat(peopleInDepartment).contains(people);
}
- protected Person newPerson(String name, String mobile, Department department) {
- return newPerson(IdentifierSequence.nextId(), name, mobile, department);
+ private Employee newEmployee(String name, String mobile, Department department) {
+ return newEmployee(IdentifierSequence.nextId(), name, mobile, department);
}
- protected Person newPerson(Long id, String name, String mobile, Department department) {
- Person person = Person.newPerson(department, mobile, name);
- person.setId(id);
- return person;
- }
-
- protected Person save(Person person) {
- peopleRegion.put(person.getId(), person);
- return person;
+ private Employee newEmployee(Long id, String name, String mobile, Department department) {
+ Employee employee = Employee.newEmployee(department, mobile, name);
+ employee.setId(id);
+ return employee;
}
@Before
public void setup() {
- janeDoe = save(newPerson("Jane Doe", "541-555-1234", Department.MARKETING));
- jonDoe = save(newPerson("Jon Doe", "972-555-1248", Department.ENGINEERING));
- assertThat(peopleRegion.containsValue(janeDoe)).isTrue();
- assertThat(peopleRegion.containsValue(janeDoe)).isTrue();
+ janeDoe = employeeRepository.save(newEmployee("Jane Doe", "541-555-1234", Department.MARKETING));
+ jonDoe = employeeRepository.save(newEmployee("Jon Doe", "972-555-1248", Department.ENGINEERING));
+
+ assertThat(employeesRegion).containsValue(janeDoe);
+ assertThat(employeesRegion).containsValue(jonDoe);
}
@Test
public void janeDoeUpdateSuccessful() {
- assertNoPeopleInDepartment(Department.DESIGN);
- assertThat(peopleService.isCacheMiss()).isTrue();
+
+ assertNoEmployeeInDepartment(Department.DESIGN);
+ assertThat(employeeService.isCacheMiss()).isTrue();
janeDoe.setDepartment(Department.DESIGN);
- peopleService.update(janeDoe);
+ employeeService.update(janeDoe);
+ assertThat(employeesRegion).containsValue(janeDoe);
assertPeopleInDepartment(Department.DESIGN, janeDoe);
- assertThat(peopleService.isCacheMiss()).isTrue();
+ assertThat(employeeService.isCacheMiss()).isTrue();
+
+ assertThat(employeesRegion).containsValue(janeDoe);
+ assertPeopleInDepartment(Department.DESIGN, janeDoe);
+ assertThat(employeeService.isCacheMiss()).isFalse();
}
@Test
public void jonDoeUpdateSuccessful() {
+
jonDoe.setDepartment(Department.RESEARCH_DEVELOPMENT);
- peopleService.update(jonDoe);
+ employeeService.update(jonDoe);
assertPeopleInDepartment(Department.RESEARCH_DEVELOPMENT, jonDoe);
- assertThat(peopleService.isCacheMiss()).isTrue();
+ assertThat(employeeService.isCacheMiss()).isTrue();
+
+ assertPeopleInDepartment(Department.RESEARCH_DEVELOPMENT, jonDoe);
+ assertThat(employeeService.isCacheMiss()).isFalse();
}
@Configuration
@EnableCaching
- @Import(ApplicationTestConfiguration.class)
+ @Import(TestConfiguration.class)
static class Sgf539WorkaroundConfiguration {
@Bean
@@ -177,25 +189,14 @@ public class CompoundCachePutCacheEvictIntegrationTests extends IntegrationTests
}
@Configuration
- @EnableCaching
@Import(GemFireConfiguration.class)
- static class ApplicationTestConfiguration {
+ static class TestConfiguration {
@Bean
- GemfireCacheManager cacheManager(GemFireCache gemfireCache) {
+ GemfireRepositoryFactoryBean personRepository() {
- GemfireCacheManager cacheManager = new GemfireCacheManager();
-
- cacheManager.setCache(gemfireCache);
-
- return cacheManager;
- }
-
- @Bean
- GemfireRepositoryFactoryBean personRepository() {
-
- GemfireRepositoryFactoryBean personRepository =
- new GemfireRepositoryFactoryBean<>(PersonRepository.class);
+ GemfireRepositoryFactoryBean personRepository =
+ new GemfireRepositoryFactoryBean<>(EmployeeRepository.class);
personRepository.setGemfireMappingContext(new GemfireMappingContext());
@@ -203,79 +204,16 @@ public class CompoundCachePutCacheEvictIntegrationTests extends IntegrationTests
}
@Bean
- PeopleService peopleService(PersonRepository personRepository) {
- return new PeopleService(personRepository);
+ EmployeeService peopleService(EmployeeRepository personRepository) {
+ return new EmployeeService(personRepository);
}
}
- @Configuration
- static class GemFireConfiguration {
-
- static final String DEFAULT_GEMFIRE_LOG_LEVEL = "error";
-
- Properties gemfireProperties() {
-
- Properties gemfireProperties = new Properties();
-
- gemfireProperties.setProperty("name", applicationName());
- gemfireProperties.setProperty("locators", "");
- gemfireProperties.setProperty("log-level", logLevel());
-
- return gemfireProperties;
- }
-
- String applicationName() {
- return CompoundCachePutCacheEvictIntegrationTests.class.getName();
- }
-
- String logLevel() {
- return System.getProperty("spring.data.gemfire.log.level", DEFAULT_GEMFIRE_LOG_LEVEL);
- }
-
- @Bean
- CacheFactoryBean gemfireCache() {
-
- CacheFactoryBean gemfireCache = new CacheFactoryBean();
-
- gemfireCache.setClose(true);
- gemfireCache.setProperties(gemfireProperties());
-
- return gemfireCache;
- }
-
- @Bean(name = "People")
- LocalRegionFactoryBean peopleRegion(GemFireCache gemfireCache) {
-
- LocalRegionFactoryBean peopleRegion = new LocalRegionFactoryBean<>();
-
- peopleRegion.setCache(gemfireCache);
- peopleRegion.setPersistent(false);
-
- return peopleRegion;
- }
-
- @Bean(name = "DepartmentPeople")
- LocalRegionFactoryBean departmentPeopleRegion(GemFireCache gemfireCache) {
-
- LocalRegionFactoryBean departmentPeopleRegion = new LocalRegionFactoryBean<>();
-
- departmentPeopleRegion.setCache(gemfireCache);
- departmentPeopleRegion.setPersistent(false);
-
- return departmentPeopleRegion;
- }
-
- @Bean(name = "MobilePeople")
- LocalRegionFactoryBean mobilePeopleRegion(GemFireCache gemfireCache) {
-
- LocalRegionFactoryBean mobilePeopleRegion = new LocalRegionFactoryBean<>();
-
- mobilePeopleRegion.setCache(gemfireCache);
- mobilePeopleRegion.setPersistent(false);
-
- return mobilePeopleRegion;
- }
- }
+ @ClientCacheApplication
+ @EnableCachingDefinedRegions(clientRegionShortcut = ClientRegionShortcut.LOCAL)
+ @EnableEntityDefinedRegions(basePackageClasses = Employee.class, clientRegionShortcut = ClientRegionShortcut.LOCAL)
+ @EnableGemfireCaching
+ static class GemFireConfiguration { }
public enum Department {
@@ -291,9 +229,9 @@ public class CompoundCachePutCacheEvictIntegrationTests extends IntegrationTests
}
@Data
- @Region("People")
- @RequiredArgsConstructor(staticName = "newPerson")
- public static class Person implements Serializable {
+ @Region("Employees")
+ @RequiredArgsConstructor(staticName = "newEmployee")
+ public static class Employee implements Serializable {
@Id
private Long id;
@@ -305,32 +243,32 @@ public class CompoundCachePutCacheEvictIntegrationTests extends IntegrationTests
}
@Service
- public static class PeopleService extends CacheableService {
+ public static class EmployeeService extends CacheableService {
- private final PersonRepository personRepository;
+ private final EmployeeRepository employeeRepository;
- public PeopleService(PersonRepository personRepository) {
- this.personRepository = personRepository;
+ public EmployeeService(EmployeeRepository employeeRepository) {
+ this.employeeRepository = employeeRepository;
}
- @Cacheable("DepartmentPeople")
- public List findByDepartment(Department department) {
+ @Cacheable("DepartmentEmployees")
+ public List findByDepartment(Department department) {
setCacheMiss();
- return personRepository.findByDepartment(department);
+ return employeeRepository.findByDepartment(department);
}
- @Cacheable("MobilePeople")
- public Person findByMobile(String mobile) {
+ @Cacheable("MobileEmployees")
+ public Employee findByMobile(String mobile) {
setCacheMiss();
- return personRepository.findByMobile(mobile);
+ return employeeRepository.findByMobile(mobile);
}
@Caching(
- evict = @CacheEvict(value = "DepartmentPeople", key = "#p0.department"),
- put = @CachePut(value = "MobilePeople", key="#p0.mobile")
+ evict = @CacheEvict(value = "DepartmentEmployees", key = "#p0.department"),
+ put = @CachePut(value = "MobileEmployees", key="#p0.mobile")
)
- public Person update(Person person) {
- return personRepository.save(person);
+ public Employee update(Employee employee) {
+ return employeeRepository.save(employee);
}
}
@@ -351,11 +289,11 @@ public class CompoundCachePutCacheEvictIntegrationTests extends IntegrationTests
}
}
- public interface PersonRepository extends CrudRepository {
+ public interface EmployeeRepository extends CrudRepository {
- List findByDepartment(Department department);
+ List findByDepartment(Department department);
- Person findByMobile(String mobile);
+ Employee findByMobile(String mobile);
}
}
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIndexingIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIndexingIntegrationTests.java
index 46102086..7843a902 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIndexingIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIndexingIntegrationTests.java
@@ -18,8 +18,6 @@ package org.springframework.data.gemfire.client;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -64,15 +62,8 @@ public class ClientCacheIndexingIntegrationTests extends ForkingClientServerInte
@BeforeClass
public static void startGeodeServer() throws IOException {
-
- List arguments = new ArrayList<>();
-
- arguments.add(String.format("-Dgemfire.name=%s",
- ClientCacheIndexingIntegrationTests.class.getSimpleName().contains("Server")));
-
- arguments.add(getServerContextXmlFileLocation(ClientCacheIndexingIntegrationTests.class));
-
- startGemFireServer(ServerProcess.class, arguments.toArray(new String[0]));
+ startGemFireServer(ServerProcess.class,
+ getServerContextXmlFileLocation(ClientCacheIndexingIntegrationTests.class));
}
private Index getIndex(GemFireCache gemfireCache, String indexName) {
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIntegrationTests.java
index 48275f13..04ba5c41 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIntegrationTests.java
@@ -25,12 +25,10 @@ import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
+import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
-import org.springframework.data.gemfire.tests.util.IOUtils;
/**
* Integration Tests for {@link org.apache.geode.cache.client.ClientCache}.
@@ -45,15 +43,11 @@ import org.springframework.data.gemfire.tests.util.IOUtils;
* @see org.springframework.context.annotation.Bean
* @see org.springframework.context.annotation.Configuration
* @see org.springframework.data.gemfire.client.ClientCacheFactoryBean
- * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
+ * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
*/
@SuppressWarnings("unused")
-public class ClientCacheIntegrationTests extends IntegrationTestsSupport {
-
- private ConfigurableApplicationContext newApplicationContext(Class>... annotatedClasses) {
- return new AnnotationConfigApplicationContext(annotatedClasses);
- }
+public class ClientCacheIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
private boolean testClientCacheClose(Class> clientCacheConfiguration) {
@@ -71,7 +65,7 @@ public class ClientCacheIntegrationTests extends IntegrationTestsSupport {
return clientCache.isClosed();
}
finally {
- IOUtils.close(applicationContext);
+ closeApplicationContext(applicationContext);
}
}
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheSecurityIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheSecurityIntegrationTests.java
index 52bcf18e..08c9efd0 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheSecurityIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheSecurityIntegrationTests.java
@@ -32,6 +32,7 @@ import org.apache.geode.cache.CacheLoaderException;
import org.apache.geode.cache.LoaderHelper;
import org.apache.geode.cache.Region;
+import org.springframework.core.io.ClassPathResource;
import org.springframework.data.gemfire.fork.ServerProcess;
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
import org.springframework.test.context.ContextConfiguration;
@@ -57,14 +58,20 @@ public class ClientCacheSecurityIntegrationTests extends ForkingClientServerInte
List arguments = new ArrayList();
- arguments.add(String.format("-Dgemfire.name=%1$s",
- ClientCacheSecurityIntegrationTests.class.getSimpleName().concat("Server")));
+ org.springframework.core.io.Resource trustedKeystore = new ClassPathResource("trusted.keystore");
- arguments.add(String.format("-Djavax.net.ssl.keyStore=%1$s", System.getProperty("javax.net.ssl.keyStore")));
+ //System.err.printf("trusted.keystore file is located at [%s]%n", trustedKeystore.getFile().getAbsolutePath());
+
+ arguments.add(String.format("-Dgemfire.name=%s",
+ asApplicationName(ClientCacheSecurityIntegrationTests.class).concat("Server")));
+
+ arguments.add(String.format("-Djavax.net.ssl.keyStore=%s", trustedKeystore.getFile().getAbsolutePath()));
arguments.add(getServerContextXmlFileLocation(ClientCacheSecurityIntegrationTests.class));
startGemFireServer(ServerProcess.class, arguments.toArray(new String[arguments.size()]));
+
+ System.setProperty("javax.net.ssl.keyStore", trustedKeystore.getFile().getAbsolutePath());
}
@Resource(name = "Example")
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheVariableServersIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheVariableServersIntegrationTests.java
index a813497a..8cc948cd 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheVariableServersIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheVariableServersIntegrationTests.java
@@ -19,6 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
@@ -36,9 +37,9 @@ import org.apache.geode.cache.CacheLoaderException;
import org.apache.geode.cache.LoaderHelper;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.client.Pool;
-import org.apache.geode.cache.client.PoolManager;
import org.apache.geode.cache.server.CacheServer;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
@@ -52,8 +53,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * Integration Tests testing the use of variable {@literal servers} attribute on <gfe:pool/< in SDG XML Namespace
- * configuration metadata when connecting a client and server.
+ * Integration Tests for the use of the variable {@literal servers} attribute on <gfe:pool/< element
+ * in SDG XML Namespace configuration metadata when connecting a client and server.
*
* @author John Blum
* @see org.junit.Test
@@ -91,26 +92,25 @@ public class ClientCacheVariableServersIntegrationTests extends ForkingClientSer
@AfterClass
public static void cleanup() {
- System.clearProperty("test.cache.server.port.one");
- System.clearProperty("test.cache.server.port.two");
+ Arrays.asList("test.cache.server.port.one", "test.cache.server.port.two").forEach(System::clearProperty);
}
+ @Autowired
+ private Pool serverPool;
+
@Resource(name = "Example")
private Region example;
@Before
public void setup() {
+ assertThat(this.serverPool).isNotNull();
+ assertThat(this.serverPool.getName()).isEqualTo("serverPool");
+ assertThat(this.serverPool.getServers()).hasSize(3);
assertThat(this.example).isNotNull();
assertThat(this.example.getName()).isEqualTo("Example");
assertThat(this.example.getAttributes()).isNotNull();
assertThat(this.example.getAttributes().getPoolName()).isEqualTo("serverPool");
-
- Pool pool = PoolManager.find("serverPool");
-
- assertThat(pool).isNotNull();
- assertThat(pool.getName()).isEqualTo("serverPool");
- assertThat(pool.getServers()).hasSize(3);
}
@Test
@@ -126,7 +126,7 @@ public class ClientCacheVariableServersIntegrationTests extends ForkingClientSer
private static final AtomicInteger cacheMissCounter = new AtomicInteger(0);
@Override
- public Integer load(final LoaderHelper helper) throws CacheLoaderException {
+ public Integer load(LoaderHelper helper) throws CacheLoaderException {
return cacheMissCounter.incrementAndGet();
}
@@ -147,10 +147,10 @@ public class ClientCacheVariableServersIntegrationTests extends ForkingClientSer
Map cacheServers =
CollectionUtils.nullSafeMap(applicationContext.getBeansOfType(CacheServer.class));
- for (CacheServer cacheServer : cacheServers.values()) {
- logger.info("CacheServer host:port [{}:{}]%n",
- cacheServer.getBindAddress(), cacheServer.getPort());
- }
+ assertThat(cacheServers).hasSize(3);
+
+ cacheServers.values().forEach(cacheServer -> logger.info("CacheServer host:port [{}:{}]%n",
+ cacheServer.getBindAddress(), cacheServer.getPort()));
}
}
}
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientRegionIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientRegionIntegrationTests.java
index 5ed217fe..84572e33 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientRegionIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientRegionIntegrationTests.java
@@ -22,15 +22,16 @@ import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.springframework.context.annotation.Bean;
+import org.springframework.data.gemfire.GemfireUtils;
import org.springframework.data.gemfire.config.annotation.ClientCacheApplication;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
-import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
-import org.springframework.test.context.ContextConfiguration;
+import org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
@@ -42,13 +43,13 @@ import org.springframework.test.context.junit4.SpringRunner;
* @see org.apache.geode.cache.Region
* @see org.springframework.data.gemfire.client.ClientRegionFactoryBean
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
- * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
+ * @see org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringRunner
* @since 2.0.0
*/
@RunWith(SpringRunner.class)
-@ContextConfiguration
+@GemFireUnitTest
@SuppressWarnings("unused")
public class ClientRegionIntegrationTests extends IntegrationTestsSupport {
@@ -57,11 +58,19 @@ public class ClientRegionIntegrationTests extends IntegrationTestsSupport {
@Test
public void clientRegionUsesDefaultPoolWhenUnspecified() {
+
+ assertThat(this.example).isNotNull();
+ assertThat(this.example.getName()).isEqualTo(GemfireUtils.toRegionName("Example"));
+ assertThat(this.example.getFullPath()).isEqualTo(GemfireUtils.toRegionPath("Example"));
+ assertThat(this.example.getAttributes()).isNotNull();
+ assertThat(this.example.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.NORMAL);
assertThat(this.example.getAttributes().getPoolName()).isNull();
+
+ // NOTE: A null Pool name implies the use of the Apache Geode DEFAULT Pool.
+
}
@ClientCacheApplication
- @EnableGemFireMockObjects
static class ClientRegionConfiguration {
@Bean("Example")
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AbstractCacheConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AbstractCacheConfigurationIntegrationTests.java
index f1fe5f52..3901bcb5 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AbstractCacheConfigurationIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AbstractCacheConfigurationIntegrationTests.java
@@ -18,8 +18,8 @@ package org.springframework.data.gemfire.config.annotation;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Optional;
+import java.util.function.Function;
-import org.junit.After;
import org.junit.Test;
import org.apache.geode.cache.Cache;
@@ -27,9 +27,9 @@ import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.client.ClientCache;
import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
+import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
import org.springframework.mock.env.MockPropertySource;
@@ -41,18 +41,14 @@ import org.springframework.mock.env.MockPropertySource;
* @see org.apache.geode.cache.Cache
* @see org.apache.geode.cache.GemFireCache
* @see org.apache.geode.cache.client.ClientCache
+ * @see org.springframework.context.ConfigurableApplicationContext
+ * @see org.springframework.core.env.PropertySource
* @see org.springframework.data.gemfire.config.annotation.AbstractCacheConfiguration
+ * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
* @since 2.0.2
*/
-public class AbstractCacheConfigurationIntegrationTests {
-
- private ConfigurableApplicationContext applicationContext;
-
- @After
- public void tearDown() {
- Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close);
- }
+public class AbstractCacheConfigurationIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
private void assertName(GemFireCache gemfireCache, String name) {
@@ -62,35 +58,36 @@ public class AbstractCacheConfigurationIntegrationTests {
assertThat(gemfireCache.getDistributedSystem().getProperties().getProperty("name")).isEqualTo(name);
}
- private ConfigurableApplicationContext newApplicationContext(Class>... annotatedClasses) {
- return newApplicationContext(null, annotatedClasses);
+ @Override
+ protected ConfigurableApplicationContext newApplicationContext(Class>... annotatedClasses) {
+ return newApplicationContext((PropertySource>) null, annotatedClasses);
}
private ConfigurableApplicationContext newApplicationContext(PropertySource> testPropertySource,
Class>... annotatedClasses) {
- AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
+ Function applicationContextInitializer =
+ testPropertySource != null ? applicationContext -> {
+ Optional.ofNullable(testPropertySource).ifPresent(it -> {
- Optional.ofNullable(testPropertySource).ifPresent(it -> {
+ MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources();
- MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources();
+ propertySources.addFirst(testPropertySource);
+ });
- propertySources.addFirst(testPropertySource);
- });
+ return applicationContext;
+ }
+ : Function.identity();
- applicationContext.register(annotatedClasses);
- applicationContext.registerShutdownHook();
- applicationContext.refresh();
-
- return applicationContext;
+ return newApplicationContext(applicationContextInitializer, annotatedClasses);
}
@Test
public void clientCacheNameUsesAnnotationNameAttributeDefaultValue() {
- this.applicationContext = newApplicationContext(TestClientCacheConfiguration.class);
+ newApplicationContext(TestClientCacheConfiguration.class);
- GemFireCache peerCache = this.applicationContext.getBean("gemfireCache", ClientCache.class);
+ GemFireCache peerCache = getBean("gemfireCache", ClientCache.class);
assertName(peerCache, ClientCacheConfiguration.DEFAULT_NAME);
}
@@ -101,9 +98,9 @@ public class AbstractCacheConfigurationIntegrationTests {
MockPropertySource testPropertySource = new MockPropertySource()
.withProperty("spring.data.gemfire.name", "TestClient");
- this.applicationContext = newApplicationContext(testPropertySource, TestClientCacheConfiguration.class);
+ newApplicationContext(testPropertySource, TestClientCacheConfiguration.class);
- GemFireCache peerCache = this.applicationContext.getBean("gemfireCache", ClientCache.class);
+ GemFireCache peerCache = getBean("gemfireCache", ClientCache.class);
assertName(peerCache, "TestClient");
}
@@ -111,9 +108,9 @@ public class AbstractCacheConfigurationIntegrationTests {
@Test
public void peerCacheNameUsesAnnotationNameAttributeConfiguredValue() {
- this.applicationContext = newApplicationContext(TestPeerCacheConfiguration.class);
+ newApplicationContext(TestPeerCacheConfiguration.class);
- GemFireCache peerCache = this.applicationContext.getBean("gemfireCache", Cache.class);
+ GemFireCache peerCache = getBean("gemfireCache", Cache.class);
assertName(peerCache, "TestPeerCacheApp");
}
@@ -124,9 +121,9 @@ public class AbstractCacheConfigurationIntegrationTests {
MockPropertySource testPropertySource = new MockPropertySource()
.withProperty("spring.data.gemfire.cache.name", "TestPeer");
- this.applicationContext = newApplicationContext(testPropertySource, TestPeerCacheConfiguration.class);
+ newApplicationContext(testPropertySource, TestPeerCacheConfiguration.class);
- GemFireCache peerCache = this.applicationContext.getBean("gemfireCache", Cache.class);
+ GemFireCache peerCache = getBean("gemfireCache", Cache.class);
assertName(peerCache, "TestPeer");
}
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheGeodeSecurityManagerSecurityIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheGeodeSecurityManagerSecurityIntegrationTests.java
index d0c421cd..7d5d7136 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheGeodeSecurityManagerSecurityIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheGeodeSecurityManagerSecurityIntegrationTests.java
@@ -33,6 +33,7 @@ import org.apache.geode.security.ResourcePermission;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
+import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@@ -54,6 +55,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@ActiveProfiles("apache-geode-client")
@ContextConfiguration(classes = AbstractGeodeSecurityIntegrationTests.GeodeClientConfiguration.class)
+@DirtiesContext
public class ApacheGeodeSecurityManagerSecurityIntegrationTests extends AbstractGeodeSecurityIntegrationTests {
protected static final String GEODE_SECURITY_MANAGER_PROPERTY_CONFIGURATION_PROFILE =
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheShiroIniSecurityIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheShiroIniSecurityIntegrationTests.java
index a4581ad1..5b042502 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheShiroIniSecurityIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheShiroIniSecurityIntegrationTests.java
@@ -23,6 +23,7 @@ import org.junit.runner.RunWith;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
+import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@@ -41,6 +42,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@ActiveProfiles("apache-geode-client")
@ContextConfiguration(classes = AbstractGeodeSecurityIntegrationTests.GeodeClientConfiguration.class)
+@DirtiesContext
public class ApacheShiroIniSecurityIntegrationTests extends AbstractGeodeSecurityIntegrationTests {
protected static final String SHIRO_INI_CONFIGURATION_PROFILE = "shiro-ini-configuration";
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheShiroRealmSecurityIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheShiroRealmSecurityIntegrationTests.java
index 5a3851d8..2ef6261a 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheShiroRealmSecurityIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheShiroRealmSecurityIntegrationTests.java
@@ -28,6 +28,7 @@ import org.apache.shiro.realm.text.PropertiesRealm;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
+import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@@ -47,6 +48,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@ActiveProfiles("apache-geode-client")
@ContextConfiguration(classes = AbstractGeodeSecurityIntegrationTests.GeodeClientConfiguration.class)
+@DirtiesContext
public class ApacheShiroRealmSecurityIntegrationTests extends AbstractGeodeSecurityIntegrationTests {
protected static final String SHIRO_REALM_CONFIGURATION_PROFILE = "shiro-realm-configuration";
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AutoConfiguredAuthenticationConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AutoConfiguredAuthenticationConfigurationIntegrationTests.java
index 9ba72c52..ccf60f27 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AutoConfiguredAuthenticationConfigurationIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AutoConfiguredAuthenticationConfigurationIntegrationTests.java
@@ -19,8 +19,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.data.gemfire.config.annotation.TestSecurityManager.SECURITY_PASSWORD;
import static org.springframework.data.gemfire.config.annotation.TestSecurityManager.SECURITY_USERNAME;
-import java.util.Optional;
-
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -65,7 +63,7 @@ public class AutoConfiguredAuthenticationConfigurationIntegrationTests
@After
public void tearDown() {
- Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close);
+ closeApplicationContext(this.applicationContext);
}
private ConfigurableApplicationContext newApplicationContext(PropertySource> testPropertySource,
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CacheServerPropertiesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CacheServerPropertiesIntegrationTests.java
index 0c463038..f22d39aa 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CacheServerPropertiesIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CacheServerPropertiesIntegrationTests.java
@@ -17,21 +17,19 @@ package org.springframework.data.gemfire.config.annotation;
import static org.assertj.core.api.Assertions.assertThat;
-import java.util.Optional;
+import java.util.function.Function;
-import org.junit.After;
import org.junit.Test;
import org.apache.geode.cache.server.CacheServer;
import org.apache.geode.cache.server.ClientSubscriptionConfig;
import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicy;
-import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
+import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
import org.springframework.mock.env.MockPropertySource;
@@ -44,34 +42,26 @@ import org.springframework.mock.env.MockPropertySource;
* @see org.apache.geode.cache.server.ClientSubscriptionConfig
* @see org.springframework.core.env.PropertySource
* @see org.springframework.data.gemfire.config.annotation.CacheServerApplication
- * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
+ * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
* @see org.springframework.mock.env.MockPropertySource
* @since 2.0.0
*/
-public class CacheServerPropertiesIntegrationTests extends IntegrationTestsSupport {
-
- private ConfigurableApplicationContext applicationContext;
-
- @After
- public void tearDown() {
- Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close);
- }
+public class CacheServerPropertiesIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
private ConfigurableApplicationContext newApplicationContext(PropertySource> testPropertySource,
Class>... annotatedClasses) {
- AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
+ Function applicationContextInitializer = applicationContext -> {
- MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources();
+ MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources();
- propertySources.addFirst(testPropertySource);
+ propertySources.addFirst(testPropertySource);
- applicationContext.registerShutdownHook();
- applicationContext.register(annotatedClasses);
- applicationContext.refresh();
+ return applicationContext;
+ };
- return applicationContext;
+ return newApplicationContext(applicationContextInitializer, annotatedClasses);
}
private void assertCacheServer(CacheServer cacheServer, String bindAddress, String hostnameForClients,
@@ -113,12 +103,11 @@ public class CacheServerPropertiesIntegrationTests extends IntegrationTestsSuppo
.withProperty("spring.data.gemfire.cache.server.port", "${gemfire.cache.server.port:12345}")
.withProperty("spring.data.gemfire.cache.server.TestCacheServer.subscription-eviction-policy", "MEM");
- this.applicationContext = newApplicationContext(testPropertySource, TestCacheServerConfiguration.class);
+ newApplicationContext(testPropertySource, TestCacheServerConfiguration.class);
- assertThat(this.applicationContext).isNotNull();
- assertThat(this.applicationContext.containsBean("TestCacheServer")).isTrue();
+ assertThat(containsBean("TestCacheServer")).isTrue();
- CacheServer testCacheServer = this.applicationContext.getBean("TestCacheServer", CacheServer.class);
+ CacheServer testCacheServer = getBean("TestCacheServer", CacheServer.class);
assertThat(testCacheServer).isNotNull();
assertThat(testCacheServer.getBindAddress()).isEqualTo("10.120.12.1");
@@ -173,19 +162,18 @@ public class CacheServerPropertiesIntegrationTests extends IntegrationTestsSuppo
.withProperty("spring.data.gemfire.cache.server.TestCacheServer.subscription-eviction-policy", "ENTRY")
.withProperty("spring.data.gemfire.cache.server.TestCacheServer.tcp-no-delay", true);
- this.applicationContext = newApplicationContext(testPropertySource, TestCacheServersConfiguration.class);
+ newApplicationContext(testPropertySource, TestCacheServersConfiguration.class);
- assertThat(this.applicationContext).isNotNull();
- assertThat(this.applicationContext.containsBean("TestCacheServer")).isTrue();
+ assertThat(containsBean("TestCacheServer")).isTrue();
- CacheServer gemfirCacheServer = this.applicationContext.getBean("gemfireCacheServer", CacheServer.class);
+ CacheServer gemfirCacheServer = getBean("gemfireCacheServer", CacheServer.class);
assertCacheServer(gemfirCacheServer, "192.168.0.2", "skullbox", 10000L,
500, 451000, 8, 30000,
60, 41414, 16384, 21,
"TestDiskStore", SubscriptionEvictionPolicy.MEM, false);
- CacheServer testCacheServer = this.applicationContext.getBean("TestCacheServer", CacheServer.class);
+ CacheServer testCacheServer = getBean("TestCacheServer", CacheServer.class);
assertCacheServer(testCacheServer, "10.121.12.1", "jambox", 15000L,
200, 651000, 16, 15000,
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsConsidersCacheConfigCacheNamesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsConsidersCacheConfigCacheNamesIntegrationTests.java
index e4c1d615..8525a8b5 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsConsidersCacheConfigCacheNamesIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsConsidersCacheConfigCacheNamesIntegrationTests.java
@@ -58,7 +58,7 @@ public class CachingDefinedRegionsConsidersCacheConfigCacheNamesIntegrationTests
extends SpringApplicationContextIntegrationTestsSupport {
@After
- public void tearDown() {
+ public void cleanupAfterTests() {
destroyAllGemFireMockObjects();
}
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCacheConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCacheConfigurationIntegrationTests.java
index 9954bd52..baeaaf86 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCacheConfigurationIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCacheConfigurationIntegrationTests.java
@@ -18,19 +18,14 @@ package org.springframework.data.gemfire.config.annotation;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
-import java.util.Optional;
-
-import org.junit.After;
import org.junit.Test;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.Pool;
import org.apache.geode.cache.client.SocketFactory;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
-import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
+import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
/**
@@ -42,46 +37,25 @@ import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockO
* @see org.junit.Test
* @see org.mockito.Mockito
* @see org.springframework.data.gemfire.config.annotation.ClientCacheConfiguration
- * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
+ * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
* @since 2.4.0
*/
@SuppressWarnings("unused")
-public class ClientCacheConfigurationIntegrationTests extends IntegrationTestsSupport {
-
- private ConfigurableApplicationContext applicationContext;
-
- @After
- public void tearDown() {
- Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close);
- }
-
- private ConfigurableApplicationContext newApplicationContext(Class>... annotatedClasses) {
-
- AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
-
- applicationContext.register(annotatedClasses);
- applicationContext.registerShutdownHook();
- applicationContext.refresh();
-
- return applicationContext;
- }
+public class ClientCacheConfigurationIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
@Test
public void clientCacheDefaultPoolWithCustomSocketFactory() {
- this.applicationContext =
- newApplicationContext(ClientCacheDefaultPoolWithCustomSocketFactoryConfiguration.class);
+ newApplicationContext(ClientCacheDefaultPoolWithCustomSocketFactoryConfiguration.class);
- assertThat(this.applicationContext).isNotNull();
-
- ClientCache clientCache = this.applicationContext.getBean(ClientCache.class);
+ ClientCache clientCache = getBean(ClientCache.class);
assertThat(clientCache).isNotNull();
Pool defaultPool = clientCache.getDefaultPool();
- SocketFactory mockSocketFactory = this.applicationContext.getBean("mockSocketFactory", SocketFactory.class);
+ SocketFactory mockSocketFactory = getBean("mockSocketFactory", SocketFactory.class);
assertThat(defaultPool).isNotNull();
assertThat(defaultPool.getName()).isEqualTo("DEFAULT");
@@ -93,12 +67,9 @@ public class ClientCacheConfigurationIntegrationTests extends IntegrationTestsSu
@Test
public void clientCacheDefaultPoolWithDefaultSocketFactory() {
- this.applicationContext =
- newApplicationContext(ClientCacheDefaultPoolWithDefaultSocketFactoryConfiguration.class);
+ newApplicationContext(ClientCacheDefaultPoolWithDefaultSocketFactoryConfiguration.class);
- assertThat(this.applicationContext).isNotNull();
-
- ClientCache clientCache = this.applicationContext.getBean(ClientCache.class);
+ ClientCache clientCache = getBean(ClientCache.class);
assertThat(clientCache).isNotNull();
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCachePropertiesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCachePropertiesIntegrationTests.java
index 0c900b58..983359c6 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCachePropertiesIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCachePropertiesIntegrationTests.java
@@ -18,10 +18,9 @@ package org.springframework.data.gemfire.config.annotation;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
-import java.util.Optional;
import java.util.Properties;
+import java.util.function.Function;
-import org.junit.After;
import org.junit.Test;
import org.apache.geode.cache.client.ClientCache;
@@ -32,12 +31,11 @@ import org.apache.geode.cache.control.ResourceManager;
import org.apache.geode.pdx.PdxSerializer;
import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
-import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
+import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
import org.springframework.mock.env.MockPropertySource;
@@ -51,34 +49,26 @@ import org.springframework.mock.env.MockPropertySource;
* @see org.springframework.core.env.PropertySource
* @see org.springframework.data.gemfire.client.ClientCacheFactoryBean
* @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication
- * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
+ * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
* @see org.springframework.mock.env.MockPropertySource
* @since 2.0.0
*/
-public class ClientCachePropertiesIntegrationTests extends IntegrationTestsSupport {
-
- private ConfigurableApplicationContext applicationContext;
-
- @After
- public void tearDown() {
- Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close);
- }
+public class ClientCachePropertiesIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
private ConfigurableApplicationContext newApplicationContext(PropertySource> testPropertySource,
Class>... annotatedClasses) {
- AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
+ Function applicationContextInitializer = applicationContext -> {
- MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources();
+ MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources();
- propertySources.addFirst(testPropertySource);
+ propertySources.addFirst(testPropertySource);
- applicationContext.register(annotatedClasses);
- applicationContext.registerShutdownHook();
- applicationContext.refresh();
+ return applicationContext;
+ };
- return applicationContext;
+ return newApplicationContext(applicationContextInitializer, annotatedClasses);
}
@Test
@@ -101,23 +91,22 @@ public class ClientCachePropertiesIntegrationTests extends IntegrationTestsSuppo
.withProperty("spring.data.gemfire.pool.server-group", "TestGroup")
.withProperty("spring.data.gemfire.pool.default.subscription-redundancy", 2);
- this.applicationContext = newApplicationContext(testPropertySource, TestClientCacheConfiguration.class);
+ newApplicationContext(testPropertySource, TestClientCacheConfiguration.class);
- assertThat(this.applicationContext).isNotNull();
- assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
- assertThat(this.applicationContext.containsBean("mockPdxSerializer")).isTrue();
+ assertThat(containsBean("gemfireCache")).isTrue();
+ assertThat(containsBean("mockPdxSerializer")).isTrue();
ClientCacheFactoryBean testClientCacheFactoryBean =
- this.applicationContext.getBean("&gemfireCache", ClientCacheFactoryBean.class);
+ getBean("&gemfireCache", ClientCacheFactoryBean.class);
assertThat(testClientCacheFactoryBean).isNotNull();
assertThat(testClientCacheFactoryBean.isUseBeanFactoryLocator()).isFalse();
- ClientCache testClientCache = this.applicationContext.getBean("gemfireCache", ClientCache.class);
+ ClientCache testClientCache = getBean("gemfireCache", ClientCache.class);
assertThat(testClientCache).isNotNull();
- PdxSerializer mockPdxSerializer = this.applicationContext.getBean("mockPdxSerializer", PdxSerializer.class);
+ PdxSerializer mockPdxSerializer = getBean("mockPdxSerializer", PdxSerializer.class);
assertThat(mockPdxSerializer).isNotNull();
assertThat(testClientCache).isNotNull();
@@ -202,24 +191,22 @@ public class ClientCachePropertiesIntegrationTests extends IntegrationTestsSuppo
.withProperty("spring.data.gemfire.pdx.persistent", true)
.withProperty("spring.data.gemfire.pdx.read-serialized", true);
- this.applicationContext = newApplicationContext(testPropertySource, TestDynamicClientCacheConfiguration.class);
+ newApplicationContext(testPropertySource, TestDynamicClientCacheConfiguration.class);
- assertThat(this.applicationContext).isNotNull();
- assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
- assertThat(this.applicationContext.containsBean("mockPdxSerializer")).isTrue();
+ assertThat(containsBean("gemfireCache")).isTrue();
+ assertThat(containsBean("mockPdxSerializer")).isTrue();
- ClientCacheFactoryBean clientCacheFactoryBean =
- this.applicationContext.getBean("&gemfireCache", ClientCacheFactoryBean.class);
+ ClientCacheFactoryBean clientCacheFactoryBean = getBean("&gemfireCache", ClientCacheFactoryBean.class);
assertThat(clientCacheFactoryBean).isNotNull();
- ClientCache clientCache = this.applicationContext.getBean("gemfireCache", ClientCache.class);
+ ClientCache clientCache = getBean("gemfireCache", ClientCache.class);
assertThat(clientCache).isNotNull();
- PdxSerializer mockPdxSerializer = this.applicationContext.getBean("mockPdxSerializer", PdxSerializer.class);
+ PdxSerializer mockPdxSerializer = getBean("mockPdxSerializer", PdxSerializer.class);
- SocketFactory mockSocketFactory = this.applicationContext.getBean("mockSocketFactory", SocketFactory.class);
+ SocketFactory mockSocketFactory = getBean("mockSocketFactory", SocketFactory.class);
assertThat(mockPdxSerializer).isNotNull();
assertThat(mockSocketFactory).isNotNull();
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/DiskStorePropertiesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/DiskStorePropertiesIntegrationTests.java
index 189daa35..fa49feb0 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/DiskStorePropertiesIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/DiskStorePropertiesIntegrationTests.java
@@ -17,20 +17,18 @@ package org.springframework.data.gemfire.config.annotation;
import static org.assertj.core.api.Assertions.assertThat;
-import java.util.Optional;
+import java.util.function.Function;
-import org.junit.After;
import org.junit.Test;
import org.apache.geode.cache.DiskStore;
import org.apache.geode.cache.DiskStoreFactory;
import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
-import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
+import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
import org.springframework.mock.env.MockPropertySource;
@@ -43,34 +41,26 @@ import org.springframework.mock.env.MockPropertySource;
* @see org.apache.geode.cache.DiskStoreFactory
* @see org.springframework.core.env.PropertySource
* @see org.springframework.data.gemfire.config.annotation.EnableDiskStore
- * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
+ * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
* @see org.springframework.mock.env.MockPropertySource
* @since 2.0.0
*/
-public class DiskStorePropertiesIntegrationTests extends IntegrationTestsSupport {
-
- private ConfigurableApplicationContext applicationContext;
-
- @After
- public void tearDown() {
- Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close);
- }
+public class DiskStorePropertiesIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
private ConfigurableApplicationContext newApplicationContext(PropertySource> testPropertySource,
Class>... annotatedClasses) {
- AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
+ Function applicationContextInitializer = applicationContext -> {
- MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources();
+ MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources();
- propertySources.addFirst(testPropertySource);
+ propertySources.addFirst(testPropertySource);
- applicationContext.registerShutdownHook();
- applicationContext.register(annotatedClasses);
- applicationContext.refresh();
+ return applicationContext;
+ };
- return applicationContext;
+ return newApplicationContext(applicationContextInitializer, annotatedClasses);
}
@SuppressWarnings("all")
@@ -102,12 +92,11 @@ public class DiskStorePropertiesIntegrationTests extends IntegrationTestsSupport
.withProperty("spring.data.gemfire.disk.store.time-interval", 500L)
.withProperty("spring.data.gemfire.disk.store.NonExistingDiskStore.time-interval", 30000L);
- this.applicationContext = newApplicationContext(testPropertySource, TestDiskStoreConfiguration.class);
+ newApplicationContext(testPropertySource, TestDiskStoreConfiguration.class);
- assertThat(this.applicationContext).isNotNull();
- assertThat(this.applicationContext.containsBean("TestDiskStore")).isTrue();
+ assertThat(containsBean("TestDiskStore")).isTrue();
- DiskStore testDiskStore = this.applicationContext.getBean("TestDiskStore", DiskStore.class);
+ DiskStore testDiskStore = getBean("TestDiskStore", DiskStore.class);
assertThat(testDiskStore).isNotNull();
assertThat(testDiskStore.getName()).isEqualTo("TestDiskStore");
@@ -145,19 +134,18 @@ public class DiskStorePropertiesIntegrationTests extends IntegrationTestsSupport
.withProperty("spring.data.gemfire.disk.store.TestDiskStoreTwo.time-interval", 250L)
.withProperty("spring.data.gemfire.disk.store.TestDiskStoreTwo.write-buffer-size", 65535);
- this.applicationContext = newApplicationContext(testPropertySource, TestDiskStoresConfiguration.class);
+ newApplicationContext(testPropertySource, TestDiskStoresConfiguration.class);
- assertThat(this.applicationContext).isNotNull();
- assertThat(this.applicationContext.containsBean("TestDiskStoreOne")).isTrue();
- assertThat(this.applicationContext.containsBean("TestDiskStoreTwo")).isTrue();
+ assertThat(containsBean("TestDiskStoreOne")).isTrue();
+ assertThat(containsBean("TestDiskStoreTwo")).isTrue();
- DiskStore testDiskStoreOne = this.applicationContext.getBean("TestDiskStoreOne", DiskStore.class);
+ DiskStore testDiskStoreOne = getBean("TestDiskStoreOne", DiskStore.class);
assertDiskStore(testDiskStoreOne, "TestDiskStoreOne", true, false,
60, 90.0f, 75.0f, 512L,
1024, 500L, 16384);
- DiskStore testDiskStoreTwo = this.applicationContext.getBean("TestDiskStoreTwo", DiskStore.class);
+ DiskStore testDiskStoreTwo = getBean("TestDiskStoreTwo", DiskStore.class);
assertDiskStore(testDiskStoreTwo, "TestDiskStoreTwo", true, false,
75, 95.0f, 80.0f, 2048L,
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableBeanFactoryLocatorConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableBeanFactoryLocatorConfigurationIntegrationTests.java
index 1c656df3..0fd138d1 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableBeanFactoryLocatorConfigurationIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableBeanFactoryLocatorConfigurationIntegrationTests.java
@@ -17,16 +17,11 @@ package org.springframework.data.gemfire.config.annotation;
import static org.assertj.core.api.Assertions.assertThat;
-import java.util.Optional;
-
import org.junit.After;
import org.junit.Test;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.data.gemfire.CacheFactoryBean;
-import org.springframework.data.gemfire.support.GemfireBeanFactoryLocator;
-import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
+import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
/**
@@ -34,46 +29,29 @@ import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockO
*
* @author John Blum
* @see org.junit.Test
- * @see org.springframework.context.ConfigurableApplicationContext
- * @see org.springframework.context.annotation.AnnotationConfigApplicationContext
+ * @see org.springframework.data.gemfire.CacheFactoryBean
* @see org.springframework.data.gemfire.config.annotation.BeanFactoryLocatorConfiguration
* @see org.springframework.data.gemfire.config.annotation.EnableBeanFactoryLocator
- * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
+ * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
* @since 2.0.0
*/
-public class EnableBeanFactoryLocatorConfigurationIntegrationTests extends IntegrationTestsSupport {
-
- private ConfigurableApplicationContext applicationContext;
+public class EnableBeanFactoryLocatorConfigurationIntegrationTests
+ extends SpringApplicationContextIntegrationTestsSupport {
@After
public void tearDown() {
-
- Optional.ofNullable(this.applicationContext).
- ifPresent(ConfigurableApplicationContext::close);
-
- GemfireBeanFactoryLocator.clear();
- }
-
- private ConfigurableApplicationContext newApplicationContext(Class>... annotatedClasses) {
-
- ConfigurableApplicationContext applicationContext =
- new AnnotationConfigApplicationContext(annotatedClasses);
-
- applicationContext.registerShutdownHook();
-
- return applicationContext;
+ closeAllBeanFactoryLocators();
}
private void testGemFireCacheBeanFactoryLocator(Class> configuration,
Class cacheFactoryBeanType, boolean beanFactoryLocatorEnabled) {
- this.applicationContext = newApplicationContext(configuration);
+ newApplicationContext(configuration);
- assertThat(this.applicationContext).isNotNull();
- assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
+ assertThat(containsBean("gemfireCache")).isTrue();
- CacheFactoryBean gemfireCache = this.applicationContext.getBean("&gemfireCache", CacheFactoryBean.class);
+ CacheFactoryBean gemfireCache = getBean("&gemfireCache", CacheFactoryBean.class);
assertThat(gemfireCache).isNotNull();
assertThat(gemfireCache).isInstanceOf(cacheFactoryBeanType);
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterConfigurationIntegrationTests.java
index 05522b5a..e9b8e15c 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterConfigurationIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterConfigurationIntegrationTests.java
@@ -31,7 +31,6 @@ import org.apache.geode.cache.client.ClientRegionShortcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
@@ -179,11 +178,7 @@ public class EnableClusterConfigurationIntegrationTests extends ForkingClientSer
static class GeodeServerTestConfiguration {
public static void main(String[] args) {
-
- AnnotationConfigApplicationContext applicationContext =
- new AnnotationConfigApplicationContext(GeodeServerTestConfiguration.class);
-
- applicationContext.registerShutdownHook();
+ runSpringApplication(GeodeServerTestConfiguration.class, args);
}
@Bean
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterDefinedRegionsIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterDefinedRegionsIntegrationTests.java
index 3c14d88e..6a98f34a 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterDefinedRegionsIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterDefinedRegionsIntegrationTests.java
@@ -34,7 +34,6 @@ import org.apache.geode.cache.client.ClientCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.data.gemfire.LocalRegionFactoryBean;
@@ -135,11 +134,7 @@ public class EnableClusterDefinedRegionsIntegrationTests extends ForkingClientSe
static class GeodeServerTestConfiguration {
public static void main(String[] args) {
-
- AnnotationConfigApplicationContext applicationContext =
- new AnnotationConfigApplicationContext(GeodeServerTestConfiguration.class);
-
- applicationContext.registerShutdownHook();
+ runSpringApplication(GeodeServerTestConfiguration.class, args);
}
@Bean("LocalRegion")
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableCompressionConfigurationUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableCompressionConfigurationUnitTests.java
index bd093f01..29f75733 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableCompressionConfigurationUnitTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableCompressionConfigurationUnitTests.java
@@ -30,8 +30,6 @@ import org.apache.geode.cache.client.ClientRegionShortcut;
import org.apache.geode.compression.Compressor;
import org.apache.geode.compression.SnappyCompressor;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.data.gemfire.GemfireUtils;
import org.springframework.data.gemfire.LocalRegionFactoryBean;
@@ -39,7 +37,7 @@ import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
import org.springframework.data.gemfire.ReplicatedRegionFactoryBean;
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
import org.springframework.data.gemfire.test.model.Person;
-import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
+import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
/**
@@ -51,24 +49,17 @@ import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockO
* @see org.apache.geode.cache.Region
* @see org.springframework.data.gemfire.config.annotation.CompressionConfiguration
* @see org.springframework.data.gemfire.config.annotation.EnableCompression
- * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
+ * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
* @since 2.0.0
*/
-public class EnableCompressionConfigurationUnitTests extends IntegrationTestsSupport {
-
- private ConfigurableApplicationContext applicationContext;
+public class EnableCompressionConfigurationUnitTests extends SpringApplicationContextIntegrationTestsSupport {
@After
- public void tearDown() {
- closeApplicationContext(this.applicationContext);
+ public void cleanupAfterTests() {
destroyAllGemFireMockObjects();
}
- private ConfigurableApplicationContext newApplicationContext(Class>... annotatedClasses) {
- return new AnnotationConfigApplicationContext(annotatedClasses);
- }
-
private void assertRegionCompressor(Region, ?> region, String regionName, Compressor compressor) {
assertThat(region).isNotNull();
@@ -81,40 +72,36 @@ public class EnableCompressionConfigurationUnitTests extends IntegrationTestsSup
@Test
public void enableCompressionForAllRegions() {
- this.applicationContext = newApplicationContext(EnableCompressionForAllRegionsConfiguration.class);
+ newApplicationContext(EnableCompressionForAllRegionsConfiguration.class);
- assertThat(this.applicationContext).isNotNull();
- assertThat(this.applicationContext.containsBean("ExampleClientRegion")).isFalse();
+ assertThat(containsBean("ExampleClientRegion")).isFalse();
- Compressor compressor = this.applicationContext.getBean(Compressor.class);
+ Compressor compressor = getBean(Compressor.class);
assertThat(compressor).isInstanceOf(SnappyCompressor.class);
Arrays.asList("People", "ExampleLocalRegion", "ExamplePartitionRegion", "ExampleReplicateRegion")
.forEach(regionName -> {
- assertThat(this.applicationContext.containsBean(regionName)).isTrue();
- assertRegionCompressor(this.applicationContext.getBean(regionName, Region.class),
- regionName, compressor);
+ assertThat(containsBean(regionName)).isTrue();
+ assertRegionCompressor(getBean(regionName, Region.class), regionName, compressor);
});
}
@Test
public void enableCompressionForSelectRegions() {
- this.applicationContext = newApplicationContext(EnableCompressionForSelectRegionsConfiguration.class);
+ newApplicationContext(EnableCompressionForSelectRegionsConfiguration.class);
- assertThat(this.applicationContext).isNotNull();
-
- Compressor compressor = this.applicationContext.getBean("MockCompressor", Compressor.class);
+ Compressor compressor = getBean("MockCompressor", Compressor.class);
assertThat(compressor).isNotNull();
assertThat(compressor).isNotInstanceOf(SnappyCompressor.class);
- assertThat(this.applicationContext.containsBean(SNAPPY_COMPRESSOR_BEAN_NAME)).isTrue();
+ assertThat(containsBean(SNAPPY_COMPRESSOR_BEAN_NAME)).isTrue();
Arrays.asList("People", "ExampleClientRegion").forEach(regionName -> {
- assertThat(this.applicationContext.containsBean(regionName)).isTrue();
- assertRegionCompressor(this.applicationContext.getBean(regionName, Region.class),
- regionName, "People".equals(regionName) ? compressor : null);
+ assertThat(containsBean(regionName)).isTrue();
+ assertRegionCompressor(getBean(regionName, Region.class), regionName,
+ "People".equals(regionName) ? compressor : null);
});
}
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationIntegrationTests.java
index 61ce6cb2..4c64d29b 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationIntegrationTests.java
@@ -42,7 +42,6 @@ import org.apache.geode.cache.query.CqEvent;
import org.apache.geode.cache.util.CacheListenerAdapter;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@@ -179,11 +178,7 @@ public class EnableContinuousQueriesConfigurationIntegrationTests extends Forkin
static class GeodeServerTestConfiguration {
public static void main(String[] args) {
-
- AnnotationConfigApplicationContext applicationContext =
- new AnnotationConfigApplicationContext(GeodeServerTestConfiguration.class);
-
- applicationContext.registerShutdownHook();
+ runSpringApplication(GeodeServerTestConfiguration.class, args);
}
@Bean(name = "TemperatureReadings")
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationUnitTests.java
index 8e296a24..cea32556 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationUnitTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationUnitTests.java
@@ -27,6 +27,7 @@ import static org.springframework.data.gemfire.util.ArrayUtils.asArray;
import java.lang.reflect.Proxy;
import java.util.concurrent.Executor;
+import org.junit.After;
import org.junit.Test;
import org.apache.geode.cache.GemFireCache;
@@ -45,7 +46,6 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@@ -60,10 +60,9 @@ import org.springframework.data.gemfire.repository.config.EnableGemfireRepositor
import org.springframework.data.gemfire.repository.support.GemfireRepositoryFactoryBean;
import org.springframework.data.gemfire.test.model.Person;
import org.springframework.data.gemfire.test.repo.PersonRepository;
-import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
+import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.mock.GemFireMockObjectsSupport;
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
-import org.springframework.data.gemfire.tests.util.IOUtils;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Component;
import org.springframework.util.ErrorHandler;
@@ -93,45 +92,37 @@ import lombok.Data;
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
* @since 2.0.1
*/
-public class EnableContinuousQueriesConfigurationUnitTests extends IntegrationTestsSupport {
+public class EnableContinuousQueriesConfigurationUnitTests extends SpringApplicationContextIntegrationTestsSupport {
- private ConfigurableApplicationContext newApplicationContext(Class>... annotatedClasses) {
- return new AnnotationConfigApplicationContext(annotatedClasses);
+ @After
+ public void tearDown() {
+ destroyAllGemFireMockObjects();
}
@Test
public void continuousQueryListenerContainerConfigurationIsCorrect() {
- ConfigurableApplicationContext applicationContext =
- newApplicationContext(TestContinuousQueryListenerContainerConfiguration.class);
+ newApplicationContext(TestContinuousQueryListenerContainerConfiguration.class);
- try {
+ ErrorHandler mockErrorHandler = getBean("mockErrorHandler", ErrorHandler.class);
- ErrorHandler mockErrorHandler = applicationContext.getBean("mockErrorHandler", ErrorHandler.class);
+ Executor mockTaskExecutor = getBean("mockTaskExecutor", Executor.class);
- Executor mockTaskExecutor = applicationContext.getBean("mockTaskExecutor", Executor.class);
+ Pool mockPool = getBean("mockPool", Pool.class);
- Pool mockPool = applicationContext.getBean("mockPool", Pool.class);
+ QueryService mockQueryService = getBean("mockQueryService", QueryService.class);
- QueryService mockQueryService = applicationContext.getBean("mockQueryService", QueryService.class);
+ assertThat(containsBean("continuousQueryListenerContainer")).isTrue();
- assertThat(applicationContext.containsBean("continuousQueryListenerContainer")).isTrue();
+ ContinuousQueryListenerContainer container =
+ getBean("continuousQueryListenerContainer", ContinuousQueryListenerContainer.class);
- ContinuousQueryListenerContainer container =
- applicationContext.getBean("continuousQueryListenerContainer",
- ContinuousQueryListenerContainer.class);
-
- assertThat(container).isNotNull();
- assertThat(container.getErrorHandler().orElse(null)).isEqualTo(mockErrorHandler);
- assertThat(container.getPhase()).isEqualTo(1);
- assertThat(container.getPoolName()).isEqualTo(mockPool.getName());
- assertThat(container.getQueryService()).isEqualTo(mockQueryService);
- assertThat(container.getTaskExecutor()).isEqualTo(mockTaskExecutor);
- }
- finally {
- IOUtils.close(applicationContext);
- GemFireMockObjectsSupport.destroy();
- }
+ assertThat(container).isNotNull();
+ assertThat(container.getErrorHandler().orElse(null)).isEqualTo(mockErrorHandler);
+ assertThat(container.getPhase()).isEqualTo(1);
+ assertThat(container.getPoolName()).isEqualTo(mockPool.getName());
+ assertThat(container.getQueryService()).isEqualTo(mockQueryService);
+ assertThat(container.getTaskExecutor()).isEqualTo(mockTaskExecutor);
}
private void testRegisterAndExecuteContinuousQuery(Class>... annotatedClasses) throws Exception {
@@ -139,6 +130,7 @@ public class EnableContinuousQueriesConfigurationUnitTests extends IntegrationTe
ConfigurableApplicationContext applicationContext = newApplicationContext(annotatedClasses);
try {
+
assertThat(applicationContext).isNotNull();
assertThat(applicationContext.containsBean("DEFAULT")).isTrue();
@@ -164,8 +156,8 @@ public class EnableContinuousQueriesConfigurationUnitTests extends IntegrationTe
verify(mockCqQuery, times(1)).execute();
}
finally {
- IOUtils.close(applicationContext);
- GemFireMockObjectsSupport.destroy();
+ closeApplicationContext(applicationContext);
+ destroyAllGemFireMockObjects();
}
}
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesWithClusterConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesWithClusterConfigurationIntegrationTests.java
index 0e5ae4f8..27db1adc 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesWithClusterConfigurationIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesWithClusterConfigurationIntegrationTests.java
@@ -31,7 +31,6 @@ import org.apache.geode.cache.query.CqEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@@ -129,11 +128,7 @@ public class EnableContinuousQueriesWithClusterConfigurationIntegrationTests
static class GemFireServerConfiguration {
public static void main(String[] args) {
-
- AnnotationConfigApplicationContext applicationContext =
- new AnnotationConfigApplicationContext(GemFireServerConfiguration.class);
-
- applicationContext.registerShutdownHook();
+ runSpringApplication(GemFireServerConfiguration.class, args);
}
}
}
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableDiskStoresConfigurationUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableDiskStoresConfigurationUnitTests.java
index 5fbe2b96..24611256 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableDiskStoresConfigurationUnitTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableDiskStoresConfigurationUnitTests.java
@@ -19,19 +19,15 @@ package org.springframework.data.gemfire.config.annotation;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
-import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
-import org.junit.After;
import org.junit.Test;
import org.mockito.stubbing.Answer;
import org.apache.geode.cache.DiskStore;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
-import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
+import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
/**
@@ -45,22 +41,15 @@ import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockO
* @see org.springframework.data.gemfire.config.annotation.EnableDiskStores
* @see org.springframework.data.gemfire.config.annotation.DiskStoreConfiguration
* @see org.springframework.data.gemfire.config.annotation.DiskStoresConfiguration
- * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
+ * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
* @since 1.9.0
*/
@SuppressWarnings("unused")
-public class EnableDiskStoresConfigurationUnitTests extends IntegrationTestsSupport {
+public class EnableDiskStoresConfigurationUnitTests extends SpringApplicationContextIntegrationTestsSupport {
private static final AtomicInteger MOCK_ID = new AtomicInteger(0);
- private ConfigurableApplicationContext applicationContext;
-
- @After
- public void tearDown() {
- Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close);
- }
-
private void assertDiskStore(DiskStore diskStore, String name, boolean allowForceCompaction, boolean autoCompact,
int compactionThreshold, float diskUsageCriticalPercentage, float diskUsageWarningPercentage,
long maxOplogSize, int queueSize, long timeInterval, int writeBufferSize) {
@@ -110,15 +99,6 @@ public class EnableDiskStoresConfigurationUnitTests extends IntegrationTestsSupp
}
}
- private ConfigurableApplicationContext newApplicationContext(Class>... annotatedClasses) {
-
- ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(annotatedClasses);
-
- applicationContext.registerShutdownHook();
-
- return applicationContext;
- }
-
private File newFile(String location) {
return new File(location);
}
@@ -126,9 +106,9 @@ public class EnableDiskStoresConfigurationUnitTests extends IntegrationTestsSupp
@Test
public void enableSingleDiskStore() {
- this.applicationContext = newApplicationContext(SingleDiskStoreConfiguration.class);
+ newApplicationContext(SingleDiskStoreConfiguration.class);
- DiskStore testDiskStore = this.applicationContext.getBean("TestDiskStore", DiskStore.class);
+ DiskStore testDiskStore = getBean("TestDiskStore", DiskStore.class);
assertDiskStore(testDiskStore, "TestDiskStore", true, true, 75, 95.0f, 75.0f, 8192L, 100, 2000L, 65536);
assertDiskStoreDirectoryLocations(testDiskStore, newFile("/absolute/path/to/gemfire/disk/directory"),
@@ -139,13 +119,13 @@ public class EnableDiskStoresConfigurationUnitTests extends IntegrationTestsSupp
@Test
public void enableMultipleDiskStores() {
- this.applicationContext = newApplicationContext(MultipleDiskStoresConfiguration.class);
+ newApplicationContext(MultipleDiskStoresConfiguration.class);
- DiskStore testDiskStoreOne = this.applicationContext.getBean("TestDiskStoreOne", DiskStore.class);
+ DiskStore testDiskStoreOne = getBean("TestDiskStoreOne", DiskStore.class);
assertDiskStore(testDiskStoreOne, "TestDiskStoreOne", false, true, 75, 99.0f, 90.0f, 2048L, 100, 1000L, 32768);
- DiskStore testDiskStoreTwo = this.applicationContext.getBean("TestDiskStoreTwo", DiskStore.class);
+ DiskStore testDiskStoreTwo = getBean("TestDiskStoreTwo", DiskStore.class);
assertDiskStore(testDiskStoreTwo, "TestDiskStoreTwo", true, true, 85, 99.0f, 90.0f, 4096L, 0, 1000L, 32768);
}
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsIntegrationTests.java
index ccb9cc0f..2fc76793 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsIntegrationTests.java
@@ -17,21 +17,19 @@ package org.springframework.data.gemfire.config.annotation;
import static org.assertj.core.api.Assertions.assertThat;
-import java.util.Optional;
+import java.util.function.Function;
-import org.junit.After;
import org.junit.Test;
import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.Region;
import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.data.gemfire.GemfireUtils;
import org.springframework.data.gemfire.test.model.Person;
-import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
+import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
import org.springframework.mock.env.MockPropertySource;
@@ -45,33 +43,25 @@ import org.springframework.mock.env.MockPropertySource;
* @see org.springframework.context.annotation.AnnotationConfigApplicationContext
* @see org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions
* @see org.springframework.data.gemfire.config.annotation.EntityDefinedRegionsConfiguration
- * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
+ * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
* @since 2.0.2
*/
-public class EnableEntityDefinedRegionsIntegrationTests extends IntegrationTestsSupport {
-
- private ConfigurableApplicationContext applicationContext;
-
- @After
- public void tearDown() {
- Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close);
- }
+public class EnableEntityDefinedRegionsIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
private ConfigurableApplicationContext newApplicationContext(PropertySource> testPropertySource,
- Class>... annotatedClasses) {
+ Class>... annotatedClasses) {
- AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
+ Function applicationContextInitializer = applicationContext -> {
- MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources();
+ MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources();
- propertySources.addFirst(testPropertySource);
+ propertySources.addFirst(testPropertySource);
- applicationContext.register(annotatedClasses);
- applicationContext.registerShutdownHook();
- applicationContext.refresh();
+ return applicationContext;
+ };
- return applicationContext;
+ return newApplicationContext(applicationContextInitializer, annotatedClasses);
}
@Test
@@ -81,11 +71,9 @@ public class EnableEntityDefinedRegionsIntegrationTests extends IntegrationTests
MockPropertySource testPropertySource = new MockPropertySource()
.withProperty("spring.data.gemfire.entities.base-packages", Person.class.getPackage().getName());
- this.applicationContext = newApplicationContext(testPropertySource, TestConfiguration.class);
+ newApplicationContext(testPropertySource, TestConfiguration.class);
- assertThat(this.applicationContext).isNotNull();
-
- Region people = this.applicationContext.getBean("People", Region.class);
+ Region people = getBean("People", Region.class);
assertThat(people).isNotNull();
assertThat(people.getName()).isEqualTo("People");
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsUnitTests.java
index ca9bc700..b4cbdd92 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsUnitTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsUnitTests.java
@@ -25,7 +25,6 @@ import static org.springframework.data.gemfire.util.CollectionUtils.nullSafeList
import static org.springframework.data.gemfire.util.RegionUtils.toRegionPath;
import java.util.List;
-import java.util.Optional;
import org.junit.After;
import org.junit.Test;
@@ -45,8 +44,6 @@ import org.apache.geode.cache.client.ClientRegionShortcut;
import org.apache.geode.cache.client.Pool;
import org.springframework.beans.factory.BeanCreationException;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
@@ -64,7 +61,7 @@ import org.springframework.data.gemfire.mapping.annotation.ClientRegion;
import org.springframework.data.gemfire.mapping.annotation.LocalRegion;
import org.springframework.data.gemfire.mapping.annotation.PartitionRegion;
import org.springframework.data.gemfire.mapping.annotation.ReplicateRegion;
-import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
+import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.mock.MockObjectsSupport;
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
@@ -86,21 +83,15 @@ import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockO
* @see org.springframework.data.gemfire.mapping.annotation.ReplicateRegion
* @see org.springframework.data.gemfire.mapping.annotation.ReplicateRegion
* @see org.springframework.data.gemfire.tests.mock.MockObjectsSupport
- * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
+ * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
* @since 1.9.0
*/
@SuppressWarnings({ "unchecked", "unused" })
-public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport {
-
- private ConfigurableApplicationContext applicationContext;
+public class EnableEntityDefinedRegionsUnitTests extends SpringApplicationContextIntegrationTestsSupport {
@After
public void tearDown() {
-
- Optional.ofNullable(this.applicationContext)
- .ifPresent(ConfigurableApplicationContext::close);
-
destroyAllGemFireMockObjects();
}
@@ -171,9 +162,9 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport
private void assertUndefinedRegions(String... regionBeanNames) {
stream(nullSafeArray(regionBeanNames, String.class)).forEach(regionBeanName ->
- assertThat(this.applicationContext.containsBean(regionBeanName)).isFalse());
+ assertThat(containsBean(regionBeanName)).isFalse());
- assertThat(this.applicationContext.getBeansOfType(Region.class)).hasSize(11 - length(regionBeanNames));
+ assertThat(getBeansOfType(Region.class)).hasSize(11 - length(regionBeanNames));
}
private FixedPartitionAttributes findFixedPartitionAttributes(PartitionAttributes, ?> partitionAttributes,
@@ -193,28 +184,18 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport
return null;
}
- private ConfigurableApplicationContext newApplicationContext(Class>... annotatedClasses) {
-
- ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(annotatedClasses);
-
- applicationContext.registerShutdownHook();
-
- return applicationContext;
- }
-
@Test
public void entityClientRegionsDefined() {
- this.applicationContext = newApplicationContext(ClientPersistentEntitiesConfiguration.class);
+ newApplicationContext(ClientPersistentEntitiesConfiguration.class);
- Region sessions = this.applicationContext.getBean("Sessions", Region.class);
+ Region sessions = getBean("Sessions", Region.class);
assertRegion(sessions, "Sessions", String.class, ClientRegionEntity.class);
assertRegionAttributes(sessions.getAttributes(), DataPolicy.NORMAL,
null, true, false, null, null);
- Region genericRegionEntity =
- this.applicationContext.getBean("GenericRegionEntity", Region.class);
+ Region genericRegionEntity = getBean("GenericRegionEntity", Region.class);
assertRegion(genericRegionEntity, "GenericRegionEntity", Long.class, GenericRegionEntity.class);
assertRegionAttributes(genericRegionEntity.getAttributes(), DataPolicy.EMPTY,
@@ -228,15 +209,14 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport
@Test
public void entityClientRegionsDefinedWithCustomConfiguration() {
- this.applicationContext = newApplicationContext(ClientPersistentEntitiesWithCustomConfiguration.class);
+ newApplicationContext(ClientPersistentEntitiesWithCustomConfiguration.class);
- Region