Rename @EnableGemFireGarbageCollector annotation to @EnableGemFireResourceCollector.

Rename all associated and appropriate uses of 'garbage' to 'resources'.

Resolves gh-21.
This commit is contained in:
John Blum
2020-06-17 20:07:28 -07:00
parent ad2c6c0f11
commit 36795103e7
5 changed files with 193 additions and 187 deletions

View File

@@ -30,8 +30,9 @@ import org.springframework.context.annotation.Import;
import org.springframework.test.context.event.AfterTestClassEvent; import org.springframework.test.context.event.AfterTestClassEvent;
/** /**
* The {@link EnableGemFireGarbageCollector} annotation enables the cleanup of resources (e.g. files) left behind * The {@link EnableGemFireResourceCollector} annotation enables the cleanup of resources (e.g. files) and other garbage
* by Apache Geode (VMware GemFire) after the GemFire/Geode process shuts down, even in a test context. * left behind by Apache Geode (or VMware GemFire) after the GemFire/Geode process shuts down, especially in a test
* context to avoid conflicts between test runs.
* *
* @author John Blum * @author John Blum
* @see java.lang.annotation.Documented * @see java.lang.annotation.Documented
@@ -46,17 +47,17 @@ import org.springframework.test.context.event.AfterTestClassEvent;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Inherited @Inherited
@Documented @Documented
@Import(GemFireGarbageCollectorConfiguration.class) @Import(GemFireResourceCollectorConfiguration.class)
@SuppressWarnings("unused") @SuppressWarnings("unused")
public @interface EnableGemFireGarbageCollector { public @interface EnableGemFireResourceCollector {
/** /**
* Determines the Spring {@link ApplicationEvent ApplicationEvents} that trigger the framework to cleanup after * Determines the Spring {@link ApplicationEvent ApplicationEvents} that trigger the framework to cleanup after
* Apache Geode / VMware GemFire given the junk it leaves behind after a process (e.g. CacheServer, Locator, * Apache Geode / VMware GemFire given the junk it leaves behind after a process (e.g. CacheServer, Locator,
* Manager, etc) terminates. * Manager, etc) terminates.
* *
* @return an array of {@link ApplicationEvent ApplicationEvents} that trigger the GemFire/Geode garbage collection * @return an array of {@link ApplicationEvent ApplicationEvents} that trigger the GemFire/Geode resource
* algorithm. * and garbage collection algorithm.
* @see org.springframework.context.ApplicationEvent * @see org.springframework.context.ApplicationEvent
* @see java.lang.Class * @see java.lang.Class
*/ */
@@ -65,10 +66,10 @@ public @interface EnableGemFireGarbageCollector {
/** /**
* Tries to cleanup all the {@link File Files} left behind by GemFire/Geode {@link DiskStore DiskStores}. * Tries to cleanup all the {@link File Files} left behind by GemFire/Geode {@link DiskStore DiskStores}.
* *
* @return a boolean value indicating whether the GemFire Garbage Collector should cleanup all {@link File Files} * @return a boolean value indicating whether the GemFire Resource Collector should cleanup all {@link File Files}
* left behind by GemFire/Geode {@link DiskStore DiskStores}, whether for persistence or overflow; * left behind by GemFire/Geode {@link DiskStore DiskStores}, whether for persistence or overflow;
* defaults to {@literal false}. * defaults to {@literal false}.
*/ */
boolean tryCleanDiskStoreFiles() default GemFireGarbageCollectorConfiguration.DEFAULT_CLEAN_DISK_STORE_FILES; boolean tryCleanDiskStoreFiles() default GemFireResourceCollectorConfiguration.DEFAULT_CLEAN_DISK_STORE_FILES;
} }

View File

@@ -25,14 +25,15 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportAware; import org.springframework.context.annotation.ImportAware;
import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.AnnotationMetadata;
import org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport; import org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport;
import org.springframework.data.gemfire.tests.integration.context.event.GemFireGarbageCollectorApplicationListener; import org.springframework.data.gemfire.tests.integration.context.event.GemFireResourceCollectorApplicationListener;
import org.springframework.data.gemfire.util.ArrayUtils; import org.springframework.data.gemfire.util.ArrayUtils;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
import org.springframework.test.context.event.AfterTestClassEvent; import org.springframework.test.context.event.AfterTestClassEvent;
/** /**
* Spring {@link Configuration} class used to register beans that collect garbage and other resources irresponsibly * Spring {@link Configuration} class used to register beans that collect resources and other garbage irresponsibly
* left behind by Apache Geode when its processes shutdown, even in a test context. * left behind by Apache Geode when its processes shutdown, particularly in a test context in order to avoid conflicts
* and interference between test runs.
* *
* @author John Blum * @author John Blum
* @see java.lang.annotation.Annotation * @see java.lang.annotation.Annotation
@@ -43,20 +44,19 @@ import org.springframework.test.context.event.AfterTestClassEvent;
* @see org.springframework.context.annotation.ImportAware * @see org.springframework.context.annotation.ImportAware
* @see org.springframework.core.type.AnnotationMetadata * @see org.springframework.core.type.AnnotationMetadata
* @see org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport * @see org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport
* @see org.springframework.data.gemfire.tests.integration.context.event.GemFireGarbageCollectorApplicationListener * @see org.springframework.data.gemfire.tests.integration.context.event.GemFireResourceCollectorApplicationListener
* @since 0.0.17 * @since 0.0.17
*/ */
@Configuration @Configuration
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class GemFireGarbageCollectorConfiguration extends AbstractAnnotationConfigSupport implements ImportAware { public class GemFireResourceCollectorConfiguration extends AbstractAnnotationConfigSupport implements ImportAware {
public static final boolean DEFAULT_CLEAN_DISK_STORE_FILES = false; public static final boolean DEFAULT_CLEAN_DISK_STORE_FILES = false;
private boolean tryCleanDiskStoreFiles = DEFAULT_CLEAN_DISK_STORE_FILES; private boolean tryCleanDiskStoreFiles = DEFAULT_CLEAN_DISK_STORE_FILES;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private Class<? extends ApplicationEvent>[] gemfireGarbageCollectorEventTypes = private Class<? extends ApplicationEvent>[] collectorEventTypes = new Class[] { AfterTestClassEvent.class };
new Class[] { AfterTestClassEvent.class };
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@@ -65,24 +65,24 @@ public class GemFireGarbageCollectorConfiguration extends AbstractAnnotationConf
Optional.of(importMetadata) Optional.of(importMetadata)
.filter(this::isAnnotationPresent) .filter(this::isAnnotationPresent)
.map(this::getAnnotationAttributes) .map(this::getAnnotationAttributes)
.ifPresent(enableGemFireGarbageCollectorAttributes -> { .ifPresent(enableGemFireResourceCollectorAttributes -> {
this.gemfireGarbageCollectorEventTypes = (Class<? extends ApplicationEvent>[]) this.collectorEventTypes = (Class<? extends ApplicationEvent>[])
enableGemFireGarbageCollectorAttributes.getClassArray("collectOnEvents"); enableGemFireResourceCollectorAttributes.getClassArray("collectOnEvents");
this.tryCleanDiskStoreFiles = this.tryCleanDiskStoreFiles =
enableGemFireGarbageCollectorAttributes.getBoolean("tryCleanDiskStoreFiles"); enableGemFireResourceCollectorAttributes.getBoolean("tryCleanDiskStoreFiles");
}); });
} }
@Override @Override
protected Class<? extends Annotation> getAnnotationType() { protected Class<? extends Annotation> getAnnotationType() {
return EnableGemFireGarbageCollector.class; return EnableGemFireResourceCollector.class;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected @NonNull Class<? extends ApplicationEvent>[] getGemFireGarbageCollectorEventTypes() { protected @NonNull Class<? extends ApplicationEvent>[] getConfiguredCollectorEventTypes() {
return ArrayUtils.nullSafeArray(this.gemfireGarbageCollectorEventTypes, Class.class); return ArrayUtils.nullSafeArray(this.collectorEventTypes, Class.class);
} }
protected boolean isTryCleanDiskStoreFiles() { protected boolean isTryCleanDiskStoreFiles() {
@@ -90,8 +90,8 @@ public class GemFireGarbageCollectorConfiguration extends AbstractAnnotationConf
} }
@Bean @Bean
ApplicationListener<ApplicationEvent> gemfireGarbageCollectorApplicationListener() { ApplicationListener<ApplicationEvent> gemfireResourceCollectorApplicationListener() {
return GemFireGarbageCollectorApplicationListener.create(getGemFireGarbageCollectorEventTypes()) return GemFireResourceCollectorApplicationListener.create(getConfiguredCollectorEventTypes())
.tryCleanDiskStoreFiles(isTryCleanDiskStoreFiles()); .tryCleanDiskStoreFiles(isTryCleanDiskStoreFiles());
} }
} }

View File

@@ -34,7 +34,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.data.gemfire.tests.integration.annotation.GemFireGarbageCollectorConfiguration; import org.springframework.data.gemfire.tests.integration.annotation.GemFireResourceCollectorConfiguration;
import org.springframework.data.gemfire.tests.util.FileSystemUtils; import org.springframework.data.gemfire.tests.util.FileSystemUtils;
import org.springframework.data.gemfire.util.ArrayUtils; import org.springframework.data.gemfire.util.ArrayUtils;
import org.springframework.data.gemfire.util.CollectionUtils; import org.springframework.data.gemfire.util.CollectionUtils;
@@ -47,111 +47,114 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* Spring {@link ApplicationListener} implementation used to listen for and trigger the GemFire/Geode garbage collection * Spring {@link ApplicationListener} implementation used to listen for and trigger the GemFire/Geode
* process. * resource collection algorithm.
* *
* @author John Blum * @author John Blum
* @see java.io.File * @see java.io.File
* @see java.io.FileFilter * @see java.io.FileFilter
* @see java.util.function.Predicate
* @see org.apache.geode.cache.DiskStore * @see org.apache.geode.cache.DiskStore
* @see org.springframework.context.ApplicationContext * @see org.springframework.context.ApplicationContext
* @see org.springframework.context.ApplicationContextAware * @see org.springframework.context.ApplicationContextAware
* @see org.springframework.context.ApplicationEvent * @see org.springframework.context.ApplicationEvent
* @see org.springframework.context.ApplicationListener * @see org.springframework.context.ApplicationListener
* @see org.springframework.data.gemfire.tests.integration.annotation.GemFireGarbageCollectorConfiguration * @see org.springframework.data.gemfire.tests.integration.annotation.GemFireResourceCollectorConfiguration
* @see org.springframework.test.context.event.AfterTestClassEvent * @see org.springframework.test.context.event.AfterTestClassEvent
* @since 0.0.17 * @since 0.0.17
*/ */
public class GemFireGarbageCollectorApplicationListener public class GemFireResourceCollectorApplicationListener
implements ApplicationContextAware, ApplicationListener<ApplicationEvent> { implements ApplicationContextAware, ApplicationListener<ApplicationEvent> {
protected static final File DEFAULT_SEARCH_DIRECTORY = FileSystemUtils.WORKING_DIRECTORY; protected static final File DEFAULT_SEARCH_DIRECTORY = FileSystemUtils.WORKING_DIRECTORY;
/** /**
* Factory method used to construct a new instance of {@link GemFireGarbageCollectorApplicationListener} * Factory method used to construct a new instance of {@link GemFireResourceCollectorApplicationListener}
* initialized with the {@link ApplicationEvent} objects that trigger the Gemfire/Geode garbage collection process. * initialized with the {@link ApplicationEvent} objects that trigger the Gemfire/Geode
* resource collection algorithm.
* *
* By default, the search will begin in the application working directory. * By default, the search will begin in the application working directory.
* *
* @param gemfireGarbageCollectorEventTypes array of {@link ApplicationEvent} objects triggering the GemFire/Geode * @param gemfireResourceCollectorEventTypes array of {@link ApplicationEvent} objects triggering the GemFire/Geode
* garbage collection process. * resource collection algorithm.
* @return a new instance of {@link GemFireGarbageCollectorApplicationListener}. * @return a new instance of {@link GemFireResourceCollectorApplicationListener}.
* @see #GemFireGarbageCollectorApplicationListener(File, Iterable) * @see #GemFireResourceCollectorApplicationListener(File, Iterable)
* @see org.springframework.context.ApplicationEvent * @see org.springframework.context.ApplicationEvent
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static GemFireGarbageCollectorApplicationListener create( public static GemFireResourceCollectorApplicationListener create(
@Nullable Class<? extends ApplicationEvent>... gemfireGarbageCollectorEventTypes) { @Nullable Class<? extends ApplicationEvent>... gemfireResourceCollectorEventTypes) {
return create(DEFAULT_SEARCH_DIRECTORY, return create(DEFAULT_SEARCH_DIRECTORY,
Arrays.asList(ArrayUtils.nullSafeArray(gemfireGarbageCollectorEventTypes, Class.class))); Arrays.asList(ArrayUtils.nullSafeArray(gemfireResourceCollectorEventTypes, Class.class)));
} }
/** /**
* Factory method used to construct a new instance of {@link GemFireGarbageCollectorApplicationListener} * Factory method used to construct a new instance of {@link GemFireResourceCollectorApplicationListener}
* initialized with the {@link File filesystem directory location} used to begin the search and collection of * initialized with the {@link File filesystem directory location} used to begin the search and collection of
* GemFire/Geode garbage along with the {@link ApplicationEvent} objects that trigger the Gemfire/Geode garbage * GemFire/Geode resources along with the {@link ApplicationEvent} objects that trigger the Gemfire/Geode
* collection process. * resource collection algorithm.
* *
* @param searchDirectory {@link File} referring to the filesystem directory location to begin the search; * @param searchDirectory {@link File} referring to the filesystem directory location to begin the search;
* defaults to the application working directory if {@link File} is {@literal null}. * defaults to the application working directory if {@link File} is {@literal null}.
* @param gemfireGarbageCollectorEventTypes array of {@link ApplicationEvent} objects triggering the GemFire/Geode * @param gemfireResourceCollectorEventTypes array of {@link ApplicationEvent} objects triggering the GemFire/Geode
* garbage collection process. * resource collection algorithm.
* @return a new instance of {@link GemFireGarbageCollectorApplicationListener}. * @return a new instance of {@link GemFireResourceCollectorApplicationListener}.
* @see #GemFireGarbageCollectorApplicationListener(File, Iterable) * @see #GemFireResourceCollectorApplicationListener(File, Iterable)
* @see org.springframework.context.ApplicationEvent * @see org.springframework.context.ApplicationEvent
* @see java.lang.Iterable * @see java.lang.Iterable
* @see java.io.File * @see java.io.File
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static GemFireGarbageCollectorApplicationListener create(@Nullable File searchDirectory, public static GemFireResourceCollectorApplicationListener create(@Nullable File searchDirectory,
@Nullable Class<? extends ApplicationEvent>... gemfireGarbageCollectorEventTypes) { @Nullable Class<? extends ApplicationEvent>... gemfireResourceCollectorEventTypes) {
return create(searchDirectory, Arrays.asList(ArrayUtils.nullSafeArray(gemfireGarbageCollectorEventTypes, Class.class))); return create(searchDirectory, Arrays.asList(ArrayUtils.nullSafeArray(gemfireResourceCollectorEventTypes, Class.class)));
} }
/** /**
* Factory method used to construct a new instance of {@link GemFireGarbageCollectorApplicationListener} * Factory method used to construct a new instance of {@link GemFireResourceCollectorApplicationListener}
* initialized with the {@link ApplicationEvent} objects that trigger the Gemfire/Geode garbage collection process. * initialized with the {@link ApplicationEvent} objects that trigger the Gemfire/Geode
* resource collection algorithm.
* *
* By default, the search will begin in the application working directory. * By default, the search will begin in the application working directory.
* *
* @param gemfireGarbageCollectorEventTypes {@link Iterable} of {@link ApplicationEvent} objects triggering * @param gemfireResourceCollectorEventTypes {@link Iterable} of {@link ApplicationEvent} objects triggering
* the GemFire/Geode garbage collection process. * the GemFire/Geode resource collection algorithm.
* @return a new instance of {@link GemFireGarbageCollectorApplicationListener}. * @return a new instance of {@link GemFireResourceCollectorApplicationListener}.
* @see #GemFireGarbageCollectorApplicationListener(File, Iterable) * @see #GemFireResourceCollectorApplicationListener(File, Iterable)
* @see org.springframework.context.ApplicationEvent * @see org.springframework.context.ApplicationEvent
* @see java.lang.Iterable * @see java.lang.Iterable
*/ */
public static GemFireGarbageCollectorApplicationListener create( public static GemFireResourceCollectorApplicationListener create(
@Nullable Iterable<Class<? extends ApplicationEvent>> gemfireGarbageCollectorEventTypes) { @Nullable Iterable<Class<? extends ApplicationEvent>> gemfireResourceCollectorEventTypes) {
return new GemFireGarbageCollectorApplicationListener(gemfireGarbageCollectorEventTypes); return new GemFireResourceCollectorApplicationListener(gemfireResourceCollectorEventTypes);
} }
/** /**
* Factory method used to construct a new instance of {@link GemFireGarbageCollectorApplicationListener} * Factory method used to construct a new instance of {@link GemFireResourceCollectorApplicationListener}
* initialized with the {@link File filesystem directory location} used to begin the search and collection of * initialized with the {@link File filesystem directory location} used to begin the search and collection of
* GemFire/Geode garbage along with the {@link ApplicationEvent} objects that trigger the Gemfire/Geode garbage * GemFire/Geode resources along with the {@link ApplicationEvent} objects that trigger the Gemfire/Geode
* collection process. * resource collection algorithm.
* *
* @param searchDirectory {@link File} referring to the filesystem directory location to begin the search; * @param searchDirectory {@link File} referring to the filesystem directory location to begin the search;
* defaults to the application working directory if {@link File} is {@literal null}. * defaults to the application working directory if {@link File} is {@literal null}.
* @param gemfireGarbageCollectorEventTypes {@link Iterable} of {@link ApplicationEvent} objects triggering * @param gemfireResourceCollectorEventTypes {@link Iterable} of {@link ApplicationEvent} objects triggering
* the GemFire/Geode garbage collection process. * the GemFire/Geode resource collection algorithm.
* @return a new instance of {@link GemFireGarbageCollectorApplicationListener}. * @return a new instance of {@link GemFireResourceCollectorApplicationListener}.
* @see #GemFireGarbageCollectorApplicationListener(File, Iterable) * @see #GemFireResourceCollectorApplicationListener(File, Iterable)
* @see org.springframework.context.ApplicationEvent * @see org.springframework.context.ApplicationEvent
* @see java.lang.Iterable * @see java.lang.Iterable
* @see java.io.File * @see java.io.File
*/ */
public static GemFireGarbageCollectorApplicationListener create(File searchDirectory, public static GemFireResourceCollectorApplicationListener create(File searchDirectory,
@Nullable Iterable<Class<? extends ApplicationEvent>> gemfireGarbageCollectorEventTypes) { @Nullable Iterable<Class<? extends ApplicationEvent>> gemfireResourceCollectorEventTypes) {
return new GemFireGarbageCollectorApplicationListener(searchDirectory, gemfireGarbageCollectorEventTypes); return new GemFireResourceCollectorApplicationListener(searchDirectory, gemfireResourceCollectorEventTypes);
} }
private boolean tryCleanDiskStoreFilesEnabled = GemFireGarbageCollectorConfiguration.DEFAULT_CLEAN_DISK_STORE_FILES; private boolean tryCleanDiskStoreFilesEnabled = GemFireResourceCollectorConfiguration.DEFAULT_CLEAN_DISK_STORE_FILES;
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@@ -159,51 +162,53 @@ public class GemFireGarbageCollectorApplicationListener
private final Logger logger = LoggerFactory.getLogger(getClass()); private final Logger logger = LoggerFactory.getLogger(getClass());
private final Set<Class<? extends ApplicationEvent>> gemfireGarbageCollectorEventTypes; private final Set<Class<? extends ApplicationEvent>> gemfireResourceCollectorEventTypes;
/** /**
* Constructs a new instance of {@link GemFireGarbageCollectorApplicationListener} initialized with * Constructs a new instance of {@link GemFireResourceCollectorApplicationListener} initialized with
* an {@link Iterable} of {@link ApplicationEvent} objects that trigger a GemFire/Geode garbage collection. * an {@link Iterable} of {@link ApplicationEvent} objects triggering the GemFire/Geode
* resource collection algorithm.
* *
* The search will begin in the application working directory. * The search will begin in the application working directory.
* *
* @param gemfireGarbageCollectorEventTypes {@link Iterable} of {@link ApplicationEvent} objects that trigger * @param gemfireResourceCollectorEventTypes {@link Iterable} of {@link ApplicationEvent} objects that trigger
* GemFire/Geode garbage collection. * GemFire/Geode resource collection.
* @see org.springframework.context.ApplicationEvent * @see org.springframework.context.ApplicationEvent
* @see java.lang.Iterable * @see java.lang.Iterable
*/ */
public GemFireGarbageCollectorApplicationListener( public GemFireResourceCollectorApplicationListener(
@Nullable Iterable<Class<? extends ApplicationEvent>> gemfireGarbageCollectorEventTypes) { @Nullable Iterable<Class<? extends ApplicationEvent>> gemfireResourceCollectorEventTypes) {
this(FileSystemUtils.WORKING_DIRECTORY, gemfireGarbageCollectorEventTypes); this(FileSystemUtils.WORKING_DIRECTORY, gemfireResourceCollectorEventTypes);
} }
/** /**
* Constructs a new instance of {@link GemFireGarbageCollectorApplicationListener} initialized with * Constructs a new instance of {@link GemFireResourceCollectorApplicationListener} initialized with
* a {@link File} referring to the directory to begin the search for GemFire/Geode garbage along with * a {@link File} referring to the directory to begin the search for GemFire/Geode resources along with
* an {@link Iterable} of {@link ApplicationEvent} objects that trigger a GemFire/Geode garbage collection. * an {@link Iterable} of {@link ApplicationEvent} objects triggering the GemFire/Geode resource collection
* algorithm.
* *
* @param searchDirectory {@link File} referring to the directory begin collecting GemFire/Geode garbage. * @param searchDirectory {@link File} referring to the directory begin collecting GemFire/Geode resources.
* @param gemfireGarbageCollectorEventTypes {@link Iterable} of {@link ApplicationEvent} objects that trigger * @param gemfireResourceCollectorEventTypes {@link Iterable} of {@link ApplicationEvent} objects that trigger
* GemFire/Geode garbage collection. * GemFire/Geode resource collection.
* @see org.springframework.context.ApplicationEvent * @see org.springframework.context.ApplicationEvent
* @see java.lang.Iterable * @see java.lang.Iterable
*/ */
public GemFireGarbageCollectorApplicationListener(@Nullable File searchDirectory, public GemFireResourceCollectorApplicationListener(@Nullable File searchDirectory,
@Nullable Iterable<Class<? extends ApplicationEvent>> gemfireGarbageCollectorEventTypes) { @Nullable Iterable<Class<? extends ApplicationEvent>> gemfireResourceCollectorEventTypes) {
this.searchDirectory = searchDirectory != null ? searchDirectory : DEFAULT_SEARCH_DIRECTORY; this.searchDirectory = searchDirectory != null ? searchDirectory : DEFAULT_SEARCH_DIRECTORY;
Set<Class<? extends ApplicationEvent>> resolvedGemFireGarbageCollectorEventTypes = Set<Class<? extends ApplicationEvent>> resolvedGemFireResourceCollectorEventTypes =
StreamSupport.stream(CollectionUtils.nullSafeIterable(gemfireGarbageCollectorEventTypes).spliterator(), false) StreamSupport.stream(CollectionUtils.nullSafeIterable(gemfireResourceCollectorEventTypes).spliterator(), false)
.filter(Objects::nonNull) .filter(Objects::nonNull)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
resolvedGemFireGarbageCollectorEventTypes = !resolvedGemFireGarbageCollectorEventTypes.isEmpty() resolvedGemFireResourceCollectorEventTypes = !resolvedGemFireResourceCollectorEventTypes.isEmpty()
? resolvedGemFireGarbageCollectorEventTypes ? resolvedGemFireResourceCollectorEventTypes
: Collections.singleton(AfterTestClassEvent.class); : Collections.singleton(AfterTestClassEvent.class);
this.gemfireGarbageCollectorEventTypes = Collections.unmodifiableSet(resolvedGemFireGarbageCollectorEventTypes); this.gemfireResourceCollectorEventTypes = Collections.unmodifiableSet(resolvedGemFireResourceCollectorEventTypes);
} }
/** /**
@@ -232,33 +237,33 @@ public class GemFireGarbageCollectorApplicationListener
/** /**
* Returns a configured {@link Set} of {@link ApplicationEvent} {@link Class types} that trigger the GemFire/Geode * Returns a configured {@link Set} of {@link ApplicationEvent} {@link Class types} that trigger the GemFire/Geode
* garbage collection process. * resource collection algorithm.
* *
* @return a configured {@link Set} of {@link ApplicationEvent} {@link Class types} that trigger the GemFire/Geode * @return a configured {@link Set} of {@link ApplicationEvent} {@link Class types} that trigger the GemFire/Geode
* garbage collection process. * resource collection algorithm.
* @see org.springframework.context.ApplicationEvent * @see org.springframework.context.ApplicationEvent
* @see java.util.Set * @see java.util.Set
*/ */
protected @NonNull Set<Class<? extends ApplicationEvent>> getConfiguredGemFireGarbageCollectorEventTypes() { protected @NonNull Set<Class<? extends ApplicationEvent>> getConfiguredGemFireResourceCollectorEventTypes() {
return this.gemfireGarbageCollectorEventTypes; return this.gemfireResourceCollectorEventTypes;
} }
/** /**
* Determines whether the given {@link ApplicationEvent} is a configured event for triggering the GemFire/Geode * Determines whether the given {@link ApplicationEvent} is a configured event for triggering the GemFire/Geode
* garbage collection process. * resource collection algorithm.
* *
* @param event {@link ApplicationEvent} to evaluate. * @param event {@link ApplicationEvent} to evaluate.
* @return a boolean value determining whether the given {@link ApplicationEvent} is a configured event * @return a boolean value determining whether the given {@link ApplicationEvent} is a configured event
* for triggering the GemFire/Geode garbage collection process. * for triggering the GemFire/Geode resource collection algorithm.
* @see org.springframework.context.ApplicationEvent * @see org.springframework.context.ApplicationEvent
* @see #getConfiguredGemFireGarbageCollectorEventTypes() * @see #getConfiguredGemFireResourceCollectorEventTypes()
*/ */
protected boolean isGemFireGarbageCollectorEvent(@Nullable ApplicationEvent event) { protected boolean isGemFireResourceCollectorEvent(@Nullable ApplicationEvent event) {
for (Class<? extends ApplicationEvent> gemfireGarbageCollectorEventType for (Class<? extends ApplicationEvent> gemfireResourceCollectorEventType
: getConfiguredGemFireGarbageCollectorEventTypes()) { : getConfiguredGemFireResourceCollectorEventTypes()) {
if (gemfireGarbageCollectorEventType.isInstance(event)) { if (gemfireResourceCollectorEventType.isInstance(event)) {
return true; return true;
} }
} }
@@ -268,7 +273,7 @@ public class GemFireGarbageCollectorApplicationListener
/** /**
* Returns the configured SLF4J {@link Logger} to log events and messages originating from this * Returns the configured SLF4J {@link Logger} to log events and messages originating from this
* {@link ApplicationListener} during the GemFire/Geode garbage collection process. * {@link ApplicationListener} during the GemFire/Geode resource collection algorithm.
* *
* @return the configured SLF4 {@link Logger}. * @return the configured SLF4 {@link Logger}.
* @see org.slf4j.Logger * @see org.slf4j.Logger
@@ -279,10 +284,10 @@ public class GemFireGarbageCollectorApplicationListener
/** /**
* Returns the configured {@link File directory} referring to the filesystem location to begin the search for * Returns the configured {@link File directory} referring to the filesystem location to begin the search for
* GemFire/Geode garbage. * GemFire/Geode resources and other garbage.
* *
* @return the configured {@link File directory} referring to the filesystem location to begin the search for * @return the configured {@link File directory} referring to the filesystem location to begin the search for
* GemFire/Geode garbage. * GemFire/Geode resources and other garbage.
* @see java.io.File * @see java.io.File
*/ */
protected @NonNull File getSearchDirectory() { protected @NonNull File getSearchDirectory() {
@@ -290,12 +295,12 @@ public class GemFireGarbageCollectorApplicationListener
} }
/** /**
* Determines whether this {@link ApplicationListener GemFire/Geode Garbage Collector} should try to cleanup all * Determines whether this {@link ApplicationListener GemFire/Geode Resource Collector} should try to cleanup all
* {@link DiskStore} {@link File Files} as well. * {@link DiskStore} {@link File Files} as well.
* *
* {@link DiskStore} {@link File Files} are maintained in {@link DiskStore#getDiskDirs()}. * {@link DiskStore} {@link File Files} are maintained in {@link DiskStore#getDiskDirs()}.
* *
* @return a boolean value indicating whether this {@link ApplicationListener GemFire/Geode Garbage Collector} * @return a boolean value indicating whether this {@link ApplicationListener GemFire/Geode Resource Collector}
* should try to cleanup all {@link DiskStore} {@link File Files}. * should try to cleanup all {@link DiskStore} {@link File Files}.
*/ */
protected boolean isTryCleanDiskStoreFilesEnabled() { protected boolean isTryCleanDiskStoreFilesEnabled() {
@@ -304,18 +309,18 @@ public class GemFireGarbageCollectorApplicationListener
/** /**
* Handles a Spring Container {@link ApplicationEvent} by determining whether the event is a configured event * Handles a Spring Container {@link ApplicationEvent} by determining whether the event is a configured event
* for triggering the GemFire/Geode garbage collection. * for triggering the GemFire/Geode resource collection.
* *
* @param event {@link ApplicationEvent} to evaluate. * @param event {@link ApplicationEvent} to evaluate.
* @see #isGemFireGarbageCollectorEvent(ApplicationEvent) * @see #isGemFireResourceCollectorEvent(ApplicationEvent)
* @see #collectGemFireGarbage(File) * @see #collectGemFireResources(File)
* @see org.springframework.context.ApplicationEvent * @see org.springframework.context.ApplicationEvent
*/ */
@Override @Override
public void onApplicationEvent(@NonNull ApplicationEvent event) { public void onApplicationEvent(@NonNull ApplicationEvent event) {
if (isGemFireGarbageCollectorEvent(event)) { if (isGemFireResourceCollectorEvent(event)) {
collectGemFireGarbage(getSearchDirectory()); collectGemFireResources(getSearchDirectory());
} }
if (isTryCleanDiskStoreFilesEnabled()) if (isTryCleanDiskStoreFilesEnabled())
@@ -324,19 +329,19 @@ public class GemFireGarbageCollectorApplicationListener
/** /**
* A {@link File} referring to the filesystem directory location to begin the search for and collection of * A {@link File} referring to the filesystem directory location to begin the search for and collection of
* GemFire/Geode garbage. * GemFire/Geode resources and other garbage.
* *
* @param directory {@link File} referring to the filesystem directory location to begin the search * @param directory {@link File} referring to the filesystem directory location to begin the search
* and collection process; must not be {@literal null}. * and resource collection process; must not be {@literal null}.
* @throws IllegalArgumentException if {@link File} is {@literal null} or not a directory. * @throws IllegalArgumentException if {@link File} is {@literal null} or not a directory.
* @see java.io.File * @see java.io.File
*/ */
protected void collectGemFireGarbage(@NonNull File directory) { protected void collectGemFireResources(@NonNull File directory) {
Assert.isTrue(FileSystemUtils.isDirectory(directory), Assert.isTrue(FileSystemUtils.isDirectory(directory),
() -> String.format("File [%s] must be a directory", directory)); () -> String.format("File [%s] must be a directory", directory));
for (File file : FileSystemUtils.safeListFiles(directory, GemFireGarbageFileFilter.INSTANCE)) { for (File file : FileSystemUtils.safeListFiles(directory, GemFireResourceFileFilter.INSTANCE)) {
if (FileSystemUtils.isDirectory(file)) { if (FileSystemUtils.isDirectory(file)) {
FileSystemUtils.deleteRecursive(file); FileSystemUtils.deleteRecursive(file);
} }
@@ -377,19 +382,19 @@ public class GemFireGarbageCollectorApplicationListener
* Configures whether to try and cleanup all {@link File Files} generated from managed {@link DiskStore DiskStores}. * Configures whether to try and cleanup all {@link File Files} generated from managed {@link DiskStore DiskStores}.
* *
* @param enable boolean value dis/enabling {@link DiskStore} {@link File} cleanup. * @param enable boolean value dis/enabling {@link DiskStore} {@link File} cleanup.
* @return this {@link GemFireGarbageCollectorApplicationListener}. * @return this {@link GemFireResourceCollectorApplicationListener}.
*/ */
public GemFireGarbageCollectorApplicationListener tryCleanDiskStoreFiles(boolean enable) { public GemFireResourceCollectorApplicationListener tryCleanDiskStoreFiles(boolean enable) {
this.tryCleanDiskStoreFilesEnabled = enable; this.tryCleanDiskStoreFilesEnabled = enable;
return this; return this;
} }
/** /**
* {@link FileFilter} implementation matching {@link File directories} or GemFire/Geode garbage. * {@link FileFilter} implementation matching {@link File directories} or GemFire/Geode resources (e.g. files).
*/ */
protected static class GemFireGarbageFileFilter implements FileFilter { protected static class GemFireResourceFileFilter implements FileFilter {
protected static final GemFireGarbageFileFilter INSTANCE = new GemFireGarbageFileFilter(); protected static final GemFireResourceFileFilter INSTANCE = new GemFireResourceFileFilter();
protected static final FileFilter DIRECTORY_FILE_FILTER = FileSystemUtils.DirectoryOnlyFilter.INSTANCE; protected static final FileFilter DIRECTORY_FILE_FILTER = FileSystemUtils.DirectoryOnlyFilter.INSTANCE;
@@ -439,10 +444,10 @@ public class GemFireGarbageCollectorApplicationListener
@Override @Override
public boolean accept(File pathname) { public boolean accept(File pathname) {
return getDirectoryFileFilter().accept(pathname) || isGemFireGarbage(pathname); return getDirectoryFileFilter().accept(pathname) || isGemFireResource(pathname);
} }
protected boolean isGemFireGarbage(@Nullable File file) { protected boolean isGemFireResource(@Nullable File file) {
return Objects.nonNull(file) && isFileExtensionOrFileNameMatch(file); return Objects.nonNull(file) && isFileExtensionOrFileNameMatch(file);
} }

View File

@@ -29,7 +29,7 @@ import java.util.Set;
import org.junit.Test; import org.junit.Test;
import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.AnnotationMetadata;
import org.springframework.data.gemfire.tests.integration.context.event.GemFireGarbageCollectorApplicationListener; import org.springframework.data.gemfire.tests.integration.context.event.GemFireResourceCollectorApplicationListener;
import org.springframework.data.gemfire.tests.support.MapBuilder; import org.springframework.data.gemfire.tests.support.MapBuilder;
import org.springframework.data.gemfire.tests.util.ReflectionUtils; import org.springframework.data.gemfire.tests.util.ReflectionUtils;
import org.springframework.test.context.event.AfterTestClassEvent; import org.springframework.test.context.event.AfterTestClassEvent;
@@ -37,15 +37,15 @@ import org.springframework.test.context.event.AfterTestExecutionEvent;
import org.springframework.test.context.event.AfterTestMethodEvent; import org.springframework.test.context.event.AfterTestMethodEvent;
/** /**
* Unit Tests for {@link GemFireGarbageCollectorConfiguration}. * Unit Tests for {@link GemFireResourceCollectorConfiguration}.
* *
* @author John Blum * @author John Blum
* @see org.junit.Test * @see org.junit.Test
* @see org.mockito.Mockito * @see org.mockito.Mockito
* @see org.springframework.data.gemfire.tests.integration.annotation.GemFireGarbageCollectorConfiguration * @see GemFireResourceCollectorConfiguration
* @since 0.0.17 * @since 0.0.17
*/ */
public class GemFireGarbageCollectorConfigurationUnitTests { public class GemFireResourceCollectorConfigurationUnitTests {
@Test @Test
public void setImportMetadataParsesConfiguration() { public void setImportMetadataParsesConfiguration() {
@@ -58,40 +58,40 @@ public class GemFireGarbageCollectorConfigurationUnitTests {
AnnotationMetadata mockAnnotationMetadata = mock(AnnotationMetadata.class); AnnotationMetadata mockAnnotationMetadata = mock(AnnotationMetadata.class);
doReturn(true).when(mockAnnotationMetadata) doReturn(true).when(mockAnnotationMetadata)
.hasAnnotation(EnableGemFireGarbageCollector.class.getName()); .hasAnnotation(EnableGemFireResourceCollector.class.getName());
doReturn(annotationAttributes).when(mockAnnotationMetadata) doReturn(annotationAttributes).when(mockAnnotationMetadata)
.getAnnotationAttributes(EnableGemFireGarbageCollector.class.getName()); .getAnnotationAttributes(EnableGemFireResourceCollector.class.getName());
GemFireGarbageCollectorConfiguration configuration = new GemFireGarbageCollectorConfiguration(); GemFireResourceCollectorConfiguration configuration = new GemFireResourceCollectorConfiguration();
assertThat(configuration.getGemFireGarbageCollectorEventTypes()).containsExactly(AfterTestClassEvent.class); assertThat(configuration.getConfiguredCollectorEventTypes()).containsExactly(AfterTestClassEvent.class);
assertThat(configuration.isTryCleanDiskStoreFiles()).isFalse(); assertThat(configuration.isTryCleanDiskStoreFiles()).isFalse();
configuration.setImportMetadata(mockAnnotationMetadata); configuration.setImportMetadata(mockAnnotationMetadata);
assertThat(configuration.getGemFireGarbageCollectorEventTypes()) assertThat(configuration.getConfiguredCollectorEventTypes())
.containsExactly(AfterTestMethodEvent.class, AfterTestExecutionEvent.class); .containsExactly(AfterTestMethodEvent.class, AfterTestExecutionEvent.class);
assertThat(configuration.isTryCleanDiskStoreFiles()).isTrue(); assertThat(configuration.isTryCleanDiskStoreFiles()).isTrue();
verify(mockAnnotationMetadata, times(1)) verify(mockAnnotationMetadata, times(1))
.hasAnnotation(eq(EnableGemFireGarbageCollector.class.getName())); .hasAnnotation(eq(EnableGemFireResourceCollector.class.getName()));
verify(mockAnnotationMetadata, times(1)) verify(mockAnnotationMetadata, times(1))
.getAnnotationAttributes(eq(EnableGemFireGarbageCollector.class.getName())); .getAnnotationAttributes(eq(EnableGemFireResourceCollector.class.getName()));
} }
@Test @Test
public void createsGemFireGarbageCollectorApplicationListenerWithDefaultConfiguration() public void createsGemFireResourceCollectorApplicationListenerWithDefaultConfiguration()
throws NoSuchFieldException { throws NoSuchFieldException {
GemFireGarbageCollectorConfiguration configuration = new GemFireGarbageCollectorConfiguration(); GemFireResourceCollectorConfiguration configuration = new GemFireResourceCollectorConfiguration();
assertThat(configuration.getGemFireGarbageCollectorEventTypes()).containsExactly(AfterTestClassEvent.class); assertThat(configuration.getConfiguredCollectorEventTypes()).containsExactly(AfterTestClassEvent.class);
assertThat(configuration.isTryCleanDiskStoreFiles()).isFalse(); assertThat(configuration.isTryCleanDiskStoreFiles()).isFalse();
GemFireGarbageCollectorApplicationListener listener = GemFireResourceCollectorApplicationListener listener =
(GemFireGarbageCollectorApplicationListener) configuration.gemfireGarbageCollectorApplicationListener(); (GemFireResourceCollectorApplicationListener) configuration.gemfireResourceCollectorApplicationListener();
assertThat(ReflectionUtils.<Set<Class<?>>>getFieldValue(listener, "gemfireGarbageCollectorEventTypes")) assertThat(ReflectionUtils.<Set<Class<?>>>getFieldValue(listener, "gemfireResourceCollectorEventTypes"))
.containsExactly(AfterTestClassEvent.class); .containsExactly(AfterTestClassEvent.class);
assertThat(ReflectionUtils.<Boolean>getFieldValue(listener, "tryCleanDiskStoreFilesEnabled")) assertThat(ReflectionUtils.<Boolean>getFieldValue(listener, "tryCleanDiskStoreFilesEnabled"))
@@ -99,23 +99,23 @@ public class GemFireGarbageCollectorConfigurationUnitTests {
} }
@Test @Test
public void createsGemFireGarbageCollectorApplicationListenerWithCustomConfiguration() public void createsGemFireResourceCollectorApplicationListenerWithCustomConfiguration()
throws NoSuchFieldException { throws NoSuchFieldException {
GemFireGarbageCollectorConfiguration configuration = spy(new GemFireGarbageCollectorConfiguration()); GemFireResourceCollectorConfiguration configuration = spy(new GemFireResourceCollectorConfiguration());
doReturn(new Class<?>[] { AfterTestMethodEvent.class, AfterTestExecutionEvent.class }) doReturn(new Class<?>[] { AfterTestMethodEvent.class, AfterTestExecutionEvent.class })
.when(configuration).getGemFireGarbageCollectorEventTypes(); .when(configuration).getConfiguredCollectorEventTypes();
doReturn(true).when(configuration).isTryCleanDiskStoreFiles(); doReturn(true).when(configuration).isTryCleanDiskStoreFiles();
assertThat(configuration.getGemFireGarbageCollectorEventTypes()) assertThat(configuration.getConfiguredCollectorEventTypes())
.containsExactly(AfterTestMethodEvent.class, AfterTestExecutionEvent.class); .containsExactly(AfterTestMethodEvent.class, AfterTestExecutionEvent.class);
assertThat(configuration.isTryCleanDiskStoreFiles()).isTrue(); assertThat(configuration.isTryCleanDiskStoreFiles()).isTrue();
GemFireGarbageCollectorApplicationListener listener = GemFireResourceCollectorApplicationListener listener =
(GemFireGarbageCollectorApplicationListener) configuration.gemfireGarbageCollectorApplicationListener(); (GemFireResourceCollectorApplicationListener) configuration.gemfireResourceCollectorApplicationListener();
assertThat(ReflectionUtils.<Set<Class<?>>>getFieldValue(listener, "gemfireGarbageCollectorEventTypes")) assertThat(ReflectionUtils.<Set<Class<?>>>getFieldValue(listener, "gemfireResourceCollectorEventTypes"))
.containsExactlyInAnyOrder(AfterTestMethodEvent.class, AfterTestExecutionEvent.class); .containsExactlyInAnyOrder(AfterTestMethodEvent.class, AfterTestExecutionEvent.class);
assertThat(ReflectionUtils.<Boolean>getFieldValue(listener, "tryCleanDiskStoreFilesEnabled")) assertThat(ReflectionUtils.<Boolean>getFieldValue(listener, "tryCleanDiskStoreFilesEnabled"))

View File

@@ -32,14 +32,14 @@ import org.junit.Test;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
import org.springframework.data.gemfire.tests.integration.context.event.GemFireGarbageCollectorApplicationListener.GemFireGarbageFileFilter; import org.springframework.data.gemfire.tests.integration.context.event.GemFireResourceCollectorApplicationListener.GemFireResourceFileFilter;
import org.springframework.test.context.TestContext; import org.springframework.test.context.TestContext;
import org.springframework.test.context.event.AfterTestClassEvent; import org.springframework.test.context.event.AfterTestClassEvent;
import org.springframework.test.context.event.AfterTestExecutionEvent; import org.springframework.test.context.event.AfterTestExecutionEvent;
import org.springframework.test.context.event.AfterTestMethodEvent; import org.springframework.test.context.event.AfterTestMethodEvent;
/** /**
* Unit Tests for {@link GemFireGarbageCollectorApplicationListener}. * Unit Tests for {@link GemFireResourceCollectorApplicationListener}.
* *
* @author John Blum * @author John Blum
* @see java.io.File * @see java.io.File
@@ -47,11 +47,11 @@ import org.springframework.test.context.event.AfterTestMethodEvent;
* @see org.mockito.Mockito * @see org.mockito.Mockito
* @see org.springframework.context.ApplicationContext * @see org.springframework.context.ApplicationContext
* @see org.springframework.context.ApplicationEvent * @see org.springframework.context.ApplicationEvent
* @see org.springframework.data.gemfire.tests.integration.context.event.GemFireGarbageCollectorApplicationListener * @see GemFireResourceCollectorApplicationListener
* @since 0.0.17 * @since 0.0.17
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class GemFireGarbageCollectorApplicationListenerUnitTests { public class GemFireResourceCollectorApplicationListenerUnitTests {
private static File mockDirectory(String pathname) { private static File mockDirectory(String pathname) {
@@ -76,42 +76,42 @@ public class GemFireGarbageCollectorApplicationListenerUnitTests {
} }
@Test @Test
public void constructNewGemFireGarbageCollectorApplicationListener() { public void constructNewGemFireResourceCollectorApplicationListener() {
File searchDirectory = new File("/path/to/gemfire/junk"); File searchDirectory = new File("/path/to/gemfire/junk");
Iterable<Class<? extends ApplicationEvent>> eventTypes = Collections.singleton(AfterTestMethodEvent.class); Iterable<Class<? extends ApplicationEvent>> eventTypes = Collections.singleton(AfterTestMethodEvent.class);
GemFireGarbageCollectorApplicationListener listener = GemFireResourceCollectorApplicationListener listener =
new GemFireGarbageCollectorApplicationListener(searchDirectory, eventTypes); new GemFireResourceCollectorApplicationListener(searchDirectory, eventTypes);
assertThat(listener).isNotNull(); assertThat(listener).isNotNull();
assertThat(listener.getApplicationContext().orElse(null)).isNull(); assertThat(listener.getApplicationContext().orElse(null)).isNull();
assertThat(listener.getConfiguredGemFireGarbageCollectorEventTypes()) assertThat(listener.getConfiguredGemFireResourceCollectorEventTypes())
.containsExactly(AfterTestMethodEvent.class); .containsExactly(AfterTestMethodEvent.class);
assertThat(listener.getLogger()).isNotNull(); assertThat(listener.getLogger()).isNotNull();
assertThat(listener.getLogger().getName()).isEqualTo(GemFireGarbageCollectorApplicationListener.class.getName()); assertThat(listener.getLogger().getName()).isEqualTo(GemFireResourceCollectorApplicationListener.class.getName());
assertThat(listener.isTryCleanDiskStoreFilesEnabled()).isFalse(); assertThat(listener.isTryCleanDiskStoreFilesEnabled()).isFalse();
assertThat(listener.getSearchDirectory()).isEqualTo(searchDirectory); assertThat(listener.getSearchDirectory()).isEqualTo(searchDirectory);
} }
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void createNewGemFireGarbageCollectorApplicationListener() { public void createNewGemFireResourceCollectorApplicationListener() {
GemFireGarbageCollectorApplicationListener listener = GemFireResourceCollectorApplicationListener listener =
GemFireGarbageCollectorApplicationListener.create(AfterTestExecutionEvent.class) GemFireResourceCollectorApplicationListener.create(AfterTestExecutionEvent.class)
.tryCleanDiskStoreFiles(true); .tryCleanDiskStoreFiles(true);
assertThat(listener).isNotNull(); assertThat(listener).isNotNull();
assertThat(listener.getApplicationContext().orElse(null)).isNull(); assertThat(listener.getApplicationContext().orElse(null)).isNull();
assertThat(listener.getConfiguredGemFireGarbageCollectorEventTypes()) assertThat(listener.getConfiguredGemFireResourceCollectorEventTypes())
.containsExactly(AfterTestExecutionEvent.class); .containsExactly(AfterTestExecutionEvent.class);
assertThat(listener.getLogger()).isNotNull(); assertThat(listener.getLogger()).isNotNull();
assertThat(listener.getLogger().getName()).isEqualTo(GemFireGarbageCollectorApplicationListener.class.getName()); assertThat(listener.getLogger().getName()).isEqualTo(GemFireResourceCollectorApplicationListener.class.getName());
assertThat(listener.isTryCleanDiskStoreFilesEnabled()).isTrue(); assertThat(listener.isTryCleanDiskStoreFilesEnabled()).isTrue();
assertThat(listener.getSearchDirectory()) assertThat(listener.getSearchDirectory())
.isEqualTo(GemFireGarbageCollectorApplicationListener.DEFAULT_SEARCH_DIRECTORY); .isEqualTo(GemFireResourceCollectorApplicationListener.DEFAULT_SEARCH_DIRECTORY);
} }
@Test @Test
@@ -120,7 +120,7 @@ public class GemFireGarbageCollectorApplicationListenerUnitTests {
ApplicationContext mockApplicationContext = mock(ApplicationContext.class); ApplicationContext mockApplicationContext = mock(ApplicationContext.class);
GemFireGarbageCollectorApplicationListener listener = GemFireGarbageCollectorApplicationListener.create(); GemFireResourceCollectorApplicationListener listener = GemFireResourceCollectorApplicationListener.create();
assertThat(listener).isNotNull(); assertThat(listener).isNotNull();
assertThat(listener.getApplicationContext().orElse(null)).isNull(); assertThat(listener.getApplicationContext().orElse(null)).isNull();
@@ -135,22 +135,22 @@ public class GemFireGarbageCollectorApplicationListenerUnitTests {
} }
@Test @Test
public void onApplicationEventCallsCollectGemFireGarbageAndCollectGemFireDiskStoreFiles() { public void onApplicationEventCallsCollectGemFireResourceAndCollectGemFireDiskStoreFiles() {
ApplicationEvent mockApplicationEvent = mock(ApplicationEvent.class); ApplicationEvent mockApplicationEvent = mock(ApplicationEvent.class);
GemFireGarbageCollectorApplicationListener listener = spy(GemFireGarbageCollectorApplicationListener.create()); GemFireResourceCollectorApplicationListener listener = spy(GemFireResourceCollectorApplicationListener.create());
doReturn(true).when(listener).isGemFireGarbageCollectorEvent(any()); doReturn(true).when(listener).isGemFireResourceCollectorEvent(any());
doReturn(true).when(listener).isTryCleanDiskStoreFilesEnabled(); doReturn(true).when(listener).isTryCleanDiskStoreFilesEnabled();
doNothing().when(listener).collectGemFireDiskStoreFiles(); doNothing().when(listener).collectGemFireDiskStoreFiles();
doNothing().when(listener).collectGemFireGarbage(any()); doNothing().when(listener).collectGemFireResources(any());
listener.onApplicationEvent(mockApplicationEvent); listener.onApplicationEvent(mockApplicationEvent);
verify(listener, times(1)).isGemFireGarbageCollectorEvent(eq(mockApplicationEvent)); verify(listener, times(1)).isGemFireResourceCollectorEvent(eq(mockApplicationEvent));
verify(listener, times(1)) verify(listener, times(1))
.collectGemFireGarbage(eq(GemFireGarbageCollectorApplicationListener.DEFAULT_SEARCH_DIRECTORY)); .collectGemFireResources(eq(GemFireResourceCollectorApplicationListener.DEFAULT_SEARCH_DIRECTORY));
verify(listener, times(1)).isTryCleanDiskStoreFilesEnabled(); verify(listener, times(1)).isTryCleanDiskStoreFilesEnabled();
verify(listener, times(1)).collectGemFireDiskStoreFiles(); verify(listener, times(1)).collectGemFireDiskStoreFiles();
} }
@@ -160,8 +160,8 @@ public class GemFireGarbageCollectorApplicationListenerUnitTests {
AfterTestClassEvent mockEvent = mock(AfterTestClassEvent.class); AfterTestClassEvent mockEvent = mock(AfterTestClassEvent.class);
assertThat(GemFireGarbageCollectorApplicationListener.create() assertThat(GemFireResourceCollectorApplicationListener.create()
.isGemFireGarbageCollectorEvent(mockEvent)).isTrue(); .isGemFireResourceCollectorEvent(mockEvent)).isTrue();
} }
@Test @Test
@@ -169,8 +169,8 @@ public class GemFireGarbageCollectorApplicationListenerUnitTests {
ApplicationEvent mockEvent = mock(AfterTestMethodEventSubType.class); ApplicationEvent mockEvent = mock(AfterTestMethodEventSubType.class);
assertThat(GemFireGarbageCollectorApplicationListener.create(AfterTestMethodEvent.class) assertThat(GemFireResourceCollectorApplicationListener.create(AfterTestMethodEvent.class)
.isGemFireGarbageCollectorEvent(mockEvent)).isTrue(); .isGemFireResourceCollectorEvent(mockEvent)).isTrue();
} }
@Test @Test
@@ -178,19 +178,19 @@ public class GemFireGarbageCollectorApplicationListenerUnitTests {
ApplicationEvent mockEvent = mock(AfterTestClassEvent.class); ApplicationEvent mockEvent = mock(AfterTestClassEvent.class);
assertThat(GemFireGarbageCollectorApplicationListener.create(AfterTestMethodEvent.class) assertThat(GemFireResourceCollectorApplicationListener.create(AfterTestMethodEvent.class)
.isGemFireGarbageCollectorEvent(mockEvent)).isFalse(); .isGemFireResourceCollectorEvent(mockEvent)).isFalse();
} }
@Test @Test
public void isGemFireCollectorEventWithNullIsNullSafeReturnsFalse() { public void isGemFireCollectorEventWithNullIsNullSafeReturnsFalse() {
assertThat(GemFireGarbageCollectorApplicationListener.create().isGemFireGarbageCollectorEvent(null)).isFalse(); assertThat(GemFireResourceCollectorApplicationListener.create().isGemFireResourceCollectorEvent(null)).isFalse();
} }
@Test @Test
public void gemfireGarbageFileFilterAcceptsAllDirectories() { public void gemfireResourceFileFilterAcceptsAllDirectories() {
GemFireGarbageFileFilter fileFilter = GemFireGarbageFileFilter.INSTANCE; GemFireResourceFileFilter fileFilter = GemFireResourceFileFilter.INSTANCE;
assertThat(fileFilter).isNotNull(); assertThat(fileFilter).isNotNull();
assertThat(fileFilter.accept(mockDirectory("GemFire"))).isTrue(); assertThat(fileFilter.accept(mockDirectory("GemFire"))).isTrue();
@@ -200,9 +200,9 @@ public class GemFireGarbageCollectorApplicationListenerUnitTests {
} }
@Test @Test
public void gemfireGarbageFileFilterAcceptsFilesWithMatchingExtension() { public void gemfireResourceFileFilterAcceptsFilesWithMatchingExtension() {
GemFireGarbageFileFilter fileFilter = GemFireGarbageFileFilter.INSTANCE; GemFireResourceFileFilter fileFilter = GemFireResourceFileFilter.INSTANCE;
assertThat(fileFilter).isNotNull(); assertThat(fileFilter).isNotNull();
assertThat(fileFilter.accept(mockFile("gem.dat"))).isTrue(); assertThat(fileFilter.accept(mockFile("gem.dat"))).isTrue();
@@ -219,9 +219,9 @@ public class GemFireGarbageCollectorApplicationListenerUnitTests {
} }
@Test @Test
public void gemfireGarbageFileFilterAcceptsFilesWithMatchingName() { public void gemfireResourceFileFilterAcceptsFilesWithMatchingName() {
GemFireGarbageFileFilter fileFilter = GemFireGarbageFileFilter.INSTANCE; GemFireResourceFileFilter fileFilter = GemFireResourceFileFilter.INSTANCE;
assertThat(fileFilter).isNotNull(); assertThat(fileFilter).isNotNull();
assertThat(fileFilter.accept(mockFile("BACKUP123"))).isTrue(); assertThat(fileFilter.accept(mockFile("BACKUP123"))).isTrue();
@@ -237,9 +237,9 @@ public class GemFireGarbageCollectorApplicationListenerUnitTests {
} }
@Test @Test
public void gemfireGarbageFileFilterDeniesFilesWithNonMatchingExtension() { public void gemfireResourceFileFilterDeniesFilesWithNonMatchingExtension() {
GemFireGarbageFileFilter fileFilter = GemFireGarbageFileFilter.INSTANCE; GemFireResourceFileFilter fileFilter = GemFireResourceFileFilter.INSTANCE;
assertThat(fileFilter).isNotNull(); assertThat(fileFilter).isNotNull();
assertThat(fileFilter.accept(mockFile("gem.data"))).isFalse(); assertThat(fileFilter.accept(mockFile("gem.data"))).isFalse();
@@ -252,9 +252,9 @@ public class GemFireGarbageCollectorApplicationListenerUnitTests {
} }
@Test @Test
public void gemfireGarbageFileFilterDeniesFilesWithNonMatchingName() { public void gemfireResourceFileFilterDeniesFilesWithNonMatchingName() {
GemFireGarbageFileFilter fileFilter = GemFireGarbageFileFilter.INSTANCE; GemFireResourceFileFilter fileFilter = GemFireResourceFileFilter.INSTANCE;
assertThat(fileFilter).isNotNull(); assertThat(fileFilter).isNotNull();
assertThat(fileFilter.accept(mockFile("DAT.backup"))).isFalse(); assertThat(fileFilter.accept(mockFile("DAT.backup"))).isFalse();
@@ -263,10 +263,10 @@ public class GemFireGarbageCollectorApplicationListenerUnitTests {
} }
@Test @Test
public void gemfireGarbageFileFilterDeniesNullFiles() { public void gemfireResourceFileFilterDeniesNullFiles() {
assertThat(GemFireGarbageFileFilter.INSTANCE).isNotNull(); assertThat(GemFireResourceFileFilter.INSTANCE).isNotNull();
assertThat(GemFireGarbageFileFilter.INSTANCE.accept(null)).isFalse(); assertThat(GemFireResourceFileFilter.INSTANCE.accept(null)).isFalse();
} }
static class AfterTestMethodEventSubType extends AfterTestMethodEvent { static class AfterTestMethodEventSubType extends AfterTestMethodEvent {