kylixs commented on a change in pull request #9274:
URL: https://github.com/apache/dubbo/pull/9274#discussion_r749949690
##########
File path:
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/DownloadZookeeperInitializer.java
##########
@@ -46,46 +47,77 @@
private static final String ZOOKEEPER_BINARY_URL_FORMAT =
"https://archive.apache.org/dist/zookeeper/zookeeper-%s/" +
ZOOKEEPER_FILE_NAME_FORMAT;
/**
- * The temporary directory name
+ * The temporary directory.
*/
- private static final String TEMPORARY_DIRECTORY_NAME =
"dubbo-mocked-zookeeper";
+ private static final String TEMPORARY_DIRECTORY = "zookeeper";
+
+ /**
+ * Returns {@code true} if the file exists with the given file path,
otherwise {@code false}.
+ *
+ * @param filePath the file path to check.
+ */
+ private boolean checkFile(Path filePath) {
+ return Files.exists(filePath) && filePath.toFile().isFile();
+ }
@Override
protected void doInitialize(ZookeeperContext context) throws
DubboTestException {
+ // checks the zookeeper binary file exists or not
+ if (checkFile(context.getSourceFile())) {
+ return;
+ }
String zookeeperFileName = String.format(ZOOKEEPER_FILE_NAME_FORMAT,
context.getVersion());
+ Path temporaryFilePath;
try {
-
context.setSourceFile(Paths.get(Files.createTempDirectory("").getParent().toString(),
- TEMPORARY_DIRECTORY_NAME,
- zookeeperFileName));
+ temporaryFilePath =
Paths.get(Files.createTempDirectory("").getParent().toString(),
+ TEMPORARY_DIRECTORY,
+ zookeeperFileName);
} catch (IOException e) {
- throw new RuntimeException(String.format("Cannot create the
temporary directory, related directory:%s/%s",
- TEMPORARY_DIRECTORY_NAME, zookeeperFileName), e);
- }
- // check if the zookeeper binary file exists
- if (context.getSourceFile() != null &&
context.getSourceFile().toFile().isFile()) {
- return;
+ throw new RuntimeException(String.format("Cannot create the
temporary directory, file path: %s", TEMPORARY_DIRECTORY), e);
}
+
// create the temporary directory path.
- if (!Files.exists(context.getSourceFile())) {
- try {
- Files.createDirectories(context.getSourceFile());
- } catch (IOException e) {
- throw new RuntimeException(String.format("Failed to create the
temporary directory to save zookeeper binary file, file path:%s",
context.getSourceFile()), e);
- }
+ try {
+ Files.createDirectories(temporaryFilePath.getParent());
+ } catch (IOException e) {
+ throw new RuntimeException(String.format("Failed to create the
temporary directory to save zookeeper binary file, file path:%s",
temporaryFilePath.getParent()), e);
}
- // download zookeeper binary file
+
+ // download zookeeper binary file in temporary directory.
String zookeeperBinaryUrl = String.format(ZOOKEEPER_BINARY_URL_FORMAT,
context.getVersion(), context.getVersion());
try {
logger.info("It is beginning to download the zookeeper binary
archive, it will take several minutes...");
URL zookeeperBinaryURL = new URL(zookeeperBinaryUrl);
InputStream inputStream = zookeeperBinaryURL.openStream();
- Files.copy(inputStream, context.getSourceFile(),
StandardCopyOption.REPLACE_EXISTING);
+ Files.copy(inputStream, temporaryFilePath,
StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) {
throw new RuntimeException(String.format("Download zookeeper
binary archive failed, download url:%s, file path:%s",
Review comment:
Prompt the user to download manually when the download fails, and put it
in the specified directory.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]