Refactor test classes in conjunction with reusing forked test JVMs per test class.
Resolves gh-296.
This commit is contained in:
@@ -272,7 +272,6 @@
|
||||
<reuseForks>true</reuseForks>
|
||||
<systemProperties>
|
||||
<java.util.logging.config.file>${basedir}/src/test/resources/java-util-logging.properties</java.util.logging.config.file>
|
||||
<javax.net.ssl.keyStore>${basedir}/src/test/resources/trusted.keystore</javax.net.ssl.keyStore>
|
||||
<gemfire.disableShutdownHook>true</gemfire.disableShutdownHook>
|
||||
<logback.log.level>error</logback.log.level>
|
||||
<spring.profiles.active>apache-geode</spring.profiles.active>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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()));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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> T get(Object key, Class<T> 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> T get(Object key, Callable<T> 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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.expiration;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -158,6 +158,64 @@ public abstract class AbstractFactoryBeanSupport<T>
|
||||
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<Logger> 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<T>
|
||||
* @see #getLog()
|
||||
*/
|
||||
protected void logDebug(Supplier<String> message) {
|
||||
Optional.ofNullable(getLog())
|
||||
getOptionalLog()
|
||||
.filter(Logger::isDebugEnabled)
|
||||
.ifPresent(log -> log.debug(message.get()));
|
||||
}
|
||||
@@ -214,7 +272,7 @@ public abstract class AbstractFactoryBeanSupport<T>
|
||||
* @see #getLog()
|
||||
*/
|
||||
protected void logInfo(Supplier<String> message) {
|
||||
Optional.ofNullable(getLog())
|
||||
getOptionalLog()
|
||||
.filter(Logger::isInfoEnabled)
|
||||
.ifPresent(log -> log.info(message.get()));
|
||||
}
|
||||
@@ -239,7 +297,7 @@ public abstract class AbstractFactoryBeanSupport<T>
|
||||
* @see #getLog()
|
||||
*/
|
||||
protected void logWarning(Supplier<String> message) {
|
||||
Optional.ofNullable(getLog())
|
||||
getOptionalLog()
|
||||
.filter(Logger::isWarnEnabled)
|
||||
.ifPresent(log -> log.warn(message.get()));
|
||||
}
|
||||
@@ -264,7 +322,7 @@ public abstract class AbstractFactoryBeanSupport<T>
|
||||
* @see #getLog()
|
||||
*/
|
||||
protected void logError(Supplier<String> message) {
|
||||
Optional.ofNullable(getLog())
|
||||
getOptionalLog()
|
||||
.filter(Logger::isErrorEnabled)
|
||||
.ifPresent(log -> log.error(message.get()));
|
||||
}
|
||||
|
||||
@@ -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<ConnectionEndpo
|
||||
private final String host;
|
||||
|
||||
/**
|
||||
* Converts the InetSocketAddress into a ConnectionEndpoint.
|
||||
* Factory method used to construct a new {@link ConnectionEndpoint} with the given {@link Integer port}
|
||||
* listening on the default host.
|
||||
*
|
||||
* @param socketAddress the InetSocketAddress used to construct and initialize the ConnectionEndpoint.
|
||||
* @return a ConnectionEndpoint representing the InetSocketAddress.
|
||||
* @param port {@link Integer port} of the {@link ConnectionEndpoint}.
|
||||
* @return a new {@link ConnectionEndpoint} with the given {@link Integer port} listening on the default host.
|
||||
* @see #from(String, int)
|
||||
*/
|
||||
public static @NonNull ConnectionEndpoint from(int port) {
|
||||
return from(DEFAULT_HOST, port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method used to construct a new {@link ConnectionEndpoint} for the given {@link String host}
|
||||
* and {@link Integer port}.
|
||||
*
|
||||
* @param host {@link String host} of the {@link ConnectionEndpoint}.
|
||||
* @param port {@link Integer port} of the {@link ConnectionEndpoint}.
|
||||
* @return a new {@link ConnectionEndpoint} with the given {@link String host} and {@link Integer port}.
|
||||
*/
|
||||
public static @NonNull ConnectionEndpoint from(String host, int port) {
|
||||
return new ConnectionEndpoint(host, port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method used to convert the given {@link InetSocketAddress} into a {@link ConnectionEndpoint}.
|
||||
*
|
||||
* @param socketAddress {@link InetSocketAddress} used to construct, configure and initialize
|
||||
* the {@link ConnectionEndpoint}.
|
||||
* @return a {@link ConnectionEndpoint} representing the {@link InetSocketAddress}.
|
||||
* @see java.net.InetSocketAddress
|
||||
*/
|
||||
public static ConnectionEndpoint from(InetSocketAddress socketAddress) {
|
||||
public static @NonNull ConnectionEndpoint from(@NonNull InetSocketAddress socketAddress) {
|
||||
return new ConnectionEndpoint(socketAddress.getHostString(), socketAddress.getPort());
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.support;
|
||||
|
||||
import java.util.Properties;
|
||||
@@ -40,14 +39,17 @@ import org.springframework.util.Assert;
|
||||
* a Spring {@link ApplicationContext}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see java.util.Properties
|
||||
* @see org.apache.geode.cache.CacheCallback
|
||||
* @see org.apache.geode.cache.Declarable
|
||||
* @see org.springframework.beans.factory.BeanFactory
|
||||
* @see org.springframework.beans.factory.DisposableBean
|
||||
* @see org.springframework.beans.factory.config.ConfigurableListableBeanFactory
|
||||
* @see org.springframework.context.ApplicationContext
|
||||
* @see org.springframework.context.ApplicationListener
|
||||
* @see org.springframework.context.event.ContextRefreshedEvent
|
||||
* @see org.springframework.data.gemfire.support.SpringContextBootstrappingInitializer
|
||||
* @see org.springframework.data.gemfire.support.WiringDeclarableSupport
|
||||
* @see org.apache.geode.cache.Declarable
|
||||
* @since 1.3.4
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@@ -91,8 +93,10 @@ public abstract class LazyWiringDeclarableSupport extends WiringDeclarableSuppor
|
||||
* @see #isInitialized()
|
||||
*/
|
||||
protected void assertInitialized() {
|
||||
Assert.state(isInitialized(), String.format(
|
||||
"This Declarable object [%s] has not been properly configured and initialized", getClass().getName()));
|
||||
|
||||
Assert.state(isInitialized(),
|
||||
String.format("This Declarable object [%s] has not been properly configured and initialized",
|
||||
getClass().getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,8 +112,10 @@ public abstract class LazyWiringDeclarableSupport extends WiringDeclarableSuppor
|
||||
* @see #isNotInitialized()
|
||||
*/
|
||||
protected void assertUninitialized() {
|
||||
Assert.state(isNotInitialized(), String.format(
|
||||
"This Declarable object [%s] has already been configured and initialized", getClass().getName()));
|
||||
|
||||
Assert.state(isNotInitialized(),
|
||||
String.format("This Declarable object [%s] has already been configured and initialized",
|
||||
getClass().getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,6 +156,7 @@ public abstract class LazyWiringDeclarableSupport extends WiringDeclarableSuppor
|
||||
*/
|
||||
@Override
|
||||
public final void init(Properties parameters) {
|
||||
|
||||
setParameters(parameters);
|
||||
|
||||
try {
|
||||
@@ -176,8 +183,9 @@ public abstract class LazyWiringDeclarableSupport extends WiringDeclarableSuppor
|
||||
* @see java.util.Properties
|
||||
*/
|
||||
synchronized void doInit(BeanFactory beanFactory, Properties parameters) {
|
||||
this.initialized = (isInitialized() || configureThis(beanFactory,
|
||||
parameters.getProperty(TEMPLATE_BEAN_NAME_PROPERTY)));
|
||||
|
||||
this.initialized = isInitialized()
|
||||
|| configureThis(beanFactory, parameters.getProperty(TEMPLATE_BEAN_NAME_PROPERTY));
|
||||
|
||||
doPostInit(parameters);
|
||||
}
|
||||
@@ -192,8 +200,7 @@ public abstract class LazyWiringDeclarableSupport extends WiringDeclarableSuppor
|
||||
* @see #doInit(BeanFactory, Properties)
|
||||
* @see java.util.Properties
|
||||
*/
|
||||
protected void doPostInit(Properties parameters) {
|
||||
}
|
||||
protected void doPostInit(Properties parameters) { }
|
||||
|
||||
/**
|
||||
* Null-safe operation to return the parameters passed to this {@link Declarable} object when created by GemFire
|
||||
@@ -204,8 +211,10 @@ public abstract class LazyWiringDeclarableSupport extends WiringDeclarableSuppor
|
||||
* @see java.util.Properties
|
||||
*/
|
||||
protected Properties nullSafeGetParameters() {
|
||||
Properties parameters = parametersReference.get();
|
||||
return (parameters != null ? parameters : new Properties());
|
||||
|
||||
Properties parameters = this.parametersReference.get();
|
||||
|
||||
return parameters != null ? parameters : new Properties();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,7 +225,7 @@ public abstract class LazyWiringDeclarableSupport extends WiringDeclarableSuppor
|
||||
* @see java.util.Properties
|
||||
*/
|
||||
protected void setParameters(Properties parameters) {
|
||||
parametersReference.set(parameters);
|
||||
this.parametersReference.set(parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -232,10 +241,11 @@ public abstract class LazyWiringDeclarableSupport extends WiringDeclarableSuppor
|
||||
@Override
|
||||
@SuppressWarnings("all")
|
||||
public final void onApplicationEvent(ContextRefreshedEvent event) {
|
||||
|
||||
ApplicationContext applicationContext = event.getApplicationContext();
|
||||
|
||||
Assert.isTrue(applicationContext instanceof ConfigurableApplicationContext, String.format(
|
||||
"The Spring ApplicationContext [%s] must be an instance of ConfigurableApplicationContext",
|
||||
Assert.isTrue(applicationContext instanceof ConfigurableApplicationContext,
|
||||
String.format("The Spring ApplicationContext [%s] must be an instance of ConfigurableApplicationContext",
|
||||
applicationContext));
|
||||
|
||||
ConfigurableListableBeanFactory beanFactory =
|
||||
@@ -255,6 +265,7 @@ public abstract class LazyWiringDeclarableSupport extends WiringDeclarableSuppor
|
||||
*/
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
|
||||
SpringContextBootstrappingInitializer.unregister(this);
|
||||
setParameters(null);
|
||||
this.initialized = false;
|
||||
|
||||
@@ -54,6 +54,9 @@ import org.slf4j.LoggerFactory;
|
||||
* is not invoked until after GemFire creates and initializes the GemFire {@link Cache} for use.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see java.util.Properties
|
||||
* @see org.apache.geode.cache.Cache
|
||||
* @see org.apache.geode.cache.Declarable
|
||||
* @see org.springframework.context.ApplicationContext
|
||||
* @see org.springframework.context.ApplicationListener
|
||||
* @see org.springframework.context.ConfigurableApplicationContext
|
||||
@@ -62,14 +65,12 @@ import org.slf4j.LoggerFactory;
|
||||
* @see org.springframework.context.event.ApplicationEventMulticaster
|
||||
* @see org.springframework.context.support.ClassPathXmlApplicationContext
|
||||
* @see org.springframework.core.io.DefaultResourceLoader
|
||||
* @see org.apache.geode.cache.Cache
|
||||
* @see org.apache.geode.cache.Declarable
|
||||
* @link https://gemfire.docs.pivotal.io/latest/userguide/index.html#basic_config/the_cache/setting_cache_initializer.html
|
||||
* @link https://jira.springsource.org/browse/SGF-248
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class SpringContextBootstrappingInitializer implements Declarable, ApplicationListener<ApplicationContextEvent> {
|
||||
public class SpringContextBootstrappingInitializer implements ApplicationListener<ApplicationContextEvent>, 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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<String> 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<String> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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<String, Cat> 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<String, Dog> 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";
|
||||
|
||||
@@ -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 <a href="https://jira.spring.io/browse/SGF-432">IndexFactoryBean traps IndexExistsException instead of IndexNameConflictException</a>
|
||||
* @see <a href="https://jira.spring.io/browse/SGF-637">Improve IndexFactoryBean's resilience and options for handling GemFire IndexExistsExceptions and IndexNameConflictExceptions</a>
|
||||
* @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) {
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Long, Person> peopleRegion;
|
||||
@Autowired
|
||||
private EmployeeService employeeService;
|
||||
|
||||
protected void assertNoPeopleInDepartment(Department department) {
|
||||
@Resource(name = "Employees")
|
||||
private org.apache.geode.cache.Region<Long, Employee> employeesRegion;
|
||||
|
||||
private void assertNoEmployeeInDepartment(Department department) {
|
||||
assertPeopleInDepartment(department);
|
||||
}
|
||||
|
||||
protected void assertPeopleInDepartment(Department department, Person... people) {
|
||||
List<Person> peopleInDepartment = peopleService.findByDepartment(department);
|
||||
private void assertPeopleInDepartment(Department department, Employee... people) {
|
||||
|
||||
List<Employee> 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<EmployeeRepository, Employee, Long> personRepository() {
|
||||
|
||||
GemfireCacheManager cacheManager = new GemfireCacheManager();
|
||||
|
||||
cacheManager.setCache(gemfireCache);
|
||||
|
||||
return cacheManager;
|
||||
}
|
||||
|
||||
@Bean
|
||||
GemfireRepositoryFactoryBean<PersonRepository, Person, Long> personRepository() {
|
||||
|
||||
GemfireRepositoryFactoryBean<PersonRepository, Person, Long> personRepository =
|
||||
new GemfireRepositoryFactoryBean<>(PersonRepository.class);
|
||||
GemfireRepositoryFactoryBean<EmployeeRepository, Employee, Long> 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<Long, Person> peopleRegion(GemFireCache gemfireCache) {
|
||||
|
||||
LocalRegionFactoryBean<Long, Person> peopleRegion = new LocalRegionFactoryBean<>();
|
||||
|
||||
peopleRegion.setCache(gemfireCache);
|
||||
peopleRegion.setPersistent(false);
|
||||
|
||||
return peopleRegion;
|
||||
}
|
||||
|
||||
@Bean(name = "DepartmentPeople")
|
||||
LocalRegionFactoryBean<Long, Person> departmentPeopleRegion(GemFireCache gemfireCache) {
|
||||
|
||||
LocalRegionFactoryBean<Long, Person> departmentPeopleRegion = new LocalRegionFactoryBean<>();
|
||||
|
||||
departmentPeopleRegion.setCache(gemfireCache);
|
||||
departmentPeopleRegion.setPersistent(false);
|
||||
|
||||
return departmentPeopleRegion;
|
||||
}
|
||||
|
||||
@Bean(name = "MobilePeople")
|
||||
LocalRegionFactoryBean<Long, Person> mobilePeopleRegion(GemFireCache gemfireCache) {
|
||||
|
||||
LocalRegionFactoryBean<Long, Person> 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<Person> findByDepartment(Department department) {
|
||||
@Cacheable("DepartmentEmployees")
|
||||
public List<Employee> 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<Person, Long> {
|
||||
public interface EmployeeRepository extends CrudRepository<Employee, Long> {
|
||||
|
||||
List<Person> findByDepartment(Department department);
|
||||
List<Employee> findByDepartment(Department department);
|
||||
|
||||
Person findByMobile(String mobile);
|
||||
Employee findByMobile(String mobile);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String> 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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<String> arguments = new ArrayList<String>();
|
||||
|
||||
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")
|
||||
|
||||
@@ -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<String, Integer> 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<String, Integer> helper) throws CacheLoaderException {
|
||||
public Integer load(LoaderHelper<String, Integer> helper) throws CacheLoaderException {
|
||||
return cacheMissCounter.incrementAndGet();
|
||||
}
|
||||
|
||||
@@ -147,10 +147,10 @@ public class ClientCacheVariableServersIntegrationTests extends ForkingClientSer
|
||||
Map<String, CacheServer> 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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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<ConfigurableApplicationContext, ConfigurableApplicationContext> 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");
|
||||
}
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<ConfigurableApplicationContext, ConfigurableApplicationContext> 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,
|
||||
|
||||
@@ -58,7 +58,7 @@ public class CachingDefinedRegionsConsidersCacheConfigCacheNamesIntegrationTests
|
||||
extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
public void cleanupAfterTests() {
|
||||
destroyAllGemFireMockObjects();
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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<ConfigurableApplicationContext, ConfigurableApplicationContext> 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();
|
||||
|
||||
@@ -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<ConfigurableApplicationContext, ConfigurableApplicationContext> 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,
|
||||
|
||||
@@ -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 <T extends CacheFactoryBean> void testGemFireCacheBeanFactoryLocator(Class<?> configuration,
|
||||
Class<T> 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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<ConfigurableApplicationContext, ConfigurableApplicationContext> 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<Long, Person> people = this.applicationContext.getBean("People", Region.class);
|
||||
Region<Long, Person> people = getBean("People", Region.class);
|
||||
|
||||
assertThat(people).isNotNull();
|
||||
assertThat(people.getName()).isEqualTo("People");
|
||||
|
||||
@@ -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<String, ClientRegionEntity> sessions = this.applicationContext.getBean("Sessions", Region.class);
|
||||
Region<String, ClientRegionEntity> sessions = getBean("Sessions", Region.class);
|
||||
|
||||
assertRegion(sessions, "Sessions", String.class, ClientRegionEntity.class);
|
||||
assertRegionAttributes(sessions.getAttributes(), DataPolicy.NORMAL,
|
||||
null, true, false, null, null);
|
||||
|
||||
Region<Long, GenericRegionEntity> genericRegionEntity =
|
||||
this.applicationContext.getBean("GenericRegionEntity", Region.class);
|
||||
Region<Long, GenericRegionEntity> 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<Object, Object> sessions = this.applicationContext.getBean("Sessions", Region.class);
|
||||
Region<Object, Object> sessions = getBean("Sessions", Region.class);
|
||||
|
||||
assertRegionWithAttributes(sessions, "Sessions", DataPolicy.NORMAL,
|
||||
null, true, false, null, null);
|
||||
|
||||
Region<Object, Object> genericRegionEntity =
|
||||
this.applicationContext.getBean("GenericRegionEntity", Region.class);
|
||||
Region<Object, Object> genericRegionEntity = getBean("GenericRegionEntity", Region.class);
|
||||
|
||||
assertRegionWithAttributes(genericRegionEntity, "GenericRegionEntity", DataPolicy.NORMAL,
|
||||
null, true, false, "TestPool", null);
|
||||
@@ -249,38 +229,33 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport
|
||||
@Test
|
||||
public void entityClientRegionsDefinedWithServerRegionMappingAnnotations() {
|
||||
|
||||
this.applicationContext =
|
||||
newApplicationContext(ClientPersistentEntitiesWithServerRegionMappingAnnotationsConfiguration.class);
|
||||
newApplicationContext(ClientPersistentEntitiesWithServerRegionMappingAnnotationsConfiguration.class);
|
||||
|
||||
Region<String, ClientRegionEntity> sessions = this.applicationContext.getBean("Sessions", Region.class);
|
||||
Region<String, ClientRegionEntity> sessions = getBean("Sessions", Region.class);
|
||||
|
||||
assertRegion(sessions, "Sessions", String.class, ClientRegionEntity.class);
|
||||
assertRegionAttributes(sessions.getAttributes(), DataPolicy.NORMAL,
|
||||
null, true, false, null, null);
|
||||
|
||||
Region<Long, GenericRegionEntity> genericRegionEntity =
|
||||
this.applicationContext.getBean("GenericRegionEntity", Region.class);
|
||||
Region<Long, GenericRegionEntity> genericRegionEntity = getBean("GenericRegionEntity", Region.class);
|
||||
|
||||
assertRegion(genericRegionEntity, "GenericRegionEntity", Long.class, GenericRegionEntity.class);
|
||||
assertRegionAttributes(genericRegionEntity.getAttributes(), DataPolicy.EMPTY,
|
||||
null, true, false, null, null);
|
||||
|
||||
Region<String, LocalRegionEntity> localRegionEntity =
|
||||
this.applicationContext.getBean("LocalRegionEntity", Region.class);
|
||||
Region<String, LocalRegionEntity> localRegionEntity = getBean("LocalRegionEntity", Region.class);
|
||||
|
||||
assertRegion(localRegionEntity, "LocalRegionEntity", String.class, LocalRegionEntity.class);
|
||||
assertRegionAttributes(localRegionEntity.getAttributes(), DataPolicy.EMPTY,
|
||||
null, true, false, null, null);
|
||||
|
||||
Region<Long, PartitionRegionEntity> customers =
|
||||
this.applicationContext.getBean("Customers", Region.class);
|
||||
Region<Long, PartitionRegionEntity> customers = getBean("Customers", Region.class);
|
||||
|
||||
assertRegion(customers, "Customers", Long.class, PartitionRegionEntity.class);
|
||||
assertRegionAttributes(customers.getAttributes(), DataPolicy.EMPTY,
|
||||
null, true, false, null, null);
|
||||
|
||||
Region<Object, ReplicateRegionEntity> accounts =
|
||||
this.applicationContext.getBean("Accounts", Region.class);
|
||||
Region<Object, ReplicateRegionEntity> accounts = getBean("Accounts", Region.class);
|
||||
|
||||
assertRegion(accounts, "Accounts", Object.class, ReplicateRegionEntity.class);
|
||||
assertRegionAttributes(accounts.getAttributes(), DataPolicy.EMPTY,
|
||||
@@ -293,9 +268,9 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport
|
||||
@Test
|
||||
public void entityPeerPartitionRegionsDefined() {
|
||||
|
||||
this.applicationContext = newApplicationContext(PeerPartitionRegionPersistentEntitiesConfiguration.class);
|
||||
newApplicationContext(PeerPartitionRegionPersistentEntitiesConfiguration.class);
|
||||
|
||||
Region<Object, Object> customers = this.applicationContext.getBean("Customers", Region.class);
|
||||
Region<Object, Object> customers = getBean("Customers", Region.class);
|
||||
|
||||
assertRegionWithAttributes(customers, "Customers", DataPolicy.PERSISTENT_PARTITION, null,
|
||||
true, false, null, Scope.DISTRIBUTED_NO_ACK);
|
||||
@@ -306,12 +281,12 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport
|
||||
assertFixedPartitionAttributes(findFixedPartitionAttributes(customers.getAttributes().getPartitionAttributes(),
|
||||
"two"), "two", false, 21);
|
||||
|
||||
Region<Object, Object> contactEvents = this.applicationContext.getBean("ContactEvents", Region.class);
|
||||
Region<Object, Object> contactEvents = getBean("ContactEvents", Region.class);
|
||||
|
||||
assertRegionWithAttributes(contactEvents, "ContactEvents", DataPolicy.PERSISTENT_PARTITION,
|
||||
"mockDiskStore", false, true, null, Scope.DISTRIBUTED_NO_ACK);
|
||||
assertPartitionAttributes(contactEvents.getAttributes().getPartitionAttributes(), "Customers",
|
||||
this.applicationContext.getBean("mockPartitionResolver", PartitionResolver.class), 2);
|
||||
getBean("mockPartitionResolver", PartitionResolver.class), 2);
|
||||
|
||||
assertUndefinedRegions("ClientRegionEntity", "Sessions", "CollocatedPartitionRegionEntity",
|
||||
"GenericRegionEntity", "LocalRegionEntity", "NonEntity", "PartitionRegionEntity", "ReplicateRegionEntity",
|
||||
@@ -322,7 +297,7 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport
|
||||
public void entityPartitionRegionAlreadyDefinedThrowsRegionExistsException() {
|
||||
|
||||
try {
|
||||
this.applicationContext = newApplicationContext(ExistingPartitionRegionPersistentEntitiesConfiguration.class);
|
||||
newApplicationContext(ExistingPartitionRegionPersistentEntitiesConfiguration.class);
|
||||
}
|
||||
catch (BeanCreationException expected) {
|
||||
|
||||
@@ -336,9 +311,9 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport
|
||||
@Test
|
||||
public void entityReplicateRegionAlreadyDefinedIgnoresEntityDefinedRegionDefinition() {
|
||||
|
||||
this.applicationContext = newApplicationContext(ExistingReplicateRegionPersistentEntitiesConfiguration.class);
|
||||
newApplicationContext(ExistingReplicateRegionPersistentEntitiesConfiguration.class);
|
||||
|
||||
Region<Object, Object> accounts = this.applicationContext.getBean("Accounts", Region.class);
|
||||
Region<Object, Object> accounts = getBean("Accounts", Region.class);
|
||||
|
||||
assertRegionWithAttributes(accounts, "Accounts", DataPolicy.REPLICATE,
|
||||
null, true, false, null, Scope.DISTRIBUTED_NO_ACK);
|
||||
@@ -347,27 +322,26 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport
|
||||
@Test
|
||||
public void entityServerRegionsDefined() {
|
||||
|
||||
this.applicationContext = newApplicationContext(ServerPersistentEntitiesConfiguration.class);
|
||||
newApplicationContext(ServerPersistentEntitiesConfiguration.class);
|
||||
|
||||
Region<Object, Object> accounts = this.applicationContext.getBean("Accounts", Region.class);
|
||||
Region<Object, Object> accounts = getBean("Accounts", Region.class);
|
||||
|
||||
assertRegionWithAttributes(accounts, "Accounts", DataPolicy.REPLICATE,
|
||||
null, true, false, null, Scope.DISTRIBUTED_ACK);
|
||||
|
||||
Region<Object, Object> customers = this.applicationContext.getBean("Customers", Region.class);
|
||||
Region<Object, Object> customers = getBean("Customers", Region.class);
|
||||
|
||||
assertRegionWithAttributes(customers, "Customers", DataPolicy.PERSISTENT_PARTITION,
|
||||
null, true, false, null, Scope.DISTRIBUTED_NO_ACK);
|
||||
assertPartitionAttributes(customers.getAttributes().getPartitionAttributes(), null,
|
||||
null, 1);
|
||||
|
||||
Region<Object, Object> localRegionEntity = this.applicationContext.getBean("LocalRegionEntity", Region.class);
|
||||
Region<Object, Object> localRegionEntity = getBean("LocalRegionEntity", Region.class);
|
||||
|
||||
assertRegionWithAttributes(localRegionEntity, "LocalRegionEntity", DataPolicy.NORMAL,
|
||||
null, true, false, null, Scope.LOCAL);
|
||||
|
||||
Region<Object, Object> genericRegionEntity =
|
||||
this.applicationContext.getBean("GenericRegionEntity", Region.class);
|
||||
Region<Object, Object> genericRegionEntity = getBean("GenericRegionEntity", Region.class);
|
||||
|
||||
assertRegionWithAttributes(genericRegionEntity, "GenericRegionEntity", DataPolicy.PARTITION,
|
||||
null, true, false, null, Scope.DISTRIBUTED_NO_ACK);
|
||||
@@ -379,26 +353,24 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport
|
||||
@Test
|
||||
public void entityServerRegionsDefinedWithCustomConfiguration() {
|
||||
|
||||
this.applicationContext = newApplicationContext(ServerPersistentEntitiesWithCustomConfiguration.class);
|
||||
newApplicationContext(ServerPersistentEntitiesWithCustomConfiguration.class);
|
||||
|
||||
Region<Object, Object> accounts = this.applicationContext.getBean("Sessions", Region.class);
|
||||
Region<Object, Object> accounts = getBean("Sessions", Region.class);
|
||||
|
||||
assertRegionWithAttributes(accounts, "Sessions", DataPolicy.REPLICATE,
|
||||
null, true, false, null, Scope.DISTRIBUTED_ACK);
|
||||
|
||||
Region<Object, Object> genericRegionEntity =
|
||||
this.applicationContext.getBean("GenericRegionEntity", Region.class);
|
||||
Region<Object, Object> genericRegionEntity = getBean("GenericRegionEntity", Region.class);
|
||||
|
||||
assertRegionWithAttributes(genericRegionEntity, "GenericRegionEntity", DataPolicy.REPLICATE,
|
||||
null, true, false, null, Scope.DISTRIBUTED_ACK);
|
||||
|
||||
Region<Object, Object> localRegionEntity =
|
||||
this.applicationContext.getBean("LocalRegionEntity", Region.class);
|
||||
Region<Object, Object> localRegionEntity = getBean("LocalRegionEntity", Region.class);
|
||||
|
||||
assertRegionWithAttributes(localRegionEntity, "LocalRegionEntity", DataPolicy.NORMAL,
|
||||
null, true, false, null, Scope.LOCAL);
|
||||
|
||||
Region<Object, Object> customers = this.applicationContext.getBean("Customers", Region.class);
|
||||
Region<Object, Object> customers = getBean("Customers", Region.class);
|
||||
|
||||
assertRegionWithAttributes(customers, "Customers", DataPolicy.PERSISTENT_PARTITION,
|
||||
null, true, false, null, Scope.DISTRIBUTED_NO_ACK);
|
||||
@@ -410,22 +382,19 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport
|
||||
@Test
|
||||
public void entityServerRegionsDefinedWithClientRegionMappingAnnotations() {
|
||||
|
||||
this.applicationContext =
|
||||
newApplicationContext(ServerPersistentEntitiesWithClientRegionMappingAnnotationsConfiguration.class);
|
||||
newApplicationContext(ServerPersistentEntitiesWithClientRegionMappingAnnotationsConfiguration.class);
|
||||
|
||||
Region<Object, Object> sessions = this.applicationContext.getBean("Sessions", Region.class);
|
||||
Region<Object, Object> sessions = getBean("Sessions", Region.class);
|
||||
|
||||
assertRegionWithAttributes(sessions, "Sessions", DataPolicy.PARTITION,
|
||||
null, true, false, null, Scope.DISTRIBUTED_NO_ACK);
|
||||
|
||||
Region<Object, Object> genericRegionEntity =
|
||||
this.applicationContext.getBean("GenericRegionEntity", Region.class);
|
||||
Region<Object, Object> genericRegionEntity = getBean("GenericRegionEntity", Region.class);
|
||||
|
||||
assertRegionWithAttributes(genericRegionEntity, "GenericRegionEntity", DataPolicy.PARTITION,
|
||||
null, true, false, null, Scope.DISTRIBUTED_NO_ACK);
|
||||
|
||||
Region<Object, Object> customers =
|
||||
this.applicationContext.getBean("Customers", Region.class);
|
||||
Region<Object, Object> customers = getBean("Customers", Region.class);
|
||||
|
||||
assertRegionWithAttributes(customers, "Customers", DataPolicy.PERSISTENT_PARTITION,
|
||||
null, true, false, null, Scope.DISTRIBUTED_NO_ACK);
|
||||
|
||||
@@ -52,7 +52,7 @@ public class EnableEvictionConfigurationIntegrationTests extends SpringApplicati
|
||||
private static final String GEMFIRE_LOG_LEVEL = "error";
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
public void cleanupAfterTests() {
|
||||
destroyAllGemFireMockObjects();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,15 +28,13 @@ import org.apache.geode.cache.EvictionAttributes;
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.util.ObjectSizer;
|
||||
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.ReplicatedRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.eviction.EvictionActionType;
|
||||
import org.springframework.data.gemfire.eviction.EvictionAttributesFactoryBean;
|
||||
import org.springframework.data.gemfire.eviction.EvictionPolicyType;
|
||||
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.util.ArrayUtils;
|
||||
|
||||
@@ -55,13 +53,10 @@ import org.springframework.data.gemfire.util.ArrayUtils;
|
||||
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
|
||||
* @since 1.9.0
|
||||
*/
|
||||
public class EnableEvictionConfigurationUnitTests extends IntegrationTestsSupport {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
public class EnableEvictionConfigurationUnitTests extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
closeApplicationContext(this.applicationContext);
|
||||
public void cleanupAfterTests() {
|
||||
destroyAllGemFireMockObjects();
|
||||
}
|
||||
|
||||
@@ -88,11 +83,7 @@ public class EnableEvictionConfigurationUnitTests extends IntegrationTestsSuppor
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <K, V> Region<K, V> getRegion(String beanName) {
|
||||
return applicationContext.getBean(beanName, Region.class);
|
||||
}
|
||||
|
||||
private AnnotationConfigApplicationContext newApplicationContext(Class<?>... annotatedClasses) {
|
||||
return new AnnotationConfigApplicationContext(annotatedClasses);
|
||||
return getBean(beanName, Region.class);
|
||||
}
|
||||
|
||||
private EvictionAttributes newEvictionAttributes(Integer maximum, EvictionPolicyType type, EvictionActionType action,
|
||||
@@ -112,35 +103,35 @@ public class EnableEvictionConfigurationUnitTests extends IntegrationTestsSuppor
|
||||
@Test
|
||||
public void usesDefaultEvictionPolicyConfiguration() {
|
||||
|
||||
applicationContext = newApplicationContext(DefaultEvictionPolicyConfiguration.class);
|
||||
newApplicationContext(DefaultEvictionPolicyConfiguration.class);
|
||||
|
||||
EvictionAttributes defaultEvictionAttributes = EvictionAttributes.createLRUEntryAttributes();
|
||||
|
||||
assertEvictionAttributes(applicationContext.getBean("PartitionRegion", Region.class), defaultEvictionAttributes);
|
||||
assertEvictionAttributes(applicationContext.getBean("ReplicateRegion", Region.class), defaultEvictionAttributes);
|
||||
assertEvictionAttributes(getBean("PartitionRegion", Region.class), defaultEvictionAttributes);
|
||||
assertEvictionAttributes(getBean("ReplicateRegion", Region.class), defaultEvictionAttributes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesCustomEvictionPolicyConfiguration() {
|
||||
|
||||
applicationContext = newApplicationContext(CustomEvictionPolicyConfiguration.class);
|
||||
newApplicationContext(CustomEvictionPolicyConfiguration.class);
|
||||
|
||||
ObjectSizer mockObjectSizer = applicationContext.getBean("mockObjectSizer", ObjectSizer.class);
|
||||
ObjectSizer mockObjectSizer = getBean("mockObjectSizer", ObjectSizer.class);
|
||||
|
||||
EvictionAttributes customEvictionAttributes =
|
||||
newEvictionAttributes(65536, EvictionPolicyType.MEMORY_SIZE, EvictionActionType.OVERFLOW_TO_DISK,
|
||||
mockObjectSizer);
|
||||
|
||||
assertEvictionAttributes(applicationContext.getBean("PartitionRegion", Region.class), customEvictionAttributes);
|
||||
assertEvictionAttributes(applicationContext.getBean("ReplicateRegion", Region.class), customEvictionAttributes);
|
||||
assertEvictionAttributes(getBean("PartitionRegion", Region.class), customEvictionAttributes);
|
||||
assertEvictionAttributes(getBean("ReplicateRegion", Region.class), customEvictionAttributes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesRegionSpecificEvictionPolicyConfiguration() {
|
||||
|
||||
applicationContext = newApplicationContext(RegionSpecificEvictionPolicyConfiguration.class);
|
||||
newApplicationContext(RegionSpecificEvictionPolicyConfiguration.class);
|
||||
|
||||
ObjectSizer mockObjectSizer = applicationContext.getBean("mockObjectSizer", ObjectSizer.class);
|
||||
ObjectSizer mockObjectSizer = getBean("mockObjectSizer", ObjectSizer.class);
|
||||
|
||||
EvictionAttributes partitionRegionEvictionAttributes =
|
||||
newEvictionAttributes(null, EvictionPolicyType.HEAP_PERCENTAGE, EvictionActionType.OVERFLOW_TO_DISK,
|
||||
@@ -149,26 +140,22 @@ public class EnableEvictionConfigurationUnitTests extends IntegrationTestsSuppor
|
||||
EvictionAttributes replicateRegionEvictionAttributes = newEvictionAttributes(10000,
|
||||
EvictionPolicyType.ENTRY_COUNT, EvictionActionType.LOCAL_DESTROY);
|
||||
|
||||
assertEvictionAttributes(applicationContext.getBean("PartitionRegion", Region.class),
|
||||
partitionRegionEvictionAttributes);
|
||||
assertEvictionAttributes(getBean("PartitionRegion", Region.class), partitionRegionEvictionAttributes);
|
||||
|
||||
assertEvictionAttributes(applicationContext.getBean("ReplicateRegion", Region.class),
|
||||
replicateRegionEvictionAttributes);
|
||||
assertEvictionAttributes(getBean("ReplicateRegion", Region.class), replicateRegionEvictionAttributes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesLastMatchingEvictionPolicyConfiguration() {
|
||||
|
||||
applicationContext = newApplicationContext(LastMatchingWinsEvictionPolicyConfiguration.class);
|
||||
newApplicationContext(LastMatchingWinsEvictionPolicyConfiguration.class);
|
||||
|
||||
EvictionAttributes lastMatchingEvictionAttributes =
|
||||
newEvictionAttributes(99, EvictionPolicyType.ENTRY_COUNT, EvictionActionType.OVERFLOW_TO_DISK);
|
||||
|
||||
assertEvictionAttributes(applicationContext.getBean("PartitionRegion", Region.class),
|
||||
lastMatchingEvictionAttributes);
|
||||
assertEvictionAttributes(getBean("PartitionRegion", Region.class), lastMatchingEvictionAttributes);
|
||||
|
||||
assertEvictionAttributes(applicationContext.getBean("ReplicateRegion", Region.class),
|
||||
lastMatchingEvictionAttributes);
|
||||
assertEvictionAttributes(getBean("ReplicateRegion", Region.class), lastMatchingEvictionAttributes);
|
||||
}
|
||||
|
||||
@PeerCacheApplication
|
||||
|
||||
@@ -17,9 +17,6 @@ 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.apache.geode.cache.DataPolicy;
|
||||
@@ -29,11 +26,10 @@ import org.apache.geode.cache.client.ClientRegionShortcut;
|
||||
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.gemfire.expiration.AnnotationBasedExpiration;
|
||||
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.stereotype.Service;
|
||||
|
||||
@@ -48,35 +44,12 @@ import org.springframework.stereotype.Service;
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableExpiration
|
||||
* @see org.springframework.data.gemfire.config.annotation.ExpirationConfiguration
|
||||
* @see org.springframework.data.gemfire.expiration.AnnotationBasedExpiration
|
||||
* @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 EnableExpirationConfigurationIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
private static final String GEMFIRE_LOG_LEVEL = "error";
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
|
||||
Optional.ofNullable(this.applicationContext)
|
||||
.ifPresent(ConfigurableApplicationContext::close);
|
||||
|
||||
destroyAllGemFireMockObjects();
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(Class<?>... annotatedClasses) {
|
||||
this.applicationContext = new AnnotationConfigApplicationContext(annotatedClasses);
|
||||
return this.applicationContext;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <K, V> Region<K, V> getRegion(ConfigurableApplicationContext applicationContext, String beanName) {
|
||||
return applicationContext.getBean(beanName, Region.class);
|
||||
}
|
||||
public class EnableExpirationConfigurationIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
private void assertRegionExpirationConfiguration(ConfigurableApplicationContext applicationContext,
|
||||
String regionBeanName) {
|
||||
@@ -94,6 +67,11 @@ public class EnableExpirationConfigurationIntegrationTests extends IntegrationTe
|
||||
.isInstanceOf(AnnotationBasedExpiration.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <K, V> Region<K, V> getRegion(ConfigurableApplicationContext applicationContext, String beanName) {
|
||||
return applicationContext.getBean(beanName, Region.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertApplicationCachingDefinedRegionsExpirationPoliciesAreCorrect() {
|
||||
|
||||
@@ -116,7 +94,7 @@ public class EnableExpirationConfigurationIntegrationTests extends IntegrationTe
|
||||
"People");
|
||||
}
|
||||
|
||||
@ClientCacheApplication(name = "EnableExpirationConfigurationIntegrationTests", logLevel = GEMFIRE_LOG_LEVEL)
|
||||
@ClientCacheApplication(name = "EnableExpirationConfigurationIntegrationTests")
|
||||
@EnableCachingDefinedRegions(clientRegionShortcut = ClientRegionShortcut.LOCAL)
|
||||
@EnableExpiration
|
||||
@EnableGemFireMockObjects
|
||||
@@ -142,13 +120,13 @@ public class EnableExpirationConfigurationIntegrationTests extends IntegrationTe
|
||||
}
|
||||
}
|
||||
|
||||
@ClientCacheApplication(name = "EnableExpirationConfigurationIntegrationTests", logLevel = GEMFIRE_LOG_LEVEL)
|
||||
@ClientCacheApplication(name = "EnableExpirationConfigurationIntegrationTests")
|
||||
@EnableEntityDefinedRegions(basePackageClasses = Person.class, clientRegionShortcut = ClientRegionShortcut.LOCAL)
|
||||
@EnableExpiration
|
||||
@EnableGemFireMockObjects
|
||||
static class ClientCacheRegionExpirationConfiguration { }
|
||||
|
||||
@PeerCacheApplication(name = "EnableExpirationConfigurationIntegrationTests", logLevel = GEMFIRE_LOG_LEVEL)
|
||||
@PeerCacheApplication(name = "EnableExpirationConfigurationIntegrationTests")
|
||||
@EnableEntityDefinedRegions(basePackageClasses = Person.class, serverRegionShortcut = RegionShortcut.LOCAL)
|
||||
@EnableExpiration
|
||||
@EnableGemFireMockObjects
|
||||
|
||||
@@ -22,8 +22,6 @@ import static org.mockito.Mockito.when;
|
||||
import static org.springframework.data.gemfire.config.annotation.EnableExpiration.ExpirationPolicy;
|
||||
import static org.springframework.data.gemfire.config.annotation.EnableExpiration.ExpirationType;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -33,12 +31,10 @@ import org.apache.geode.cache.ExpirationAttributes;
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.Region;
|
||||
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.gemfire.LocalRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.expiration.ExpirationActionType;
|
||||
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.util.ArrayUtils;
|
||||
|
||||
@@ -56,20 +52,14 @@ import org.springframework.data.gemfire.util.ArrayUtils;
|
||||
* @see org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableExpiration
|
||||
* @see org.springframework.data.gemfire.config.annotation.ExpirationConfiguration
|
||||
* @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
|
||||
*/
|
||||
public class EnableExpirationConfigurationUnitTests extends IntegrationTestsSupport {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
public class EnableExpirationConfigurationUnitTests extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
|
||||
Optional.ofNullable(this.applicationContext)
|
||||
.ifPresent(ConfigurableApplicationContext::close);
|
||||
|
||||
public void cleanupAfterTests() {
|
||||
destroyAllGemFireMockObjects();
|
||||
}
|
||||
|
||||
@@ -122,11 +112,7 @@ public class EnableExpirationConfigurationUnitTests extends IntegrationTestsSupp
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <K, V> Region<K, V> getRegion(String beanName) {
|
||||
return this.applicationContext.getBean(beanName, Region.class);
|
||||
}
|
||||
|
||||
private AnnotationConfigApplicationContext newApplicationContext(Class<?>... annotatedClasses) {
|
||||
return new AnnotationConfigApplicationContext(annotatedClasses);
|
||||
return getBean(beanName, Region.class);
|
||||
}
|
||||
|
||||
private ExpirationAttributes newExpirationAttributes(int timeout, ExpirationActionType action) {
|
||||
@@ -141,7 +127,7 @@ public class EnableExpirationConfigurationUnitTests extends IntegrationTestsSupp
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void usesDefaultExpirationPolicyConfiguration() {
|
||||
|
||||
this.applicationContext = newApplicationContext(DefaultExpirationPolicyConfiguration.class);
|
||||
newApplicationContext(DefaultExpirationPolicyConfiguration.class);
|
||||
|
||||
ExpirationAttributes expectedExpiration = newExpirationAttributes(0, ExpirationActionType.INVALIDATE);
|
||||
|
||||
@@ -158,7 +144,7 @@ public class EnableExpirationConfigurationUnitTests extends IntegrationTestsSupp
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void usesCustomIdleTimeoutExpirationPolicyConfiguration() {
|
||||
|
||||
this.applicationContext = newApplicationContext(CustomIdleTimeoutExpirationPolicyConfiguration.class);
|
||||
newApplicationContext(CustomIdleTimeoutExpirationPolicyConfiguration.class);
|
||||
|
||||
ExpirationAttributes expectedExpiration = newExpirationAttributes(300, ExpirationActionType.LOCAL_DESTROY);
|
||||
|
||||
@@ -176,7 +162,7 @@ public class EnableExpirationConfigurationUnitTests extends IntegrationTestsSupp
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void usesCustomTimeToLiveExpirationPolicyConfiguration() {
|
||||
|
||||
this.applicationContext = newApplicationContext(CustomTimeToLiveTimeoutExpirationPolicyConfiguration.class);
|
||||
newApplicationContext(CustomTimeToLiveTimeoutExpirationPolicyConfiguration.class);
|
||||
|
||||
ExpirationAttributes expectedExpiration = newExpirationAttributes(900, ExpirationActionType.LOCAL_INVALIDATE);
|
||||
|
||||
@@ -194,7 +180,7 @@ public class EnableExpirationConfigurationUnitTests extends IntegrationTestsSupp
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void usesRegionSpecificExpirationPolicyConfiguration() {
|
||||
|
||||
this.applicationContext = newApplicationContext(RegionSpecificExpirationPolicyConfiguration.class);
|
||||
newApplicationContext(RegionSpecificExpirationPolicyConfiguration.class);
|
||||
|
||||
ExpirationAttributes expectedIdleTimeout = newExpirationAttributes(180, ExpirationActionType.INVALIDATE);
|
||||
ExpirationAttributes expectedTimeToLive = newExpirationAttributes(360, ExpirationActionType.DESTROY);
|
||||
@@ -213,7 +199,7 @@ public class EnableExpirationConfigurationUnitTests extends IntegrationTestsSupp
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void usesMixedExpirationPolicyConfiguration() {
|
||||
|
||||
this.applicationContext = newApplicationContext(MixedExpirationPolicyConfiguration.class);
|
||||
newApplicationContext(MixedExpirationPolicyConfiguration.class);
|
||||
|
||||
ExpirationAttributes expectedIdleTimeout = newExpirationAttributes(60, ExpirationActionType.LOCAL_INVALIDATE);
|
||||
ExpirationAttributes expectedTimeToLive = newExpirationAttributes(600, ExpirationActionType.DESTROY);
|
||||
|
||||
@@ -23,50 +23,86 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.geode.cache.wan.GatewayReceiver;
|
||||
import org.apache.geode.cache.wan.GatewayTransportFilter;
|
||||
|
||||
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.core.annotation.Order;
|
||||
import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport;
|
||||
import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean;
|
||||
|
||||
/**
|
||||
* Tests for {@link EnableGatewayReceiver}.
|
||||
*
|
||||
* @author Udo Kohlmeyer
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.apache.geode.cache.server.CacheServer
|
||||
* @see org.springframework.context.annotation.Configuration
|
||||
* @see org.apache.geode.cache.wan.GatewayReceiver
|
||||
* @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.annotation.GatewayReceiverConfiguration
|
||||
* @see org.springframework.data.gemfire.config.annotation.GatewayReceiverConfigurer
|
||||
* @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean
|
||||
* @see GatewayReceiverConfigurer
|
||||
* @see GatewayReceiverConfiguration
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public class EnableGatewayReceiverConfigurationTests {
|
||||
public class EnableGatewayReceiverConfigurationIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
@Test
|
||||
public void annotationConfiguredGatewayTransportFiltersOrdered() {
|
||||
|
||||
@After
|
||||
public void shutdown() {
|
||||
Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close);
|
||||
newApplicationContext(TestConfigurationFromAnnotation.class);
|
||||
|
||||
TestGatewayReceiverConfigurer gatewayReceiverConfigurer =
|
||||
(TestGatewayReceiverConfigurer) getBean(GatewayReceiverConfigurer.class);
|
||||
|
||||
GatewayReceiver gatewayReceiver = getBean("GatewayReceiver",GatewayReceiver.class);
|
||||
|
||||
assertThat(gatewayReceiver.getStartPort()).isEqualTo(12000);
|
||||
assertThat(gatewayReceiver.getEndPort()).isEqualTo(13000);
|
||||
assertThat(gatewayReceiver.getBindAddress()).isEqualTo("localhost");
|
||||
assertThat(gatewayReceiver.getHostnameForSenders()).isEqualTo("hostnameLocalhost");
|
||||
assertThat(gatewayReceiver.getMaximumTimeBetweenPings()).isEqualTo(5000);
|
||||
assertThat(gatewayReceiver.getSocketBufferSize()).isEqualTo(32768);
|
||||
assertThat(gatewayReceiver.isManualStart()).isEqualTo(false);
|
||||
assertThat(gatewayReceiver.getGatewayTransportFilters().size()).isEqualTo(2);
|
||||
assertThat(((EnableGatewayReceiverConfigurationIntegrationTests.TestGatewayTransportFilter)gatewayReceiver.getGatewayTransportFilters().get(0)).name).isEqualTo("transportBean1");
|
||||
assertThat(((EnableGatewayReceiverConfigurationIntegrationTests.TestGatewayTransportFilter)gatewayReceiver.getGatewayTransportFilters().get(1)).name).isEqualTo("transportBean2");
|
||||
assertThat(gatewayReceiverConfigurer.beanNames.toArray()).isEqualTo(new String[]{"transportBean1", "transportBean2"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beanConfiguredGatewayTransportFiltersOrdered() {
|
||||
|
||||
newApplicationContext(TestConfigurationWithOrder.class);
|
||||
|
||||
TestGatewayReceiverConfigurer gatewayReceiverConfigurer =
|
||||
(TestGatewayReceiverConfigurer) getBean(GatewayReceiverConfigurer.class);
|
||||
|
||||
GatewayReceiver gatewayReceiver = getBean("GatewayReceiver",GatewayReceiver.class);
|
||||
|
||||
assertThat(gatewayReceiver.getStartPort()).isEqualTo(10000);
|
||||
assertThat(gatewayReceiver.getEndPort()).isEqualTo(11000);
|
||||
assertThat(gatewayReceiver.getBindAddress()).isEqualTo("localhost");
|
||||
assertThat(gatewayReceiver.getHostnameForSenders()).isEqualTo("hostnameLocalhost");
|
||||
assertThat(gatewayReceiver.getMaximumTimeBetweenPings()).isEqualTo(1000);
|
||||
assertThat(gatewayReceiver.getSocketBufferSize()).isEqualTo(16384);
|
||||
assertThat(gatewayReceiver.isManualStart()).isEqualTo(false);
|
||||
assertThat(gatewayReceiver.getGatewayTransportFilters().size()).isEqualTo(2);
|
||||
assertThat(((EnableGatewayReceiverConfigurationIntegrationTests.TestGatewayTransportFilter)gatewayReceiver.getGatewayTransportFilters().get(0)).name).isEqualTo("transportBean1");
|
||||
assertThat(((EnableGatewayReceiverConfigurationIntegrationTests.TestGatewayTransportFilter)gatewayReceiver.getGatewayTransportFilters().get(1)).name).isEqualTo("transportBean2");
|
||||
assertThat(gatewayReceiverConfigurer.beanNames.toArray()).isEqualTo(new String[]{"transportBean1", "transportBean2"});
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@CacheServerApplication
|
||||
@EnableGatewayReceiver(manualStart = false, startPort = 10000, endPort = 11000, maximumTimeBetweenPings = 1000,
|
||||
socketBufferSize = 16384, bindAddress = "localhost",transportFilters = {"transportBean1", "transportBean2"},
|
||||
hostnameForSenders = "hostnameLocalhost")
|
||||
socketBufferSize = 16384, bindAddress = "localhost",transportFilters = {"transportBean1", "transportBean2"},
|
||||
hostnameForSenders = "hostnameLocalhost")
|
||||
@SuppressWarnings("unused")
|
||||
static class TestConfigurationWithOrder {
|
||||
|
||||
@Bean("transportBean1")
|
||||
@@ -87,11 +123,11 @@ public class EnableGatewayReceiverConfigurationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@CacheServerApplication
|
||||
@EnableGatewayReceiver(manualStart = false, startPort = 12000, endPort = 13000, maximumTimeBetweenPings = 5000,
|
||||
socketBufferSize = 32768, transportFilters = {"transportBean1", "transportBean2"}, bindAddress = "localhost",
|
||||
hostnameForSenders = "hostnameLocalhost")
|
||||
socketBufferSize = 32768, transportFilters = {"transportBean1", "transportBean2"}, bindAddress = "localhost",
|
||||
hostnameForSenders = "hostnameLocalhost")
|
||||
@SuppressWarnings("unused")
|
||||
static class TestConfigurationFromAnnotation {
|
||||
|
||||
@Bean("transportBean1")
|
||||
@@ -110,52 +146,6 @@ public class EnableGatewayReceiverConfigurationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void annotationConfiguredGatewayTransportFiltersOrdered() {
|
||||
|
||||
this.applicationContext = newApplicationContext(TestConfigurationFromAnnotation.class);
|
||||
|
||||
TestGatewayReceiverConfigurer gatewayReceiverConfigurer =
|
||||
(TestGatewayReceiverConfigurer) this.applicationContext.getBean(GatewayReceiverConfigurer.class);
|
||||
|
||||
GatewayReceiver gatewayReceiver = this.applicationContext.getBean("GatewayReceiver",GatewayReceiver.class);
|
||||
|
||||
assertThat(gatewayReceiver.getStartPort()).isEqualTo(12000);
|
||||
assertThat(gatewayReceiver.getEndPort()).isEqualTo(13000);
|
||||
assertThat(gatewayReceiver.getBindAddress()).isEqualTo("localhost");
|
||||
assertThat(gatewayReceiver.getHostnameForSenders()).isEqualTo("hostnameLocalhost");
|
||||
assertThat(gatewayReceiver.getMaximumTimeBetweenPings()).isEqualTo(5000);
|
||||
assertThat(gatewayReceiver.getSocketBufferSize()).isEqualTo(32768);
|
||||
assertThat(gatewayReceiver.isManualStart()).isEqualTo(false);
|
||||
assertThat(gatewayReceiver.getGatewayTransportFilters().size()).isEqualTo(2);
|
||||
assertThat(((EnableGatewayReceiverConfigurationTests.TestGatewayTransportFilter)gatewayReceiver.getGatewayTransportFilters().get(0)).name).isEqualTo("transportBean1");
|
||||
assertThat(((EnableGatewayReceiverConfigurationTests.TestGatewayTransportFilter)gatewayReceiver.getGatewayTransportFilters().get(1)).name).isEqualTo("transportBean2");
|
||||
assertThat(gatewayReceiverConfigurer.beanNames.toArray()).isEqualTo(new String[]{"transportBean1", "transportBean2"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beanConfiguredGatewayTransportFiltersOrdered() {
|
||||
|
||||
this.applicationContext = newApplicationContext(TestConfigurationWithOrder.class);
|
||||
|
||||
TestGatewayReceiverConfigurer gatewayReceiverConfigurer =
|
||||
(TestGatewayReceiverConfigurer) this.applicationContext.getBean(GatewayReceiverConfigurer.class);
|
||||
|
||||
GatewayReceiver gatewayReceiver = this.applicationContext.getBean("GatewayReceiver",GatewayReceiver.class);
|
||||
|
||||
assertThat(gatewayReceiver.getStartPort()).isEqualTo(10000);
|
||||
assertThat(gatewayReceiver.getEndPort()).isEqualTo(11000);
|
||||
assertThat(gatewayReceiver.getBindAddress()).isEqualTo("localhost");
|
||||
assertThat(gatewayReceiver.getHostnameForSenders()).isEqualTo("hostnameLocalhost");
|
||||
assertThat(gatewayReceiver.getMaximumTimeBetweenPings()).isEqualTo(1000);
|
||||
assertThat(gatewayReceiver.getSocketBufferSize()).isEqualTo(16384);
|
||||
assertThat(gatewayReceiver.isManualStart()).isEqualTo(false);
|
||||
assertThat(gatewayReceiver.getGatewayTransportFilters().size()).isEqualTo(2);
|
||||
assertThat(((EnableGatewayReceiverConfigurationTests.TestGatewayTransportFilter)gatewayReceiver.getGatewayTransportFilters().get(0)).name).isEqualTo("transportBean1");
|
||||
assertThat(((EnableGatewayReceiverConfigurationTests.TestGatewayTransportFilter)gatewayReceiver.getGatewayTransportFilters().get(1)).name).isEqualTo("transportBean2");
|
||||
assertThat(gatewayReceiverConfigurer.beanNames.toArray()).isEqualTo(new String[]{"transportBean1", "transportBean2"});
|
||||
}
|
||||
|
||||
private static class TestGatewayReceiverConfigurer implements GatewayReceiverConfigurer, Iterable<String> {
|
||||
|
||||
private final List<String> beanNames = new ArrayList<>();
|
||||
@@ -173,7 +163,7 @@ public class EnableGatewayReceiverConfigurationTests {
|
||||
|
||||
private static class TestGatewayTransportFilter implements GatewayTransportFilter {
|
||||
|
||||
private String name;
|
||||
private final String name;
|
||||
|
||||
public TestGatewayTransportFilter(String name) {
|
||||
this.name = name;
|
||||
@@ -189,13 +179,4 @@ public class EnableGatewayReceiverConfigurationTests {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(Class<?>... annotatedClasses) {
|
||||
|
||||
ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(annotatedClasses);
|
||||
|
||||
applicationContext.registerShutdownHook();
|
||||
|
||||
return applicationContext;
|
||||
}
|
||||
}
|
||||
@@ -20,20 +20,19 @@ 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.GemFireCache;
|
||||
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.CacheFactoryBean;
|
||||
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.util.ArrayUtils;
|
||||
import org.springframework.mock.env.MockPropertySource;
|
||||
@@ -52,41 +51,35 @@ import org.springframework.util.StringUtils;
|
||||
* @see org.springframework.context.ConfigurableApplicationContext
|
||||
* @see org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
* @see org.springframework.core.env.PropertySource
|
||||
* @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
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSupport {
|
||||
public class EnableGemFirePropertiesIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close);
|
||||
}
|
||||
|
||||
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) {
|
||||
Class<?>... annotatedClasses) {
|
||||
|
||||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
|
||||
Function<ConfigurableApplicationContext, ConfigurableApplicationContext> 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.registerShutdownHook();
|
||||
applicationContext.register(annotatedClasses);
|
||||
applicationContext.refresh();
|
||||
|
||||
return applicationContext;
|
||||
return newApplicationContext(applicationContextInitializer, annotatedClasses);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,13 +98,11 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup
|
||||
.withProperty("spring.data.gemfire.security.log.level", "info")
|
||||
.withProperty("spring.data.gemfire.security.properties-file", "/path/to/security.properties");
|
||||
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestAuthGemFirePropertiesConfiguration.class);
|
||||
newApplicationContext(testPropertySource, TestAuthGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
assertThat(containsBean("gemfireCache")).isTrue();
|
||||
|
||||
GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class);
|
||||
GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.getDistributedSystem()).isNotNull();
|
||||
@@ -141,13 +132,11 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup
|
||||
.withProperty("spring.data.gemfire.service.http.ssl-require-authentication", "true")
|
||||
.withProperty("spring.data.gemfire.service.http.dev-rest-api.start", "true");
|
||||
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestHttpGemFirePropertiesConfiguration.class);
|
||||
newApplicationContext(testPropertySource, TestHttpGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
assertThat(containsBean("gemfireCache")).isTrue();
|
||||
|
||||
GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class);
|
||||
GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.getDistributedSystem()).isNotNull();
|
||||
@@ -168,13 +157,11 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup
|
||||
.withProperty("spring.data.gemfire.locator.host", "10.64.32.16")
|
||||
.withProperty("spring.data.gemfire.locator.port", "11235");
|
||||
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestLocatorGemFirePropertiesConfiguration.class);
|
||||
newApplicationContext(testPropertySource, TestLocatorGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
assertThat(containsBean("gemfireCache")).isTrue();
|
||||
|
||||
GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class);
|
||||
GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.getDistributedSystem()).isNotNull();
|
||||
@@ -194,13 +181,11 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup
|
||||
.withProperty("spring.data.gemfire.logging.log-file-size-limit", "10")
|
||||
.withProperty("spring.data.gemfire.logging.level", "info");
|
||||
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestLoggingGemFirePropertiesConfiguration.class);
|
||||
newApplicationContext(testPropertySource, TestLoggingGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
assertThat(containsBean("gemfireCache")).isTrue();
|
||||
|
||||
GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class);
|
||||
GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.getDistributedSystem()).isNotNull();
|
||||
@@ -226,13 +211,11 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup
|
||||
.withProperty("spring.data.gemfire.manager.start", "true")
|
||||
.withProperty("spring.data.gemfire.manager.update-rate", "1000");
|
||||
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestManagerGemFirePropertiesConfiguration.class);
|
||||
newApplicationContext(testPropertySource, TestManagerGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
assertThat(containsBean("gemfireCache")).isTrue();
|
||||
|
||||
GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class);
|
||||
GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.getDistributedSystem()).isNotNull();
|
||||
@@ -257,13 +240,11 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup
|
||||
.withProperty("spring.data.gemfire.service.memcached.port", "2468")
|
||||
.withProperty("spring.data.gemfire.service.memcached.protocol", "BINARY");
|
||||
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestMemcachedServerGemFirePropertiesConfiguration.class);
|
||||
newApplicationContext(testPropertySource, TestMemcachedServerGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
assertThat(containsBean("gemfireCache")).isTrue();
|
||||
|
||||
GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class);
|
||||
GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.getDistributedSystem()).isNotNull();
|
||||
@@ -278,16 +259,14 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup
|
||||
@Test
|
||||
public void nameAndGroupsAnnotationBasedGemFirePropertiesConfiguration() {
|
||||
|
||||
this.applicationContext =
|
||||
newApplicationContext(TestNameAndGroupsAnnotationBasedGemFirePropertiesConfiguration.class);
|
||||
newApplicationContext(TestNameAndGroupsAnnotationBasedGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("gemfireProperties")).isTrue();
|
||||
assertThat(containsBean("gemfireCache")).isTrue();
|
||||
assertThat(containsBean("gemfireProperties")).isTrue();
|
||||
|
||||
//Properties gemfireProperties = this.applicationContext.getBean("gemfireProperties", Properties.class);
|
||||
|
||||
GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class);
|
||||
GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.getDistributedSystem()).isNotNull();
|
||||
@@ -307,13 +286,11 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup
|
||||
PropertySource testPropertySource = new MockPropertySource("TestPropertySource")
|
||||
.withProperty("spring.data.gemfire.cache.off-heap.memory-size", "1024g");
|
||||
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestOffHeapGemFirePropertiesConfiguration.class);
|
||||
newApplicationContext(testPropertySource, TestOffHeapGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
assertThat(containsBean("gemfireCache")).isTrue();
|
||||
|
||||
GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class);
|
||||
GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.getDistributedSystem()).isNotNull();
|
||||
@@ -334,14 +311,12 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup
|
||||
.withProperty("spring.data.gemfire.pdx.read-serialized", "true")
|
||||
.withProperty("spring.data.gemfire.pdx.serializer-bean-name", "mockPdxSerializer");
|
||||
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestPdxGemFirePropertiesConfiguration.class);
|
||||
newApplicationContext(testPropertySource, TestPdxGemFirePropertiesConfiguration.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();
|
||||
|
||||
CacheFactoryBean gemfireCache = this.applicationContext.getBean("&gemfireCache", CacheFactoryBean.class);
|
||||
CacheFactoryBean gemfireCache = getBean("&gemfireCache", CacheFactoryBean.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.getPdxDiskStoreName()).isEqualTo("TestDiskStore");
|
||||
@@ -349,7 +324,7 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup
|
||||
assertThat(gemfireCache.getPdxPersistent()).isTrue();
|
||||
assertThat(gemfireCache.getPdxReadSerialized()).isTrue();
|
||||
|
||||
PdxSerializer mockPdxSerializer = this.applicationContext.getBean("mockPdxSerializer", PdxSerializer.class);
|
||||
PdxSerializer mockPdxSerializer = getBean("mockPdxSerializer", PdxSerializer.class);
|
||||
|
||||
assertThat(mockPdxSerializer).isNotNull();
|
||||
assertThat(gemfireCache.getPdxSerializer()).isEqualTo(mockPdxSerializer);
|
||||
@@ -362,13 +337,11 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup
|
||||
.withProperty("spring.data.gemfire.service.redis.bind-address", "10.16.8.4")
|
||||
.withProperty("spring.data.gemfire.service.redis.port", "13579");
|
||||
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestRedisServerGemFirePropertiesConfiguration.class);
|
||||
newApplicationContext(testPropertySource, TestRedisServerGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
assertThat(containsBean("gemfireCache")).isTrue();
|
||||
|
||||
GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class);
|
||||
GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.getDistributedSystem()).isNotNull();
|
||||
@@ -390,13 +363,11 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup
|
||||
.withProperty("spring.data.gemfire.security.postprocessor.class-name", "example.security.PostProcessor")
|
||||
.withProperty("spring.data.gemfire.security.shiro.ini-resource-path", "/path/to/shiro.ini");
|
||||
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestSecurityGemFirePropertiesConfiguration.class);
|
||||
newApplicationContext(testPropertySource, TestSecurityGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
assertThat(containsBean("gemfireCache")).isTrue();
|
||||
|
||||
GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class);
|
||||
GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.getDistributedSystem()).isNotNull();
|
||||
@@ -414,13 +385,11 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup
|
||||
@Test
|
||||
public void serializableObjectFilterAndValidateSerializableObjectsGemFirePropertiesConfiguration() {
|
||||
|
||||
this.applicationContext =
|
||||
newApplicationContext(TestSerializableObjectFilterAndValidateSerializableObjectsGemFirePropertiesConfiguration.class);
|
||||
newApplicationContext(TestSerializableObjectFilterAndValidateSerializableObjectsGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireProperties")).isTrue();
|
||||
assertThat(containsBean("gemfireProperties")).isTrue();
|
||||
|
||||
Properties gemfireProperties = this.applicationContext.getBean("gemfireProperties", Properties.class);
|
||||
Properties gemfireProperties = getBean("gemfireProperties", Properties.class);
|
||||
|
||||
assertThat(gemfireProperties).isNotNull();
|
||||
assertThat(gemfireProperties.containsKey("serializable-object-filter")).isTrue();
|
||||
@@ -446,14 +415,12 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup
|
||||
.withProperty("spring.data.gemfire.security.ssl.truststore.type", "PKCS11")
|
||||
.withProperty("spring.data.gemfire.security.ssl.web-require-authentication", "true");
|
||||
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestSslGemFirePropertiesConfiguration.class);
|
||||
newApplicationContext(testPropertySource, TestSslGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("gemfireProperties")).isTrue();
|
||||
assertThat(containsBean("gemfireCache")).isTrue();
|
||||
assertThat(containsBean("gemfireProperties")).isTrue();
|
||||
|
||||
GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class);
|
||||
GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.getDistributedSystem()).isNotNull();
|
||||
@@ -490,13 +457,11 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup
|
||||
.withProperty("spring.data.gemfire.stats.enable-time-statistics", "true")
|
||||
.withProperty("spring.data.gemfire.stats.sample-rate", "100");
|
||||
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestStatisticsGemFirePropertiesConfiguration.class);
|
||||
newApplicationContext(testPropertySource, TestStatisticsGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
assertThat(containsBean("gemfireCache")).isTrue();
|
||||
|
||||
GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class);
|
||||
GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.getDistributedSystem()).isNotNull();
|
||||
|
||||
@@ -30,7 +30,6 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -55,7 +54,6 @@ import org.apache.geode.cache.query.QueryService;
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
|
||||
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.Configuration;
|
||||
@@ -68,6 +66,7 @@ import org.springframework.data.gemfire.config.annotation.test.entities.GenericR
|
||||
import org.springframework.data.gemfire.config.annotation.test.entities.LocalRegionEntity;
|
||||
import org.springframework.data.gemfire.config.annotation.test.entities.NonEntity;
|
||||
import org.springframework.data.gemfire.config.annotation.test.entities.ReplicateRegionEntity;
|
||||
import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@@ -90,10 +89,11 @@ import org.springframework.lang.Nullable;
|
||||
* @see org.springframework.data.gemfire.config.annotation.IndexConfiguration
|
||||
* @see org.springframework.data.gemfire.mapping.annotation.Indexed
|
||||
* @see org.springframework.data.gemfire.mapping.annotation.LuceneIndexed
|
||||
* @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
|
||||
* @since 1.9.0
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unused" })
|
||||
public class EnableIndexingConfigurationUnitTests {
|
||||
public class EnableIndexingConfigurationUnitTests extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
private static final Set<Index> indexes = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
@@ -125,14 +125,8 @@ public class EnableIndexingConfigurationUnitTests {
|
||||
return null;
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
|
||||
Optional.ofNullable(this.applicationContext)
|
||||
.ifPresent(ConfigurableApplicationContext::close);
|
||||
|
||||
indexes.clear();
|
||||
}
|
||||
|
||||
@@ -154,22 +148,13 @@ public class EnableIndexingConfigurationUnitTests {
|
||||
assertThat(index.getType()).isEqualTo(indexType.getGemfireIndexType());
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(Class<?>... annotatedClasses) {
|
||||
|
||||
ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(annotatedClasses);
|
||||
|
||||
applicationContext.registerShutdownHook();
|
||||
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void persistentEntityIndexesAreCreated() {
|
||||
|
||||
this.applicationContext = newApplicationContext(IndexingEnabledWithIndexedPersistentEntityConfiguration.class);
|
||||
newApplicationContext(IndexingEnabledWithIndexedPersistentEntityConfiguration.class);
|
||||
|
||||
assertLuceneIndexes(this.applicationContext);
|
||||
assertOqlIndexes(this.applicationContext);
|
||||
assertLuceneIndexes(requireApplicationContext());
|
||||
assertOqlIndexes(requireApplicationContext());
|
||||
}
|
||||
|
||||
private void assertLuceneIndexes(ConfigurableApplicationContext applicationContext) {
|
||||
@@ -198,10 +183,9 @@ public class EnableIndexingConfigurationUnitTests {
|
||||
@Test
|
||||
public void persistentEntityIndexesAreNotCreated() {
|
||||
|
||||
this.applicationContext =
|
||||
newApplicationContext(IndexingNotEnabledWithIndexedPersistentEntityConfiguration.class);
|
||||
newApplicationContext(IndexingNotEnabledWithIndexedPersistentEntityConfiguration.class);
|
||||
|
||||
Map<String, Index> indexes = this.applicationContext.getBeansOfType(Index.class);
|
||||
Map<String, Index> indexes = getBeansOfType(Index.class);
|
||||
|
||||
assertThat(indexes).isNotNull();
|
||||
assertThat(indexes).isEmpty();
|
||||
@@ -210,10 +194,9 @@ public class EnableIndexingConfigurationUnitTests {
|
||||
@Test
|
||||
public void indexAnnotatedEntityPropertyIsIgnoredWithExistingIndexHavingSameDefinition() {
|
||||
|
||||
this.applicationContext =
|
||||
newApplicationContext(IndexAnnotatedEntityPropertyIsIgnoredWithExistingIndexHavingSameDefinitionConfiguration.class);
|
||||
newApplicationContext(IndexAnnotatedEntityPropertyIsIgnoredWithExistingIndexHavingSameDefinitionConfiguration.class);
|
||||
|
||||
Index firstNameIndex = this.applicationContext.getBean("LoyalCustomersFirstNameFunctionalIdx", Index.class);
|
||||
Index firstNameIndex = getBean("LoyalCustomersFirstNameFunctionalIdx", Index.class);
|
||||
|
||||
assertOqlIndex(firstNameIndex, "LoyalCustomersFirstNameFunctionalIdx",
|
||||
"first_name", "/LoyalCustomers", IndexType.FUNCTIONAL);
|
||||
@@ -224,10 +207,9 @@ public class EnableIndexingConfigurationUnitTests {
|
||||
@Test
|
||||
public void indexAnnotatedEntityPropertyIsIgnoredWithExistingIndexHavingSameName() {
|
||||
|
||||
this.applicationContext =
|
||||
newApplicationContext(IndexAnnotatedEntityPropertyIsIgnoredWithExistingIndexHavingSameNameConfiguration.class);
|
||||
newApplicationContext(IndexAnnotatedEntityPropertyIsIgnoredWithExistingIndexHavingSameNameConfiguration.class);
|
||||
|
||||
Index lastNameIndex = this.applicationContext.getBean("LastNameIdx", Index.class);
|
||||
Index lastNameIndex = getBean("LastNameIdx", Index.class);
|
||||
|
||||
assertOqlIndex(lastNameIndex, "LastNameIdx", "last_name", "/People", IndexType.HASH);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.data.gemfire.config.annotation;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
@@ -27,8 +26,6 @@ import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.control.ResourceManager;
|
||||
|
||||
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;
|
||||
@@ -37,7 +34,7 @@ import org.springframework.data.gemfire.LocalRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.ReplicatedRegionFactoryBean;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -49,27 +46,17 @@ import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockO
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableOffHeap
|
||||
* @see org.springframework.data.gemfire.config.annotation.OffHeapConfiguration
|
||||
* @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 EnableOffHeapConfigurationUnitTests extends IntegrationTestsSupport {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
public class EnableOffHeapConfigurationUnitTests extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
|
||||
Optional.ofNullable(this.applicationContext)
|
||||
.ifPresent(ConfigurableApplicationContext::close);
|
||||
|
||||
public void cleanupAfterTests() {
|
||||
destroyAllGemFireMockObjects();
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(Class<?>... annotatedClasses) {
|
||||
return new AnnotationConfigApplicationContext(annotatedClasses);
|
||||
}
|
||||
|
||||
private void assertRegionOffHeap(Region<?, ?> region, String regionName, boolean offHeapEnabled) {
|
||||
|
||||
assertThat(region).isNotNull();
|
||||
@@ -82,11 +69,9 @@ public class EnableOffHeapConfigurationUnitTests extends IntegrationTestsSupport
|
||||
@Test
|
||||
public void offHeapCriticalAndEvictionMemoryPercentagesConfiguredProperly() {
|
||||
|
||||
this.applicationContext = newApplicationContext(OffHeapCriticalAndEvictionMemoryPercentagesConfiguration.class);
|
||||
newApplicationContext(OffHeapCriticalAndEvictionMemoryPercentagesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
|
||||
GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class);
|
||||
GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.getDistributedSystem()).isNotNull();
|
||||
@@ -106,11 +91,9 @@ public class EnableOffHeapConfigurationUnitTests extends IntegrationTestsSupport
|
||||
@Test
|
||||
public void offHeapConfiguredForAllRegions() {
|
||||
|
||||
this.applicationContext = newApplicationContext(EnableOffHeapForAllRegionsConfiguration.class);
|
||||
newApplicationContext(EnableOffHeapForAllRegionsConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
|
||||
GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class);
|
||||
GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.getDistributedSystem()).isNotNull();
|
||||
@@ -120,20 +103,17 @@ public class EnableOffHeapConfigurationUnitTests extends IntegrationTestsSupport
|
||||
|
||||
Arrays.asList("People", "ExampleLocalRegion", "ExamplePartitionRegion", "ExampleReplicateRegion")
|
||||
.forEach(regionName -> {
|
||||
assertThat(this.applicationContext.containsBean(regionName)).isTrue();
|
||||
assertRegionOffHeap(this.applicationContext.getBean(regionName, Region.class),
|
||||
regionName, true);
|
||||
assertThat(containsBean(regionName)).isTrue();
|
||||
assertRegionOffHeap(getBean(regionName, Region.class), regionName, true);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void offHeapConfiguredForSelectRegions() {
|
||||
|
||||
this.applicationContext = newApplicationContext(EnableOffHeapForSelectRegionsConfiguration.class);
|
||||
newApplicationContext(EnableOffHeapForSelectRegionsConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
|
||||
GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class);
|
||||
GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.getDistributedSystem()).isNotNull();
|
||||
@@ -143,9 +123,9 @@ public class EnableOffHeapConfigurationUnitTests extends IntegrationTestsSupport
|
||||
|
||||
Arrays.asList("People", "ExampleLocalRegion", "ExamplePartitionRegion", "ExampleReplicateRegion")
|
||||
.forEach(regionName -> {
|
||||
assertThat(this.applicationContext.containsBean(regionName)).isTrue();
|
||||
assertRegionOffHeap(this.applicationContext.getBean(regionName, Region.class),
|
||||
regionName, Arrays.asList("People", "ExamplePartitionRegion").contains(regionName));
|
||||
assertThat(containsBean(regionName)).isTrue();
|
||||
assertRegionOffHeap(getBean(regionName, Region.class), regionName,
|
||||
Arrays.asList("People", "ExamplePartitionRegion").contains(regionName));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,6 @@ 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;
|
||||
|
||||
@@ -27,17 +25,14 @@ import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.client.ClientRegionShortcut;
|
||||
import org.apache.geode.pdx.PdxSerializer;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
import org.springframework.data.gemfire.DiskStoreFactoryBean;
|
||||
import org.springframework.data.gemfire.LocalRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.mapping.MappingPdxSerializer;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -49,53 +44,40 @@ import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockO
|
||||
* @see org.apache.geode.pdx.PdxSerializer
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnablePdx
|
||||
* @see org.springframework.data.gemfire.config.annotation.PdxConfiguration
|
||||
* @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
|
||||
*/
|
||||
public class EnablePdxConfigurationIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
@Autowired
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
public class EnablePdxConfigurationIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
|
||||
Optional.ofNullable(this.applicationContext)
|
||||
.ifPresent(ConfigurableApplicationContext::close);
|
||||
|
||||
public void cleanupAfterTests() {
|
||||
destroyAllGemFireMockObjects();
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(Class<?>... annotatedClasses) {
|
||||
return new AnnotationConfigApplicationContext(annotatedClasses);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void regionBeanDefinitionDependsOnPdxDiskStoreBean() {
|
||||
|
||||
this.applicationContext = newApplicationContext(TestEnablePdxWithDiskStoreConfiguration.class);
|
||||
newApplicationContext(TestEnablePdxWithDiskStoreConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("MockPdxSerializer")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("TestDiskStore")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("TestRegion")).isTrue();
|
||||
assertThat(containsBean("gemfireCache")).isTrue();
|
||||
assertThat(containsBean("MockPdxSerializer")).isTrue();
|
||||
assertThat(containsBean("TestDiskStore")).isTrue();
|
||||
assertThat(containsBean("TestRegion")).isTrue();
|
||||
|
||||
CacheFactoryBean gemfireCache = this.applicationContext.getBean("&gemfireCache", CacheFactoryBean.class);
|
||||
CacheFactoryBean gemfireCache = getBean("&gemfireCache", CacheFactoryBean.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.getPdxSerializer())
|
||||
.isEqualTo(this.applicationContext.getBean("MockPdxSerializer", PdxSerializer.class));
|
||||
assertThat(gemfireCache.getPdxSerializer()).isEqualTo(getBean("MockPdxSerializer", PdxSerializer.class));
|
||||
|
||||
BeanDefinition testDiskStoreBeanDefinition =
|
||||
this.applicationContext.getBeanFactory().getBeanDefinition("TestDiskStore");
|
||||
requireApplicationContext().getBeanFactory().getBeanDefinition("TestDiskStore");
|
||||
|
||||
assertThat(testDiskStoreBeanDefinition).isNotNull();
|
||||
assertThat(testDiskStoreBeanDefinition.getDependsOn()).isNullOrEmpty();
|
||||
|
||||
BeanDefinition testRegionBeanDefinition =
|
||||
this.applicationContext.getBeanFactory().getBeanDefinition("TestRegion");
|
||||
requireApplicationContext().getBeanFactory().getBeanDefinition("TestRegion");
|
||||
|
||||
assertThat(testRegionBeanDefinition).isNotNull();
|
||||
assertThat(testRegionBeanDefinition.getDependsOn()).containsExactly("TestDiskStore");
|
||||
@@ -104,26 +86,25 @@ public class EnablePdxConfigurationIntegrationTests extends IntegrationTestsSupp
|
||||
@Test
|
||||
public void regionBeanDefinitionHasNoDependencies() {
|
||||
|
||||
this.applicationContext = newApplicationContext(TestEnablePdxConfigurationWithNoDiskStoreConfiguration.class);
|
||||
newApplicationContext(TestEnablePdxConfigurationWithNoDiskStoreConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("TestDiskStore")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("TestRegion")).isTrue();
|
||||
assertThat(containsBean("gemfireCache")).isTrue();
|
||||
assertThat(containsBean("TestDiskStore")).isTrue();
|
||||
assertThat(containsBean("TestRegion")).isTrue();
|
||||
|
||||
CacheFactoryBean gemfireCache = this.applicationContext.getBean("&gemfireCache", CacheFactoryBean.class);
|
||||
CacheFactoryBean gemfireCache = getBean("&gemfireCache", CacheFactoryBean.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.getPdxSerializer()).isInstanceOf(MappingPdxSerializer.class);
|
||||
|
||||
BeanDefinition testDiskStoreBeanDefinition =
|
||||
this.applicationContext.getBeanFactory().getBeanDefinition("TestDiskStore");
|
||||
requireApplicationContext().getBeanFactory().getBeanDefinition("TestDiskStore");
|
||||
|
||||
assertThat(testDiskStoreBeanDefinition).isNotNull();
|
||||
assertThat(testDiskStoreBeanDefinition.getDependsOn()).isNullOrEmpty();
|
||||
|
||||
BeanDefinition testRegionBeanDefinition =
|
||||
this.applicationContext.getBeanFactory().getBeanDefinition("TestRegion");
|
||||
requireApplicationContext().getBeanFactory().getBeanDefinition("TestRegion");
|
||||
|
||||
assertThat(testRegionBeanDefinition).isNotNull();
|
||||
assertThat(testRegionBeanDefinition.getDependsOn()).isNullOrEmpty();
|
||||
|
||||
@@ -19,8 +19,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
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.Cache;
|
||||
@@ -28,10 +28,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.IntegrationTestsSupport;
|
||||
import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport;
|
||||
import org.springframework.data.gemfire.util.ArrayUtils;
|
||||
import org.springframework.mock.env.MockPropertySource;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -53,22 +52,15 @@ import org.springframework.util.StringUtils;
|
||||
* @see org.springframework.core.env.PropertySource
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableSsl
|
||||
* @see org.springframework.data.gemfire.config.annotation.SslConfiguration
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public class EnableSslConfigurationDefaultContextIntegrationTests extends IntegrationTestsSupport {
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class EnableSslConfigurationDefaultContextIntegrationTests
|
||||
extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
private static final String GEMFIRE_LOG_LEVEL = "error";
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
|
||||
Optional.ofNullable(this.applicationContext)
|
||||
.ifPresent(ConfigurableApplicationContext::close);
|
||||
}
|
||||
|
||||
private void assertGemFirePropertiesCorrectlySet(Properties gemfireProperties) {
|
||||
|
||||
assertThat(gemfireProperties).isNotNull();
|
||||
@@ -90,19 +82,18 @@ public class EnableSslConfigurationDefaultContextIntegrationTests extends Integr
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(PropertySource<?> testPropertySource,
|
||||
Class<?>... annotatedClasses) {
|
||||
Class<?>... annotatedClasses) {
|
||||
|
||||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
|
||||
Function<ConfigurableApplicationContext, ConfigurableApplicationContext> 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);
|
||||
}
|
||||
|
||||
private PropertySource setSpringDataGemFireProperties() {
|
||||
@@ -129,15 +120,13 @@ public class EnableSslConfigurationDefaultContextIntegrationTests extends Integr
|
||||
@Test
|
||||
public void sslAnnotationBasedClientConfigurationIsCorrect() {
|
||||
|
||||
this.applicationContext = newApplicationContext(new MockPropertySource("TestPropertySource"),
|
||||
newApplicationContext(new MockPropertySource("TestPropertySource"),
|
||||
SslAnnotationBasedClientConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache"));
|
||||
assertThat(this.applicationContext.containsBean("gemfireProperties"));
|
||||
assertThat(containsBean("gemfireCache"));
|
||||
assertThat(containsBean("gemfireProperties"));
|
||||
|
||||
GemFireCache clientCache =
|
||||
this.applicationContext.getBean("gemfireCache", GemFireCache.class);
|
||||
GemFireCache clientCache = getBean("gemfireCache", GemFireCache.class);
|
||||
|
||||
//Get Properties from GemFire
|
||||
Properties gemfireProperties = clientCache.getDistributedSystem().getProperties();
|
||||
@@ -152,14 +141,12 @@ public class EnableSslConfigurationDefaultContextIntegrationTests extends Integr
|
||||
|
||||
PropertySource testPropertySource = setSpringDataGemFireProperties();
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, SslPropertyBasedClientConfiguration.class);
|
||||
newApplicationContext(testPropertySource, SslPropertyBasedClientConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache"));
|
||||
assertThat(this.applicationContext.containsBean("gemfireProperties"));
|
||||
assertThat(containsBean("gemfireCache"));
|
||||
assertThat(containsBean("gemfireProperties"));
|
||||
|
||||
GemFireCache clientCache =
|
||||
this.applicationContext.getBean("gemfireCache", GemFireCache.class);
|
||||
GemFireCache clientCache = getBean("gemfireCache", GemFireCache.class);
|
||||
|
||||
assertThat(clientCache).isNotNull();
|
||||
|
||||
@@ -193,16 +180,14 @@ public class EnableSslConfigurationDefaultContextIntegrationTests extends Integr
|
||||
@Test
|
||||
public void sslAnnotationBasedPeerConfigurationIsCorrect(){
|
||||
|
||||
this.applicationContext =
|
||||
newApplicationContext(new MockPropertySource("TestPropertySource"),
|
||||
SslAnnotationBasedPeerConfiguration.class);
|
||||
newApplicationContext(new MockPropertySource("TestPropertySource"),
|
||||
SslAnnotationBasedPeerConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache"));
|
||||
assertThat(this.applicationContext.containsBean("gemfireProperties"));
|
||||
assertThat(containsBean("gemfireCache"));
|
||||
assertThat(containsBean("gemfireProperties"));
|
||||
|
||||
GemFireCache peerCache = getBean("gemfireCache", GemFireCache.class);
|
||||
|
||||
GemFireCache peerCache =
|
||||
this.applicationContext.getBean("gemfireCache", GemFireCache.class);
|
||||
assertThat(peerCache).isNotNull();
|
||||
|
||||
Properties gemfireProperties = peerCache.getDistributedSystem().getProperties();
|
||||
@@ -215,14 +200,12 @@ public class EnableSslConfigurationDefaultContextIntegrationTests extends Integr
|
||||
|
||||
PropertySource testPropertySource = setSpringDataGemFireProperties();
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, SslPropertyBasedPeerConfiguration.class);
|
||||
newApplicationContext(testPropertySource, SslPropertyBasedPeerConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache"));
|
||||
assertThat(this.applicationContext.containsBean("gemfireProperties"));
|
||||
assertThat(containsBean("gemfireCache"));
|
||||
assertThat(containsBean("gemfireProperties"));
|
||||
|
||||
GemFireCache peerCache =
|
||||
this.applicationContext.getBean("gemfireCache", GemFireCache.class);
|
||||
GemFireCache peerCache = getBean("gemfireCache", GemFireCache.class);
|
||||
|
||||
assertThat(peerCache).isNotNull();
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.client.ClientRegionShortcut;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
|
||||
@@ -69,9 +69,14 @@ public class EnableSslConfigurationIntegrationTests extends ForkingClientServerI
|
||||
|
||||
@BeforeClass
|
||||
public static void startGeodeServer() throws Exception {
|
||||
|
||||
org.springframework.core.io.Resource trustedKeystore = new ClassPathResource("trusted.keystore");
|
||||
|
||||
startGemFireServer(GeodeServerTestConfiguration.class,
|
||||
String.format("-Dgemfire.name=%s", asApplicationName(EnableSslConfigurationIntegrationTests.class)),
|
||||
String.format("-Djavax.net.ssl.keyStore=%s", System.getProperty("javax.net.ssl.keyStore")));
|
||||
String.format("-Dgemfire.name=%s", asApplicationName(EnableSslConfigurationIntegrationTests.class).concat("Server")),
|
||||
String.format("-Djavax.net.ssl.keyStore=%s", trustedKeystore.getFile().getAbsolutePath()));
|
||||
|
||||
System.setProperty("javax.net.ssl.keyStore", trustedKeystore.getFile().getAbsolutePath());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -111,11 +116,7 @@ public class EnableSslConfigurationIntegrationTests extends ForkingClientServerI
|
||||
static class GeodeServerTestConfiguration {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
AnnotationConfigApplicationContext applicationContext =
|
||||
new AnnotationConfigApplicationContext(GeodeServerTestConfiguration.class);
|
||||
|
||||
applicationContext.registerShutdownHook();
|
||||
runSpringApplication(GeodeServerTestConfiguration.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -135,7 +136,6 @@ public class EnableSslConfigurationIntegrationTests extends ForkingClientServerI
|
||||
|
||||
echoRegion.setCache(gemfireCache);
|
||||
echoRegion.setCacheLoader(echoCacheLoader());
|
||||
echoRegion.setClose(false);
|
||||
echoRegion.setPersistent(false);
|
||||
|
||||
return echoRegion;
|
||||
@@ -152,8 +152,8 @@ public class EnableSslConfigurationIntegrationTests extends ForkingClientServerI
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
public void close() { }
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,16 +19,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
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.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.data.gemfire.util.ArrayUtils;
|
||||
import org.springframework.mock.env.MockPropertySource;
|
||||
@@ -43,47 +42,36 @@ import org.springframework.util.StringUtils;
|
||||
* @see org.apache.geode.cache.GemFireCache
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableSsl
|
||||
* @see org.springframework.data.gemfire.config.annotation.SslConfiguration
|
||||
* @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.1.0
|
||||
*/
|
||||
public class EnableSslConfigurationUnitTests extends IntegrationTestsSupport {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close);
|
||||
}
|
||||
public class EnableSslConfigurationUnitTests extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(PropertySource<?> testPropertySource,
|
||||
Class<?>... annotatedClasses) {
|
||||
|
||||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
|
||||
Function<ConfigurableApplicationContext, ConfigurableApplicationContext> 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
|
||||
public void sslAnnotationBasedConfigurationIsCorrect() {
|
||||
|
||||
this.applicationContext = newApplicationContext(new MockPropertySource("TestPropertySource"),
|
||||
SslAnnotationBasedConfiguration.class);
|
||||
newApplicationContext(new MockPropertySource("TestPropertySource"), SslAnnotationBasedConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache"));
|
||||
assertThat(this.applicationContext.containsBean("gemfireProperties"));
|
||||
assertThat(containsBean("gemfireCache"));
|
||||
assertThat(containsBean("gemfireProperties"));
|
||||
|
||||
ClientCacheFactoryBean clientCache =
|
||||
this.applicationContext.getBean("&gemfireCache", ClientCacheFactoryBean.class);
|
||||
ClientCacheFactoryBean clientCache = getBean("&gemfireCache", ClientCacheFactoryBean.class);
|
||||
|
||||
assertThat(clientCache).isNotNull();
|
||||
|
||||
@@ -128,14 +116,12 @@ public class EnableSslConfigurationUnitTests extends IntegrationTestsSupport {
|
||||
.withProperty("spring.data.gemfire.security.ssl.use-default-context", "true")
|
||||
.withProperty("spring.data.gemfire.security.ssl.web-require-authentication", "true");
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, SslPropertyBasedConfiguration.class);
|
||||
newApplicationContext(testPropertySource, SslPropertyBasedConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache"));
|
||||
assertThat(this.applicationContext.containsBean("gemfireProperties"));
|
||||
assertThat(containsBean("gemfireCache"));
|
||||
assertThat(containsBean("gemfireProperties"));
|
||||
|
||||
ClientCacheFactoryBean clientCache =
|
||||
this.applicationContext.getBean("&gemfireCache", ClientCacheFactoryBean.class);
|
||||
ClientCacheFactoryBean clientCache = getBean("&gemfireCache", ClientCacheFactoryBean.class);
|
||||
|
||||
assertThat(clientCache).isNotNull();
|
||||
|
||||
|
||||
@@ -19,62 +19,57 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.Collections;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.geode.cache.wan.GatewayReceiver;
|
||||
import org.apache.geode.cache.wan.GatewayTransportFilter;
|
||||
|
||||
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.core.env.MutablePropertySources;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport;
|
||||
import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean;
|
||||
import org.springframework.mock.env.MockPropertySource;
|
||||
|
||||
/**
|
||||
* Tests for {@link EnableGatewayReceiver}.
|
||||
* Integration Tests for {@link EnableGatewayReceiver}.
|
||||
*
|
||||
* @author Udo Kohlmeyer
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.apache.geode.cache.server.CacheServer
|
||||
* @see org.apache.geode.cache.wan.GatewayReceiver
|
||||
* @see org.apache.geode.cache.wan.GatewayTransportFilter
|
||||
* @see org.springframework.context.annotation.Bean
|
||||
* @see org.springframework.context.annotation.Configuration
|
||||
* @see org.springframework.core.env.PropertySources
|
||||
* @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.annotation.GatewayReceiverConfiguration
|
||||
* @see org.springframework.data.gemfire.config.annotation.GatewayReceiverConfigurer
|
||||
* @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean
|
||||
* @see GatewayReceiverConfigurer
|
||||
* @see GatewayReceiverConfiguration
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public class GatewayReceiverConfigurerTests {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close);
|
||||
}
|
||||
public class GatewayReceiverConfigurerIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(PropertySource<?> testPropertySource,
|
||||
Class<?>... annotatedClasses) {
|
||||
Class<?>... annotatedClasses) {
|
||||
|
||||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
|
||||
Function<ConfigurableApplicationContext, ConfigurableApplicationContext> 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);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,12 +77,12 @@ public class GatewayReceiverConfigurerTests {
|
||||
|
||||
MockPropertySource testPropertySource = new MockPropertySource();
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource,
|
||||
GatewayReceiverConfigurerTests.TestConfigurationWithProperties.class);
|
||||
newApplicationContext(testPropertySource,
|
||||
GatewayReceiverConfigurerIntegrationTests.TestConfigurationWithProperties.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("GatewayReceiver")).isTrue();
|
||||
GatewayReceiver gatewayReceiver = this.applicationContext.getBean("GatewayReceiver", GatewayReceiver.class);
|
||||
assertThat(containsBean("GatewayReceiver")).isTrue();
|
||||
|
||||
GatewayReceiver gatewayReceiver = getBean("GatewayReceiver", GatewayReceiver.class);
|
||||
|
||||
assertThat(gatewayReceiver.getStartPort()).isEqualTo(23000);
|
||||
assertThat(gatewayReceiver.getEndPort()).isEqualTo(25000);
|
||||
@@ -97,8 +92,7 @@ public class GatewayReceiverConfigurerTests {
|
||||
assertThat(gatewayReceiver.getSocketBufferSize()).isEqualTo(987654);
|
||||
assertThat(gatewayReceiver.isManualStart()).isEqualTo(false);
|
||||
assertThat(gatewayReceiver.getGatewayTransportFilters().size()).isEqualTo(1);
|
||||
assertThat(
|
||||
((TestGatewayTransportFilter) gatewayReceiver.getGatewayTransportFilters().get(0)).name)
|
||||
assertThat(((TestGatewayTransportFilter) gatewayReceiver.getGatewayTransportFilters().get(0)).name)
|
||||
.isEqualTo("transportBean1");
|
||||
|
||||
}
|
||||
@@ -116,12 +110,12 @@ public class GatewayReceiverConfigurerTests {
|
||||
.withProperty("spring.data.gemfire.gateway.receiver.manual-start", true)
|
||||
.withProperty("spring.data.gemfire.gateway.receiver.transport-filters", "transportBean1,transportBean2");
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource,
|
||||
GatewayReceiverConfigurerTests.TestConfigurationWithProperties.class);
|
||||
newApplicationContext(testPropertySource,
|
||||
GatewayReceiverConfigurerIntegrationTests.TestConfigurationWithProperties.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("GatewayReceiver")).isTrue();
|
||||
GatewayReceiver gatewayReceiver = this.applicationContext.getBean("GatewayReceiver", GatewayReceiver.class);
|
||||
assertThat(containsBean("GatewayReceiver")).isTrue();
|
||||
|
||||
GatewayReceiver gatewayReceiver = getBean("GatewayReceiver", GatewayReceiver.class);
|
||||
|
||||
assertThat(gatewayReceiver.getStartPort()).isEqualTo(23000);
|
||||
assertThat(gatewayReceiver.getEndPort()).isEqualTo(25000);
|
||||
@@ -131,8 +125,7 @@ public class GatewayReceiverConfigurerTests {
|
||||
assertThat(gatewayReceiver.getSocketBufferSize()).isEqualTo(987654);
|
||||
assertThat(gatewayReceiver.isManualStart()).isEqualTo(false);
|
||||
assertThat(gatewayReceiver.getGatewayTransportFilters().size()).isEqualTo(1);
|
||||
assertThat(
|
||||
((TestGatewayTransportFilter) gatewayReceiver.getGatewayTransportFilters().get(0)).name)
|
||||
assertThat(((TestGatewayTransportFilter) gatewayReceiver.getGatewayTransportFilters().get(0)).name)
|
||||
.isEqualTo("transportBean1");
|
||||
|
||||
}
|
||||
@@ -147,12 +140,12 @@ public class GatewayReceiverConfigurerTests {
|
||||
.withProperty("spring.data.gemfire.gateway.receiver.manual-start", true)
|
||||
.withProperty("spring.data.gemfire.gateway.receiver.transport-filters", "transportBean2,transportBean1");
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource,
|
||||
GatewayReceiverConfigurerTests.TestConfiguration.class);
|
||||
newApplicationContext(testPropertySource,
|
||||
GatewayReceiverConfigurerIntegrationTests.TestConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("GatewayReceiver")).isTrue();
|
||||
GatewayReceiver gatewayReceiver = this.applicationContext.getBean("GatewayReceiver", GatewayReceiver.class);
|
||||
assertThat(containsBean("GatewayReceiver")).isTrue();
|
||||
|
||||
GatewayReceiver gatewayReceiver = getBean("GatewayReceiver", GatewayReceiver.class);
|
||||
|
||||
assertThat(gatewayReceiver.getStartPort()).isEqualTo(10000);
|
||||
assertThat(gatewayReceiver.getEndPort()).isEqualTo(11000);
|
||||
@@ -162,28 +155,26 @@ public class GatewayReceiverConfigurerTests {
|
||||
assertThat(gatewayReceiver.getSocketBufferSize()).isEqualTo(32768);
|
||||
assertThat(gatewayReceiver.isManualStart()).isEqualTo(true);
|
||||
assertThat(gatewayReceiver.getGatewayTransportFilters().size()).isEqualTo(2);
|
||||
assertThat(
|
||||
((TestGatewayTransportFilter) gatewayReceiver.getGatewayTransportFilters().get(0)).name)
|
||||
assertThat(((TestGatewayTransportFilter) gatewayReceiver.getGatewayTransportFilters().get(0)).name)
|
||||
.isEqualTo("transportBean2");
|
||||
assertThat(
|
||||
((TestGatewayTransportFilter) gatewayReceiver.getGatewayTransportFilters().get(1)).name)
|
||||
assertThat(((TestGatewayTransportFilter) gatewayReceiver.getGatewayTransportFilters().get(1)).name)
|
||||
.isEqualTo("transportBean1");
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@CacheServerApplication
|
||||
@EnableGatewayReceiver
|
||||
@SuppressWarnings("unused")
|
||||
static class TestConfigurationWithProperties {
|
||||
|
||||
@Bean("transportBean1")
|
||||
GatewayTransportFilter createGatewayTransportBean1() {
|
||||
return new GatewayReceiverConfigurerTests.TestGatewayTransportFilter("transportBean1");
|
||||
return new GatewayReceiverConfigurerIntegrationTests.TestGatewayTransportFilter("transportBean1");
|
||||
}
|
||||
|
||||
@Bean("transportBean2")
|
||||
GatewayTransportFilter createGatewayTransportBean2() {
|
||||
return new GatewayReceiverConfigurerTests.TestGatewayTransportFilter("transportBean2");
|
||||
return new GatewayReceiverConfigurerIntegrationTests.TestGatewayTransportFilter("transportBean2");
|
||||
}
|
||||
|
||||
@Bean("gatewayConfigurer")
|
||||
@@ -196,26 +187,26 @@ public class GatewayReceiverConfigurerTests {
|
||||
bean.setManualStart(false);
|
||||
bean.setMaximumTimeBetweenPings(1234567);
|
||||
bean.setSocketBufferSize(987654);
|
||||
bean.setTransportFilters(Arrays.asList(createGatewayTransportBean1()));
|
||||
bean.setTransportFilters(Collections.singletonList(createGatewayTransportBean1()));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@CacheServerApplication
|
||||
@EnableGatewayReceiver(manualStart = false, startPort = 10000, endPort = 11000, maximumTimeBetweenPings = 1000,
|
||||
socketBufferSize = 16384, bindAddress = "localhost",transportFilters = {"transportBean1", "transportBean2"},
|
||||
hostnameForSenders = "hostnameLocalhost")
|
||||
@SuppressWarnings("unused")
|
||||
static class TestConfiguration {
|
||||
|
||||
@Bean("transportBean1")
|
||||
GatewayTransportFilter createGatewayTransportBean1() {
|
||||
return new GatewayReceiverConfigurerTests.TestGatewayTransportFilter("transportBean1");
|
||||
return new GatewayReceiverConfigurerIntegrationTests.TestGatewayTransportFilter("transportBean1");
|
||||
}
|
||||
|
||||
@Bean("transportBean2")
|
||||
GatewayTransportFilter createGatewayTransportBean2() {
|
||||
return new GatewayReceiverConfigurerTests.TestGatewayTransportFilter("transportBean2");
|
||||
return new GatewayReceiverConfigurerIntegrationTests.TestGatewayTransportFilter("transportBean2");
|
||||
}
|
||||
|
||||
@Bean("gatewayConfigurer")
|
||||
@@ -230,7 +221,7 @@ public class GatewayReceiverConfigurerTests {
|
||||
|
||||
private static class TestGatewayTransportFilter implements GatewayTransportFilter {
|
||||
|
||||
private String name;
|
||||
private final String name;
|
||||
|
||||
public TestGatewayTransportFilter(String name) {
|
||||
this.name = name;
|
||||
@@ -23,83 +23,67 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.geode.cache.wan.GatewayReceiver;
|
||||
import org.apache.geode.cache.wan.GatewayTransportFilter;
|
||||
|
||||
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.wan.GatewayReceiverFactoryBean;
|
||||
import org.springframework.mock.env.MockPropertySource;
|
||||
|
||||
/**
|
||||
* Tests for {@link EnableGatewayReceiver}.
|
||||
* Integration Tests for {@link EnableGatewayReceiver}, {@link GatewayReceiverConfiguration}
|
||||
* and {@link GatewayReceiverConfigurer}.
|
||||
*
|
||||
* @author Udo Kohlmeyer
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.apache.geode.cache.server.CacheServer
|
||||
* @see org.springframework.context.annotation.Configuration
|
||||
* @see org.apache.geode.cache.wan.GatewayReceiver
|
||||
* @see org.springframework.context.annotation.Bean
|
||||
* @see org.springframework.data.gemfire.config.annotation.GatewayReceiverConfigurer
|
||||
* @see org.springframework.data.gemfire.config.annotation.GatewayReceiverConfiguration
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public class GatewayReceiverPropertiesTests extends IntegrationTestsSupport {
|
||||
public class GatewayReceiverPropertiesIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
@Override
|
||||
protected ConfigurableApplicationContext processBeforeRefresh(ConfigurableApplicationContext applicationContext) {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close);
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(PropertySource<?> testPropertySource,
|
||||
Class<?>... annotatedClasses) {
|
||||
|
||||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
|
||||
MockPropertySource testPropertySource = new MockPropertySource()
|
||||
.withProperty("spring.data.gemfire.gateway.receiver.bind-address", "123.123.123.123")
|
||||
.withProperty("spring.data.gemfire.gateway.receiver.hostname-for-senders", "testHostName")
|
||||
.withProperty("spring.data.gemfire.gateway.receiver.start-port", 16000)
|
||||
.withProperty("spring.data.gemfire.gateway.receiver.end-port", 17000)
|
||||
.withProperty("spring.data.gemfire.gateway.receiver.maximum-time-between-pings", 30000)
|
||||
.withProperty("spring.data.gemfire.gateway.receiver.socket-buffer-size", 32768)
|
||||
.withProperty("spring.data.gemfire.gateway.receiver.manual-start", true)
|
||||
.withProperty("spring.data.gemfire.gateway.receiver.transport-filters", "transportBean2,transportBean1");
|
||||
|
||||
MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources();
|
||||
|
||||
propertySources.addFirst(testPropertySource);
|
||||
|
||||
applicationContext.registerShutdownHook();
|
||||
applicationContext.register(annotatedClasses);
|
||||
applicationContext.refresh();
|
||||
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gatewayReceiverPropertiesConfiguration() {
|
||||
|
||||
MockPropertySource testPropertySource = new MockPropertySource()
|
||||
.withProperty("spring.data.gemfire.gateway.receiver.bind-address", "123.123.123.123")
|
||||
.withProperty("spring.data.gemfire.gateway.receiver.hostname-for-senders", "testHostName")
|
||||
.withProperty("spring.data.gemfire.gateway.receiver.start-port", 16000)
|
||||
.withProperty("spring.data.gemfire.gateway.receiver.end-port", 17000)
|
||||
.withProperty("spring.data.gemfire.gateway.receiver.maximum-time-between-pings", 30000)
|
||||
.withProperty("spring.data.gemfire.gateway.receiver.socket-buffer-size", 32768)
|
||||
.withProperty("spring.data.gemfire.gateway.receiver.manual-start", true)
|
||||
.withProperty("spring.data.gemfire.gateway.receiver.transport-filters", "transportBean2,transportBean1");
|
||||
newApplicationContext(GatewayReceiverPropertiesIntegrationTests.TestConfigurationWithProperties.class);
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource,
|
||||
GatewayReceiverPropertiesTests.TestConfigurationWithProperties.class);
|
||||
assertThat(requireApplicationContext().containsBean("GatewayReceiver")).isTrue();
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("GatewayReceiver")).isTrue();
|
||||
GatewayReceiver gatewayReceiver = this.applicationContext.getBean("GatewayReceiver",GatewayReceiver.class);
|
||||
GatewayReceiver gatewayReceiver = getBean("GatewayReceiver", GatewayReceiver.class);
|
||||
|
||||
assertThat(gatewayReceiver.getStartPort()).isEqualTo(16000);
|
||||
assertThat(gatewayReceiver.getEndPort()).isEqualTo(17000);
|
||||
@@ -116,27 +100,44 @@ public class GatewayReceiverPropertiesTests extends IntegrationTestsSupport {
|
||||
|
||||
@CacheServerApplication
|
||||
@EnableGatewayReceiver
|
||||
@SuppressWarnings("unused")
|
||||
static class TestConfigurationWithProperties{
|
||||
|
||||
@Bean("transportBean1")
|
||||
GatewayTransportFilter createGatewayTransportBean1() {
|
||||
return new GatewayReceiverPropertiesTests.TestGatewayTransportFilter("transportBean1");
|
||||
return new GatewayReceiverPropertiesIntegrationTests.TestGatewayTransportFilter("transportBean1");
|
||||
}
|
||||
|
||||
@Bean("transportBean2")
|
||||
GatewayTransportFilter createGatewayTransportBean2() {
|
||||
return new GatewayReceiverPropertiesTests.TestGatewayTransportFilter("transportBean2");
|
||||
return new GatewayReceiverPropertiesIntegrationTests.TestGatewayTransportFilter("transportBean2");
|
||||
}
|
||||
|
||||
@Bean("gatewayConfigurer")
|
||||
GatewayReceiverConfigurer gatewayReceiverConfigurer() {
|
||||
return new GatewayReceiverPropertiesTests.TestGatewayReceiverConfigurer();
|
||||
return new GatewayReceiverPropertiesIntegrationTests.TestGatewayReceiverConfigurer();
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestGatewayReceiverConfigurer implements GatewayReceiverConfigurer, Iterable<String> {
|
||||
|
||||
private final List<String> beanNames = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public Iterator<String> iterator() {
|
||||
return Collections.unmodifiableList(this.beanNames).iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(String beanName, GatewayReceiverFactoryBean bean) {
|
||||
bean.getTransportFilters().stream().forEach(transportFilter ->
|
||||
this.beanNames.add(((GatewayReceiverPropertiesIntegrationTests.TestGatewayTransportFilter) transportFilter).name));
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestGatewayTransportFilter implements GatewayTransportFilter {
|
||||
|
||||
private String name;
|
||||
private final String name;
|
||||
|
||||
public TestGatewayTransportFilter(String name) {
|
||||
this.name = name;
|
||||
@@ -152,19 +153,4 @@ public class GatewayReceiverPropertiesTests extends IntegrationTestsSupport {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestGatewayReceiverConfigurer implements GatewayReceiverConfigurer, Iterable<String> {
|
||||
|
||||
private final List<String> beanNames = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public Iterator<String> iterator() {
|
||||
return Collections.unmodifiableList(this.beanNames).iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(String beanName, GatewayReceiverFactoryBean bean) {
|
||||
bean.getTransportFilters().stream().forEach(o -> beanNames.add(((GatewayReceiverPropertiesTests.TestGatewayTransportFilter) o).name));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,6 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.TreeMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -37,11 +36,9 @@ import org.apache.geode.cache.wan.GatewayQueueEvent;
|
||||
import org.apache.geode.cache.wan.GatewaySender;
|
||||
import org.apache.geode.cache.wan.GatewayTransportFilter;
|
||||
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
|
||||
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.wan.GatewaySenderFactoryBean;
|
||||
import org.springframework.data.gemfire.wan.OrderPolicyType;
|
||||
@@ -61,7 +58,7 @@ import org.springframework.data.gemfire.wan.OrderPolicyType;
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableGatewaySenders
|
||||
* @see org.springframework.data.gemfire.config.annotation.GatewaySenderConfigurer
|
||||
* @see org.springframework.data.gemfire.config.annotation.GatewaySenderConfiguration
|
||||
* @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.data.gemfire.wan.GatewaySenderFactoryBean
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
@@ -69,29 +66,22 @@ import org.springframework.data.gemfire.wan.OrderPolicyType;
|
||||
* @since 2.2.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class GatewaySenderConfigurationIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
public class GatewaySenderConfigurationIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
@After
|
||||
public void shutdown() {
|
||||
|
||||
Optional.ofNullable(this.applicationContext)
|
||||
.ifPresent(ConfigurableApplicationContext::close);
|
||||
|
||||
public void cleanupAfterTests() {
|
||||
destroyAllGemFireMockObjects();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void annotationConfigurationOfMultipleGatewaySendersWithDefaultsFromParent() {
|
||||
|
||||
this.applicationContext = newApplicationContext(BaseGatewaySenderTestConfiguration.class,
|
||||
newApplicationContext(BaseGatewaySenderTestConfiguration.class,
|
||||
TestConfigurationOfMultipleGatewaySenderAnnotationsButWithDefaultsFromParent.class);
|
||||
|
||||
TestGatewaySenderConfigurer gatewaySenderConfigurer =
|
||||
this.applicationContext.getBean(TestGatewaySenderConfigurer.class);
|
||||
TestGatewaySenderConfigurer gatewaySenderConfigurer = getBean(TestGatewaySenderConfigurer.class);
|
||||
|
||||
Map<String, GatewaySender> beansOfType = this.applicationContext.getBeansOfType(GatewaySender.class);
|
||||
Map<String, GatewaySender> beansOfType = getBeansOfType(GatewaySender.class);
|
||||
|
||||
String[] senders = new String[] { "TestGatewaySender", "TestGatewaySender2" };
|
||||
|
||||
@@ -100,7 +90,7 @@ public class GatewaySenderConfigurationIntegrationTests extends IntegrationTests
|
||||
|
||||
for (String sender : senders) {
|
||||
|
||||
GatewaySender gatewaySender = this.applicationContext.getBean(sender, GatewaySender.class);
|
||||
GatewaySender gatewaySender = getBean(sender, GatewaySender.class);
|
||||
|
||||
assertThat(gatewaySender.isManualStart()).isEqualTo(true);
|
||||
assertThat(gatewaySender.getRemoteDSId()).isEqualTo(2);
|
||||
@@ -127,8 +117,8 @@ public class GatewaySenderConfigurationIntegrationTests extends IntegrationTests
|
||||
assertThat(gatewaySenderConfigurer.beanNames.get(gatewaySender.getId()).toArray())
|
||||
.isEqualTo(new String[] { "transportBean2", "transportBean1" });
|
||||
|
||||
Region<?, ?> region1 = this.applicationContext.getBean("Region1", Region.class);
|
||||
Region<?, ?> region2 = this.applicationContext.getBean("Region2", Region.class);
|
||||
Region<?, ?> region1 = getBean("Region1", Region.class);
|
||||
Region<?, ?> region2 = getBean("Region2", Region.class);
|
||||
|
||||
assertThat(region1.getAttributes().getGatewaySenderIds())
|
||||
.containsExactlyInAnyOrder("TestGatewaySender", "TestGatewaySender2");
|
||||
@@ -140,10 +130,10 @@ public class GatewaySenderConfigurationIntegrationTests extends IntegrationTests
|
||||
@Test
|
||||
public void annotationConfiguredMultipleGatewaySenders() {
|
||||
|
||||
this.applicationContext = newApplicationContext(BaseGatewaySenderTestConfiguration.class,
|
||||
newApplicationContext(BaseGatewaySenderTestConfiguration.class,
|
||||
TestConfigurationWithMultipleGatewaySenderAnnotations.class);
|
||||
|
||||
Map<String, GatewaySender> beansOfType = this.applicationContext.getBeansOfType(GatewaySender.class);
|
||||
Map<String, GatewaySender> beansOfType = getBeansOfType(GatewaySender.class);
|
||||
|
||||
assertThat(beansOfType.keySet().toArray()).containsExactlyInAnyOrder("TestGatewaySender", "TestGatewaySender2");
|
||||
}
|
||||
@@ -151,13 +141,11 @@ public class GatewaySenderConfigurationIntegrationTests extends IntegrationTests
|
||||
@Test
|
||||
public void annotationConfiguredGatewaySender() {
|
||||
|
||||
this.applicationContext = newApplicationContext(BaseGatewaySenderTestConfiguration.class,
|
||||
TestConfigurationWithAnnotations.class);
|
||||
newApplicationContext(BaseGatewaySenderTestConfiguration.class, TestConfigurationWithAnnotations.class);
|
||||
|
||||
TestGatewaySenderConfigurer gatewaySenderConfigurer =
|
||||
this.applicationContext.getBean(TestGatewaySenderConfigurer.class);
|
||||
TestGatewaySenderConfigurer gatewaySenderConfigurer = getBean(TestGatewaySenderConfigurer.class);
|
||||
|
||||
GatewaySender gatewaySender = this.applicationContext.getBean("TestGatewaySender", GatewaySender.class);
|
||||
GatewaySender gatewaySender = getBean("TestGatewaySender", GatewaySender.class);
|
||||
|
||||
assertThat(gatewaySender.isManualStart()).isEqualTo(true);
|
||||
assertThat(gatewaySender.getRemoteDSId()).isEqualTo(2);
|
||||
@@ -169,7 +157,7 @@ public class GatewaySenderConfigurationIntegrationTests extends IntegrationTests
|
||||
assertThat(gatewaySender.getDiskStoreName()).isEqualTo("someDiskStore");
|
||||
assertThat(gatewaySender.getOrderPolicy()).isEqualTo(GatewaySender.OrderPolicy.PARTITION);
|
||||
assertThat(gatewaySender.getGatewayEventFilters())
|
||||
.containsExactlyInAnyOrder(this.applicationContext.getBean("SomeEventFilter", GatewayEventFilter.class));
|
||||
.containsExactlyInAnyOrder(getBean("SomeEventFilter", GatewayEventFilter.class));
|
||||
assertThat(((TestGatewayEventSubstitutionFilter) gatewaySender.getGatewayEventSubstitutionFilter()).name)
|
||||
.isEqualTo("SomeEventSubstitutionFilter");
|
||||
assertThat(gatewaySender.getAlertThreshold()).isEqualTo(1234);
|
||||
@@ -183,8 +171,8 @@ public class GatewaySenderConfigurationIntegrationTests extends IntegrationTests
|
||||
assertThat(gatewaySenderConfigurer.beanNames.get(gatewaySender.getId()).toArray())
|
||||
.isEqualTo(new String[] { "transportBean2", "transportBean1" });
|
||||
|
||||
Region<?, ?> region1 = this.applicationContext.getBean("Region1", Region.class);
|
||||
Region<?, ?> region2 = this.applicationContext.getBean("Region2", Region.class);
|
||||
Region<?, ?> region1 = getBean("Region1", Region.class);
|
||||
Region<?, ?> region2 = getBean("Region2", Region.class);
|
||||
|
||||
assertThat(region1.getAttributes().getGatewaySenderIds()).containsExactlyInAnyOrder("TestGatewaySender");
|
||||
assertThat(region2.getAttributes().getGatewaySenderIds()).containsExactlyInAnyOrder("TestGatewaySender");
|
||||
@@ -193,13 +181,13 @@ public class GatewaySenderConfigurationIntegrationTests extends IntegrationTests
|
||||
@Test
|
||||
public void annotationConfigurationOfMultipleGatewaySendersWithOverrides() {
|
||||
|
||||
this.applicationContext = newApplicationContext(BaseGatewaySenderTestConfiguration.class,
|
||||
newApplicationContext(BaseGatewaySenderTestConfiguration.class,
|
||||
TestConfigurationOfMultipleGatewaySenderAnnotationsWithOverrides.class);
|
||||
|
||||
TestGatewaySenderConfigurer gatewaySenderConfigurer =
|
||||
this.applicationContext.getBean("gatewayConfigurer", TestGatewaySenderConfigurer.class);
|
||||
getBean("gatewayConfigurer", TestGatewaySenderConfigurer.class);
|
||||
|
||||
Map<String, GatewaySender> beansOfType = this.applicationContext.getBeansOfType(GatewaySender.class);
|
||||
Map<String, GatewaySender> beansOfType = getBeansOfType(GatewaySender.class);
|
||||
|
||||
String[] senders = new String[] { "TestGatewaySender", "TestGatewaySender2" };
|
||||
|
||||
@@ -208,7 +196,7 @@ public class GatewaySenderConfigurationIntegrationTests extends IntegrationTests
|
||||
|
||||
for (String sender : senders) {
|
||||
|
||||
GatewaySender gatewaySender = this.applicationContext.getBean(sender, GatewaySender.class);
|
||||
GatewaySender gatewaySender = getBean(sender, GatewaySender.class);
|
||||
|
||||
assertThat(gatewaySender.isManualStart()).isEqualTo(true);
|
||||
assertThat(gatewaySender.getRemoteDSId()).isEqualTo(2);
|
||||
@@ -228,36 +216,26 @@ public class GatewaySenderConfigurationIntegrationTests extends IntegrationTests
|
||||
assertThat(gatewaySender.getSocketBufferSize()).isEqualTo(16384);
|
||||
}
|
||||
|
||||
GatewaySender gatewaySender = this.applicationContext.getBean("TestGatewaySender", GatewaySender.class);
|
||||
GatewaySender gatewaySender = getBean("TestGatewaySender", GatewaySender.class);
|
||||
|
||||
assertThat(gatewaySender.getGatewayTransportFilters().size()).isEqualTo(1);
|
||||
assertThat(((GatewaySenderConfigurationIntegrationTests.TestGatewayTransportFilter) gatewaySender
|
||||
.getGatewayTransportFilters().get(0)).name).isEqualTo("transportBean1");
|
||||
|
||||
gatewaySender = this.applicationContext.getBean("TestGatewaySender2", GatewaySender.class);
|
||||
gatewaySender = getBean("TestGatewaySender2", GatewaySender.class);
|
||||
|
||||
assertThat(gatewaySender.getGatewayTransportFilters().size()).isEqualTo(2);
|
||||
assertThat(gatewaySenderConfigurer.beanNames.get(gatewaySender.getId()).toArray())
|
||||
.isEqualTo(new String[] { "transportBean2", "transportBean1" });
|
||||
|
||||
Region<?, ?> region1 = this.applicationContext.getBean("Region1", Region.class);
|
||||
Region<?, ?> region2 = this.applicationContext.getBean("Region2", Region.class);
|
||||
Region<?, ?> region1 = getBean("Region1", Region.class);
|
||||
Region<?, ?> region2 = getBean("Region2", Region.class);
|
||||
|
||||
assertThat(region1.getAttributes().getGatewaySenderIds()).containsExactlyInAnyOrder("TestGatewaySender2");
|
||||
assertThat(region2.getAttributes().getGatewaySenderIds())
|
||||
.containsExactlyInAnyOrder("TestGatewaySender", "TestGatewaySender2");
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(Class<?>... annotatedClasses) {
|
||||
|
||||
AnnotationConfigApplicationContext applicationContext =
|
||||
new AnnotationConfigApplicationContext(annotatedClasses);
|
||||
|
||||
applicationContext.registerShutdownHook();
|
||||
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
@EnableGatewaySenders(gatewaySenders = {
|
||||
@EnableGatewaySender(name = "TestGatewaySender", manualStart = true, remoteDistributedSystemId = 2,
|
||||
diskSynchronous = true, batchConflationEnabled = true, parallel = true, persistent = false,
|
||||
|
||||
@@ -20,9 +20,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.geode.cache.EntryEvent;
|
||||
@@ -35,13 +34,12 @@ import org.apache.geode.cache.wan.GatewaySender;
|
||||
import org.apache.geode.cache.wan.GatewayTransportFilter;
|
||||
|
||||
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.core.env.MutablePropertySources;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
|
||||
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;
|
||||
|
||||
@@ -49,45 +47,40 @@ import org.springframework.mock.env.MockPropertySource;
|
||||
* Tests for {@link EnableGatewaySenders} and {@link EnableGatewaySender}.
|
||||
*
|
||||
* @author Udo Kohlmeyer
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.apache.geode.cache.GemFireCache
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.apache.geode.cache.wan.GatewaySender
|
||||
* @see org.springframework.context.annotation.Configuration
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableGatewaySender
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableGatewaySenders
|
||||
* @see org.springframework.data.gemfire.config.annotation.GatewaySenderConfiguration
|
||||
* @see org.springframework.data.gemfire.config.annotation.GatewaySendersConfiguration
|
||||
* @see org.springframework.data.gemfire.config.annotation.GatewaySenderConfigurer
|
||||
* @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.data.gemfire.wan.GatewaySenderFactoryBean
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 2.2.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class GatewaySenderConfigurerTests extends IntegrationTestsSupport {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@After
|
||||
public void shutdown() {
|
||||
Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close);
|
||||
}
|
||||
public class GatewaySenderConfigurerTests extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(PropertySource<?> testPropertySource,
|
||||
Class<?>... annotatedClasses) {
|
||||
|
||||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
|
||||
Function<ConfigurableApplicationContext, ConfigurableApplicationContext> 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);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -104,11 +97,10 @@ public class GatewaySenderConfigurerTests extends IntegrationTestsSupport {
|
||||
testPropertySource.setProperty("spring.data.gemfire.gateway.sender.TestGatewaySender2.socket-read-timeout", 4000);
|
||||
testPropertySource.setProperty("spring.data.gemfire.gateway.sender.socket-buffer-size", 16384);
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource,
|
||||
BaseGatewaySenderTestConfiguration.class,
|
||||
newApplicationContext(testPropertySource, BaseGatewaySenderTestConfiguration.class,
|
||||
TestTwoGatewaySenderConfigurersBasic.class);
|
||||
|
||||
Map<String, GatewaySender> beansOfType = this.applicationContext.getBeansOfType(GatewaySender.class);
|
||||
Map<String, GatewaySender> beansOfType = getBeansOfType(GatewaySender.class);
|
||||
|
||||
String[] senders = new String[] { "TestGatewaySender", "TestGatewaySender2" };
|
||||
|
||||
@@ -117,7 +109,7 @@ public class GatewaySenderConfigurerTests extends IntegrationTestsSupport {
|
||||
|
||||
for (String sender : senders) {
|
||||
|
||||
GatewaySender gatewaySender = this.applicationContext.getBean(sender, GatewaySender.class);
|
||||
GatewaySender gatewaySender = getBean(sender, GatewaySender.class);
|
||||
|
||||
assertThat(gatewaySender.isManualStart()).isEqualTo(false);
|
||||
assertThat(gatewaySender.getRemoteDSId()).isEqualTo(2);
|
||||
@@ -137,8 +129,8 @@ public class GatewaySenderConfigurerTests extends IntegrationTestsSupport {
|
||||
|
||||
assertThat(gatewaySender.getGatewayTransportFilters().size()).isEqualTo(0);
|
||||
|
||||
Region<?, ?> region1 = this.applicationContext.getBean("Region1", Region.class);
|
||||
Region<?, ?> region2 = this.applicationContext.getBean("Region2", Region.class);
|
||||
Region<?, ?> region1 = getBean("Region1", Region.class);
|
||||
Region<?, ?> region2 = getBean("Region2", Region.class);
|
||||
|
||||
assertThat(region1.getAttributes().getGatewaySenderIds())
|
||||
.containsExactlyInAnyOrder("TestGatewaySender", "TestGatewaySender2");
|
||||
|
||||
@@ -21,8 +21,8 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.TreeMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -39,12 +39,11 @@ import org.apache.geode.cache.wan.GatewaySender;
|
||||
import org.apache.geode.cache.wan.GatewayTransportFilter;
|
||||
|
||||
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.PartitionedRegionFactoryBean;
|
||||
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.wan.GatewaySenderFactoryBean;
|
||||
import org.springframework.data.gemfire.wan.OrderPolicyType;
|
||||
@@ -62,23 +61,33 @@ import org.springframework.mock.env.MockPropertySource;
|
||||
* @see org.springframework.context.annotation.Configuration
|
||||
* @see org.springframework.data.gemfire.config.annotation.GatewaySenderConfiguration
|
||||
* @see org.springframework.data.gemfire.config.annotation.GatewaySenderConfigurer
|
||||
* @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.data.gemfire.wan.GatewaySenderFactoryBean
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSupport {
|
||||
public class GatewaySenderPropertiesIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
private ConfigurableApplicationContext newApplicationContext(PropertySource<?> testPropertySource,
|
||||
Class<?>... annotatedClasses) {
|
||||
|
||||
Function<ConfigurableApplicationContext, ConfigurableApplicationContext> applicationContextInitializer =
|
||||
applicationContext -> {
|
||||
|
||||
MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources();
|
||||
|
||||
propertySources.addFirst(testPropertySource);
|
||||
|
||||
return applicationContext;
|
||||
};
|
||||
|
||||
return newApplicationContext(applicationContextInitializer, annotatedClasses);
|
||||
}
|
||||
|
||||
@After
|
||||
public void shutdown() {
|
||||
|
||||
Optional.ofNullable(this.applicationContext)
|
||||
.ifPresent(ConfigurableApplicationContext::close);
|
||||
|
||||
public void cleanupAfterTests() {
|
||||
destroyAllGemFireMockObjects();
|
||||
}
|
||||
|
||||
@@ -129,13 +138,12 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup
|
||||
"transportBean1")
|
||||
.withProperty("spring.data.gemfire.gateway.sender.TestGatewaySender2.regions", "Region1");
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, BaseGatewaySenderTestConfiguration.class,
|
||||
newApplicationContext(testPropertySource, BaseGatewaySenderTestConfiguration.class,
|
||||
TestConfigurationWithPropertiesMultipleGatewaySenders.class);
|
||||
|
||||
TestGatewaySenderConfigurer gatewaySenderConfigurer =
|
||||
this.applicationContext.getBean(TestGatewaySenderConfigurer.class);
|
||||
TestGatewaySenderConfigurer gatewaySenderConfigurer = getBean(TestGatewaySenderConfigurer.class);
|
||||
|
||||
GatewaySender gatewaySender = this.applicationContext.getBean("TestGatewaySender", GatewaySender.class);
|
||||
GatewaySender gatewaySender = getBean("TestGatewaySender", GatewaySender.class);
|
||||
|
||||
assertThat(gatewaySender.isManualStart()).isEqualTo(true);
|
||||
assertThat(gatewaySender.getRemoteDSId()).isEqualTo(2);
|
||||
@@ -159,7 +167,7 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup
|
||||
assertThat(gatewaySenderConfigurer.beanNames.get(gatewaySender.getId()).toArray())
|
||||
.isEqualTo(new String[] { "transportBean2", "transportBean1" });
|
||||
|
||||
gatewaySender = this.applicationContext.getBean("TestGatewaySender2", GatewaySender.class);
|
||||
gatewaySender = getBean("TestGatewaySender2", GatewaySender.class);
|
||||
|
||||
assertThat(gatewaySender.isManualStart()).isEqualTo(false);
|
||||
assertThat(gatewaySender.getRemoteDSId()).isEqualTo(3);
|
||||
@@ -183,14 +191,12 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup
|
||||
assertThat(gatewaySenderConfigurer.beanNames.get(gatewaySender.getId()).toArray())
|
||||
.isEqualTo(new String[] { "transportBean1" });
|
||||
|
||||
Region<?, ?> region1 = this.applicationContext.getBean("Region1", Region.class);
|
||||
Region<?, ?> region2 = this.applicationContext.getBean("Region2", Region.class);
|
||||
Region<?, ?> region1 = getBean("Region1", Region.class);
|
||||
Region<?, ?> region2 = getBean("Region2", Region.class);
|
||||
|
||||
assertThat(region1.getAttributes().getGatewaySenderIds())
|
||||
.containsExactlyInAnyOrder("TestGatewaySender", "TestGatewaySender2");
|
||||
assertThat(region2.getAttributes().getGatewaySenderIds())
|
||||
.containsExactlyInAnyOrder("TestGatewaySender");
|
||||
|
||||
assertThat(region2.getAttributes().getGatewaySenderIds()) .containsExactlyInAnyOrder("TestGatewaySender");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -240,13 +246,12 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup
|
||||
"transportBean1")
|
||||
.withProperty("spring.data.gemfire.gateway.sender.TestGatewaySender2.regions", "");
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, BaseGatewaySenderTestConfiguration.class,
|
||||
newApplicationContext(testPropertySource, BaseGatewaySenderTestConfiguration.class,
|
||||
TestConfigurationWithMultipleGatewaySenderAnnotations.class);
|
||||
|
||||
TestGatewaySenderConfigurer gatewaySenderConfigurer =
|
||||
this.applicationContext.getBean(TestGatewaySenderConfigurer.class);
|
||||
TestGatewaySenderConfigurer gatewaySenderConfigurer = getBean(TestGatewaySenderConfigurer.class);
|
||||
|
||||
GatewaySender gatewaySender = this.applicationContext.getBean("TestGatewaySender", GatewaySender.class);
|
||||
GatewaySender gatewaySender = getBean("TestGatewaySender", GatewaySender.class);
|
||||
|
||||
assertThat(gatewaySender.isManualStart()).isEqualTo(true);
|
||||
assertThat(gatewaySender.getRemoteDSId()).isEqualTo(2);
|
||||
@@ -270,7 +275,7 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup
|
||||
assertThat(gatewaySenderConfigurer.beanNames.get(gatewaySender.getId()).toArray())
|
||||
.isEqualTo(new String[] { "transportBean2", "transportBean1" });
|
||||
|
||||
gatewaySender = this.applicationContext.getBean("TestGatewaySender2", GatewaySender.class);
|
||||
gatewaySender = getBean("TestGatewaySender2", GatewaySender.class);
|
||||
|
||||
assertThat(gatewaySender.isManualStart()).isEqualTo(false);
|
||||
assertThat(gatewaySender.getRemoteDSId()).isEqualTo(3);
|
||||
@@ -294,14 +299,13 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup
|
||||
assertThat(gatewaySenderConfigurer.beanNames.get(gatewaySender.getId()).toArray())
|
||||
.isEqualTo(new String[] { "transportBean1" });
|
||||
|
||||
Region<?, ?> region1 = this.applicationContext.getBean("Region1", Region.class);
|
||||
Region<?, ?> region2 = this.applicationContext.getBean("Region2", Region.class);
|
||||
Region<?, ?> region1 = getBean("Region1", Region.class);
|
||||
Region<?, ?> region2 = getBean("Region2", Region.class);
|
||||
|
||||
assertThat(region1.getAttributes().getGatewaySenderIds())
|
||||
.containsExactlyInAnyOrder("TestGatewaySender", "TestGatewaySender2");
|
||||
assertThat(region2.getAttributes().getGatewaySenderIds())
|
||||
.containsExactlyInAnyOrder("TestGatewaySender", "TestGatewaySender2");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -330,13 +334,12 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup
|
||||
"transportBean2, transportBean1")
|
||||
.withProperty("spring.data.gemfire.gateway.sender.TestGatewaySender.regions", "Region1,Region2");
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, BaseGatewaySenderTestConfiguration.class,
|
||||
newApplicationContext(testPropertySource, BaseGatewaySenderTestConfiguration.class,
|
||||
TestConfigurationWithProperties.class);
|
||||
|
||||
TestGatewaySenderConfigurer gatewaySenderConfigurer =
|
||||
this.applicationContext.getBean(TestGatewaySenderConfigurer.class);
|
||||
TestGatewaySenderConfigurer gatewaySenderConfigurer = getBean(TestGatewaySenderConfigurer.class);
|
||||
|
||||
GatewaySender gatewaySender = this.applicationContext.getBean("TestGatewaySender", GatewaySender.class);
|
||||
GatewaySender gatewaySender = getBean("TestGatewaySender", GatewaySender.class);
|
||||
|
||||
assertThat(gatewaySender.isManualStart()).isEqualTo(true);
|
||||
assertThat(gatewaySender.getRemoteDSId()).isEqualTo(2);
|
||||
@@ -360,14 +363,11 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup
|
||||
assertThat(gatewaySenderConfigurer.beanNames.get(gatewaySender.getId()).toArray())
|
||||
.isEqualTo(new String[] { "transportBean2", "transportBean1" });
|
||||
|
||||
Region<?, ?> region1 = this.applicationContext.getBean("Region1", Region.class);
|
||||
Region<?, ?> region2 = this.applicationContext.getBean("Region2", Region.class);
|
||||
|
||||
assertThat(region1.getAttributes().getGatewaySenderIds())
|
||||
.containsExactlyInAnyOrder("TestGatewaySender");
|
||||
assertThat(region2.getAttributes().getGatewaySenderIds())
|
||||
.containsExactlyInAnyOrder("TestGatewaySender");
|
||||
Region<?, ?> region1 = getBean("Region1", Region.class);
|
||||
Region<?, ?> region2 = getBean("Region2", Region.class);
|
||||
|
||||
assertThat(region1.getAttributes().getGatewaySenderIds()).containsExactlyInAnyOrder("TestGatewaySender");
|
||||
assertThat(region2.getAttributes().getGatewaySenderIds()).containsExactlyInAnyOrder("TestGatewaySender");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -396,13 +396,12 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup
|
||||
"transportBean2, transportBean1")
|
||||
.withProperty("spring.data.gemfire.gateway.sender.regions", "Region1,Region2");
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, BaseGatewaySenderTestConfiguration.class,
|
||||
newApplicationContext(testPropertySource, BaseGatewaySenderTestConfiguration.class,
|
||||
TestConfigurationWithProperties.class);
|
||||
|
||||
TestGatewaySenderConfigurer gatewaySenderConfigurer =
|
||||
this.applicationContext.getBean(TestGatewaySenderConfigurer.class);
|
||||
TestGatewaySenderConfigurer gatewaySenderConfigurer = getBean(TestGatewaySenderConfigurer.class);
|
||||
|
||||
GatewaySender gatewaySender = this.applicationContext.getBean("TestGatewaySender", GatewaySender.class);
|
||||
GatewaySender gatewaySender = getBean("TestGatewaySender", GatewaySender.class);
|
||||
|
||||
assertThat(gatewaySender.isManualStart()).isEqualTo(true);
|
||||
assertThat(gatewaySender.getRemoteDSId()).isEqualTo(2);
|
||||
@@ -426,14 +425,11 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup
|
||||
assertThat(gatewaySenderConfigurer.beanNames.get(gatewaySender.getId()).toArray())
|
||||
.isEqualTo(new String[] { "transportBean2", "transportBean1" });
|
||||
|
||||
Region<?, ?> region1 = this.applicationContext.getBean("Region1", Region.class);
|
||||
Region<?, ?> region2 = this.applicationContext.getBean("Region2", Region.class);
|
||||
|
||||
assertThat(region1.getAttributes().getGatewaySenderIds())
|
||||
.containsExactlyInAnyOrder("TestGatewaySender");
|
||||
assertThat(region2.getAttributes().getGatewaySenderIds())
|
||||
.containsExactlyInAnyOrder("TestGatewaySender");
|
||||
Region<?, ?> region1 = getBean("Region1", Region.class);
|
||||
Region<?, ?> region2 = getBean("Region2", Region.class);
|
||||
|
||||
assertThat(region1.getAttributes().getGatewaySenderIds()).containsExactlyInAnyOrder("TestGatewaySender");
|
||||
assertThat(region2.getAttributes().getGatewaySenderIds()).containsExactlyInAnyOrder("TestGatewaySender");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -463,13 +459,12 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup
|
||||
"transportBean2, transportBean1")
|
||||
.withProperty("spring.data.gemfire.gateway.sender.regions", "Region1,Region2");
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, BaseGatewaySenderTestConfiguration.class,
|
||||
newApplicationContext(testPropertySource, BaseGatewaySenderTestConfiguration.class,
|
||||
TestConfigurationWithProperties.class);
|
||||
|
||||
TestGatewaySenderConfigurer gatewaySenderConfigurer =
|
||||
this.applicationContext.getBean(TestGatewaySenderConfigurer.class);
|
||||
TestGatewaySenderConfigurer gatewaySenderConfigurer = getBean(TestGatewaySenderConfigurer.class);
|
||||
|
||||
GatewaySender gatewaySender = this.applicationContext.getBean("TestGatewaySender", GatewaySender.class);
|
||||
GatewaySender gatewaySender = getBean("TestGatewaySender", GatewaySender.class);
|
||||
|
||||
assertThat(gatewaySender.isManualStart()).isEqualTo(false);
|
||||
assertThat(gatewaySender.getRemoteDSId()).isEqualTo(2);
|
||||
@@ -493,30 +488,11 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup
|
||||
assertThat(gatewaySenderConfigurer.beanNames.get(gatewaySender.getId()).toArray())
|
||||
.isEqualTo(new String[] { "transportBean2", "transportBean1" });
|
||||
|
||||
Region<?, ?> region1 = this.applicationContext.getBean("Region1", Region.class);
|
||||
Region<?, ?> region2 = this.applicationContext.getBean("Region2", Region.class);
|
||||
Region<?, ?> region1 = getBean("Region1", Region.class);
|
||||
Region<?, ?> region2 = getBean("Region2", Region.class);
|
||||
|
||||
assertThat(region1.getAttributes().getGatewaySenderIds())
|
||||
.containsExactlyInAnyOrder("TestGatewaySender");
|
||||
assertThat(region2.getAttributes().getGatewaySenderIds())
|
||||
.containsExactlyInAnyOrder("TestGatewaySender");
|
||||
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(PropertySource<?> testPropertySource,
|
||||
Class<?>... annotatedClasses) {
|
||||
|
||||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
|
||||
|
||||
MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources();
|
||||
|
||||
propertySources.addFirst(testPropertySource);
|
||||
|
||||
applicationContext.registerShutdownHook();
|
||||
applicationContext.register(annotatedClasses);
|
||||
applicationContext.refresh();
|
||||
|
||||
return applicationContext;
|
||||
assertThat(region1.getAttributes().getGatewaySenderIds()).containsExactlyInAnyOrder("TestGatewaySender");
|
||||
assertThat(region2.getAttributes().getGatewaySenderIds()).containsExactlyInAnyOrder("TestGatewaySender");
|
||||
}
|
||||
|
||||
@EnableGatewaySenders(gatewaySenders = {
|
||||
|
||||
@@ -21,21 +21,20 @@ import static org.mockito.Mockito.mock;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.lucene.LuceneIndex;
|
||||
import org.apache.geode.cache.lucene.LuceneService;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
@@ -47,7 +46,10 @@ import org.springframework.data.gemfire.mapping.annotation.ClientRegion;
|
||||
import org.springframework.data.gemfire.mapping.annotation.LocalRegion;
|
||||
import org.springframework.data.gemfire.mapping.annotation.ReplicateRegion;
|
||||
import org.springframework.data.gemfire.search.lucene.LuceneIndexFactoryBean;
|
||||
import org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor;
|
||||
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.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Integration Tests for {@link IndexConfigurer}.
|
||||
@@ -57,21 +59,26 @@ import org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireM
|
||||
* @see org.apache.geode.cache.GemFireCache
|
||||
* @see org.apache.geode.cache.lucene.LuceneIndex
|
||||
* @see org.apache.geode.cache.query.Index
|
||||
* @see org.springframework.context.ApplicationContext
|
||||
* @see org.springframework.data.gemfire.IndexFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.annotation.IndexConfigurer
|
||||
* @see org.springframework.data.gemfire.search.lucene.LuceneIndexFactoryBean
|
||||
* @see org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class IndexConfigurerIntegrationTests {
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
public class IndexConfigurerIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
private static ConfigurableApplicationContext applicationContext;
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
|
||||
applicationContext = newApplicationContext(TestConfiguration.class);
|
||||
@Before
|
||||
public void setup() {
|
||||
|
||||
assertThat(applicationContext).isNotNull();
|
||||
assertThat(applicationContext.containsBean("CustomersFirstNameFunctionalIdx")).isTrue();
|
||||
@@ -83,20 +90,8 @@ public class IndexConfigurerIntegrationTests {
|
||||
assertThat(applicationContext.containsBean("TitleLuceneIdx")).isTrue();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() {
|
||||
Optional.ofNullable(applicationContext).ifPresent(ConfigurableApplicationContext::close);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private static ConfigurableApplicationContext newApplicationContext(Class<?>... annotatedClasses) {
|
||||
ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(annotatedClasses);
|
||||
applicationContext.registerShutdownHook();
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private void assertIndexConfigurerInvocations(TestIndexConfigurer indexConfigurer, String... indexBeanNames) {
|
||||
|
||||
assertThat(indexConfigurer).isNotNull();
|
||||
assertThat(indexConfigurer).contains(indexBeanNames);
|
||||
assertThat(indexConfigurer).hasSize(indexBeanNames.length);
|
||||
@@ -121,7 +116,6 @@ public class IndexConfigurerIntegrationTests {
|
||||
}
|
||||
|
||||
@PeerCacheApplication
|
||||
@EnableIndexing
|
||||
@EnableEntityDefinedRegions(basePackageClasses = NonEntity.class,
|
||||
excludeFilters = {
|
||||
@ComponentScan.Filter(type = FilterType.ANNOTATION,
|
||||
@@ -130,6 +124,8 @@ public class IndexConfigurerIntegrationTests {
|
||||
classes = CollocatedPartitionRegionEntity.class)
|
||||
}
|
||||
)
|
||||
@EnableIndexing
|
||||
@EnableGemFireMockObjects
|
||||
static class TestConfiguration {
|
||||
|
||||
@Bean("LoyalCustomers")
|
||||
@@ -144,11 +140,6 @@ public class IndexConfigurerIntegrationTests {
|
||||
return localRegion;
|
||||
}
|
||||
|
||||
@Bean
|
||||
GemFireMockObjectsBeanPostProcessor testBeanPostProcessor() {
|
||||
return new GemFireMockObjectsBeanPostProcessor();
|
||||
}
|
||||
|
||||
@Bean
|
||||
BeanPostProcessor indexFactoryBeanReplacingBeanPostProcessor() {
|
||||
|
||||
@@ -158,6 +149,7 @@ public class IndexConfigurerIntegrationTests {
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
|
||||
if (bean instanceof LuceneIndexFactoryBean) {
|
||||
|
||||
LuceneIndexFactoryBean luceneIndexFactoryBean = (LuceneIndexFactoryBean) bean;
|
||||
LuceneService mockLuceneService = mock(LuceneService.class);
|
||||
LuceneIndex mockLuceneIndex = mock(LuceneIndex.class);
|
||||
|
||||
@@ -19,9 +19,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Fail.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
@@ -29,10 +26,8 @@ import org.apache.geode.cache.client.ClientCache;
|
||||
import org.apache.geode.distributed.Locator;
|
||||
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -50,43 +45,26 @@ import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockO
|
||||
* @see org.springframework.data.gemfire.config.annotation.LocatorApplicationConfiguration
|
||||
* @see org.springframework.context.ConfigurableApplicationContext
|
||||
* @see org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
* @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
|
||||
* @since 2.2.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class LocatorApplicationCannotCoexistWithCacheApplicationIntegrationTests extends IntegrationTestsSupport {
|
||||
public class LocatorApplicationCannotCoexistWithCacheApplicationIntegrationTests
|
||||
extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
private static final String GEMFIRE_LOG_LEVEL = "error";
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private void testCacheAndLocatorApplication(Class<?> testConfiguration) {
|
||||
|
||||
try {
|
||||
|
||||
this.applicationContext = newApplicationContext(testConfiguration);
|
||||
this.applicationContext.getBean(GemFireCache.class);
|
||||
this.applicationContext.getBean(Locator.class);
|
||||
newApplicationContext(testConfiguration);
|
||||
getBean(GemFireCache.class);
|
||||
getBean(Locator.class);
|
||||
|
||||
fail("Caches and Locators cannot coexist!");
|
||||
|
||||
}
|
||||
catch (BeanDefinitionStoreException expected) {
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.apache.geode.distributed.Locator;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.gemfire.GemfireUtils;
|
||||
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
@@ -52,6 +53,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @since 2.2.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
@SuppressWarnings("unused")
|
||||
public class LocatorApplicationIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
@@ -76,6 +78,10 @@ public class LocatorApplicationIntegrationTests extends IntegrationTestsSupport
|
||||
|
||||
Cache peerCache = null;
|
||||
|
||||
assertThat(distributedSystemProperties.getProperty("locators"))
|
||||
.describedAs("Locators was [%s]", distributedSystemProperties.getProperty("locators"))
|
||||
.isNotEmpty();
|
||||
|
||||
try {
|
||||
peerCache = new CacheFactory()
|
||||
.set("name", LocatorApplicationIntegrationTests.class.getSimpleName())
|
||||
@@ -83,6 +89,7 @@ public class LocatorApplicationIntegrationTests extends IntegrationTestsSupport
|
||||
.set("cache-xml-file", distributedSystemProperties.getProperty("cache-xml-file"))
|
||||
.set("jmx-manager", distributedSystemProperties.getProperty("jmx-manager"))
|
||||
.set("locators", distributedSystemProperties.getProperty("locators"))
|
||||
//.set("locators", "localhost[0]") // This locators configuration setting causes the test to fail
|
||||
.set("log-file", distributedSystemProperties.getProperty("log-file"))
|
||||
.set("log-level", distributedSystemProperties.getProperty("log-level"))
|
||||
.create();
|
||||
|
||||
@@ -19,10 +19,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
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.distributed.Locator;
|
||||
@@ -30,12 +29,11 @@ import org.apache.geode.distributed.Locator;
|
||||
import org.springframework.beans.BeansException;
|
||||
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.core.env.MutablePropertySources;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.data.gemfire.LocatorFactoryBean;
|
||||
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.lang.Nullable;
|
||||
import org.springframework.mock.env.MockPropertySource;
|
||||
@@ -48,39 +46,31 @@ import org.springframework.mock.env.MockPropertySource;
|
||||
* @see java.util.Properties
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.distributed.Locator
|
||||
\ * @see org.springframework.core.env.PropertySource
|
||||
* @see org.springframework.context.ConfigurableApplicationContext
|
||||
* @see org.springframework.core.env.PropertySource
|
||||
* @see org.springframework.data.gemfire.LocatorFactoryBean
|
||||
* @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.2.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class LocatorApplicationPropertiesIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
|
||||
Optional.ofNullable(this.applicationContext)
|
||||
.ifPresent(ConfigurableApplicationContext::close);
|
||||
}
|
||||
public class LocatorApplicationPropertiesIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(PropertySource<?> testPropertySource,
|
||||
Class<?>... annotatedClasses) {
|
||||
Class<?>... annotatedClasses) {
|
||||
|
||||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
|
||||
Function<ConfigurableApplicationContext, ConfigurableApplicationContext> 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
|
||||
@@ -94,9 +84,9 @@ public class LocatorApplicationPropertiesIntegrationTests extends IntegrationTes
|
||||
.withProperty("spring.data.gemfire.locator.port", 54321)
|
||||
.withProperty("spring.data.gemfire.locators", "host1[1234],host2[6789]");
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, TestConfiguration.class);
|
||||
newApplicationContext(testPropertySource, TestConfiguration.class);
|
||||
|
||||
LocatorFactoryBean locatorFactoryBean = this.applicationContext.getBean(LocatorFactoryBean.class);
|
||||
LocatorFactoryBean locatorFactoryBean = getBean(LocatorFactoryBean.class);
|
||||
|
||||
assertThat(locatorFactoryBean).isNotNull();
|
||||
assertThat(locatorFactoryBean.getBindAddress().orElse(null)).isEqualTo("10.120.240.32");
|
||||
|
||||
@@ -31,10 +31,9 @@ import org.junit.Test;
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.core.env.PropertiesPropertySource;
|
||||
import org.springframework.data.gemfire.GemFireProperties;
|
||||
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
|
||||
import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport;
|
||||
import org.springframework.data.gemfire.util.ArrayUtils;
|
||||
import org.springframework.data.gemfire.util.PropertiesBuilder;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -51,36 +50,23 @@ import org.springframework.util.StringUtils;
|
||||
* @see org.springframework.core.env.PropertiesPropertySource
|
||||
* @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableLogging
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.util.PropertiesBuilder
|
||||
* @since 1.9.0
|
||||
*/
|
||||
public class LoggingConfigurationIntegrationTests extends IntegrationTestsSupport {
|
||||
public class LoggingConfigurationIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
private final AtomicReference<Properties> propertiesReference = new AtomicReference<>(null);
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
|
||||
@Before @After
|
||||
public void setupAndTearDown() {
|
||||
this.propertiesReference.set(null);
|
||||
|
||||
deleteLogFiles();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
|
||||
Optional.ofNullable(this.applicationContext)
|
||||
.ifPresent(ConfigurableApplicationContext::close);
|
||||
|
||||
deleteLogFiles();
|
||||
}
|
||||
|
||||
private void assertGemFireCacheLogLevelAndLogFile(String logLevel, String logFile) {
|
||||
|
||||
GemFireCache gemfireCache = this.applicationContext.getBean(GemFireCache.class);
|
||||
GemFireCache gemfireCache = getBean(GemFireCache.class);
|
||||
|
||||
logFile = StringUtils.hasText(logFile) ? logFile : "";
|
||||
|
||||
@@ -104,23 +90,15 @@ public class LoggingConfigurationIntegrationTests extends IntegrationTestsSuppor
|
||||
Arrays.stream(ArrayUtils.nullSafeArray(files, File.class)).forEach(File::delete);
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(Class<?>... annotatedClasses) {
|
||||
|
||||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
|
||||
|
||||
applicationContext.register(annotatedClasses);
|
||||
applicationContext.registerShutdownHook();
|
||||
@Override
|
||||
protected ConfigurableApplicationContext processBeforeRefresh(ConfigurableApplicationContext applicationContext) {
|
||||
|
||||
Optional.ofNullable(this.propertiesReference.get())
|
||||
.ifPresent(properties -> applicationContext.getEnvironment()
|
||||
.getPropertySources()
|
||||
.addFirst(new PropertiesPropertySource("Test Properties", properties)));
|
||||
|
||||
applicationContext.refresh();
|
||||
|
||||
this.applicationContext = applicationContext;
|
||||
|
||||
return applicationContext;
|
||||
return super.processBeforeRefresh(applicationContext);
|
||||
}
|
||||
|
||||
private void with(Properties properties) {
|
||||
|
||||
@@ -117,7 +117,7 @@ public class PeerCacheApplicationWithAddedCacheServerIntegrationTests
|
||||
static class TestLocatorConfiguration {
|
||||
|
||||
public static void main(String[] args) {
|
||||
runSpringApplication(TestLocatorConfiguration.class);
|
||||
runSpringApplication(TestLocatorConfiguration.class, args);
|
||||
block();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.Cache;
|
||||
@@ -29,12 +28,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.CacheFactoryBean;
|
||||
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;
|
||||
|
||||
@@ -49,35 +47,27 @@ import org.springframework.mock.env.MockPropertySource;
|
||||
* @see org.springframework.core.env.PropertySource
|
||||
* @see org.springframework.data.gemfire.CacheFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.annotation.PeerCacheApplication
|
||||
* @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
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class PeerCachePropertiesIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close);
|
||||
}
|
||||
public class PeerCachePropertiesIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(PropertySource<?> testPropertySource,
|
||||
Class<?>... annotatedClasses) {
|
||||
Class<?>... annotatedClasses) {
|
||||
|
||||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
|
||||
Function<ConfigurableApplicationContext, ConfigurableApplicationContext> 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
|
||||
@@ -95,15 +85,14 @@ public class PeerCachePropertiesIntegrationTests extends IntegrationTestsSupport
|
||||
.withProperty("spring.data.gemfire.pdx.ignore-unread-fields", false)
|
||||
.withProperty("spring.data.gemfire.pdx.persistent", true);
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, TestPeerCacheConfiguration.class);
|
||||
newApplicationContext(testPropertySource, TestPeerCacheConfiguration.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();
|
||||
|
||||
Cache testPeerCache = this.applicationContext.getBean("gemfireCache", Cache.class);
|
||||
Cache testPeerCache = getBean("gemfireCache", Cache.class);
|
||||
|
||||
PdxSerializer mockPdxSerializer = this.applicationContext.getBean("mockPdxSerializer", PdxSerializer.class);
|
||||
PdxSerializer mockPdxSerializer = getBean("mockPdxSerializer", PdxSerializer.class);
|
||||
|
||||
assertThat(testPeerCache).isNotNull();
|
||||
assertThat(mockPdxSerializer).isNotNull();
|
||||
@@ -143,14 +132,13 @@ public class PeerCachePropertiesIntegrationTests extends IntegrationTestsSupport
|
||||
.withProperty("spring.data.gemfire.cache.peer.search-timeout", 120)
|
||||
.withProperty("spring.data.gemfire.cache.peer.use-cluster-configuration", true);
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, TestDynamicPeerCacheConfiguration.class);
|
||||
newApplicationContext(testPropertySource, TestDynamicPeerCacheConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
assertThat(containsBean("gemfireCache")).isTrue();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = this.applicationContext.getBean("&gemfireCache", CacheFactoryBean.class);
|
||||
CacheFactoryBean cacheFactoryBean = getBean("&gemfireCache", CacheFactoryBean.class);
|
||||
|
||||
Cache cache = this.applicationContext.getBean("gemfireCache", Cache.class);
|
||||
Cache cache = getBean("gemfireCache", Cache.class);
|
||||
|
||||
assertThat(cacheFactoryBean).isNotNull();
|
||||
assertThat(cacheFactoryBean.isUseBeanFactoryLocator()).isTrue();
|
||||
|
||||
@@ -19,8 +19,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.geode.cache.client.ClientCache;
|
||||
@@ -29,11 +29,10 @@ import org.apache.geode.cache.client.PoolFactory;
|
||||
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.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;
|
||||
|
||||
@@ -50,34 +49,27 @@ import org.springframework.mock.env.MockPropertySource;
|
||||
* @see org.springframework.data.gemfire.config.annotation.AddPoolsConfiguration
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnablePool
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnablePools
|
||||
* @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
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class PoolPropertiesIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
closeApplicationContext(this.applicationContext);
|
||||
}
|
||||
public class PoolPropertiesIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(PropertySource<?> testPropertySource,
|
||||
Class<?>... annotatedClasses) {
|
||||
Class<?>... annotatedClasses) {
|
||||
|
||||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
|
||||
Function<ConfigurableApplicationContext, ConfigurableApplicationContext> 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 assertPool(Pool pool, int freeConnectionTimeout, long idleTimeout, int loadConditioningInterval,
|
||||
@@ -130,15 +122,14 @@ public class PoolPropertiesIntegrationTests extends IntegrationTestsSupport {
|
||||
.withProperty("spring.data.gemfire.pool.subscription-enabled", true)
|
||||
.withProperty("spring.data.gemfire.pool.TestPool.subscription-redundancy", 2);
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, TestPoolConfiguration.class);
|
||||
newApplicationContext(testPropertySource, TestPoolConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("TestPool")).isTrue();
|
||||
assertThat(containsBean("gemfireCache")).isTrue();
|
||||
assertThat(containsBean("TestPool")).isTrue();
|
||||
|
||||
Pool testPool = this.applicationContext.getBean("TestPool", Pool.class);
|
||||
Pool testPool = getBean("TestPool", Pool.class);
|
||||
|
||||
SocketFactory mockSocketFactory = this.applicationContext.getBean("mockSocketFactory", SocketFactory.class);
|
||||
SocketFactory mockSocketFactory = getBean("mockSocketFactory", SocketFactory.class);
|
||||
|
||||
assertThat(testPool).isNotNull();
|
||||
assertThat(mockSocketFactory).isNotNull();
|
||||
@@ -236,21 +227,20 @@ public class PoolPropertiesIntegrationTests extends IntegrationTestsSupport {
|
||||
.withProperty("spring.data.gemfire.pool.TestPoolTwo.subscription-redundancy", 4)
|
||||
.withProperty("spring.data.gemfire.pool.TestPoolTwo.thread-local-connections", true);
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, TestPoolsConfiguration.class);
|
||||
newApplicationContext(testPropertySource, TestPoolsConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("TestPoolOne")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("TestPoolTwo")).isTrue();
|
||||
assertThat(containsBean("gemfireCache")).isTrue();
|
||||
assertThat(containsBean("TestPoolOne")).isTrue();
|
||||
assertThat(containsBean("TestPoolTwo")).isTrue();
|
||||
|
||||
ClientCache gemfireCache = this.applicationContext.getBean(ClientCache.class);
|
||||
ClientCache gemfireCache = getBean(ClientCache.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
|
||||
Pool defaultPool = gemfireCache.getDefaultPool();
|
||||
|
||||
SocketFactory mockSocketFactoryOne = this.applicationContext.getBean("mockSocketFactoryOne", SocketFactory.class);
|
||||
SocketFactory mockSocketFactoryTwo = this.applicationContext.getBean("mockSocketFactoryTwo", SocketFactory.class);
|
||||
SocketFactory mockSocketFactoryOne = getBean("mockSocketFactoryOne", SocketFactory.class);
|
||||
SocketFactory mockSocketFactoryTwo = getBean("mockSocketFactoryTwo", SocketFactory.class);
|
||||
|
||||
assertThat(mockSocketFactoryOne).isNotNull();
|
||||
assertThat(mockSocketFactoryTwo).isNotNull();
|
||||
@@ -263,7 +253,7 @@ public class PoolPropertiesIntegrationTests extends IntegrationTestsSupport {
|
||||
true, 300000, 3,
|
||||
true);
|
||||
|
||||
Pool testPoolOne = this.applicationContext.getBean("TestPoolOne", Pool.class);
|
||||
Pool testPoolOne = getBean("TestPoolOne", Pool.class);
|
||||
|
||||
assertPool(testPoolOne, 30000, 300000L, 120000,
|
||||
500, 50, true, "TestPoolOne", 5000L,
|
||||
@@ -272,7 +262,7 @@ public class PoolPropertiesIntegrationTests extends IntegrationTestsSupport {
|
||||
true, 180000, 2,
|
||||
true);
|
||||
|
||||
Pool testPoolTwo = this.applicationContext.getBean("TestPoolTwo", Pool.class);
|
||||
Pool testPoolTwo = getBean("TestPoolTwo", Pool.class);
|
||||
|
||||
assertPool(testPoolTwo, 20000, 15000L, 60000,
|
||||
1000, 100, true, "TestPoolTwo", 20000L,
|
||||
|
||||
@@ -28,8 +28,6 @@ import org.junit.Test;
|
||||
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
|
||||
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;
|
||||
@@ -42,7 +40,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.annotation.EnableGemFireMockObjects;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
@@ -56,17 +54,14 @@ import org.springframework.util.ReflectionUtils;
|
||||
* @see org.springframework.data.gemfire.PeerRegionFactoryBean
|
||||
* @see org.springframework.data.gemfire.client.ClientRegionFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.annotation.RegionConfigurer
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor
|
||||
* @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public class RegionConfigurerIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
public class RegionConfigurerIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
closeApplicationContext(this.applicationContext);
|
||||
public void cleanupAfterTests() {
|
||||
destroyAllGemFireMockObjects();
|
||||
}
|
||||
|
||||
@@ -84,15 +79,6 @@ public class RegionConfigurerIntegrationTests extends IntegrationTestsSupport {
|
||||
.orElseGet(Collections::emptySet);
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(Class<?>... annotatedClasses) {
|
||||
|
||||
ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(annotatedClasses);
|
||||
|
||||
applicationContext.registerShutdownHook();
|
||||
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
private void assertRegionConfigurerInvocations(Iterable<String> actualRegionBeanNames,
|
||||
String... expectedRegionBeanNames) {
|
||||
|
||||
@@ -104,53 +90,45 @@ public class RegionConfigurerIntegrationTests extends IntegrationTestsSupport {
|
||||
@Test
|
||||
public void clientRegionConfigurersCalledSuccessfully() {
|
||||
|
||||
this.applicationContext = newApplicationContext(ClientTestConfiguration.class);
|
||||
newApplicationContext(ClientTestConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("Test")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("Sessions")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("GenericRegionEntity")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("testRegionConfigurerOne")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("testRegionConfigurerTwo")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("testRegionConfigurerThree")).isTrue();
|
||||
assertThat(containsBean("Test")).isTrue();
|
||||
assertThat(containsBean("Sessions")).isTrue();
|
||||
assertThat(containsBean("GenericRegionEntity")).isTrue();
|
||||
assertThat(containsBean("testRegionConfigurerOne")).isTrue();
|
||||
assertThat(containsBean("testRegionConfigurerTwo")).isTrue();
|
||||
assertThat(containsBean("testRegionConfigurerThree")).isTrue();
|
||||
|
||||
assertRegionConfigurerInvocations(
|
||||
this.applicationContext.getBean("testRegionConfigurerOne", TestRegionConfigurer.class),
|
||||
assertRegionConfigurerInvocations(getBean("testRegionConfigurerOne", TestRegionConfigurer.class),
|
||||
"GenericRegionEntity", "Sessions");
|
||||
|
||||
assertRegionConfigurerInvocations(
|
||||
this.applicationContext.getBean("testRegionConfigurerTwo", TestRegionConfigurer.class),
|
||||
assertRegionConfigurerInvocations(getBean("testRegionConfigurerTwo", TestRegionConfigurer.class),
|
||||
"GenericRegionEntity", "Sessions");
|
||||
|
||||
assertRegionConfigurerInvocations(
|
||||
resolveBeanNames(this.applicationContext.getBean("testRegionConfigurerThree", RegionConfigurer.class)),
|
||||
"GenericRegionEntity", "Sessions");
|
||||
assertRegionConfigurerInvocations(resolveBeanNames(getBean("testRegionConfigurerThree",
|
||||
RegionConfigurer.class)), "GenericRegionEntity", "Sessions");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void peerRegionConfigurersCalledSuccessfully() {
|
||||
|
||||
this.applicationContext = newApplicationContext(PeerTestConfiguration.class);
|
||||
newApplicationContext(PeerTestConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("Test")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("GenericRegionEntity")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("Customers")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("testRegionConfigurerOne")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("testRegionConfigurerTwo")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("testRegionConfigurerThree")).isTrue();
|
||||
assertThat(containsBean("Test")).isTrue();
|
||||
assertThat(containsBean("GenericRegionEntity")).isTrue();
|
||||
assertThat(containsBean("Customers")).isTrue();
|
||||
assertThat(containsBean("testRegionConfigurerOne")).isTrue();
|
||||
assertThat(containsBean("testRegionConfigurerTwo")).isTrue();
|
||||
assertThat(containsBean("testRegionConfigurerThree")).isTrue();
|
||||
|
||||
assertRegionConfigurerInvocations(
|
||||
this.applicationContext.getBean("testRegionConfigurerOne", TestRegionConfigurer.class),
|
||||
assertRegionConfigurerInvocations(getBean("testRegionConfigurerOne", TestRegionConfigurer.class),
|
||||
"Customers", "GenericRegionEntity");
|
||||
|
||||
assertRegionConfigurerInvocations(
|
||||
this.applicationContext.getBean("testRegionConfigurerTwo", TestRegionConfigurer.class),
|
||||
assertRegionConfigurerInvocations(getBean("testRegionConfigurerTwo", TestRegionConfigurer.class),
|
||||
"Customers", "GenericRegionEntity");
|
||||
|
||||
assertRegionConfigurerInvocations(
|
||||
resolveBeanNames(this.applicationContext.getBean("testRegionConfigurerThree", RegionConfigurer.class)),
|
||||
"Customers", "GenericRegionEntity");
|
||||
assertRegionConfigurerInvocations(resolveBeanNames(getBean("testRegionConfigurerThree",
|
||||
RegionConfigurer.class)),"Customers", "GenericRegionEntity");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
||||
@@ -37,7 +37,8 @@ import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.data.gemfire.GemFireProperties;
|
||||
import org.springframework.data.gemfire.support.DisableBeanDefinitionOverridingApplicationContextInitializer;
|
||||
import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects;
|
||||
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.test.context.junit4.SpringRunner;
|
||||
|
||||
@@ -57,7 +58,8 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @see org.springframework.context.annotation.Import
|
||||
* @see org.springframework.context.annotation.Profile
|
||||
* @see org.springframework.data.gemfire.GemFireProperties
|
||||
* @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @see <a href="https://stackoverflow.com/questions/69202828/error-bean-definition-overriding-clientgemfirepropertiesconfigurer">Error - Bean Definition Overriding - ClientGemFirePropertiesConfigurer</a>
|
||||
@@ -67,10 +69,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
//@ActiveProfiles("incorrect-test-configuration")
|
||||
@ContextConfiguration(initializers = DisableBeanDefinitionOverridingApplicationContextInitializer.class)
|
||||
@SuppressWarnings("unused")
|
||||
public class UsingAnnotationConfigWithBeanDefinitionOverridingDisabledIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
public class UsingAnnotationConfigWithBeanDefinitionOverridingDisabledIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
@Autowired
|
||||
private GemFireCache cache;
|
||||
@@ -78,9 +77,9 @@ public class UsingAnnotationConfigWithBeanDefinitionOverridingDisabledIntegratio
|
||||
@Before
|
||||
public void assertApplicationContextBeanDefinitionOverridingIsDisabled() {
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
ConfigurableApplicationContext applicationContext = requireApplicationContext();
|
||||
|
||||
ConfigurableListableBeanFactory beanFactory = this.applicationContext.getBeanFactory();
|
||||
ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory();
|
||||
|
||||
assertThat(beanFactory).isInstanceOf(DefaultListableBeanFactory.class);
|
||||
|
||||
@@ -90,14 +89,15 @@ public class UsingAnnotationConfigWithBeanDefinitionOverridingDisabledIntegratio
|
||||
.map(beanName -> applicationContext.getBeanFactory().getBeanDefinition(beanName))
|
||||
.map(BeanDefinition::getBeanClassName)
|
||||
.filter(beanClassName -> String.valueOf(beanClassName).contains("ClientGemFirePropertiesConfigurer"))
|
||||
.count()).isEqualTo(2); }
|
||||
.count()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gemfireCacheSecurityAndSslConfigurationIsCorrect() {
|
||||
|
||||
assertThat(this.cache).isNotNull();
|
||||
//assertThat(this.cache.getName())
|
||||
// .isEqualTo(UsingAnnotationConfigWithBeanDefinitionOverridingDisabledIntegrationTests.class.getSimpleName());
|
||||
assertThat(this.cache.getName())
|
||||
.isEqualTo(UsingAnnotationConfigWithBeanDefinitionOverridingDisabledIntegrationTests.class.getSimpleName());
|
||||
|
||||
DistributedSystem distributedSystem = this.cache.getDistributedSystem();
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config.annotation.support;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -38,12 +37,12 @@ import org.apache.geode.ra.GFConnectionFactory;
|
||||
|
||||
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.Import;
|
||||
import org.springframework.data.gemfire.config.annotation.EnableGemFireAsLastResource;
|
||||
import org.springframework.data.gemfire.config.annotation.GemFireAsLastResourceConfiguration;
|
||||
import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
@@ -62,47 +61,39 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* @see org.apache.geode.ra.GFConnectionFactory
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableGemFireAsLastResource
|
||||
* @see org.springframework.data.gemfire.config.annotation.GemFireAsLastResourceConfiguration
|
||||
* @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
|
||||
* @see org.springframework.transaction.PlatformTransactionManager
|
||||
* @see org.springframework.transaction.annotation.EnableTransactionManagement
|
||||
* @see org.springframework.transaction.annotation.Transactional
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public class EnableGemFireAsLastResourceIntegrationTests {
|
||||
public class EnableGemFireAsLastResourceIntegrationTests extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
private static List<SpringGemFireTransactionEvents> transactionEvents = new ArrayList<>();
|
||||
private static final List<SpringGemFireTransactionEvents> transactionEvents = new ArrayList<>();
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
transactionEvents.clear();
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(Class<?>... annotatedClasses) {
|
||||
ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(annotatedClasses);
|
||||
applicationContext.registerShutdownHook();
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configurationIsCorrect() {
|
||||
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
newApplicationContext(TestGemFireAsLastResourceConfiguration.class);
|
||||
newApplicationContext(TestGemFireAsLastResourceConfiguration.class);
|
||||
|
||||
assertThat(applicationContext).isNotNull();
|
||||
|
||||
GemFireCache gemfireCache = applicationContext.getBean("gemfireCache", GemFireCache.class);
|
||||
GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.getCopyOnRead()).isTrue();
|
||||
|
||||
GemFireAsLastResourceConnectionAcquiringAspect connectionAcquiringAspect =
|
||||
applicationContext.getBean(GemFireAsLastResourceConnectionAcquiringAspect.class);
|
||||
getBean(GemFireAsLastResourceConnectionAcquiringAspect.class);
|
||||
|
||||
assertThat(connectionAcquiringAspect).isNotNull();
|
||||
assertThat(connectionAcquiringAspect.getOrder()).isEqualTo(3);
|
||||
|
||||
GemFireAsLastResourceConnectionClosingAspect connectionClosingAspect =
|
||||
applicationContext.getBean(GemFireAsLastResourceConnectionClosingAspect.class);
|
||||
getBean(GemFireAsLastResourceConnectionClosingAspect.class);
|
||||
|
||||
assertThat(connectionClosingAspect).isNotNull();
|
||||
assertThat(connectionClosingAspect.getOrder()).isEqualTo(1);
|
||||
@@ -219,6 +210,7 @@ public class EnableGemFireAsLastResourceIntegrationTests {
|
||||
@Configuration
|
||||
@EnableGemFireAsLastResource
|
||||
@EnableTransactionManagement(order = 2)
|
||||
@SuppressWarnings("unused")
|
||||
static class TestGemFireAsLastResourceConfiguration {
|
||||
|
||||
@Bean("gemfireCache")
|
||||
@@ -282,12 +274,12 @@ public class EnableGemFireAsLastResourceIntegrationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableGemFireAsLastResource
|
||||
static class TestMissingEnableTransactionManagementAnnotationConfiguration {
|
||||
}
|
||||
static class TestMissingEnableTransactionManagementAnnotationConfiguration { }
|
||||
|
||||
@Configuration
|
||||
@EnableGemFireAsLastResource
|
||||
@EnableTransactionManagement
|
||||
@SuppressWarnings("unused")
|
||||
static class TestMissingEnableTransactionManagementOrderAttributeConfiguration {
|
||||
|
||||
@Bean("transactionManager")
|
||||
@@ -298,6 +290,7 @@ public class EnableGemFireAsLastResourceIntegrationTests {
|
||||
|
||||
@Configuration
|
||||
@Import(TestGemFireAsLastResourceConfiguration.class)
|
||||
@SuppressWarnings("unused")
|
||||
static class TestSpringApplicationConfiguration {
|
||||
|
||||
@Bean("TestTransactionalServiceClass")
|
||||
@@ -330,8 +323,8 @@ public class EnableGemFireAsLastResourceIntegrationTests {
|
||||
|
||||
}
|
||||
|
||||
@Service("TestTransactionalServiceClass")
|
||||
@Transactional
|
||||
@Service("TestTransactionalServiceClass")
|
||||
static class TestTransactionalServiceClass implements TestTransactionalService {
|
||||
|
||||
public void doInTransactionCommits() {
|
||||
|
||||
@@ -25,13 +25,9 @@ import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.RegionAttributes;
|
||||
import org.apache.geode.cache.SubscriptionAttributes;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.PeerRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -44,27 +40,25 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @see org.apache.geode.cache.SubscriptionAttributes
|
||||
* @see org.springframework.data.gemfire.SubscriptionAttributesFactoryBean
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer
|
||||
* @see org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(locations = "subscription-ns.xml",
|
||||
initializers = GemFireMockObjectsApplicationContextInitializer.class)
|
||||
@GemFireUnitTest
|
||||
@SuppressWarnings({ "rawtypes", "unused" })
|
||||
public class CacheSubscriptionTest extends IntegrationTestsSupport {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
public class CacheSubscriptionNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
@Test
|
||||
public void testReplicatedRegionSubscriptionAllPolicy() throws Exception {
|
||||
public void replicateRegionSubscriptionAllPolicy() {
|
||||
|
||||
assertThat(applicationContext.containsBean("replicALL")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("replicALL")).isTrue();
|
||||
|
||||
PeerRegionFactoryBean regionFactoryBean = applicationContext.getBean("&replicALL", PeerRegionFactoryBean.class);
|
||||
RegionAttributes regionAttributes = TestUtils.readField("attributes", regionFactoryBean);
|
||||
PeerRegionFactoryBean regionFactoryBean =
|
||||
requireApplicationContext().getBean("&replicALL", PeerRegionFactoryBean.class);
|
||||
|
||||
RegionAttributes regionAttributes = regionFactoryBean.getAttributes();
|
||||
|
||||
assertThat(regionAttributes).isNotNull();
|
||||
|
||||
@@ -75,12 +69,14 @@ public class CacheSubscriptionTest extends IntegrationTestsSupport {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartitionRegionSubscriptionCacheContentPolicy() throws Exception {
|
||||
public void partitionRegionSubscriptionCacheContentPolicy() {
|
||||
|
||||
assertThat(applicationContext.containsBean("partCACHE_CONTENT")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("partCACHE_CONTENT")).isTrue();
|
||||
|
||||
PeerRegionFactoryBean regionFactoryBean = applicationContext.getBean("&partCACHE_CONTENT", PeerRegionFactoryBean.class);
|
||||
RegionAttributes regionAttributes = TestUtils.readField("attributes", regionFactoryBean);
|
||||
PeerRegionFactoryBean regionFactoryBean =
|
||||
requireApplicationContext().getBean("&partCACHE_CONTENT", PeerRegionFactoryBean.class);
|
||||
|
||||
RegionAttributes regionAttributes = regionFactoryBean.getAttributes();
|
||||
|
||||
assertThat(regionAttributes).isNotNull();
|
||||
|
||||
@@ -91,12 +87,14 @@ public class CacheSubscriptionTest extends IntegrationTestsSupport {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartitionRegionSubscriptionDefaultPolicy() throws Exception {
|
||||
public void partitionRegionSubscriptionDefaultPolicy() {
|
||||
|
||||
assertThat(applicationContext.containsBean("partDEFAULT")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("partDEFAULT")).isTrue();
|
||||
|
||||
PeerRegionFactoryBean regionFactoryBean = applicationContext.getBean("&partDEFAULT", PeerRegionFactoryBean.class);
|
||||
RegionAttributes regionAttributes = TestUtils.readField("attributes", regionFactoryBean);
|
||||
PeerRegionFactoryBean regionFactoryBean =
|
||||
requireApplicationContext().getBean("&partDEFAULT", PeerRegionFactoryBean.class);
|
||||
|
||||
RegionAttributes regionAttributes = regionFactoryBean.getAttributes();
|
||||
|
||||
assertThat(regionAttributes).isNotNull();
|
||||
|
||||
@@ -22,43 +22,36 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import org.apache.geode.pdx.PdxSerializer;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
import org.springframework.data.gemfire.config.support.PdxDiskStoreAwareBeanFactoryPostProcessor;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Integration Tests with test case testing the SDG XML namespace configuration metadata when PDX is configured
|
||||
* in Apache Geode.
|
||||
* Integration Tests testing SDG XML namespace configuration metadata when PDX is configured in Apache Geode.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.pdx.PdxSerializer
|
||||
* @see org.springframework.data.gemfire.CacheFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.support.PdxDiskStoreAwareBeanFactoryPostProcessor
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer
|
||||
* @see org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 1.3.3
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(locations = "cache-using-pdx-ns.xml",
|
||||
initializers = GemFireMockObjectsApplicationContextInitializer.class)
|
||||
@GemFireUnitTest
|
||||
@SuppressWarnings("unused")
|
||||
public class CacheUsingPdxNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void testApplicationContextHasPdxDiskStoreAwareBeanFactoryPostProcessor() {
|
||||
|
||||
PdxDiskStoreAwareBeanFactoryPostProcessor postProcessor =
|
||||
applicationContext.getBean(PdxDiskStoreAwareBeanFactoryPostProcessor.class);
|
||||
requireApplicationContext().getBean(PdxDiskStoreAwareBeanFactoryPostProcessor.class);
|
||||
|
||||
// NOTE the postProcessor reference will not be null as the ApplicationContext.getBean(:Class) method (getting
|
||||
// a bean by Class type) will throw a NoSuchBeanDefinitionException if no bean of type
|
||||
@@ -71,14 +64,16 @@ public class CacheUsingPdxNamespaceIntegrationTests extends IntegrationTestsSupp
|
||||
@Test
|
||||
public void testCachePdxConfiguration() {
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = applicationContext.getBean("&gemfireCache", CacheFactoryBean.class);
|
||||
CacheFactoryBean cacheFactoryBean =
|
||||
requireApplicationContext().getBean("&gemfireCache", CacheFactoryBean.class);
|
||||
|
||||
assertThat(cacheFactoryBean).isNotNull();
|
||||
assertThat(cacheFactoryBean.getPdxDiskStoreName()).isEqualTo("pdxStore");
|
||||
assertThat(Boolean.TRUE.equals(cacheFactoryBean.getPdxPersistent())).isTrue();
|
||||
assertThat(Boolean.TRUE.equals(cacheFactoryBean.getPdxReadSerialized())).isTrue();
|
||||
|
||||
PdxSerializer autoSerializer = applicationContext.getBean("autoSerializer", PdxSerializer.class);
|
||||
PdxSerializer autoSerializer =
|
||||
requireApplicationContext().getBean("autoSerializer", PdxSerializer.class);
|
||||
|
||||
assertThat(autoSerializer).isNotNull();
|
||||
assertThat(cacheFactoryBean.getPdxSerializer()).isSameAs(autoSerializer);
|
||||
|
||||
@@ -15,17 +15,12 @@
|
||||
*/
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static java.util.Arrays.stream;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.data.Offset.offset;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -45,16 +40,13 @@ import org.apache.geode.cache.client.ClientRegionShortcut;
|
||||
import org.apache.geode.cache.util.CacheWriterAdapter;
|
||||
import org.apache.geode.compression.Compressor;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.SimpleCacheListener;
|
||||
import org.springframework.data.gemfire.SimpleObjectSizer;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.client.Interest;
|
||||
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;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
@@ -69,41 +61,53 @@ import org.springframework.util.ObjectUtils;
|
||||
* @see org.springframework.data.gemfire.client.ClientRegionFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.xml.ClientRegionParser
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(locations = "client-ns.xml", initializers = GemFireMockObjectsApplicationContextInitializer.class)
|
||||
@GemFireUnitTest
|
||||
@SuppressWarnings("unused")
|
||||
public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
private void assertInterest(boolean expectedDurable, boolean expectedReceiveValues,
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() {
|
||||
stream(nullSafeArray(new File(".").list((dir, name) -> name.startsWith("BACKUP")), String.class))
|
||||
.forEach(fileName -> new File(fileName).delete());
|
||||
InterestResultPolicy expectedPolicy, Interest<Object> actualInterest) {
|
||||
|
||||
assertThat(actualInterest).isNotNull();
|
||||
assertThat(actualInterest.isDurable()).isEqualTo(expectedDurable);
|
||||
assertThat(actualInterest.isReceiveValues()).isEqualTo(expectedReceiveValues);
|
||||
assertThat(actualInterest.getPolicy()).isEqualTo(expectedPolicy);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private Interest getInterestWithKey(String key, Interest... interests) {
|
||||
|
||||
for (Interest interest : interests) {
|
||||
if (interest.getKey().equals(key)) {
|
||||
return interest;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanNames() {
|
||||
public void beanNamesAreCorrect() {
|
||||
|
||||
assertThat(applicationContext.containsBean("SimpleRegion")).isTrue();
|
||||
assertThat(applicationContext.containsBean("Publisher")).isTrue();
|
||||
assertThat(applicationContext.containsBean("ComplexRegion")).isTrue();
|
||||
assertThat(applicationContext.containsBean("PersistentRegion")).isTrue();
|
||||
assertThat(applicationContext.containsBean("OverflowRegion")).isTrue();
|
||||
assertThat(applicationContext.containsBean("Compressed")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("SimpleRegion")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("Publisher")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("ComplexRegion")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("PersistentRegion")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("OverflowRegion")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("Compressed")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleClientRegion() {
|
||||
public void simpleClientRegionConfigurationIsCorrect() {
|
||||
|
||||
assertThat(applicationContext.containsBean("simple")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("simple")).isTrue();
|
||||
|
||||
Region<?, ?> simple = applicationContext.getBean("simple", Region.class);
|
||||
Region<?, ?> simple = requireApplicationContext().getBean("simple", Region.class);
|
||||
|
||||
assertThat(simple).as("The 'SimpleRegion' Client Region was not properly configured and initialized!")
|
||||
.isNotNull();
|
||||
@@ -115,12 +119,12 @@ public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSuppo
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testPublishingClientRegion() throws Exception {
|
||||
public void publishingClientRegionConfigurationIsCorrect() throws Exception {
|
||||
|
||||
assertThat(applicationContext.containsBean("empty")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("empty")).isTrue();
|
||||
|
||||
ClientRegionFactoryBean emptyClientRegionFactoryBean = applicationContext
|
||||
.getBean("&empty", ClientRegionFactoryBean.class);
|
||||
ClientRegionFactoryBean emptyClientRegionFactoryBean =
|
||||
requireApplicationContext().getBean("&empty", ClientRegionFactoryBean.class);
|
||||
|
||||
assertThat(emptyClientRegionFactoryBean).isNotNull();
|
||||
assertThat(TestUtils.<Object>readField("dataPolicy", emptyClientRegionFactoryBean)).isEqualTo(DataPolicy.EMPTY);
|
||||
@@ -131,12 +135,12 @@ public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSuppo
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testComplexClientRegion() throws Exception {
|
||||
public void complexClientRegionConfigurationIsCorrect() throws Exception {
|
||||
|
||||
assertThat(applicationContext.containsBean("complex")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("complex")).isTrue();
|
||||
|
||||
ClientRegionFactoryBean complexClientRegionFactoryBean = applicationContext
|
||||
.getBean("&complex", ClientRegionFactoryBean.class);
|
||||
ClientRegionFactoryBean complexClientRegionFactoryBean =
|
||||
requireApplicationContext().getBean("&complex", ClientRegionFactoryBean.class);
|
||||
|
||||
assertThat(complexClientRegionFactoryBean).isNotNull();
|
||||
|
||||
@@ -144,7 +148,7 @@ public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSuppo
|
||||
|
||||
assertThat(ObjectUtils.isEmpty(cacheListeners)).isFalse();
|
||||
assertThat(cacheListeners.length).isEqualTo(2);
|
||||
assertThat(applicationContext.getBean("c-listener")).isSameAs(cacheListeners[0]);
|
||||
assertThat(requireApplicationContext().getBean("c-listener")).isSameAs(cacheListeners[0]);
|
||||
assertThat(cacheListeners[1] instanceof SimpleCacheListener).isTrue();
|
||||
assertThat(cacheListeners[1]).isNotSameAs(cacheListeners[0]);
|
||||
|
||||
@@ -160,11 +164,11 @@ public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSuppo
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testPersistentClientRegion() {
|
||||
public void persistentClientRegionConfigurationIsCorrect() {
|
||||
|
||||
assertThat(applicationContext.containsBean("persistent")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("persistent")).isTrue();
|
||||
|
||||
Region<?, ?> persistent = applicationContext.getBean("persistent", Region.class);
|
||||
Region<?, ?> persistent = requireApplicationContext().getBean("persistent", Region.class);
|
||||
|
||||
assertThat(persistent)
|
||||
.describedAs("The 'PersistentRegion' Region was not properly configured and initialized!")
|
||||
@@ -182,12 +186,12 @@ public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSuppo
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testOverflowClientRegion() throws Exception {
|
||||
public void overflowClientRegionConfigurationIsCorrect() throws Exception {
|
||||
|
||||
assertThat(applicationContext.containsBean("overflow")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("overflow")).isTrue();
|
||||
|
||||
ClientRegionFactoryBean overflowClientRegionFactoryBean = applicationContext
|
||||
.getBean("&overflow", ClientRegionFactoryBean.class);
|
||||
ClientRegionFactoryBean overflowClientRegionFactoryBean =
|
||||
requireApplicationContext().getBean("&overflow", ClientRegionFactoryBean.class);
|
||||
|
||||
assertThat(overflowClientRegionFactoryBean).isNotNull();
|
||||
assertThat(TestUtils.<Object>readField("diskStoreName", overflowClientRegionFactoryBean)).isEqualTo("diskStore");
|
||||
@@ -209,12 +213,12 @@ public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSuppo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientRegionWithCacheLoaderAndCacheWriter() throws Exception {
|
||||
public void clientRegionWithCacheLoaderAndCacheWriterConfigurationIsCorrect() throws Exception {
|
||||
|
||||
assertThat(applicationContext.containsBean("loadWithWrite")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("loadWithWrite")).isTrue();
|
||||
|
||||
ClientRegionFactoryBean<?, ?> factory =
|
||||
applicationContext.getBean("&loadWithWrite", ClientRegionFactoryBean.class);
|
||||
requireApplicationContext().getBean("&loadWithWrite", ClientRegionFactoryBean.class);
|
||||
|
||||
assertThat(factory).isNotNull();
|
||||
assertThat(TestUtils.<Object>readField("name", factory)).isEqualTo("LoadedFullOfWrites");
|
||||
@@ -224,11 +228,11 @@ public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSuppo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompressedReplicateRegion() {
|
||||
public void compressedReplicateRegionConfigurationIsCorrect() {
|
||||
|
||||
assertThat(applicationContext.containsBean("Compressed")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("Compressed")).isTrue();
|
||||
|
||||
Region<?, ?> compressed = applicationContext.getBean("Compressed", Region.class);
|
||||
Region<?, ?> compressed = requireApplicationContext().getBean("Compressed", Region.class);
|
||||
|
||||
assertThat(compressed).as("The 'Compressed' Client Region was not properly configured and initialized!")
|
||||
.isNotNull();
|
||||
@@ -238,21 +242,25 @@ public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSuppo
|
||||
assertThat(compressed.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.EMPTY);
|
||||
assertThat(compressed.getAttributes().getPoolName()).isEqualTo("gemfire-pool");
|
||||
assertThat(compressed.getAttributes().getCompressor() instanceof TestCompressor)
|
||||
.as(String.format("Expected 'TestCompressor'; but was '%1$s'!",
|
||||
ObjectUtils.nullSafeClassName(compressed.getAttributes().getCompressor()))).isTrue();
|
||||
.describedAs(String.format("Expected 'TestCompressor'; but was '%s'!",
|
||||
ObjectUtils.nullSafeClassName(compressed.getAttributes().getCompressor())))
|
||||
.isTrue();
|
||||
assertThat(compressed.getAttributes().getCompressor().toString()).isEqualTo("STD");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testClientRegionWithAttributes() {
|
||||
public void clientRegionWithAttributesConfigurationIsCorrect() {
|
||||
|
||||
assertThat(applicationContext.containsBean("client-with-attributes")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("client-with-attributes")).isTrue();
|
||||
|
||||
Region<Long, String> clientRegion = applicationContext.getBean("client-with-attributes", Region.class);
|
||||
Region<Long, String> clientRegion =
|
||||
requireApplicationContext().getBean("client-with-attributes", Region.class);
|
||||
|
||||
assertThat(clientRegion)
|
||||
.as("The 'client-with-attributes' Client Region was not properly configured and initialized!").isNotNull();
|
||||
.describedAs("The 'client-with-attributes' Client Region was not properly configured and initialized!")
|
||||
.isNotNull();
|
||||
|
||||
assertThat(clientRegion.getName()).isEqualTo("client-with-attributes");
|
||||
assertThat(clientRegion.getFullPath()).isEqualTo(Region.SEPARATOR + "client-with-attributes");
|
||||
assertThat(clientRegion.getAttributes()).isNotNull();
|
||||
@@ -270,12 +278,12 @@ public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSuppo
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testClientRegionWithRegisteredInterests() throws Exception {
|
||||
public void clientRegionWithRegisteredInterestsConfigurationIsCorrect() throws Exception {
|
||||
|
||||
assertThat(applicationContext.containsBean("client-with-interests")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("client-with-interests")).isTrue();
|
||||
|
||||
ClientRegionFactoryBean<?, ?> factoryBean =
|
||||
applicationContext.getBean("&client-with-interests", ClientRegionFactoryBean.class);
|
||||
requireApplicationContext().getBean("&client-with-interests", ClientRegionFactoryBean.class);
|
||||
|
||||
assertThat(factoryBean).isNotNull();
|
||||
|
||||
@@ -287,7 +295,8 @@ public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSuppo
|
||||
assertInterest(true, false, InterestResultPolicy.KEYS, getInterestWithKey(".*", interests));
|
||||
assertInterest(true, false, InterestResultPolicy.KEYS_VALUES, getInterestWithKey("keyPrefix.*", interests));
|
||||
|
||||
Region<Object, Object> mockClientRegion = applicationContext.getBean("client-with-interests", Region.class);
|
||||
Region<Object, Object> mockClientRegion =
|
||||
requireApplicationContext().getBean("client-with-interests", Region.class);
|
||||
|
||||
assertThat(mockClientRegion).isNotNull();
|
||||
|
||||
@@ -298,27 +307,6 @@ public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSuppo
|
||||
eq(InterestResultPolicy.KEYS_VALUES), eq(true), eq(false));
|
||||
}
|
||||
|
||||
private void assertInterest(boolean expectedDurable, boolean expectedReceiveValues,
|
||||
InterestResultPolicy expectedPolicy, Interest<Object> actualInterest) {
|
||||
|
||||
assertThat(actualInterest).isNotNull();
|
||||
assertThat(actualInterest.isDurable()).isEqualTo(expectedDurable);
|
||||
assertThat(actualInterest.isReceiveValues()).isEqualTo(expectedReceiveValues);
|
||||
assertThat(actualInterest.getPolicy()).isEqualTo(expectedPolicy);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private Interest getInterestWithKey(String key, Interest... interests) {
|
||||
|
||||
for (Interest interest : interests) {
|
||||
if (interest.getKey().equals(key)) {
|
||||
return interest;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final class TestCacheLoader implements CacheLoader<Object, Object> {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.apache.geode.cache.client.ClientRegionShortcut;
|
||||
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
|
||||
|
||||
/**
|
||||
* Integration Tests for client {@link Region} bean definition with both {@literal data-policy}(i.e. {@link DataPolicy})
|
||||
@@ -36,16 +37,17 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.apache.geode.cache.client.ClientRegionShortcut
|
||||
* @see org.springframework.context.support.ClassPathXmlApplicationContext
|
||||
* @see org.springframework.data.gemfire.client.ClientCacheFactoryBean
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @since 1.3.3
|
||||
*/
|
||||
public class ClientRegionUsingDataPolicyAndShortcutIntegrationTests {
|
||||
public class ClientRegionUsingDataPolicyAndShortcutIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
@Test(expected = BeanDefinitionParsingException.class)
|
||||
public void testClientRegionBeanDefinitionWithDataPolicyAndShortcut() {
|
||||
|
||||
try {
|
||||
new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/data/gemfire/config/xml/client-region-using-datapolicy-and-shortcut.xml");
|
||||
new ClassPathXmlApplicationContext(getContextXmlFileLocation(ClientRegionUsingDataPolicyAndShortcutIntegrationTests.class));
|
||||
}
|
||||
catch (BeanDefinitionParsingException expected) {
|
||||
|
||||
|
||||
@@ -1,233 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.apache.geode.cache.Cache;
|
||||
import org.apache.geode.cache.CustomExpiry;
|
||||
import org.apache.geode.cache.DataPolicy;
|
||||
import org.apache.geode.cache.DiskStore;
|
||||
import org.apache.geode.cache.DiskStoreFactory;
|
||||
import org.apache.geode.cache.EvictionAction;
|
||||
import org.apache.geode.cache.EvictionAlgorithm;
|
||||
import org.apache.geode.cache.EvictionAttributes;
|
||||
import org.apache.geode.cache.ExpirationAction;
|
||||
import org.apache.geode.cache.ExpirationAttributes;
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.Region.Entry;
|
||||
import org.apache.geode.cache.RegionAttributes;
|
||||
import org.apache.geode.cache.Scope;
|
||||
import org.apache.geode.cache.util.ObjectSizer;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.PeerRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.ReplicatedRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.SimpleObjectSizer;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
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.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
/**
|
||||
* Integration Tests for {@link Region}, {@link EvictionAttributes} and {@link DiskStore} SDG XML namespace
|
||||
* configuration metadata parsing.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.DiskStore
|
||||
* @see org.apache.geode.cache.ExpirationAttributes
|
||||
* @see org.apache.geode.cache.EvictionAttributes
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.apache.geode.cache.RegionAttributes
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(locations = "diskstore-ns.xml",
|
||||
initializers = GemFireMockObjectsApplicationContextInitializer.class)
|
||||
@SuppressWarnings("unused")
|
||||
// TODO: Move test cases into a DiskStoreIntegrationTests class
|
||||
public class DiskStoreEvictionAndExpirationRegionParsingIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
private static File diskStoreDirectory;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("diskStore1")
|
||||
private DiskStore diskStore;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
diskStoreDirectory = new File("./tmp");
|
||||
assertThat(diskStoreDirectory.isDirectory() || diskStoreDirectory.mkdirs()).isTrue();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() {
|
||||
|
||||
FileSystemUtils.deleteRecursively(diskStoreDirectory);
|
||||
|
||||
for (String name : nullSafeArray(new File(".")
|
||||
.list((dir, name) -> name.startsWith("BACKUP")), String.class)) {
|
||||
|
||||
new File(name).delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiskStore() {
|
||||
|
||||
assertThat(applicationContext.getBean("ds2")).isNotNull();
|
||||
applicationContext.getBean("diskStore1");
|
||||
assertThat(diskStore).isNotNull();
|
||||
assertThat(diskStore.getName()).isEqualTo("diskStore1");
|
||||
assertThat(diskStore.getQueueSize()).isEqualTo(50);
|
||||
assertThat(diskStore.getAutoCompact()).isTrue();
|
||||
assertThat(diskStore.getCompactionThreshold()).isEqualTo(DiskStoreFactory.DEFAULT_COMPACTION_THRESHOLD);
|
||||
assertThat(diskStore.getTimeInterval()).isEqualTo(9999);
|
||||
assertThat(diskStore.getMaxOplogSize()).isEqualTo(1);
|
||||
assertThat(diskStore.getDiskDirs()[0]).isEqualTo(diskStoreDirectory);
|
||||
Cache cache = applicationContext.getBean("gemfireCache", Cache.class);
|
||||
assertThat(cache.findDiskStore("diskStore1")).isSameAs(diskStore);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testReplicatedDataRegionAttributes() throws Exception {
|
||||
|
||||
assertThat(applicationContext.containsBean("replicated-data")).isTrue();
|
||||
|
||||
PeerRegionFactoryBean replicatedDataRegionFactoryBean = applicationContext.getBean("&replicated-data", PeerRegionFactoryBean.class);
|
||||
|
||||
assertThat(replicatedDataRegionFactoryBean instanceof ReplicatedRegionFactoryBean).isTrue();
|
||||
assertThat(replicatedDataRegionFactoryBean.getDataPolicy()).isEqualTo(DataPolicy.REPLICATE);
|
||||
assertThat(replicatedDataRegionFactoryBean.getDataPolicy().withPersistence()).isFalse();
|
||||
assertThat(TestUtils.<String>readField("diskStoreName", replicatedDataRegionFactoryBean)).isEqualTo("diskStore1");
|
||||
assertThat(TestUtils.<Object>readField("scope", replicatedDataRegionFactoryBean)).isNull();
|
||||
|
||||
Region replicatedDataRegion = applicationContext.getBean("replicated-data", Region.class);
|
||||
|
||||
RegionAttributes replicatedDataRegionAttributes = TestUtils.readField("attributes", replicatedDataRegionFactoryBean);
|
||||
|
||||
assertThat(replicatedDataRegionAttributes).isNotNull();
|
||||
assertThat(replicatedDataRegionAttributes.getScope()).isEqualTo(Scope.DISTRIBUTED_NO_ACK);
|
||||
|
||||
EvictionAttributes replicatedDataEvictionAttributes = replicatedDataRegionAttributes.getEvictionAttributes();
|
||||
|
||||
assertThat(replicatedDataEvictionAttributes).isNotNull();
|
||||
assertThat(replicatedDataEvictionAttributes.getAction()).isEqualTo(EvictionAction.OVERFLOW_TO_DISK);
|
||||
assertThat(replicatedDataEvictionAttributes.getAlgorithm()).isEqualTo(EvictionAlgorithm.LRU_ENTRY);
|
||||
assertThat(replicatedDataEvictionAttributes.getMaximum()).isEqualTo(50);
|
||||
assertThat(replicatedDataEvictionAttributes.getObjectSizer()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testPartitionDataOptions() throws Exception {
|
||||
|
||||
assertThat(applicationContext.containsBean("partition-data")).isTrue();
|
||||
|
||||
PeerRegionFactoryBean regionFactoryBean = applicationContext.getBean("&partition-data", PeerRegionFactoryBean.class);
|
||||
|
||||
assertThat(regionFactoryBean instanceof PartitionedRegionFactoryBean).isTrue();
|
||||
assertThat(TestUtils.<Boolean>readField("persistent", regionFactoryBean)).isTrue();
|
||||
RegionAttributes attrs = TestUtils.readField("attributes", regionFactoryBean);
|
||||
|
||||
EvictionAttributes evicAttr = attrs.getEvictionAttributes();
|
||||
|
||||
assertThat(evicAttr.getAction()).isEqualTo(EvictionAction.LOCAL_DESTROY);
|
||||
assertThat(evicAttr.getAlgorithm()).isEqualTo(EvictionAlgorithm.LRU_MEMORY);
|
||||
|
||||
ObjectSizer sizer = evicAttr.getObjectSizer();
|
||||
|
||||
assertThat(sizer.getClass()).isEqualTo(SimpleObjectSizer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testEntryTtl() throws Exception {
|
||||
|
||||
assertThat(applicationContext.containsBean("replicated-data")).isTrue();
|
||||
|
||||
PeerRegionFactoryBean fb = applicationContext.getBean("&replicated-data", PeerRegionFactoryBean.class);
|
||||
RegionAttributes attrs = TestUtils.readField("attributes", fb);
|
||||
|
||||
ExpirationAttributes entryTTL = attrs.getEntryTimeToLive();
|
||||
assertThat(entryTTL.getTimeout()).isEqualTo(100);
|
||||
assertThat(entryTTL.getAction()).isEqualTo(ExpirationAction.DESTROY);
|
||||
|
||||
ExpirationAttributes entryTTI = attrs.getEntryIdleTimeout();
|
||||
assertThat(entryTTI.getTimeout()).isEqualTo(200);
|
||||
assertThat(entryTTI.getAction()).isEqualTo(ExpirationAction.INVALIDATE);
|
||||
|
||||
ExpirationAttributes regionTTL = attrs.getRegionTimeToLive();
|
||||
assertThat(regionTTL.getTimeout()).isEqualTo(300);
|
||||
assertThat(regionTTL.getAction()).isEqualTo(ExpirationAction.DESTROY);
|
||||
|
||||
ExpirationAttributes regionTTI = attrs.getRegionIdleTimeout();
|
||||
assertThat(regionTTI.getTimeout()).isEqualTo(400);
|
||||
assertThat(regionTTI.getAction()).isEqualTo(ExpirationAction.INVALIDATE);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testCustomExpiry() throws Exception {
|
||||
|
||||
assertThat(applicationContext.containsBean("replicated-data-custom-expiry")).isTrue();
|
||||
|
||||
PeerRegionFactoryBean fb = applicationContext.getBean("&replicated-data-custom-expiry", PeerRegionFactoryBean.class);
|
||||
RegionAttributes attrs = TestUtils.readField("attributes", fb);
|
||||
|
||||
assertThat(attrs.getCustomEntryIdleTimeout()).isNotNull();
|
||||
assertThat(attrs.getCustomEntryTimeToLive()).isNotNull();
|
||||
|
||||
assertThat(attrs.getCustomEntryIdleTimeout() instanceof TestCustomExpiry).isTrue();
|
||||
assertThat(attrs.getCustomEntryTimeToLive() instanceof TestCustomExpiry).isTrue();
|
||||
}
|
||||
|
||||
public static class TestCustomExpiry<K,V> implements CustomExpiry<K,V> {
|
||||
|
||||
@Override
|
||||
public ExpirationAttributes getExpiry(Entry<K, V> entry) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() { }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -20,16 +20,37 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import java.io.File;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.apache.geode.cache.CustomExpiry;
|
||||
import org.apache.geode.cache.DataPolicy;
|
||||
import org.apache.geode.cache.DiskStore;
|
||||
import org.apache.geode.cache.DiskStoreFactory;
|
||||
import org.apache.geode.cache.EvictionAction;
|
||||
import org.apache.geode.cache.EvictionAlgorithm;
|
||||
import org.apache.geode.cache.EvictionAttributes;
|
||||
import org.apache.geode.cache.ExpirationAction;
|
||||
import org.apache.geode.cache.ExpirationAttributes;
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.RegionAttributes;
|
||||
import org.apache.geode.cache.Scope;
|
||||
import org.apache.geode.cache.util.ObjectSizer;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.PeerRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.ReplicatedRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.SimpleObjectSizer;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
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.data.gemfire.tests.util.FileSystemUtils;
|
||||
import org.springframework.data.gemfire.util.ArrayUtils;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
@@ -39,43 +60,210 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.DiskStore
|
||||
* @see org.springframework.data.gemfire.DiskStoreFactoryBean
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer
|
||||
* @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(locations = "diskstore-ns.xml",
|
||||
initializers = GemFireMockObjectsApplicationContextInitializer.class)
|
||||
@GemFireUnitTest
|
||||
@SuppressWarnings("unused")
|
||||
public class DiskStoreNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
private static File diskStoreDirectory;
|
||||
|
||||
@Autowired
|
||||
private GemFireCache cache;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("diskStore1")
|
||||
private DiskStore diskStoreOne;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("ds2")
|
||||
private DiskStore diskStoreTwo;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("fullyConfiguredDiskStore")
|
||||
private DiskStore diskStore;
|
||||
private DiskStore fullyConfiguredDiskStore;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("props")
|
||||
private Properties props;
|
||||
@Qualifier("diskStoreProperties")
|
||||
private Properties diskStoreProperties;
|
||||
|
||||
@BeforeClass
|
||||
public static void createDiskStoreDirectory() {
|
||||
createDirectory(diskStoreDirectory = new File("./tmp"));
|
||||
diskStoreDirectory.deleteOnExit();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void deleteDiskStoreDirectory() {
|
||||
|
||||
FileSystemUtils.deleteRecursive(diskStoreDirectory);
|
||||
|
||||
for (String name : ArrayUtils.nullSafeArray(FileSystemUtils.WORKING_DIRECTORY
|
||||
.list((dir, name) -> name.startsWith("BACKUP")), String.class)) {
|
||||
new File(name).delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiskStoreConfiguration() {
|
||||
public void diskStoreOneIsAccessibleFromTheCache() {
|
||||
assertThat(this.cache.findDiskStore("diskStore1")).isSameAs(this.diskStoreOne);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void diskStoreTwoConfigurationIsCorrect() {
|
||||
|
||||
assertThat(diskStoreTwo).isNotNull();
|
||||
assertThat(diskStoreTwo.getName()).isEqualTo("ds2");
|
||||
assertThat(diskStoreTwo.getQueueSize()).isEqualTo(50);
|
||||
assertThat(diskStoreTwo.getAutoCompact()).isTrue();
|
||||
assertThat(diskStoreTwo.getCompactionThreshold()).isEqualTo(DiskStoreFactory.DEFAULT_COMPACTION_THRESHOLD);
|
||||
assertThat(diskStoreTwo.getTimeInterval()).isEqualTo(9999);
|
||||
assertThat(diskStoreTwo.getMaxOplogSize()).isEqualTo(1);
|
||||
assertThat(diskStoreTwo.getDiskDirs()[0]).isEqualTo(diskStoreDirectory.getParentFile());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fullyConfiguredDiskStoreConfigurationIsCorrect() {
|
||||
|
||||
assertThat(fullyConfiguredDiskStore)
|
||||
.describedAs("The 'fullyConfiguredDiskStore' was not properly configured and initialized")
|
||||
.isNotNull();
|
||||
|
||||
assertThat(fullyConfiguredDiskStore.getName()).isEqualTo("fullyConfiguredDiskStore");
|
||||
assertThat(fullyConfiguredDiskStore.getAllowForceCompaction()).isEqualTo(Boolean.valueOf(diskStoreProperties.getProperty("allowForceCompaction")));
|
||||
assertThat(fullyConfiguredDiskStore.getAutoCompact()).isEqualTo(Boolean.valueOf(diskStoreProperties.getProperty("autoCompact")));
|
||||
assertThat(Long.valueOf(fullyConfiguredDiskStore.getCompactionThreshold())).isEqualTo(Long.valueOf(diskStoreProperties.getProperty("compactionThreshold")));
|
||||
assertThat(Double.valueOf(fullyConfiguredDiskStore.getDiskUsageCriticalPercentage())).isEqualTo(Double.valueOf(diskStoreProperties.getProperty("diskUsageCriticalPercentage")));
|
||||
assertThat(Double.valueOf(fullyConfiguredDiskStore.getDiskUsageWarningPercentage())).isEqualTo(Double.valueOf(diskStoreProperties.getProperty("diskUsageWarningPercentage")));
|
||||
assertThat(Long.valueOf(fullyConfiguredDiskStore.getMaxOplogSize())).isEqualTo(Long.valueOf(diskStoreProperties.getProperty("maxOplogSize")));
|
||||
assertThat(Long.valueOf(fullyConfiguredDiskStore.getQueueSize())).isEqualTo(Long.valueOf(diskStoreProperties.getProperty("queueSize")));
|
||||
assertThat(Long.valueOf(fullyConfiguredDiskStore.getTimeInterval())).isEqualTo(Long.valueOf(diskStoreProperties.getProperty("timeInterval")));
|
||||
assertThat(Long.valueOf(fullyConfiguredDiskStore.getWriteBufferSize())).isEqualTo(Long.valueOf(diskStoreProperties.getProperty("writeBufferSize")));
|
||||
assertThat(fullyConfiguredDiskStore.getDiskDirs()).isNotNull();
|
||||
assertThat(fullyConfiguredDiskStore.getDiskDirs().length).isEqualTo(1);
|
||||
assertThat(fullyConfiguredDiskStore.getDiskDirs()[0]).isEqualTo(new File(diskStoreProperties.getProperty("location")));
|
||||
assertThat(Long.valueOf(fullyConfiguredDiskStore.getDiskDirSizes()[0])).isEqualTo(Long.valueOf(diskStoreProperties.getProperty("maxSize")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void replicatedDataRegionAttributesIsConfiguredCorrectly() throws Exception {
|
||||
|
||||
assertThat(requireApplicationContext().containsBean("replicated-data")).isTrue();
|
||||
|
||||
PeerRegionFactoryBean replicatedDataRegionFactoryBean =
|
||||
requireApplicationContext().getBean("&replicated-data", PeerRegionFactoryBean.class);
|
||||
|
||||
assertThat(replicatedDataRegionFactoryBean instanceof ReplicatedRegionFactoryBean).isTrue();
|
||||
assertThat(replicatedDataRegionFactoryBean.getDataPolicy()).isEqualTo(DataPolicy.REPLICATE);
|
||||
assertThat(replicatedDataRegionFactoryBean.getDataPolicy().withPersistence()).isFalse();
|
||||
assertThat(TestUtils.<String>readField("diskStoreName", replicatedDataRegionFactoryBean)).isEqualTo("diskStore1");
|
||||
assertThat(TestUtils.<Object>readField("scope", replicatedDataRegionFactoryBean)).isNull();
|
||||
|
||||
Region replicatedDataRegion = requireApplicationContext().getBean("replicated-data", Region.class);
|
||||
|
||||
RegionAttributes replicatedDataRegionAttributes = TestUtils.readField("attributes", replicatedDataRegionFactoryBean);
|
||||
|
||||
assertThat(replicatedDataRegionAttributes).isNotNull();
|
||||
assertThat(replicatedDataRegionAttributes.getScope()).isEqualTo(Scope.DISTRIBUTED_NO_ACK);
|
||||
|
||||
EvictionAttributes replicatedDataEvictionAttributes = replicatedDataRegionAttributes.getEvictionAttributes();
|
||||
|
||||
assertThat(replicatedDataEvictionAttributes).isNotNull();
|
||||
assertThat(replicatedDataEvictionAttributes.getAction()).isEqualTo(EvictionAction.OVERFLOW_TO_DISK);
|
||||
assertThat(replicatedDataEvictionAttributes.getAlgorithm()).isEqualTo(EvictionAlgorithm.LRU_ENTRY);
|
||||
assertThat(replicatedDataEvictionAttributes.getMaximum()).isEqualTo(50);
|
||||
assertThat(replicatedDataEvictionAttributes.getObjectSizer()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void partitionDataOptionsAreCorrect() throws Exception {
|
||||
|
||||
assertThat(requireApplicationContext().containsBean("partition-data")).isTrue();
|
||||
|
||||
PeerRegionFactoryBean regionFactoryBean =
|
||||
requireApplicationContext().getBean("&partition-data", PeerRegionFactoryBean.class);
|
||||
|
||||
assertThat(regionFactoryBean).isInstanceOf(PartitionedRegionFactoryBean.class);
|
||||
assertThat(TestUtils.<Boolean>readField("persistent", regionFactoryBean)).isTrue();
|
||||
|
||||
RegionAttributes regionAttributes = TestUtils.readField("attributes", regionFactoryBean);
|
||||
|
||||
assertThat(regionAttributes).isNotNull();
|
||||
|
||||
EvictionAttributes evictionAttributes = regionAttributes.getEvictionAttributes();
|
||||
|
||||
assertThat(evictionAttributes.getAction()).isEqualTo(EvictionAction.LOCAL_DESTROY);
|
||||
assertThat(evictionAttributes.getAlgorithm()).isEqualTo(EvictionAlgorithm.LRU_MEMORY);
|
||||
|
||||
ObjectSizer sizer = evictionAttributes.getObjectSizer();
|
||||
|
||||
assertThat(sizer.getClass()).isEqualTo(SimpleObjectSizer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void entryTtlConfigurationIsCorrect() throws Exception {
|
||||
|
||||
assertThat(requireApplicationContext().containsBean("replicated-data")).isTrue();
|
||||
|
||||
PeerRegionFactoryBean regionFactoryBean =
|
||||
requireApplicationContext().getBean("&replicated-data", PeerRegionFactoryBean.class);
|
||||
|
||||
RegionAttributes regionAttributes = TestUtils.readField("attributes", regionFactoryBean);
|
||||
|
||||
ExpirationAttributes entryTTL = regionAttributes.getEntryTimeToLive();
|
||||
|
||||
assertThat(entryTTL.getTimeout()).isEqualTo(100);
|
||||
assertThat(entryTTL.getAction()).isEqualTo(ExpirationAction.DESTROY);
|
||||
|
||||
ExpirationAttributes entryTTI = regionAttributes.getEntryIdleTimeout();
|
||||
|
||||
assertThat(entryTTI.getTimeout()).isEqualTo(200);
|
||||
assertThat(entryTTI.getAction()).isEqualTo(ExpirationAction.INVALIDATE);
|
||||
|
||||
ExpirationAttributes regionTTL = regionAttributes.getRegionTimeToLive();
|
||||
|
||||
assertThat(regionTTL.getTimeout()).isEqualTo(300);
|
||||
assertThat(regionTTL.getAction()).isEqualTo(ExpirationAction.DESTROY);
|
||||
|
||||
ExpirationAttributes regionTTI = regionAttributes.getRegionIdleTimeout();
|
||||
|
||||
assertThat(regionTTI.getTimeout()).isEqualTo(400);
|
||||
assertThat(regionTTI.getAction()).isEqualTo(ExpirationAction.INVALIDATE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testCustomExpiry() throws Exception {
|
||||
|
||||
assertThat(requireApplicationContext().containsBean("replicated-data-with-custom-expiry")).isTrue();
|
||||
|
||||
PeerRegionFactoryBean regionFactoryBean =
|
||||
requireApplicationContext().getBean("&replicated-data-with-custom-expiry", PeerRegionFactoryBean.class);
|
||||
|
||||
RegionAttributes regionAttributes = TestUtils.readField("attributes", regionFactoryBean);
|
||||
|
||||
assertThat(regionAttributes.getCustomEntryIdleTimeout()).isInstanceOf(TestCustomExpiry.class);
|
||||
assertThat(regionAttributes.getCustomEntryTimeToLive()).isInstanceOf(TestCustomExpiry.class);
|
||||
}
|
||||
|
||||
public static class TestCustomExpiry<K,V> implements CustomExpiry<K,V> {
|
||||
|
||||
@Override
|
||||
public ExpirationAttributes getExpiry(Region.Entry<K, V> entry) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() { }
|
||||
|
||||
assertThat(diskStore).as("The 'fullyConfiguredDiskStore' was not properly configured and initialized").isNotNull();
|
||||
assertThat(diskStore.getName()).isEqualTo("fullyConfiguredDiskStore");
|
||||
assertThat(diskStore.getAllowForceCompaction()).isEqualTo(Boolean.valueOf(props.getProperty("allowForceCompaction")));
|
||||
assertThat(diskStore.getAutoCompact()).isEqualTo(Boolean.valueOf(props.getProperty("autoCompact")));
|
||||
assertThat(Long.valueOf(diskStore.getCompactionThreshold())).isEqualTo(Long.valueOf(props.getProperty("compactionThreshold")));
|
||||
assertThat(Double.valueOf(diskStore.getDiskUsageCriticalPercentage())).isEqualTo(Double.valueOf(props.getProperty("diskUsageCriticalPercentage")));
|
||||
assertThat(Double.valueOf(diskStore.getDiskUsageWarningPercentage())).isEqualTo(Double.valueOf(props.getProperty("diskUsageWarningPercentage")));
|
||||
assertThat(Long.valueOf(diskStore.getMaxOplogSize())).isEqualTo(Long.valueOf(props.getProperty("maxOplogSize")));
|
||||
assertThat(Long.valueOf(diskStore.getQueueSize())).isEqualTo(Long.valueOf(props.getProperty("queueSize")));
|
||||
assertThat(Long.valueOf(diskStore.getTimeInterval())).isEqualTo(Long.valueOf(props.getProperty("timeInterval")));
|
||||
assertThat(Long.valueOf(diskStore.getWriteBufferSize())).isEqualTo(Long.valueOf(props.getProperty("writeBufferSize")));
|
||||
assertThat(diskStore.getDiskDirs()).isNotNull();
|
||||
assertThat(diskStore.getDiskDirs().length).isEqualTo(1);
|
||||
assertThat(diskStore.getDiskDirs()[0]).isEqualTo(new File(props.getProperty("location")));
|
||||
assertThat(Long.valueOf(diskStore.getDiskDirSizes()[0])).isEqualTo(Long.valueOf(props.getProperty("maxSize")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,7 @@ import org.apache.geode.cache.execute.FunctionContext;
|
||||
import org.apache.geode.cache.execute.FunctionService;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -41,25 +40,24 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @see org.apache.geode.cache.execute.FunctionContext
|
||||
* @see org.apache.geode.cache.execute.FunctionService
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer
|
||||
* @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(locations="function-service-ns.xml",
|
||||
initializers= GemFireMockObjectsApplicationContextInitializer.class)
|
||||
@GemFireUnitTest
|
||||
@SuppressWarnings("unused")
|
||||
public class FunctionServiceNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
@Test
|
||||
public void testFunctionsRegistered() {
|
||||
public void functionsAreRegistered() {
|
||||
|
||||
assertThat(FunctionService.getRegisteredFunctions().size()).isEqualTo(2);
|
||||
assertThat(FunctionService.getFunction("function1")).isNotNull();
|
||||
assertThat(FunctionService.getFunction("function2")).isNotNull();
|
||||
}
|
||||
|
||||
public static class Function1 implements Function<Object> {
|
||||
public static class FunctionOne implements Function<Object> {
|
||||
|
||||
@Override
|
||||
public void execute(FunctionContext functionContext) { }
|
||||
@@ -70,7 +68,7 @@ public class FunctionServiceNamespaceIntegrationTests extends IntegrationTestsSu
|
||||
}
|
||||
}
|
||||
|
||||
public static class Function2 implements Function<Object> {
|
||||
public static class FunctionTwo implements Function<Object> {
|
||||
|
||||
@Override
|
||||
public void execute(FunctionContext functionContext) { }
|
||||
|
||||
@@ -17,12 +17,10 @@ package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.geode.cache.Region;
|
||||
@@ -40,7 +38,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.data.gemfire.PeerRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.RecreatingSpringApplicationContextTest;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor;
|
||||
import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer;
|
||||
import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean;
|
||||
|
||||
/**
|
||||
@@ -53,34 +51,28 @@ import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean;
|
||||
* @see org.apache.geode.cache.wan.GatewayReceiver
|
||||
* @see org.apache.geode.cache.wan.GatewaySender
|
||||
* @see org.springframework.data.gemfire.RecreatingSpringApplicationContextTest
|
||||
* @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer
|
||||
* @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean
|
||||
* @see org.springframework.data.gemfire.wan.GatewaySenderFactoryBean
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationContextTest {
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() {
|
||||
|
||||
for (String name : new File(".").list((file, filename) -> filename.startsWith("BACKUP"))) {
|
||||
new File(name).delete();
|
||||
}
|
||||
}
|
||||
public class GemfireV7GatewayNamespaceIntegrationTests extends RecreatingSpringApplicationContextTest {
|
||||
|
||||
@Override
|
||||
protected <T extends ConfigurableApplicationContext> T configureContext(T context) {
|
||||
context.getBeanFactory().addBeanPostProcessor(new GemFireMockObjectsBeanPostProcessor());
|
||||
new GemFireMockObjectsApplicationContextInitializer().initialize(context);
|
||||
return context;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String location() {
|
||||
return "/org/springframework/data/gemfire/config/xml/gateway-v7-ns.xml";
|
||||
return getContextXmlFileLocation(GemfireV7GatewayNamespaceIntegrationTests.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asyncEventQueueConfigurationIsCorrect() {
|
||||
|
||||
AsyncEventQueue asyncEventQueue =
|
||||
this.applicationContext.getBean("async-event-queue", AsyncEventQueue.class);
|
||||
AsyncEventQueue asyncEventQueue = getBean("async-event-queue", AsyncEventQueue.class);
|
||||
|
||||
assertThat(asyncEventQueue).isNotNull();
|
||||
assertThat(asyncEventQueue.isBatchConflationEnabled()).isTrue();
|
||||
@@ -98,7 +90,7 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo
|
||||
public void gatewaySenderFactoryBeanConfigurationIsCorrect() throws Exception {
|
||||
|
||||
GatewaySenderFactoryBean gatewaySenderFactoryBean =
|
||||
this.applicationContext.getBean("&gateway-sender", GatewaySenderFactoryBean.class);
|
||||
getBean("&gateway-sender", GatewaySenderFactoryBean.class);
|
||||
|
||||
assertThat(gatewaySenderFactoryBean).isNotNull();
|
||||
assertThat(gatewaySenderFactoryBean.getCache()).isNotNull();
|
||||
@@ -127,14 +119,15 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void nestedGatewaySenderConfigurationIsCorrect() throws Exception {
|
||||
|
||||
Region<?, ?> region = this.applicationContext.getBean("region-with-nested-gateway-sender", Region.class);
|
||||
Region<?, ?> region = getBean("region-with-nested-gateway-sender", Region.class);
|
||||
|
||||
assertThat(region).isNotNull();
|
||||
assertThat(region.getAttributes()).isNotNull();
|
||||
assertThat(region.getAttributes().getGatewaySenderIds()).isNotNull();
|
||||
assertThat(region.getAttributes().getGatewaySenderIds()).hasSize(2);
|
||||
|
||||
PeerRegionFactoryBean regionFactoryBean = applicationContext.getBean("®ion-with-nested-gateway-sender", PeerRegionFactoryBean.class);
|
||||
PeerRegionFactoryBean regionFactoryBean =
|
||||
getBean("®ion-with-nested-gateway-sender", PeerRegionFactoryBean.class);
|
||||
|
||||
List<GatewaySender> gatewaySenders = TestUtils.readField("gatewaySenders", regionFactoryBean);
|
||||
|
||||
@@ -178,8 +171,7 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo
|
||||
public void gatewaySenderWithEventTransportFilterRefsConfigurationIsCorrect() throws Exception {
|
||||
|
||||
GatewaySenderFactoryBean gatewaySenderFactoryBean =
|
||||
this.applicationContext.getBean("&gateway-sender-with-event-transport-filter-refs",
|
||||
GatewaySenderFactoryBean.class);
|
||||
getBean("&gateway-sender-with-event-transport-filter-refs", GatewaySenderFactoryBean.class);
|
||||
|
||||
assertThat(gatewaySenderFactoryBean).isNotNull();
|
||||
assertThat(gatewaySenderFactoryBean.getCache()).isNotNull();
|
||||
@@ -189,12 +181,13 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo
|
||||
assertThat(gatewaySenderFactoryBean.getDispatcherThreads()).isEqualTo(10);
|
||||
assertThat(gatewaySenderFactoryBean.isManualStart()).isTrue();
|
||||
|
||||
List<GatewayEventFilter> eventFilters = TestUtils.readField("eventFilters", gatewaySenderFactoryBean);
|
||||
List<GatewayEventFilter> eventFilters =
|
||||
TestUtils.readField("eventFilters", gatewaySenderFactoryBean);
|
||||
|
||||
assertThat(eventFilters).isNotNull();
|
||||
assertThat(eventFilters).hasSize(1);
|
||||
assertThat(eventFilters.get(0)).isInstanceOf(TestEventFilter.class);
|
||||
assertThat(eventFilters.get(0)).isSameAs(applicationContext.getBean("event-filter"));
|
||||
assertThat(eventFilters.get(0)).isSameAs(getBean("event-filter", GatewayEventFilter.class));
|
||||
|
||||
List<GatewayTransportFilter> transportFilters =
|
||||
TestUtils.readField("transportFilters", gatewaySenderFactoryBean);
|
||||
@@ -202,14 +195,13 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo
|
||||
assertThat(transportFilters).isNotNull();
|
||||
assertThat(transportFilters).hasSize(1);
|
||||
assertThat(transportFilters.get(0)).isInstanceOf(TestTransportFilter.class);
|
||||
assertThat(transportFilters.get(0)).isSameAs(applicationContext.getBean("transport-filter"));
|
||||
assertThat(transportFilters.get(0)).isSameAs(getBean("transport-filter", GatewayTransportFilter.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gatewayReceiverConfigurationIsCorrect() {
|
||||
|
||||
GatewayReceiver gatewayReceiver =
|
||||
this.applicationContext.getBean("gateway-receiver", GatewayReceiver.class);
|
||||
GatewayReceiver gatewayReceiver = getBean("gateway-receiver", GatewayReceiver.class);
|
||||
|
||||
assertThat(gatewayReceiver).isNotNull();
|
||||
assertThat(gatewayReceiver.getBindAddress()).isEqualTo("192.168.0.1");
|
||||
@@ -28,8 +28,7 @@ import org.apache.geode.cache.wan.GatewaySender;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -41,7 +40,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @see org.apache.geode.cache.wan.GatewayReceiver
|
||||
* @see org.apache.geode.cache.wan.GatewaySender
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer
|
||||
* @see org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest
|
||||
* @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean
|
||||
* @see org.springframework.data.gemfire.wan.GatewaySenderFactoryBean
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
@@ -49,8 +48,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(locations = "gateway-v8-ns.xml",
|
||||
initializers = GemFireMockObjectsApplicationContextInitializer.class)
|
||||
@GemFireUnitTest
|
||||
@SuppressWarnings("unused")
|
||||
public class GemfireV8GatewayNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.apache.geode.cache.DataPolicy;
|
||||
import org.apache.geode.cache.Region;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.data.gemfire.PeerRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.RegionAttributesFactoryBean;
|
||||
@@ -38,6 +39,7 @@ import org.springframework.data.gemfire.tests.integration.IntegrationTestsSuppor
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.springframework.data.gemfire.PeerRegionFactoryBean
|
||||
* @see org.springframework.data.gemfire.client.ClientRegionFactoryBean
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
@@ -46,13 +48,15 @@ import org.springframework.data.gemfire.tests.integration.IntegrationTestsSuppor
|
||||
public class InvalidRegionDefinitionUsingBeansNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
private static final String CONFIG_LOCATION =
|
||||
"org/springframework/data/gemfire/config/xml/InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceTest.xml";
|
||||
"org/springframework/data/gemfire/config/xml/InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceIntegrationTests.xml";
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testInvalidDataPolicyPersistentAttributeSettings() {
|
||||
|
||||
ConfigurableApplicationContext applicationContext = null;
|
||||
|
||||
try {
|
||||
new ClassPathXmlApplicationContext(CONFIG_LOCATION);
|
||||
applicationContext = new ClassPathXmlApplicationContext(CONFIG_LOCATION);
|
||||
}
|
||||
catch (BeanCreationException expected) {
|
||||
|
||||
@@ -62,6 +66,9 @@ public class InvalidRegionDefinitionUsingBeansNamespaceIntegrationTests extends
|
||||
|
||||
throw (IllegalArgumentException) expected.getCause();
|
||||
}
|
||||
finally {
|
||||
closeApplicationContext(applicationContext);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
||||
@@ -24,8 +24,7 @@ import org.apache.geode.cache.Region;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException;
|
||||
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.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor;
|
||||
import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport;
|
||||
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
@@ -38,40 +37,31 @@ import org.xml.sax.SAXParseException;
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.springframework.context.ConfigurableApplicationContext
|
||||
* @see org.springframework.context.support.GenericXmlApplicationContext
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public class InvalidRegionExpirationAttributesNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
private String contextConfigLocation() {
|
||||
return getClass().getName().replaceAll("\\.", "/").concat("-context.xml");
|
||||
}
|
||||
public class InvalidRegionExpirationAttributesNamespaceIntegrationTests
|
||||
extends SpringApplicationContextIntegrationTestsSupport {
|
||||
|
||||
private ConfigurableApplicationContext createApplicationContext() {
|
||||
return new GenericXmlApplicationContext();
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext configureContext(ConfigurableApplicationContext applicationContext) {
|
||||
applicationContext.getBeanFactory().addBeanPostProcessor(new GemFireMockObjectsBeanPostProcessor());
|
||||
return applicationContext;
|
||||
}
|
||||
GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
|
||||
|
||||
private ConfigurableApplicationContext initializeApplicationContext(ConfigurableApplicationContext applicationContext) {
|
||||
|
||||
assertThat(applicationContext).isInstanceOf(GenericXmlApplicationContext.class);
|
||||
((GenericXmlApplicationContext) applicationContext).load(contextConfigLocation());
|
||||
applicationContext.load(getContextXmlFileLocation(InvalidRegionExpirationAttributesNamespaceIntegrationTests.class));
|
||||
applicationContext.registerShutdownHook();
|
||||
applicationContext.refresh();
|
||||
|
||||
setApplicationContext(applicationContext);
|
||||
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
@Test(expected = XmlBeanDefinitionStoreException.class)
|
||||
public void testInvalidXmlSyntax() {
|
||||
public void invalidXmlSyntaxThrowsException() {
|
||||
|
||||
try {
|
||||
initializeApplicationContext(configureContext(createApplicationContext()));
|
||||
createApplicationContext();
|
||||
}
|
||||
catch (XmlBeanDefinitionStoreException expected) {
|
||||
assertThat(expected).hasCauseInstanceOf(SAXParseException.class);
|
||||
|
||||
@@ -17,6 +17,9 @@ package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -25,6 +28,7 @@ import org.apache.geode.internal.datasource.GemFireBasicDataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
|
||||
import org.springframework.data.gemfire.tests.util.FileSystemUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@@ -36,14 +40,21 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.Cache
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration("jndi-binding-ns.xml")
|
||||
@ContextConfiguration
|
||||
@SuppressWarnings("unused")
|
||||
public class JndiBindingsIntegrationTests extends IntegrationTestsSupport {
|
||||
public class JndiBindingsNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
@AfterClass
|
||||
public static void cleanupAfterTests() {
|
||||
FileSystemUtils.deleteRecursive(new File(FileSystemUtils.WORKING_DIRECTORY, "newDB"));
|
||||
FileSystemUtils.newFile(FileSystemUtils.WORKING_DIRECTORY, "derby.log").delete();
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private Cache cache;
|
||||
@@ -53,7 +64,7 @@ public class JndiBindingsIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
Object dataSourceObject = cache.getJNDIContext().lookup("java:/SimpleDataSource");
|
||||
|
||||
assertThat(dataSourceObject instanceof GemFireBasicDataSource).isTrue();
|
||||
assertThat(dataSourceObject).isInstanceOf(GemFireBasicDataSource.class);
|
||||
|
||||
GemFireBasicDataSource dataSource = (GemFireBasicDataSource) dataSourceObject;
|
||||
|
||||
@@ -26,12 +26,9 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import org.apache.geode.internal.datasource.ConfigProperty;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -41,21 +38,16 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.context.ApplicationContext
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer
|
||||
* @see org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(locations = "jndi-binding-with-property-placeholders-ns.xml",
|
||||
initializers = GemFireMockObjectsApplicationContextInitializer.class)
|
||||
public class JndiBindingsPropertyPlaceholderIntegrationTests extends IntegrationTestsSupport {
|
||||
@GemFireUnitTest
|
||||
public class JndiBindingsWithPropertyPlaceholdersNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
@Autowired
|
||||
@SuppressWarnings("unused")
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
protected void assertPropertyValueExists(String expectedPropertyName, String expectedPropertyValue,
|
||||
private void assertPropertyValueExists(String expectedPropertyName, String expectedPropertyValue,
|
||||
List<ConfigProperty> properties) {
|
||||
|
||||
for (ConfigProperty property : properties) {
|
||||
@@ -70,9 +62,9 @@ public class JndiBindingsPropertyPlaceholderIntegrationTests extends Integration
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheJndiDataSourceConfiguration() {
|
||||
public void cacheJndiContextDataSourceConfigurationIsCorrect() {
|
||||
|
||||
CacheFactoryBean factory = applicationContext.getBean("&gemfireCache", CacheFactoryBean.class);
|
||||
CacheFactoryBean factory = requireApplicationContext().getBean("&gemfireCache", CacheFactoryBean.class);
|
||||
|
||||
List<CacheFactoryBean.JndiDataSource> jndiDataSources = factory.getJndiDataSources();
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.apache.geode.cache.Region;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
|
||||
import org.springframework.data.gemfire.util.SpringUtils;
|
||||
|
||||
/**
|
||||
* Integration Tests for multiple Apache Geode {@link GemFireCache caches}.
|
||||
@@ -43,28 +44,42 @@ public class MultipleCacheIntegrationTests extends IntegrationTestsSupport {
|
||||
@Test
|
||||
public void testMultipleCaches() {
|
||||
|
||||
String configLocation = "/org/springframework/data/gemfire/config/xml/MultipleCacheTest-context.xml";
|
||||
String configLocation = getContextXmlFileLocation(MultipleCacheIntegrationTests.class);
|
||||
|
||||
ConfigurableApplicationContext context1 = new ClassPathXmlApplicationContext(configLocation);
|
||||
ConfigurableApplicationContext context2 = new ClassPathXmlApplicationContext(configLocation);
|
||||
ConfigurableApplicationContext applicationContextOne = null;
|
||||
ConfigurableApplicationContext applicationContextTwo = null;
|
||||
|
||||
Cache cache1 = context1.getBean(Cache.class);
|
||||
Cache cache2 = context2.getBean(Cache.class);
|
||||
try {
|
||||
|
||||
assertThat(cache1).isNotNull();
|
||||
assertThat(cache2).isSameAs(cache1);
|
||||
applicationContextOne = new ClassPathXmlApplicationContext(configLocation);
|
||||
applicationContextTwo = new ClassPathXmlApplicationContext(configLocation);
|
||||
|
||||
Region<?, ?> region1 = context1.getBean(Region.class);
|
||||
Region<?, ?> region2 = context2.getBean(Region.class);
|
||||
Cache cacheOne = applicationContextOne.getBean(Cache.class);
|
||||
Cache cacheTwo = applicationContextTwo.getBean(Cache.class);
|
||||
|
||||
assertThat(region1).isNotNull();
|
||||
assertThat(region2).isSameAs(region1);
|
||||
assertThat(cache1.isClosed()).isFalse();
|
||||
assertThat(region1.isDestroyed()).isFalse();
|
||||
assertThat(cacheOne).isNotNull();
|
||||
assertThat(cacheTwo).isSameAs(cacheOne);
|
||||
|
||||
context1.close();
|
||||
Region<?, ?> regionOne = applicationContextOne.getBean(Region.class);
|
||||
Region<?, ?> regionTwo = applicationContextTwo.getBean(Region.class);
|
||||
|
||||
assertThat(cache1.isClosed()).isFalse();
|
||||
assertThat(region1.isDestroyed()).as("region was destroyed").isFalse();
|
||||
assertThat(regionOne).isNotNull();
|
||||
assertThat(regionTwo).isSameAs(regionOne);
|
||||
assertThat(cacheOne.isClosed()).isFalse();
|
||||
assertThat(regionOne.isDestroyed()).isFalse();
|
||||
|
||||
applicationContextOne.close();
|
||||
|
||||
assertThat(cacheOne.isClosed()).isFalse();
|
||||
assertThat(regionOne.isDestroyed()).describedAs("Region was destroyed").isFalse();
|
||||
}
|
||||
finally {
|
||||
|
||||
final ConfigurableApplicationContext applicationContextOneRef = applicationContextOne;
|
||||
final ConfigurableApplicationContext applicationContextTwoRef = applicationContextTwo;
|
||||
|
||||
SpringUtils.safeDoOperation(() -> closeApplicationContext(applicationContextOneRef));
|
||||
SpringUtils.safeDoOperation(() -> closeApplicationContext(applicationContextTwoRef));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,49 +33,43 @@ import org.apache.geode.cache.partition.PartitionListener;
|
||||
import org.apache.geode.cache.partition.PartitionListenerAdapter;
|
||||
import org.apache.geode.compression.Compressor;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.PeerRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.SimpleCacheListener;
|
||||
import org.springframework.data.gemfire.SimplePartitionResolver;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
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;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Integration Tests for the Partitioned Region XML namespace configuration metadata.
|
||||
* Integration Tests for {@link DataPolicy#PARTITION} {@link Region} SDG XML namespace configuration metadata.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.DataPolicy#PARTITION
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.springframework.data.gemfire.PartitionedRegionFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.xml.PartitionedRegionParser
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer
|
||||
* @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(locations = "partitioned-ns.xml",
|
||||
initializers = GemFireMockObjectsApplicationContextInitializer.class)
|
||||
@GemFireUnitTest
|
||||
@SuppressWarnings("unused")
|
||||
public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void testSimplePartitionRegion() {
|
||||
|
||||
assertThat(applicationContext.containsBean("simple")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("simple")).isTrue();
|
||||
|
||||
Region<?, ?> simple = applicationContext.getBean("simple", Region.class);
|
||||
Region<?, ?> simple = requireApplicationContext().getBean("simple", Region.class);
|
||||
|
||||
assertThat(simple).isNotNull();
|
||||
assertThat(simple.getName()).isEqualTo("simple");
|
||||
@@ -88,19 +82,20 @@ public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTests
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testOptionsPartitionRegion() throws Exception {
|
||||
|
||||
assertThat(applicationContext.containsBean("options")).isTrue();
|
||||
assertThat(applicationContext.containsBean("redundant")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("options")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("redundant")).isTrue();
|
||||
|
||||
Region<?, ?> options = applicationContext.getBean("options", Region.class);
|
||||
Region<?, ?> options = requireApplicationContext().getBean("options", Region.class);
|
||||
|
||||
assertThat(options).isNotNull();
|
||||
assertThat(options.getAttributes()).isNotNull();
|
||||
assertThat(options.getName()).isEqualTo("redundant");
|
||||
assertThat(options.getAttributes()).isNotNull();
|
||||
assertThat(options.getAttributes().getOffHeap()).isTrue();
|
||||
|
||||
PeerRegionFactoryBean optionsRegionFactoryBean = applicationContext.getBean("&options", PeerRegionFactoryBean.class);
|
||||
PeerRegionFactoryBean optionsRegionFactoryBean =
|
||||
requireApplicationContext().getBean("&options", PeerRegionFactoryBean.class);
|
||||
|
||||
assertThat(optionsRegionFactoryBean instanceof PartitionedRegionFactoryBean).isTrue();
|
||||
assertThat(optionsRegionFactoryBean).isInstanceOf(PartitionedRegionFactoryBean.class);
|
||||
assertThat(TestUtils.<Object>readField("scope", optionsRegionFactoryBean)).isNull();
|
||||
assertThat(TestUtils.<Object>readField("name", optionsRegionFactoryBean)).isEqualTo("redundant");
|
||||
assertThat(TestUtils.<Object>readField("scope", optionsRegionFactoryBean)).isNull();
|
||||
@@ -123,21 +118,22 @@ public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTests
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testComplexPartitionRegion() throws Exception {
|
||||
|
||||
assertThat(applicationContext.containsBean("complex")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("complex")).isTrue();
|
||||
|
||||
PeerRegionFactoryBean complexRegionFactoryBean = applicationContext.getBean("&complex", PeerRegionFactoryBean.class);
|
||||
PeerRegionFactoryBean complexRegionFactoryBean =
|
||||
requireApplicationContext().getBean("&complex", PeerRegionFactoryBean.class);
|
||||
|
||||
CacheListener[] cacheListeners = TestUtils.readField("cacheListeners", complexRegionFactoryBean);
|
||||
|
||||
assertThat(ObjectUtils.isEmpty(cacheListeners)).isFalse();
|
||||
assertThat(cacheListeners.length).isEqualTo(2);
|
||||
assertThat(applicationContext.getBean("c-listener")).isSameAs(cacheListeners[0]);
|
||||
assertThat(cacheListeners[1] instanceof SimpleCacheListener).isTrue();
|
||||
assertThat(requireApplicationContext().getBean("c-listener")).isSameAs(cacheListeners[0]);
|
||||
assertThat(cacheListeners[1]).isInstanceOf(SimpleCacheListener.class);
|
||||
|
||||
assertThat(TestUtils.<Object>readField("cacheLoader", complexRegionFactoryBean))
|
||||
.isSameAs(applicationContext.getBean("c-loader"));
|
||||
.isSameAs(requireApplicationContext().getBean("c-loader"));
|
||||
assertThat(TestUtils.<Object>readField("cacheWriter", complexRegionFactoryBean))
|
||||
.isSameAs(applicationContext.getBean("c-writer"));
|
||||
.isSameAs(requireApplicationContext().getBean("c-writer"));
|
||||
|
||||
RegionAttributes complexRegionAttributes = TestUtils.readField("attributes", complexRegionFactoryBean);
|
||||
|
||||
@@ -156,17 +152,19 @@ public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTests
|
||||
@Test
|
||||
public void testCompressedPartitionRegion() {
|
||||
|
||||
assertThat(applicationContext.containsBean("compressed")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("compressed")).isTrue();
|
||||
|
||||
Region<?, ?> compressed = applicationContext.getBean("compressed", Region.class);
|
||||
Region<?, ?> compressed = requireApplicationContext().getBean("compressed", Region.class);
|
||||
|
||||
assertThat(compressed).as("The 'compressed' PARTITION Region was not properly configured and initialized!")
|
||||
assertThat(compressed)
|
||||
.describedAs("The 'compressed' PARTITION Region was not properly configured and initialized!")
|
||||
.isNotNull();
|
||||
|
||||
assertThat(compressed.getName()).isEqualTo("compressed");
|
||||
assertThat(compressed.getFullPath()).isEqualTo(Region.SEPARATOR + "compressed");
|
||||
assertThat(compressed.getAttributes()).isNotNull();
|
||||
assertThat(compressed.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.PARTITION);
|
||||
assertThat(compressed.getAttributes().getCompressor() instanceof TestCompressor).isTrue();
|
||||
assertThat(compressed.getAttributes().getCompressor()).isInstanceOf(TestCompressor.class);
|
||||
assertThat(compressed.getAttributes().getCompressor().toString()).isEqualTo("testCompressor");
|
||||
}
|
||||
|
||||
@@ -174,7 +172,8 @@ public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTests
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testFixedPartitionRegion() throws Exception {
|
||||
|
||||
PeerRegionFactoryBean fixedRegionFactoryBean = applicationContext.getBean("&fixed", PeerRegionFactoryBean.class);
|
||||
PeerRegionFactoryBean fixedRegionFactoryBean =
|
||||
requireApplicationContext().getBean("&fixed", PeerRegionFactoryBean.class);
|
||||
|
||||
assertThat(fixedRegionFactoryBean).isNotNull();
|
||||
|
||||
@@ -199,12 +198,14 @@ public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTests
|
||||
@Test
|
||||
public void testMultiplePartitionListeners() {
|
||||
|
||||
assertThat(applicationContext.containsBean("listeners")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("listeners")).isTrue();
|
||||
|
||||
Region<?, ?> listeners = applicationContext.getBean("listeners", Region.class);
|
||||
Region<?, ?> listeners = requireApplicationContext().getBean("listeners", Region.class);
|
||||
|
||||
assertThat(listeners).as("The 'listeners' PARTITION Region was not properly configured and initialized!")
|
||||
assertThat(listeners)
|
||||
.describedAs("The 'listeners' PARTITION Region was not properly configured and initialized!")
|
||||
.isNotNull();
|
||||
|
||||
assertThat(listeners.getName()).isEqualTo("listeners");
|
||||
assertThat(listeners.getFullPath()).isEqualTo(Region.SEPARATOR + "listeners");
|
||||
assertThat(listeners.getAttributes()).isNotNull();
|
||||
@@ -219,7 +220,7 @@ public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTests
|
||||
List<String> expectedNames = Arrays.asList("X", "Y", "Z", "ABC");
|
||||
|
||||
for (PartitionListener listener : listenersPartitionAttributes.getPartitionListeners()) {
|
||||
assertThat(listener instanceof TestPartitionListener).isTrue();
|
||||
assertThat(listener).isInstanceOf(TestPartitionListener.class);
|
||||
assertThat(expectedNames.contains(listener.toString())).isTrue();
|
||||
}
|
||||
}
|
||||
@@ -227,12 +228,14 @@ public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTests
|
||||
@Test
|
||||
public void testSinglePartitionListeners() {
|
||||
|
||||
assertThat(applicationContext.containsBean("listenerRef")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("listenerRef")).isTrue();
|
||||
|
||||
Region<?, ?> listeners = applicationContext.getBean("listenerRef", Region.class);
|
||||
Region<?, ?> listeners = requireApplicationContext().getBean("listenerRef", Region.class);
|
||||
|
||||
assertThat(listeners).as("The 'listenerRef' PARTITION Region was not properly configured and initialized!")
|
||||
assertThat(listeners)
|
||||
.describedAs("The 'listenerRef' PARTITION Region was not properly configured and initialized!")
|
||||
.isNotNull();
|
||||
|
||||
assertThat(listeners.getName()).isEqualTo("listenerRef");
|
||||
assertThat(listeners.getFullPath()).isEqualTo(Region.SEPARATOR + "listenerRef");
|
||||
assertThat(listeners.getAttributes()).isNotNull();
|
||||
@@ -243,7 +246,7 @@ public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTests
|
||||
assertThat(listenersPartitionAttributes).isNotNull();
|
||||
assertThat(listenersPartitionAttributes.getPartitionListeners()).isNotNull();
|
||||
assertThat(listenersPartitionAttributes.getPartitionListeners().length).isEqualTo(1);
|
||||
assertThat(listenersPartitionAttributes.getPartitionListeners()[0] instanceof TestPartitionListener).isTrue();
|
||||
assertThat(listenersPartitionAttributes.getPartitionListeners()[0]).isInstanceOf(TestPartitionListener.class);
|
||||
assertThat(listenersPartitionAttributes.getPartitionListeners()[0].toString()).isEqualTo("ABC");
|
||||
}
|
||||
|
||||
@@ -251,7 +254,7 @@ public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTests
|
||||
|
||||
private String name;
|
||||
|
||||
public void setName(final String name) {
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@@ -275,7 +278,7 @@ public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTests
|
||||
|
||||
private String name;
|
||||
|
||||
public void setName(final String name) {
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,16 +24,13 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import org.apache.geode.cache.client.Pool;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.data.gemfire.client.PoolAdapter;
|
||||
import org.springframework.data.gemfire.client.PoolFactoryBean;
|
||||
import org.springframework.data.gemfire.support.ConnectionEndpoint;
|
||||
import org.springframework.data.gemfire.support.ConnectionEndpointList;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -47,18 +44,15 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @see org.springframework.data.gemfire.client.PoolFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.xml.PoolParser
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer
|
||||
* @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(locations = "pool-ns.xml", initializers = GemFireMockObjectsApplicationContextInitializer.class)
|
||||
@GemFireUnitTest
|
||||
@SuppressWarnings("unused")
|
||||
public class PoolNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
private void assertConnectionEndpoint(ConnectionEndpointList connectionEndpoints,
|
||||
String expectedHost, int expectedPort) {
|
||||
|
||||
@@ -83,10 +77,10 @@ public class PoolNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
@Test
|
||||
public void gemfirePoolIsConfiguredProperly() throws Exception {
|
||||
|
||||
assertThat(applicationContext.containsBean("gemfirePool")).isTrue();
|
||||
assertThat(applicationContext.containsBean("gemfire-pool")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("gemfirePool")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("gemfire-pool")).isTrue();
|
||||
|
||||
PoolFactoryBean poolFactoryBean = applicationContext.getBean("&gemfirePool", PoolFactoryBean.class);
|
||||
PoolFactoryBean poolFactoryBean = requireApplicationContext().getBean("&gemfirePool", PoolFactoryBean.class);
|
||||
|
||||
ConnectionEndpointList locators = TestUtils.readField("locators", poolFactoryBean);
|
||||
|
||||
@@ -96,9 +90,9 @@ public class PoolNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
@Test
|
||||
public void simplePoolIsConfiguredProperly() throws Exception {
|
||||
|
||||
assertThat(applicationContext.containsBean("simple")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("simple")).isTrue();
|
||||
|
||||
PoolFactoryBean poolFactoryBean = applicationContext.getBean("&simple", PoolFactoryBean.class);
|
||||
PoolFactoryBean poolFactoryBean = requireApplicationContext().getBean("&simple", PoolFactoryBean.class);
|
||||
|
||||
ConnectionEndpointList servers = TestUtils.readField("servers", poolFactoryBean);
|
||||
|
||||
@@ -112,9 +106,9 @@ public class PoolNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
@Test
|
||||
public void locatorPoolIsConfiguredProperly() throws Exception {
|
||||
|
||||
assertThat(applicationContext.containsBean("locator")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("locator")).isTrue();
|
||||
|
||||
PoolFactoryBean poolFactoryBean = applicationContext.getBean("&locator", PoolFactoryBean.class);
|
||||
PoolFactoryBean poolFactoryBean = requireApplicationContext().getBean("&locator", PoolFactoryBean.class);
|
||||
|
||||
ConnectionEndpointList locators = TestUtils.readField("locators", poolFactoryBean);
|
||||
|
||||
@@ -134,9 +128,9 @@ public class PoolNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
@Test
|
||||
public void serverPoolIsConfiguredProperly() throws Exception {
|
||||
|
||||
assertThat(applicationContext.containsBean("server")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("server")).isTrue();
|
||||
|
||||
PoolFactoryBean poolFactoryBean = applicationContext.getBean("&server", PoolFactoryBean.class);
|
||||
PoolFactoryBean poolFactoryBean = requireApplicationContext().getBean("&server", PoolFactoryBean.class);
|
||||
Pool pool = poolFactoryBean.getPool();
|
||||
|
||||
assertThat(pool).isInstanceOf(PoolAdapter.class);
|
||||
@@ -175,9 +169,9 @@ public class PoolNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
@Test
|
||||
public void locatorsPoolIsConfiguredProperly() throws Exception {
|
||||
|
||||
assertThat(applicationContext.containsBean("locators")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("locators")).isTrue();
|
||||
|
||||
PoolFactoryBean poolFactoryBean = applicationContext.getBean("&locators", PoolFactoryBean.class);
|
||||
PoolFactoryBean poolFactoryBean = requireApplicationContext().getBean("&locators", PoolFactoryBean.class);
|
||||
|
||||
ConnectionEndpointList locators = TestUtils.readField("locators", poolFactoryBean);
|
||||
|
||||
@@ -195,9 +189,9 @@ public class PoolNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
@Test
|
||||
public void serversPoolIsConfiguredProperly() throws Exception {
|
||||
|
||||
assertThat(applicationContext.containsBean("servers")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("servers")).isTrue();
|
||||
|
||||
PoolFactoryBean poolFactoryBean = applicationContext.getBean("&servers", PoolFactoryBean.class);
|
||||
PoolFactoryBean poolFactoryBean = requireApplicationContext().getBean("&servers", PoolFactoryBean.class);
|
||||
|
||||
ConnectionEndpointList servers = TestUtils.readField("servers", poolFactoryBean);
|
||||
|
||||
|
||||
@@ -20,12 +20,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -75,26 +72,22 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer
|
||||
* @see org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @link https://jira.springsource.org/browse/SGF-178
|
||||
* @since 1.3.3
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(
|
||||
locations = "/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeTest-context.xml",
|
||||
initializers = GemFireMockObjectsApplicationContextInitializer.class)
|
||||
@GemFireUnitTest
|
||||
@SuppressWarnings("unused")
|
||||
public class RegionWithSubRegionBeanDefinitionHashCodeIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
@Autowired
|
||||
private AbstractApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void testNonParentRegionBeanDefinitionHashCode() {
|
||||
|
||||
BeanDefinition nonParentRegionBeanDefinition = applicationContext.getBeanFactory().getBeanDefinition("NON_PARENT");
|
||||
BeanDefinition nonParentRegionBeanDefinition =
|
||||
requireApplicationContext().getBeanFactory().getBeanDefinition("NON_PARENT");
|
||||
|
||||
assertThat(nonParentRegionBeanDefinition).isNotNull();
|
||||
assertThat(nonParentRegionBeanDefinition.hashCode() != 0).isTrue();
|
||||
@@ -103,7 +96,8 @@ public class RegionWithSubRegionBeanDefinitionHashCodeIntegrationTests extends I
|
||||
@Test
|
||||
public void testParentRegionBeanDefinitionHashCode() {
|
||||
|
||||
BeanDefinition parentRegionBeanDefinition = applicationContext.getBeanFactory().getBeanDefinition("PARENT");
|
||||
BeanDefinition parentRegionBeanDefinition =
|
||||
requireApplicationContext().getBeanFactory().getBeanDefinition("PARENT");
|
||||
|
||||
assertThat(parentRegionBeanDefinition).isNotNull();
|
||||
assertThat(parentRegionBeanDefinition.hashCode() != 0).isTrue();
|
||||
@@ -112,7 +106,8 @@ public class RegionWithSubRegionBeanDefinitionHashCodeIntegrationTests extends I
|
||||
@Test
|
||||
public void testChildRegionBeanDefinitionHashCode() {
|
||||
|
||||
BeanDefinition childRegionBeanDefinition = applicationContext.getBeanFactory().getBeanDefinition("/PARENT/CHILD");
|
||||
BeanDefinition childRegionBeanDefinition =
|
||||
requireApplicationContext().getBeanFactory().getBeanDefinition("/PARENT/CHILD");
|
||||
|
||||
assertThat(childRegionBeanDefinition).isNotNull();
|
||||
assertThat(childRegionBeanDefinition.hashCode() != 0).isTrue();
|
||||
|
||||
@@ -24,13 +24,10 @@ import org.apache.geode.cache.Cache;
|
||||
import org.apache.geode.cache.CacheLoader;
|
||||
import org.apache.geode.cache.Region;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.ReplicatedRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -42,23 +39,19 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @see org.apache.geode.cache.Cache
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer
|
||||
* @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(locations = "subregion-ns.xml",
|
||||
initializers = GemFireMockObjectsApplicationContextInitializer.class)
|
||||
@GemFireUnitTest
|
||||
@SuppressWarnings({ "rawtypes", "unused" })
|
||||
public class SubRegionNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void testNestedRegionsCreated() {
|
||||
|
||||
Cache cache = applicationContext.getBean(Cache.class);
|
||||
Cache cache = requireApplicationContext().getBean(Cache.class);
|
||||
|
||||
assertThat(cache.getRegion("parent")).isNotNull();
|
||||
assertThat(cache.getRegion("/parent/child")).isNotNull();
|
||||
@@ -69,9 +62,9 @@ public class SubRegionNamespaceIntegrationTests extends IntegrationTestsSupport
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testNestedReplicatedRegions() {
|
||||
|
||||
Region parent = applicationContext.getBean("parent", Region.class);
|
||||
Region child = applicationContext.getBean("/parent/child", Region.class);
|
||||
Region grandchild = applicationContext.getBean("/parent/child/grandchild", Region.class);
|
||||
Region parent = requireApplicationContext().getBean("parent", Region.class);
|
||||
Region child = requireApplicationContext().getBean("/parent/child", Region.class);
|
||||
Region grandchild = requireApplicationContext().getBean("/parent/child/grandchild", Region.class);
|
||||
|
||||
assertThat(child).isNotNull();
|
||||
assertThat(child.getName()).isEqualTo("child");
|
||||
@@ -87,9 +80,9 @@ public class SubRegionNamespaceIntegrationTests extends IntegrationTestsSupport
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testMixedNestedRegions() {
|
||||
|
||||
Region parent = applicationContext.getBean("replicatedParent", Region.class);
|
||||
Region child = applicationContext.getBean("/replicatedParent/replicatedChild", Region.class);
|
||||
Region grandchild = applicationContext.getBean("/replicatedParent/replicatedChild/partitionedGrandchild", Region.class);
|
||||
Region parent = requireApplicationContext().getBean("replicatedParent", Region.class);
|
||||
Region child = requireApplicationContext().getBean("/replicatedParent/replicatedChild", Region.class);
|
||||
Region grandchild = requireApplicationContext().getBean("/replicatedParent/replicatedChild/partitionedGrandchild", Region.class);
|
||||
|
||||
assertThat(child).isNotNull();
|
||||
assertThat(child.getFullPath()).isEqualTo("/replicatedParent/replicatedChild");
|
||||
@@ -103,18 +96,18 @@ public class SubRegionNamespaceIntegrationTests extends IntegrationTestsSupport
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testNestedRegionsWithSiblings() {
|
||||
|
||||
Region parent = applicationContext.getBean("parentWithSiblings", Region.class);
|
||||
Region child1 = applicationContext.getBean("/parentWithSiblings/child1", Region.class);
|
||||
Region parent = requireApplicationContext().getBean("parentWithSiblings", Region.class);
|
||||
Region child1 = requireApplicationContext().getBean("/parentWithSiblings/child1", Region.class);
|
||||
|
||||
assertThat(child1.getFullPath()).isEqualTo("/parentWithSiblings/child1");
|
||||
|
||||
Region child2 = applicationContext.getBean("/parentWithSiblings/child2", Region.class);
|
||||
Region child2 = requireApplicationContext().getBean("/parentWithSiblings/child2", Region.class);
|
||||
|
||||
assertThat(child2.getFullPath()).isEqualTo("/parentWithSiblings/child2");
|
||||
assertThat(parent.getSubregion("child1")).isSameAs(child1);
|
||||
assertThat(parent.getSubregion("child2")).isSameAs(child2);
|
||||
|
||||
Region grandchild1 = applicationContext.getBean("/parentWithSiblings/child1/grandChild11", Region.class);
|
||||
Region grandchild1 = requireApplicationContext().getBean("/parentWithSiblings/child1/grandChild11", Region.class);
|
||||
|
||||
assertThat(grandchild1.getFullPath()).isEqualTo("/parentWithSiblings/child1/grandChild11");
|
||||
}
|
||||
@@ -123,13 +116,14 @@ public class SubRegionNamespaceIntegrationTests extends IntegrationTestsSupport
|
||||
@SuppressWarnings("unused" )
|
||||
public void testComplexNestedRegions() throws Exception {
|
||||
|
||||
Region parent = applicationContext.getBean("complexNested", Region.class);
|
||||
Region child1 = applicationContext.getBean("/complexNested/child1", Region.class);
|
||||
Region child2 = applicationContext.getBean("/complexNested/child2", Region.class);
|
||||
Region grandchild11 = applicationContext.getBean("/complexNested/child1/grandChild11", Region.class);
|
||||
Region parent = requireApplicationContext().getBean("complexNested", Region.class);
|
||||
Region child1 = requireApplicationContext().getBean("/complexNested/child1", Region.class);
|
||||
Region child2 = requireApplicationContext().getBean("/complexNested/child2", Region.class);
|
||||
Region grandchild11 = requireApplicationContext().getBean("/complexNested/child1/grandChild11", Region.class);
|
||||
|
||||
ReplicatedRegionFactoryBean grandchild11FactoryBean =
|
||||
applicationContext.getBean("&/complexNested/child1/grandChild11", ReplicatedRegionFactoryBean.class);
|
||||
requireApplicationContext().getBean("&/complexNested/child1/grandChild11",
|
||||
ReplicatedRegionFactoryBean.class);
|
||||
|
||||
assertThat(grandchild11FactoryBean).isNotNull();
|
||||
|
||||
|
||||
@@ -30,11 +30,8 @@ import org.apache.geode.cache.asyncqueue.AsyncEvent;
|
||||
import org.apache.geode.cache.asyncqueue.AsyncEventListener;
|
||||
import org.apache.geode.cache.util.CacheListenerAdapter;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -47,20 +44,16 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer
|
||||
* @see org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 1.3.3
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(locations = "subregionsubelement-ns.xml",
|
||||
initializers = GemFireMockObjectsApplicationContextInitializer.class)
|
||||
@GemFireUnitTest
|
||||
@SuppressWarnings("unused")
|
||||
public class SubRegionSubElementNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Resource(name = "/Customers/Accounts")
|
||||
private Region<?, ?> customersAccountsRegion;
|
||||
|
||||
@@ -88,7 +81,7 @@ public class SubRegionSubElementNamespaceIntegrationTests extends IntegrationTes
|
||||
@Test
|
||||
public void testOrderItemsSubRegionGatewaySender() {
|
||||
|
||||
Region<?, ?> orderItemsRegion = applicationContext.getBean("/Orders/Items", Region.class);
|
||||
Region<?, ?> orderItemsRegion = requireApplicationContext().getBean("/Orders/Items", Region.class);
|
||||
|
||||
assertThat(orderItemsRegion).isNotNull();
|
||||
assertThat(orderItemsRegion.getAttributes()).isNotNull();
|
||||
|
||||
@@ -44,7 +44,7 @@ import org.xml.sax.SAXParseException;
|
||||
public class SubRegionWithInvalidDataPolicyTest extends IntegrationTestsSupport {
|
||||
|
||||
@Test(expected = XmlBeanDefinitionStoreException.class)
|
||||
public void testSubRegionBeanDefinitionWithInconsistentDataPolicy() {
|
||||
public void subRegionBeanDefinitionWithInconsistentDataPolicyThrowsException() {
|
||||
|
||||
try {
|
||||
new ClassPathXmlApplicationContext(
|
||||
@@ -52,7 +52,7 @@ public class SubRegionWithInvalidDataPolicyTest extends IntegrationTestsSupport
|
||||
}
|
||||
catch (XmlBeanDefinitionStoreException expected) {
|
||||
|
||||
assertThat(expected.getCause() instanceof SAXParseException).isTrue();
|
||||
assertThat(expected.getCause()).isInstanceOf(SAXParseException.class);
|
||||
assertThat(expected.getCause().getMessage().contains("PERSISTENT_PARTITION")).isTrue();
|
||||
|
||||
throw expected;
|
||||
@@ -60,7 +60,7 @@ public class SubRegionWithInvalidDataPolicyTest extends IntegrationTestsSupport
|
||||
}
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
public void testSubRegionBeanDefinitionWithInvalidDataPolicyPersistentSettings() {
|
||||
public void subRegionBeanDefinitionWithInvalidDataPolicyAndPersistentSettingsThrowsException() {
|
||||
|
||||
try {
|
||||
new ClassPathXmlApplicationContext(
|
||||
@@ -68,10 +68,9 @@ public class SubRegionWithInvalidDataPolicyTest extends IntegrationTestsSupport
|
||||
}
|
||||
catch (BeanCreationException expected) {
|
||||
|
||||
assertThat(expected.getMessage().contains("Error creating bean with name '/Parent/Child'")).isTrue();
|
||||
assertThat(expected.getCause() instanceof IllegalArgumentException).isTrue();
|
||||
assertThat(expected.getCause().getMessage())
|
||||
.isEqualTo("Data Policy [REPLICATE] is not valid when persistent is true");
|
||||
assertThat(expected).hasMessageContaining("Error creating bean with name '/Parent/Child'");
|
||||
assertThat(expected).hasCauseInstanceOf(IllegalArgumentException.class);
|
||||
assertThat(expected.getCause()).hasMessage("Data Policy [REPLICATE] is not valid when persistent is true");
|
||||
|
||||
throw expected;
|
||||
}
|
||||
|
||||
@@ -13,45 +13,45 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.geode.cache.Region;
|
||||
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
|
||||
|
||||
/**
|
||||
* The TemplateRegionDefinitionOrderErrorNamespaceTest class is a test suite of test cases testing the contract
|
||||
* and functionality of Region Templates, and specifically the correct order definition of Region Templates before
|
||||
* the Region bean definitions and concrete types that use those templates.
|
||||
* Integration Tests testing the incorrect order of Template {@link Region} bean definitions
|
||||
* and regular {@link Region} bean definitions referring to the templates.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public class TemplateRegionDefinitionOrderErrorNamespaceTest {
|
||||
|
||||
private String getConfigLocation() {
|
||||
return getClass().getName().replace(".", "/").concat("-context.xml");
|
||||
}
|
||||
public class TemplateRegionDefinitionOrderErrorNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
@Test(expected = BeanDefinitionParsingException.class)
|
||||
public void testIncorrectTemplateRegionDefinitionOrder() throws Exception {
|
||||
public void incorrectTemplateRegionBeanDefinitionOrderThrowsParseException() {
|
||||
|
||||
try {
|
||||
new ClassPathXmlApplicationContext(getConfigLocation());
|
||||
new ClassPathXmlApplicationContext(getContextXmlFileLocation(
|
||||
TemplateRegionDefinitionOrderErrorNamespaceIntegrationTests.class));
|
||||
}
|
||||
catch (BeanDefinitionParsingException expected) {
|
||||
|
||||
assertThat(expected)
|
||||
.hasMessageContaining("The Region template [RegionTemplate] must be defined before the Region [TemplateBasedPartitionRegion] referring to the template");
|
||||
assertThat(expected).hasMessageContaining("The Region template [RegionTemplate] must be defined before"
|
||||
+ " the Region [TemplateBasedPartitionRegion] referring to the template");
|
||||
|
||||
assertThat(expected).hasNoCause();
|
||||
|
||||
throw expected;
|
||||
@@ -20,12 +20,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
|
||||
import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer;
|
||||
import org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest;
|
||||
import org.springframework.data.gemfire.transaction.GemfireTransactionManager;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
@@ -34,28 +31,26 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @author Costin Leau
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.CacheFactoryBean
|
||||
* @see org.springframework.data.gemfire.transaction.GemfireTransactionManager
|
||||
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
|
||||
* @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer
|
||||
* @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(locations = "/org/springframework/data/gemfire/config/xml/tx-ns.xml",
|
||||
initializers = GemFireMockObjectsApplicationContextInitializer.class)
|
||||
@GemFireUnitTest
|
||||
@SuppressWarnings("unused")
|
||||
public class TxManagerNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
public class TransactionManagerNamespaceIntegrationTests extends IntegrationTestsSupport {
|
||||
|
||||
@Test
|
||||
public void testBasicCache() {
|
||||
public void basicCacheWithTransactionsIsConfiguredCorrectly() {
|
||||
|
||||
assertThat(applicationContext.containsBean("gemfireTransactionManager")).isTrue();
|
||||
assertThat(applicationContext.containsBean("gemfire-transaction-manager")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("gemfireTransactionManager")).isTrue();
|
||||
assertThat(requireApplicationContext().containsBean("gemfire-transaction-manager")).isTrue();
|
||||
|
||||
GemfireTransactionManager transactionManager =
|
||||
applicationContext.getBean("gemfireTransactionManager", GemfireTransactionManager.class);
|
||||
requireApplicationContext().getBean("gemfireTransactionManager", GemfireTransactionManager.class);
|
||||
|
||||
assertThat(transactionManager.isCopyOnRead()).isFalse();
|
||||
}
|
||||
@@ -20,12 +20,16 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.atLeast;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.data.gemfire.expiration.AnnotationBasedExpiration.ExpirationMetaData;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
@@ -48,16 +52,24 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.mockito.Mock
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.mockito.Spy
|
||||
* @see org.springframework.data.gemfire.expiration.AnnotationBasedExpiration
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
|
||||
public class AnnotationBasedExpirationUnitTests {
|
||||
|
||||
@BeforeClass @AfterClass
|
||||
public static void testSetupAndTearDown() {
|
||||
AnnotationBasedExpiration.BEAN_FACTORY_REFERENCE.set(null);
|
||||
AnnotationBasedExpiration.EVALUATION_CONTEXT_REFERENCE.set(null);
|
||||
}
|
||||
|
||||
private final AnnotationBasedExpiration noDefaultExpiration = new AnnotationBasedExpiration();
|
||||
|
||||
protected void assertExpiration(ExpirationAttributes expirationAttributes, int expectedTimeout,
|
||||
private void assertExpiration(ExpirationAttributes expirationAttributes, int expectedTimeout,
|
||||
ExpirationAction expectedAction) {
|
||||
|
||||
assertThat(expirationAttributes).isNotNull();
|
||||
@@ -65,7 +77,7 @@ public class AnnotationBasedExpirationUnitTests {
|
||||
assertThat(expirationAttributes.getAction()).isEqualTo(expectedAction);
|
||||
}
|
||||
|
||||
protected void assertExpiration(ExpirationMetaData expirationMetaData, int expectedTimeout,
|
||||
private void assertExpiration(ExpirationMetaData expirationMetaData, int expectedTimeout,
|
||||
ExpirationActionType expectedExpirationAction) {
|
||||
|
||||
assertThat(expirationMetaData).isNotNull();
|
||||
@@ -178,15 +190,12 @@ public class AnnotationBasedExpirationUnitTests {
|
||||
assertThat(TestUtils.<ConfigurableBeanFactory>readField("beanFactory", beanResolver)).isEqualTo(mockBeanFactory);
|
||||
|
||||
return null;
|
||||
|
||||
}).when(mockEvaluationContext).setBeanResolver(any(BeanResolver.class));
|
||||
|
||||
AnnotationBasedExpiration<Object, Object> annotationBasedExpiration = new AnnotationBasedExpiration<Object, Object>() {
|
||||
AnnotationBasedExpiration<Object, Object> annotationBasedExpiration = spy(new AnnotationBasedExpiration<>());
|
||||
|
||||
@Override
|
||||
StandardEvaluationContext newEvaluationContext() {
|
||||
return mockEvaluationContext;
|
||||
}
|
||||
};
|
||||
doReturn(mockEvaluationContext).when(annotationBasedExpiration).newEvaluationContext();
|
||||
|
||||
annotationBasedExpiration.setBeanFactory(mockBeanFactory);
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.data.gemfire.fork;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -29,6 +30,7 @@ import org.springframework.data.gemfire.GemfireUtils;
|
||||
import org.springframework.data.gemfire.tests.process.ProcessUtils;
|
||||
import org.springframework.data.gemfire.tests.util.FileSystemUtils;
|
||||
import org.springframework.data.gemfire.tests.util.ThreadUtils;
|
||||
import org.springframework.data.gemfire.util.ArrayUtils;
|
||||
|
||||
/**
|
||||
* The {@link LocatorProcess} class is a main Java class that is used fork and launch an Apache Geode {@link Locator}
|
||||
@@ -149,6 +151,9 @@ public class LocatorProcess {
|
||||
if (locator != null) {
|
||||
locator.stop();
|
||||
}
|
||||
|
||||
Arrays.stream(ArrayUtils.nullSafeArray(FileSystemUtils.WORKING_DIRECTORY.listFiles((dir, name) -> name.startsWith("vf.gf") && name.endsWith(".pid")), File.class))
|
||||
.forEach(File::delete);
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user