SGF-864 - Switch SnapshotService tests to use the temporary directory rather than 'user.home'.
This commit is contained in:
@@ -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;
|
||||
@@ -43,8 +42,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.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
@@ -57,6 +55,9 @@ import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The SnapshotServiceFactoryBean class is a Spring FactoryBean used to configure and create an instance
|
||||
* of an appropriate Pivotal GemFire Snapshot Service to perform data import and exports. A CacheSnapshotService is created
|
||||
@@ -253,7 +254,7 @@ public class SnapshotServiceFactoryBean<K, V> extends AbstractFactoryBeanSupport
|
||||
* @see #getRegion()
|
||||
*/
|
||||
protected Region<K, V> getRegion() {
|
||||
return region;
|
||||
return this.region;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -300,7 +301,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);
|
||||
}
|
||||
|
||||
@@ -355,8 +358,7 @@ public class SnapshotServiceFactoryBean<K, V> extends AbstractFactoryBeanSupport
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ignore) {
|
||||
}
|
||||
catch (Exception ignore) { }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -369,7 +371,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());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -387,8 +389,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());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -588,9 +591,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
|
||||
|
||||
@@ -29,7 +29,6 @@ import static org.junit.Assume.assumeThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Matchers.isNull;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -151,7 +150,7 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setupBeforeClass() throws Exception {
|
||||
public static void setupBeforeClass() {
|
||||
snapshotDat = mockFile("snapshot.dat");
|
||||
}
|
||||
|
||||
@@ -542,7 +541,7 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
factoryBean.onApplicationEvent(mockSnapshotEvent);
|
||||
|
||||
verify(mockSnapshotEvent, times(1)).isCacheSnapshotEvent();
|
||||
verify(mockSnapshotEvent, times(1)).matches(isNull(Region.class));
|
||||
verify(mockSnapshotEvent, times(1)).matches(ArgumentMatchers.<Region>isNull());
|
||||
verify(mockSnapshotEvent, never()).getSnapshotMetadata();
|
||||
verify(mockSnapshotService, never()).doExport(any(SnapshotMetadata.class));
|
||||
}
|
||||
@@ -676,7 +675,7 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
assertThat(factoryBean.isMatch(mockSnapshotEvent), is(false));
|
||||
|
||||
verify(mockSnapshotEvent, times(1)).isCacheSnapshotEvent();
|
||||
verify(mockSnapshotEvent, times(1)).matches(isNull(Region.class));
|
||||
verify(mockSnapshotEvent, times(1)).matches(ArgumentMatchers.<Region>isNull());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -731,8 +730,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);
|
||||
@@ -741,7 +739,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)
|
||||
);
|
||||
|
||||
@@ -765,7 +763,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)),
|
||||
|
||||
Reference in New Issue
Block a user