-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fixed the Chinese logger of schema #17721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+104
−5
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
99 changes: 99 additions & 0 deletions
99
...e/datanode/src/test/java/org/apache/iotdb/db/i18n/DataNodeSchemaMessagesZhFormatTest.java
This file contains hidden or 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,99 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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 org.apache.iotdb.db.i18n; | ||
|
|
||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
| import org.slf4j.helpers.MessageFormatter; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.URISyntaxException; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| public class DataNodeSchemaMessagesZhFormatTest { | ||
|
|
||
| private static final String ZH_MESSAGES_RELATIVE_PATH = | ||
| "src/main/i18n/zh/org/apache/iotdb/db/i18n/DataNodeSchemaMessages.java"; | ||
|
|
||
| @Test | ||
| public void testZhSlf4jTemplatesPreserveLoggerArgumentOrder() throws IOException { | ||
| Assert.assertEquals( | ||
|
Caideyipi marked this conversation as resolved.
|
||
| "从 mlog.bin 反序列化 MTree 耗时 12 ms,对应路径 root.sg", | ||
| formatSlf4j(readZhMessage("SPEND_TIME_DESERIALIZE_MTREE"), 12, "root.sg")); | ||
| Assert.assertEquals( | ||
| "跳过 128 失败,schemaRegion 目录为 C:/schema", | ||
| formatSlf4j(readZhMessage("FAILED_TO_SKIP_MLOG"), 128, "C:/schema")); | ||
| Assert.assertEquals( | ||
| "恢复 root.sg.d.s 的 tagIndex 失败,schemaRegion 为 SchemaRegionId{1}。", | ||
| formatSlf4j( | ||
| readZhMessage("FAILED_TO_RECOVER_TAG_INDEX"), "root.sg.d.s", "SchemaRegionId{1}")); | ||
| Assert.assertEquals( | ||
| "MTree 刷写耗时 321ms,SchemaRegion 为 SchemaRegionId{1}", | ||
| formatSlf4j(readZhMessage("MTREE_FLUSH_COST"), 321, "SchemaRegionId{1}")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testZhStringFormatTemplatePreservesArgumentTypesAndOrder() throws IOException { | ||
| Assert.assertEquals( | ||
| "SchemaRegion [7] 在 StorageGroup [root.sg] 中恢复失败。", | ||
| String.format(readZhMessage("SCHEMA_REGION_FAILED_TO_RECOVER"), 7, "root.sg")); | ||
| } | ||
|
|
||
| private static String formatSlf4j(String template, Object... arguments) { | ||
| return MessageFormatter.arrayFormat(template, arguments).getMessage(); | ||
| } | ||
|
|
||
| private static String readZhMessage(String constantName) throws IOException { | ||
| Path basePath = resolveZhMessagesPath(); | ||
| Assert.assertTrue("Missing zh messages file: " + basePath, Files.exists(basePath)); | ||
|
|
||
| String content = new String(Files.readAllBytes(basePath), StandardCharsets.UTF_8); | ||
| Matcher matcher = | ||
| Pattern.compile( | ||
| "public static final String\\s+" | ||
| + Pattern.quote(constantName) | ||
| + "\\s*=\\s*\"([^\"]*)\";", | ||
| Pattern.DOTALL) | ||
| .matcher(content); | ||
| Assert.assertTrue("Missing zh message constant: " + constantName, matcher.find()); | ||
| return matcher.group(1); | ||
| } | ||
|
|
||
| private static Path resolveZhMessagesPath() throws IOException { | ||
| try { | ||
| Path testClassesDir = | ||
| Paths.get( | ||
| DataNodeSchemaMessagesZhFormatTest.class | ||
| .getProtectionDomain() | ||
| .getCodeSource() | ||
| .getLocation() | ||
| .toURI()); | ||
| Path moduleBaseDir = testClassesDir.getParent().getParent(); | ||
| return moduleBaseDir.resolve(ZH_MESSAGES_RELATIVE_PATH); | ||
| } catch (URISyntaxException e) { | ||
| throw new IOException("Failed to resolve zh messages path", e); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.