Skip to content

Commit 7129b7a

Browse files
RocMarshal1996fanrui
authored andcommitted
[FLINK-38537][runtime] Fix the bug that can't compare correctly Double.NaN related attributes in StatsSummaryDto#equals method
1 parent 5215558 commit 7129b7a

File tree

2 files changed

+64
-5
lines changed

2 files changed

+64
-5
lines changed

flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/util/stats/StatsSummaryDto.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ public boolean equals(Object o) {
149149
return minimum == that.minimum
150150
&& maximum == that.maximum
151151
&& average == that.average
152-
&& p50 == that.p50
153-
&& p90 == that.p90
154-
&& p95 == that.p95
155-
&& p99 == that.p99
156-
&& p999 == that.p999;
152+
&& Double.compare(p50, that.p50) == 0
153+
&& Double.compare(p90, that.p90) == 0
154+
&& Double.compare(p95, that.p95) == 0
155+
&& Double.compare(p99, that.p99) == 0
156+
&& Double.compare(p999, that.p999) == 0;
157157
}
158158

159159
@Override
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.flink.runtime.rest.messages.util.stats;
20+
21+
import org.junit.jupiter.api.Test;
22+
23+
import static org.assertj.core.api.Assertions.assertThat;
24+
25+
/** Test for {@link org.apache.flink.runtime.rest.messages.util.stats.StatsSummaryDto}. */
26+
class StatsSummaryDtoTest {
27+
@Test
28+
void testEquals() {
29+
StatsSummaryDto dtoWithoutNaNDoubleValue =
30+
new StatsSummaryDto(1L, 1L, 1L, 0d, 0d, 0d, 0d, 0d);
31+
StatsSummaryDto dtoWithANaNDoubleValue =
32+
new StatsSummaryDto(1L, 1L, 1L, 0d, 0d, 0d, 0d, Double.NaN);
33+
assertThat(dtoWithoutNaNDoubleValue).isNotEqualTo(dtoWithANaNDoubleValue);
34+
assertThat(dtoWithANaNDoubleValue).isNotEqualTo(dtoWithoutNaNDoubleValue);
35+
36+
StatsSummaryDto dtoWithAllNaNDouble1 =
37+
new StatsSummaryDto(
38+
1L, 1L, 1L, Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN);
39+
StatsSummaryDto dtoWithAllNaNDouble2 =
40+
new StatsSummaryDto(
41+
1L, 1L, 1L, Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN);
42+
assertThat(dtoWithAllNaNDouble1).isEqualTo(dtoWithAllNaNDouble2);
43+
assertThat(dtoWithAllNaNDouble2).isEqualTo(dtoWithAllNaNDouble1);
44+
45+
StatsSummaryDto dtoWithoutNaNDoubleValue1 =
46+
new StatsSummaryDto(1L, 1L, 1L, 0d, 0d, 0d, 0d, 0d);
47+
StatsSummaryDto dtoWithoutNaNDoubleValue2 =
48+
new StatsSummaryDto(1L, 1L, 1L, 0d, 0d, 0d, 0d, 0d);
49+
assertThat(dtoWithoutNaNDoubleValue1).isEqualTo(dtoWithoutNaNDoubleValue2);
50+
assertThat(dtoWithoutNaNDoubleValue2).isEqualTo(dtoWithoutNaNDoubleValue1);
51+
52+
StatsSummaryDto dtoWithoutNaNDoubleValue3 =
53+
new StatsSummaryDto(1L, 1L, 1L, 0d, 1d, 0d, 0d, 0d);
54+
StatsSummaryDto dtoWithoutNaNDoubleValue4 =
55+
new StatsSummaryDto(1L, 1L, 1L, 0d, 0d, 0d, 0d, 0d);
56+
assertThat(dtoWithoutNaNDoubleValue3).isNotEqualTo(dtoWithoutNaNDoubleValue4);
57+
assertThat(dtoWithoutNaNDoubleValue4).isNotEqualTo(dtoWithoutNaNDoubleValue3);
58+
}
59+
}

0 commit comments

Comments
 (0)