-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [ISSUE #11967] Can not aquire the specific config * [ISSUE #11967] Can not aquire the specific config * [ISSUE #11967] Can not aquire the specific config * [ISSUE #11967] Can not aquire the specific config * [ISSUE #11967] Can not aquire the specific config
- Loading branch information
Showing
2 changed files
with
120 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
107 changes: 107 additions & 0 deletions
107
...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,107 @@ | ||
/* | ||
* Copyright 1999-2023 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.alibaba.nacos.config.server.service.dump.disk; | ||
|
||
import junit.framework.TestCase; | ||
import org.junit.Before; | ||
|
||
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 { | ||
|
||
private String cachedOsName; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
cachedOsName = System.getProperty("os.name"); | ||
} | ||
|
||
private boolean isWindows() { | ||
return cachedOsName.toLowerCase().startsWith("win"); | ||
} | ||
|
||
/** | ||
* 测试获取文件路径. | ||
*/ | ||
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(isWindows() ? "aaaa%A3%dsaknkf" : thirdLastSegment, thirdLastSegment); | ||
assertEquals(isWindows() ? "aaaa%A4%dsaknkf" : secondLastSegment, secondLastSegment); | ||
assertEquals(isWindows() ? "aaaa%A5%dsaknkf" : lastSegment, 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(isWindows() ? "aaaa%A3%dsaknkf" : thirdLastSegment, thirdLastSegment); | ||
assertEquals(isWindows() ? "aaaa%A4%dsaknkf" : secondLastSegment, secondLastSegment); | ||
assertEquals(isWindows() ? "aaaa%A5%dsaknkf" : lastSegment, 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(isWindows() ? "aaaa%A3%dsaknkf" : fourthLastSegment, fourthLastSegment); | ||
assertEquals(isWindows() ? "aaaa%A4%dsaknkf" : thirdLastSegment, thirdLastSegment); | ||
assertEquals(isWindows() ? "aaaa%A5%dsaknkf" : secondLastSegment, secondLastSegment); | ||
String lastSegment = path.getFileName().toString(); | ||
assertEquals("aaaadsaknkf", lastSegment); | ||
} | ||
} |