DATAGEODE-210 - Switch SnapshotService tests to use the temporary directory rather than 'user.home'.

This commit is contained in:
John Blum
2019-07-17 11:52:02 -07:00
parent 9c7b28e3f1
commit 703f3c93d9
2 changed files with 15 additions and 14 deletions

View File

@@ -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<K, V> extends AbstractFactoryBeanSupport
* @see #getRegion()
*/
protected Region<K, V> getRegion() {
return region;
return this.region;
}
/**
@@ -305,7 +305,9 @@ public class SnapshotServiceFactoryBean<K, V> 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<K, V> extends AbstractFactoryBeanSupport
}
}
}
catch (Exception ignore) {
}
catch (Exception ignore) { }
}
/**
@@ -374,7 +375,7 @@ public class SnapshotServiceFactoryBean<K, V> 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<K, V> extends AbstractFactoryBeanSupport
SnapshotMetadata<K, V>[] 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<K, V> extends AbstractFactoryBeanSupport
@Override
protected File[] handleLocation(SnapshotMetadata<Object, Object> configuration) {
return (configuration.isFile()
return configuration.isFile()
? handleFileLocation(configuration.getLocation())
: handleDirectoryLocation(configuration.getLocation()));
: handleDirectoryLocation(configuration.getLocation());
}
@Override

View File

@@ -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)),