From 68eb58f9e37a9cd92a50026a443a496cbb746447 Mon Sep 17 00:00:00 2001 From: javanna Date: Thu, 1 Sep 2016 19:11:01 +0200 Subject: [PATCH] [TEST] use randomPositiveLong where possible --- .../org/elasticsearch/common/unit/ByteSizeValueTests.java | 7 +------ .../java/org/elasticsearch/monitor/os/OsInfoTests.java | 6 +----- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/common/unit/ByteSizeValueTests.java b/core/src/test/java/org/elasticsearch/common/unit/ByteSizeValueTests.java index 0eada4f2cde..5104e56cb35 100644 --- a/core/src/test/java/org/elasticsearch/common/unit/ByteSizeValueTests.java +++ b/core/src/test/java/org/elasticsearch/common/unit/ByteSizeValueTests.java @@ -171,12 +171,7 @@ public class ByteSizeValueTests extends ESTestCase { } public void testSerialization() throws IOException { - //negative values cannot be serialized at the moment, we do abs but that is not enough with Long.MIN_VALUE - long l = Long.MIN_VALUE; - while (l == Long.MIN_VALUE) { - l = randomLong(); - } - ByteSizeValue byteSizeValue = new ByteSizeValue(Math.abs(l), randomFrom(ByteSizeUnit.values())); + ByteSizeValue byteSizeValue = new ByteSizeValue(randomPositiveLong(), randomFrom(ByteSizeUnit.values())); try (BytesStreamOutput out = new BytesStreamOutput()) { byteSizeValue.writeTo(out); try (StreamInput in = out.bytes().streamInput()) { diff --git a/core/src/test/java/org/elasticsearch/monitor/os/OsInfoTests.java b/core/src/test/java/org/elasticsearch/monitor/os/OsInfoTests.java index ed549b38e13..f96f6e47864 100644 --- a/core/src/test/java/org/elasticsearch/monitor/os/OsInfoTests.java +++ b/core/src/test/java/org/elasticsearch/monitor/os/OsInfoTests.java @@ -34,11 +34,7 @@ public class OsInfoTests extends ESTestCase { if (randomBoolean()) { refreshInterval = -1; } else { - refreshInterval = randomLong(); - while (refreshInterval == Long.MIN_VALUE) { - refreshInterval = randomLong(); - } - refreshInterval = Math.abs(refreshInterval); + refreshInterval = randomPositiveLong(); } String name = randomAsciiOfLengthBetween(3, 10); String arch = randomAsciiOfLengthBetween(3, 10);