This is an automated email from the ASF dual-hosted git repository.
jiangtian pushed a commit to branch dev/1.3
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/dev/1.3 by this push:
new 3f325e120b7 [to dev/1.3] Some configuration items may be commented out
when merging old version configuration files (#14249)
3f325e120b7 is described below
commit 3f325e120b7657a31aca573c26a5de5febdeb51d
Author: shuwenwei <[email protected]>
AuthorDate: Tue Dec 3 14:28:36 2024 +0800
[to dev/1.3] Some configuration items may be commented out when merging old
version configuration files (#14249)
* fix configuration file update
* add line separator before file content
* add ut
---
.../iotdb/db/utils/ConfigurationFileUtilsTest.java | 80 ++++++++++++++++++++++
.../iotdb/commons/conf/ConfigurationFileUtils.java | 2 +-
2 files changed, 81 insertions(+), 1 deletion(-)
diff --git
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/ConfigurationFileUtilsTest.java
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/ConfigurationFileUtilsTest.java
new file mode 100644
index 00000000000..89ef66db385
--- /dev/null
+++
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/ConfigurationFileUtilsTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.utils;
+
+import org.apache.iotdb.commons.conf.ConfigurationFileUtils;
+import org.apache.iotdb.db.utils.constant.TestConstant;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.Objects;
+import java.util.Properties;
+
+public class ConfigurationFileUtilsTest {
+
+ private File dir =
+ new File(TestConstant.BASE_OUTPUT_PATH + File.separator +
"ConfigurationFileUtilsTest");
+
+ @After
+ public void tearDown() throws IOException {
+ if (!dir.exists()) {
+ return;
+ }
+ for (File file : Objects.requireNonNull(dir.listFiles())) {
+ Files.delete(file.toPath());
+ }
+ Files.delete(dir.toPath());
+ }
+
+ @Test
+ public void testMergeOldVersionFiles() throws IOException,
InterruptedException {
+ dir.mkdirs();
+ File confignodeConfigFile = new File(dir + File.separator +
"iotdb-confignode.properties");
+ File datanodeConfigFile = new File(dir + File.separator +
"iotdb-datanode.properties");
+ File commonConfigFile = new File(dir + File.separator +
"iotdb-common.properties");
+ File systemConfigFile = new File(dir + File.separator +
"iotdb-system.properties");
+ generateFile(confignodeConfigFile, "a=1");
+ generateFile(datanodeConfigFile, "b=2");
+ generateFile(commonConfigFile, "c=3");
+ ConfigurationFileUtils.checkAndMayUpdate(
+ systemConfigFile.toURI().toURL(),
+ confignodeConfigFile.toURI().toURL(),
+ datanodeConfigFile.toURI().toURL(),
+ commonConfigFile.toURI().toURL());
+ Assert.assertTrue(systemConfigFile.exists());
+ Properties properties = new Properties();
+ try (FileReader fileReader = new FileReader(systemConfigFile)) {
+ properties.load(fileReader);
+ }
+ Assert.assertEquals("1", properties.getProperty("a"));
+ Assert.assertEquals("2", properties.getProperty("b"));
+ Assert.assertEquals("3", properties.getProperty("c"));
+ }
+
+ private void generateFile(File file, String content) throws IOException {
+ Files.write(file.toPath(), content.getBytes());
+ }
+}
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/ConfigurationFileUtils.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/ConfigurationFileUtils.java
index cd337686a2f..0b86d5e48c6 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/ConfigurationFileUtils.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/ConfigurationFileUtils.java
@@ -299,7 +299,7 @@ public class ConfigurationFileUtils {
}
byte[] bytes = Files.readAllBytes(file.toPath());
String content = new String(bytes);
- return content.replace(license, "");
+ return lineSeparator + content.replace(license, "");
}
private static String readConfigLines(File file) throws IOException {