Skip to content

Commit 839ee4c

Browse files
dblockkkewwei
andauthored
* Fix Flaky SettingTests Tests Signed-off-by: kkewwei <kkewwei@163.com> * add the comment to unit test Signed-off-by: kkewwei <kkewwei@163.com> --------- Signed-off-by: kkewwei <kkewwei@163.com> Co-authored-by: kkewwei <kkewwei@163.com>
1 parent f2cc3d8 commit 839ee4c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

server/src/test/java/org/opensearch/common/settings/SettingTests.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public void testMemorySize() {
201201
assertEquals(new ByteSizeValue(12), value.get());
202202

203203
assertTrue(settingUpdater.apply(Settings.builder().put("a.byte.size", "20%").build(), Settings.EMPTY));
204-
assertEquals(new ByteSizeValue((int) (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.2)), value.get());
204+
assertEquals(new ByteSizeValue((long) (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.2)), value.get());
205205
}
206206

207207
public void testMemorySizeWithFallbackValue() {
@@ -219,10 +219,12 @@ public void testMemorySizeWithFallbackValue() {
219219
assertEquals(memorySizeValue.getBytes(), JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.2, 1.0);
220220

221221
assertTrue(settingUpdater.apply(Settings.builder().put("a.byte.size", "30%").build(), Settings.EMPTY));
222-
assertEquals(new ByteSizeValue((int) (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.3)), value.get());
222+
// If value=getHeapMax()*0.3 is bigger than 2gb, and is bigger than Integer.MAX_VALUE,
223+
// then (long)((int) value) will lose precision.
224+
assertEquals(new ByteSizeValue((long) (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.3)), value.get());
223225

224226
assertTrue(settingUpdater.apply(Settings.builder().put("b.byte.size", "40%").build(), Settings.EMPTY));
225-
assertEquals(new ByteSizeValue((int) (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.4)), value.get());
227+
assertEquals(new ByteSizeValue((long) (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.4)), value.get());
226228
}
227229

228230
public void testSimpleUpdate() {

0 commit comments

Comments
 (0)