From 703f3c93d9350dd06fa97d2dee454c6775070e6b Mon Sep 17 00:00:00 2001 From: John Blum Date: Wed, 17 Jul 2019 11:52:02 -0700 Subject: [PATCH] DATAGEODE-210 - Switch SnapshotService tests to use the temporary directory rather than 'user.home'. --- .../snapshot/SnapshotServiceFactoryBean.java | 22 ++++++++++--------- .../SnapshotServiceFactoryBeanTest.java | 7 +++--- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBean.java b/src/main/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBean.java index dea1816b..d7a0953c 100644 --- a/src/main/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBean.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.snapshot; import static java.util.Arrays.stream; @@ -44,6 +43,7 @@ import org.apache.geode.cache.snapshot.CacheSnapshotService; import org.apache.geode.cache.snapshot.RegionSnapshotService; import org.apache.geode.cache.snapshot.SnapshotFilter; import org.apache.geode.cache.snapshot.SnapshotOptions; + import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationListener; @@ -258,7 +258,7 @@ public class SnapshotServiceFactoryBean extends AbstractFactoryBeanSupport * @see #getRegion() */ protected Region getRegion() { - return region; + return this.region; } /** @@ -305,7 +305,9 @@ public class SnapshotServiceFactoryBean extends AbstractFactoryBeanSupport @Override @SuppressWarnings("unchecked") public Class getObjectType() { - return Optional.ofNullable(this.snapshotServiceAdapter).map(Object::getClass) + + return Optional.ofNullable(this.snapshotServiceAdapter) + .map(Object::getClass) .orElse((Class) SnapshotServiceAdapter.class); } @@ -360,8 +362,7 @@ public class SnapshotServiceFactoryBean extends AbstractFactoryBeanSupport } } } - catch (Exception ignore) { - } + catch (Exception ignore) { } } /** @@ -374,7 +375,7 @@ public class SnapshotServiceFactoryBean extends AbstractFactoryBeanSupport * @see SnapshotApplicationEvent */ protected boolean isMatch(SnapshotApplicationEvent event) { - return (event.isCacheSnapshotEvent() || event.matches(getRegion())); + return event.isCacheSnapshotEvent() || event.matches(getRegion()); } /** @@ -392,8 +393,9 @@ public class SnapshotServiceFactoryBean extends AbstractFactoryBeanSupport SnapshotMetadata[] eventSnapshotMetadata = event.getSnapshotMetadata(); - return (!ObjectUtils.isEmpty(eventSnapshotMetadata) ? eventSnapshotMetadata - : (event instanceof ExportSnapshotApplicationEvent ? getExports() : getImports())); + return !ObjectUtils.isEmpty(eventSnapshotMetadata) + ? eventSnapshotMetadata + : (event instanceof ExportSnapshotApplicationEvent ? getExports() : getImports()); } /** @@ -593,9 +595,9 @@ public class SnapshotServiceFactoryBean extends AbstractFactoryBeanSupport @Override protected File[] handleLocation(SnapshotMetadata configuration) { - return (configuration.isFile() + return configuration.isFile() ? handleFileLocation(configuration.getLocation()) - : handleDirectoryLocation(configuration.getLocation())); + : handleDirectoryLocation(configuration.getLocation()); } @Override diff --git a/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBeanTest.java b/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBeanTest.java index 9234157d..d87395c5 100644 --- a/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBeanTest.java +++ b/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBeanTest.java @@ -742,8 +742,7 @@ public class SnapshotServiceFactoryBeanTest { SnapshotOptions mockSnapshotOptionsTwo = mock(SnapshotOptions.class, "MockSnapshotOptionsTwo"); when(mockCache.getSnapshotService()).thenReturn(mockCacheSnapshotService); - when(mockCacheSnapshotService.createOptions()).thenReturn(mockSnapshotOptionsOne) - .thenReturn(mockSnapshotOptionsTwo); + when(mockCacheSnapshotService.createOptions()).thenReturn(mockSnapshotOptionsOne).thenReturn(mockSnapshotOptionsTwo); when(mockSnapshotOptionsOne.invokeCallbacks(anyBoolean())).thenReturn(mockSnapshotOptionsOne); when(mockSnapshotOptionsOne.setFilter(eq(mockSnapshotFilterOne))).thenReturn(mockSnapshotOptionsOne); when(mockSnapshotOptionsOne.setParallelMode(anyBoolean())).thenReturn(mockSnapshotOptionsOne); @@ -752,7 +751,7 @@ public class SnapshotServiceFactoryBeanTest { when(mockSnapshotOptionsTwo.setParallelMode(anyBoolean())).thenReturn(mockSnapshotOptionsTwo); SnapshotMetadata[] expectedImports = toArray( - newSnapshotMetadata(FileSystemUtils.USER_HOME, mockSnapshotFilterOne, false, true), + newSnapshotMetadata(FileSystemUtils.TEMPORARY_DIRECTORY, mockSnapshotFilterOne, false, true), newSnapshotMetadata(mockSnapshotFilterTwo, true, false) ); @@ -776,7 +775,7 @@ public class SnapshotServiceFactoryBeanTest { verify(mockCache, times(1)).getSnapshotService(); verify(mockCacheSnapshotService, times(2)).createOptions(); verify(mockCacheSnapshotService, times(1)) - .load(eq(FileSystemUtils.safeListFiles(FileSystemUtils.USER_HOME, FileSystemUtils.FileOnlyFilter.INSTANCE)), + .load(eq(FileSystemUtils.safeListFiles(FileSystemUtils.TEMPORARY_DIRECTORY, FileSystemUtils.FileOnlyFilter.INSTANCE)), eq(SnapshotFormat.GEMFIRE), eq(mockSnapshotOptionsOne)); verify(mockCacheSnapshotService, times(1)) .load(eq(FileSystemUtils.safeListFiles(FileSystemUtils.WORKING_DIRECTORY, FileSystemUtils.FileOnlyFilter.INSTANCE)),