From 3fb37f6721fbe7641d9f10635574879faf2e2615 Mon Sep 17 00:00:00 2001 From: ZhangJian He Date: Tue, 9 Apr 2024 19:06:40 +0800 Subject: [PATCH] fix: fix windows test failure in ConfigDefTest Signed-off-by: ZhangJian He --- .../bookkeeper/common/conf/ConfigDefTest.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/bookkeeper-common/src/test/java/org/apache/bookkeeper/common/conf/ConfigDefTest.java b/bookkeeper-common/src/test/java/org/apache/bookkeeper/common/conf/ConfigDefTest.java index 7ba3e71ccae..a8bf63eaf51 100644 --- a/bookkeeper-common/src/test/java/org/apache/bookkeeper/common/conf/ConfigDefTest.java +++ b/bookkeeper-common/src/test/java/org/apache/bookkeeper/common/conf/ConfigDefTest.java @@ -27,10 +27,13 @@ import static org.junit.Assert.assertTrue; import com.google.common.collect.Lists; -import com.google.common.io.ByteStreams; + +import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.Iterator; import java.util.Set; import lombok.extern.slf4j.Slf4j; @@ -280,11 +283,15 @@ public void testBuildConfigDef() { @Test public void testSaveConfigDef() throws IOException { - byte[] confData; - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream("test_conf_2.conf")) { - confData = new byte[is.available()]; - ByteStreams.readFully(is, confData); + StringBuilder sb = new StringBuilder(); + try (InputStream is = this.getClass().getClassLoader().getResourceAsStream("test_conf_2.conf"); + BufferedReader reader = new BufferedReader(new InputStreamReader(is, UTF_8))) { + String line; + while ((line = reader.readLine()) != null) { + sb.append(line).append(System.lineSeparator()); + } } + String confData = sb.toString(); ConfigDef configDef = ConfigDef.of(TestConfig2.class); String readConf; @@ -294,7 +301,7 @@ public void testSaveConfigDef() throws IOException { log.info("\n{}", readConf); } - assertEquals(new String(confData, UTF_8), readConf); + assertEquals(confData, readConf); } }