You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by sh...@apache.org on 2024/04/21 06:00:41 UTC

(bookkeeper) branch master updated: test: fix testJvmDirectMemoryMetrics windows test failure (#4294)

This is an automated email from the ASF dual-hosted git repository.

shoothzj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new bd5218a3b7 test: fix testJvmDirectMemoryMetrics windows test failure (#4294)
bd5218a3b7 is described below

commit bd5218a3b790bfbe22d2d7c84765858352a49b04
Author: ZhangJian He <sh...@gmail.com>
AuthorDate: Sun Apr 21 14:00:34 2024 +0800

    test: fix testJvmDirectMemoryMetrics windows test failure (#4294)
    
    ### Motivation
    
    Fixed the JVM Direct Memory Metrics test failure on Windows due to differences in line separators across operating systems.
    
    ### Changes
    
    - Moved the ByteBuf allocation after metrics server started.
    - Changed the line separator in assertions from System.lineSeparator() to \n.
    Signed-off-by: ZhangJian He <sh...@gmail.com>
---
 .../bookkeeper/stats/prometheus/TestPrometheusMetricsProvider.java   | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/stats/bookkeeper-stats-providers/prometheus-metrics-provider/src/test/java/org/apache/bookkeeper/stats/prometheus/TestPrometheusMetricsProvider.java b/stats/bookkeeper-stats-providers/prometheus-metrics-provider/src/test/java/org/apache/bookkeeper/stats/prometheus/TestPrometheusMetricsProvider.java
index 6f1b196283..91c9fd4a17 100644
--- a/stats/bookkeeper-stats-providers/prometheus-metrics-provider/src/test/java/org/apache/bookkeeper/stats/prometheus/TestPrometheusMetricsProvider.java
+++ b/stats/bookkeeper-stats-providers/prometheus-metrics-provider/src/test/java/org/apache/bookkeeper/stats/prometheus/TestPrometheusMetricsProvider.java
@@ -132,15 +132,16 @@ public class TestPrometheusMetricsProvider {
         config.setProperty(PrometheusMetricsProvider.PROMETHEUS_STATS_HTTP_ENABLE, true);
         config.setProperty(PrometheusMetricsProvider.PROMETHEUS_STATS_HTTP_PORT, 0);
         config.setProperty(PrometheusMetricsProvider.PROMETHEUS_STATS_HTTP_ADDRESS, "127.0.0.1");
-        ByteBuf byteBuf = ByteBufAllocator.DEFAULT.directBuffer(25);
         PrometheusMetricsProvider provider = new PrometheusMetricsProvider();
         try {
             provider.start(config);
             assertNotNull(provider.server);
+            ByteBuf byteBuf = ByteBufAllocator.DEFAULT.directBuffer(25);
             StringWriter writer = new StringWriter();
             provider.writeAllMetrics(writer);
             String s = writer.toString();
-            String[] split = s.split(System.lineSeparator());
+            // prometheus network string uses '\n' in all platform
+            String[] split = s.split("\n");
             HashMap<String, String> map = new HashMap<>();
             for (String str : split) {
                 String[] aux = str.split(" ");