You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by mc...@apache.org on 2018/12/06 17:28:51 UTC
[geode] branch develop updated: GEODE-6143: Removing PowerMock from
BackupFileCopierIntegrationTest (#2955)
This is an automated email from the ASF dual-hosted git repository.
mcmellawatt pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new 2c3fd5b GEODE-6143: Removing PowerMock from BackupFileCopierIntegrationTest (#2955)
2c3fd5b is described below
commit 2c3fd5b05137e9be1f83ffc2c4ed876c5c60ce46
Author: Ryan McMahon <rm...@pivotal.io>
AuthorDate: Thu Dec 6 09:28:42 2018 -0800
GEODE-6143: Removing PowerMock from BackupFileCopierIntegrationTest (#2955)
---
.../backup/BackupFileCopierIntegrationTest.java | 25 +++++++---------------
.../internal/cache/backup/BackupFileCopier.java | 12 +++++++++--
2 files changed, 18 insertions(+), 19 deletions(-)
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/backup/BackupFileCopierIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/backup/BackupFileCopierIntegrationTest.java
index 2679dcf..38b44fd 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/backup/BackupFileCopierIntegrationTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/backup/BackupFileCopierIntegrationTest.java
@@ -19,12 +19,14 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.entry;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import java.io.File;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
@@ -38,11 +40,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
import org.apache.geode.cache.DiskStore;
import org.apache.geode.distributed.DistributedSystem;
@@ -54,9 +51,6 @@ import org.apache.geode.internal.cache.DiskStoreImpl;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.cache.Oplog;
-@PowerMockIgnore("*.IntegrationTest")
-@PrepareForTest({BackupFileCopier.class, URL.class})
-@RunWith(PowerMockRunner.class)
public class BackupFileCopierIntegrationTest {
private static final String CONFIG_DIRECTORY = "config";
private static final String USER_FILES = "user";
@@ -80,7 +74,7 @@ public class BackupFileCopierIntegrationTest {
tempFiles = mock(TemporaryBackupFiles.class);
tempFilesLocation = tempFolder.newFolder("temporaryBackupFiles").toPath();
when(tempFiles.getDirectory()).thenReturn(tempFilesLocation);
- fileCopier = new BackupFileCopier(cache, tempFiles);
+ fileCopier = spy(new BackupFileCopier(cache, tempFiles));
}
@Test
@@ -97,11 +91,10 @@ public class BackupFileCopierIntegrationTest {
}
@Test
- public void throwsIOExceptionIfConfigFileLocationInvalid() throws URISyntaxException {
- URL badUrl = PowerMockito.mock(URL.class);
- PowerMockito.doThrow(new URISyntaxException("", "")).when(badUrl).toURI();
- when(cache.getCacheXmlURL()).thenReturn(badUrl);
-
+ public void throwsIOExceptionIfConfigFileLocationInvalid()
+ throws URISyntaxException, MalformedURLException {
+ doReturn(new URL("http://www.test.com")).when(cache).getCacheXmlURL();
+ doThrow(new URISyntaxException("test", "test")).when(fileCopier).getSource(any());
assertThatThrownBy(() -> fileCopier.copyConfigFiles()).isInstanceOf(IOException.class);
}
@@ -257,9 +250,7 @@ public class BackupFileCopierIntegrationTest {
Path diskStoreDir = tempFolder.newFolder("diskstores").toPath();
when(tempFiles.getDiskStoreDirectory(any(), any())).thenReturn(diskStoreDir);
- PowerMockito.mockStatic(Files.class);
- PowerMockito.doThrow(new IOException()).when(Files.class);
- Files.createLink(any(), any());
+ doThrow(new IOException()).when(fileCopier).createLink(any(), any());
fileCopier.copyOplog(diskStore, oplog);
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/backup/BackupFileCopier.java b/geode-core/src/main/java/org/apache/geode/internal/cache/backup/BackupFileCopier.java
index d536bc8..c3999ff 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/backup/BackupFileCopier.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/backup/BackupFileCopier.java
@@ -82,7 +82,7 @@ class BackupFileCopier {
}
try {
- Path source = Paths.get(fileUrl.toURI());
+ Path source = getSource(fileUrl);
if (Files.notExists(source)) {
return;
}
@@ -167,7 +167,7 @@ class BackupFileCopier {
Path tempDiskDir = temporaryFiles.getDiskStoreDirectory(diskStore, dirHolder);
try {
- Files.createLink(tempDiskDir.resolve(file.getName()), file.toPath());
+ createLink(tempDiskDir.resolve(file.getName()), file.toPath());
} catch (IOException e) {
logger.warn("Unable to create hard link for {}. Reverting to file copy",
tempDiskDir.toString());
@@ -179,4 +179,12 @@ class BackupFileCopier {
JarDeployer getJarDeployer() {
return ClassPathLoader.getLatest().getJarDeployer();
}
+
+ void createLink(Path link, Path existing) throws IOException {
+ Files.createLink(link, existing);
+ }
+
+ Path getSource(URL fileUrl) throws URISyntaxException {
+ return Paths.get(fileUrl.toURI());
+ }
}