forked from alibaba/nacos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ISSUE alibaba#11967] Can not aquire the specific config
- Loading branch information
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...test/java/com/alibaba/nacos/config/server/service/dump/disk/ConfigRawDiskServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.alibaba.nacos.config.server.service.dump.disk; | ||
|
||
import junit.framework.TestCase; | ||
import java.io.File; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
public class ConfigRawDiskServiceTest extends TestCase { | ||
|
||
/** | ||
* 测试获取beta文件路径. | ||
*/ | ||
public void testTargetFile() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { | ||
Method method = ConfigRawDiskService.class.getDeclaredMethod("targetFile", String.class, String.class, String.class); | ||
method.setAccessible(true); | ||
File result = (File) method.invoke(null, "aaaa\\dsaknkf", "aaaa/dsaknkf", "aaaa:dsaknkf"); | ||
// 分解路径 | ||
Path path = Paths.get(result.getPath()); | ||
Path parent = path.getParent(); | ||
Path grandParent = parent.getParent(); | ||
// 获取最后三段路径 | ||
String lastSegment = path.getFileName().toString(); | ||
String secondLastSegment = parent.getFileName().toString(); | ||
String thirdLastSegment = grandParent.getFileName().toString(); | ||
assertEquals("aaaa%A3%dsaknkf", thirdLastSegment); | ||
assertEquals("aaaa%A2%dsaknkf", secondLastSegment); | ||
assertEquals("aaaa%A1%dsaknkf", lastSegment); | ||
} | ||
|
||
/** | ||
* 测试获取beta文件路径. | ||
*/ | ||
public void testTargetBetaFile() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { | ||
Method method = ConfigRawDiskService.class.getDeclaredMethod("targetBetaFile", String.class, String.class, String.class); | ||
method.setAccessible(true); | ||
File result = (File) method.invoke(null, "aaaa\\dsaknkf", "aaaa/dsaknkf", "aaaa:dsaknkf"); | ||
// 分解路径 | ||
Path path = Paths.get(result.getPath()); | ||
Path parent = path.getParent(); | ||
Path grandParent = parent.getParent(); | ||
// 获取最后三段路径 | ||
String lastSegment = path.getFileName().toString(); | ||
String secondLastSegment = parent.getFileName().toString(); | ||
String thirdLastSegment = grandParent.getFileName().toString(); | ||
assertEquals("aaaa%A3%dsaknkf", thirdLastSegment); | ||
assertEquals("aaaa%A2%dsaknkf", secondLastSegment); | ||
assertEquals("aaaa%A1%dsaknkf", lastSegment); | ||
|
||
} | ||
|
||
/** | ||
* 测试获取tag文件路径. | ||
* @throws NoSuchMethodException 方法不存在异常 | ||
* @throws IllegalAccessException 非法访问异常 | ||
* @throws InvocationTargetException 目标异常 | ||
*/ | ||
public void testTargetTagFile() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { | ||
Method method = ConfigRawDiskService.class.getDeclaredMethod("targetTagFile", String.class, String.class, String.class, String.class); | ||
method.setAccessible(true); | ||
File result = (File) method.invoke(null, "aaaa\\dsaknkf", "aaaa/dsaknkf", "aaaa:dsaknkf", "aaaadsaknkf"); | ||
// 分解路径 | ||
Path path = Paths.get(result.getPath()); | ||
Path parent = path.getParent(); | ||
Path grandParent = parent.getParent(); | ||
Path greatGrandParent = grandParent.getParent(); | ||
// 获取最后四段路径 | ||
String secondLastSegment = parent.getFileName().toString(); | ||
String thirdLastSegment = grandParent.getFileName().toString(); | ||
String fourthLastSegment = greatGrandParent.getFileName().toString(); | ||
assertEquals("aaaa%A3%dsaknkf", fourthLastSegment); | ||
assertEquals("aaaa%A2%dsaknkf", thirdLastSegment); | ||
assertEquals("aaaa%A1%dsaknkf", secondLastSegment); | ||
String lastSegment = path.getFileName().toString(); | ||
assertEquals("aaaadsaknkf", lastSegment); | ||
} | ||
} |