Repository: tez Updated Branches: refs/heads/master 1ae62421a -> fd9c01575
TEZ-3937. Empty partition BitSet to byte[] conversion creates one extra byte in rounding error (Jonathan Eagles via jlowe) Project: http://git-wip-us.apache.org/repos/asf/tez/repo Commit: http://git-wip-us.apache.org/repos/asf/tez/commit/fd9c0157 Tree: http://git-wip-us.apache.org/repos/asf/tez/tree/fd9c0157 Diff: http://git-wip-us.apache.org/repos/asf/tez/diff/fd9c0157 Branch: refs/heads/master Commit: fd9c015750c320a9a70b917cf22f993cf144e89e Parents: 1ae6242 Author: Jason Lowe <[email protected]> Authored: Mon May 21 09:32:08 2018 -0500 Committer: Jason Lowe <[email protected]> Committed: Mon May 21 09:32:08 2018 -0500 ---------------------------------------------------------------------- .../src/main/java/org/apache/tez/common/TezUtilsInternal.java | 2 +- tez-common/src/test/java/org/apache/tez/common/TestTezUtils.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tez/blob/fd9c0157/tez-common/src/main/java/org/apache/tez/common/TezUtilsInternal.java ---------------------------------------------------------------------- diff --git a/tez-common/src/main/java/org/apache/tez/common/TezUtilsInternal.java b/tez-common/src/main/java/org/apache/tez/common/TezUtilsInternal.java index 5ba2972..5d7aea3 100644 --- a/tez-common/src/main/java/org/apache/tez/common/TezUtilsInternal.java +++ b/tez-common/src/main/java/org/apache/tez/common/TezUtilsInternal.java @@ -238,7 +238,7 @@ public class TezUtilsInternal { if (bits == null) { return null; } - byte[] bytes = new byte[bits.length() / 8 + 1]; + byte[] bytes = new byte[(bits.length() + 7) / 8]; for (int i = 0; i < bits.length(); i++) { if (bits.get(i)) { bytes[(bytes.length) - (i / 8) - 1] |= 1 << (i % 8); http://git-wip-us.apache.org/repos/asf/tez/blob/fd9c0157/tez-common/src/test/java/org/apache/tez/common/TestTezUtils.java ---------------------------------------------------------------------- diff --git a/tez-common/src/test/java/org/apache/tez/common/TestTezUtils.java b/tez-common/src/test/java/org/apache/tez/common/TestTezUtils.java index 16efc8f..04eb2c0 100644 --- a/tez-common/src/test/java/org/apache/tez/common/TestTezUtils.java +++ b/tez-common/src/test/java/org/apache/tez/common/TestTezUtils.java @@ -81,11 +81,11 @@ public class TestTezUtils { public void testBitSetToByteArray() { BitSet bitSet = createBitSet(0); byte[] bytes = TezUtilsInternal.toByteArray(bitSet); - Assert.assertTrue(bytes.length == ((bitSet.length() / 8) + 1)); + Assert.assertEquals(bytes.length, (bitSet.length() + 7) / 8); bitSet = createBitSet(1000); bytes = TezUtilsInternal.toByteArray(bitSet); - Assert.assertTrue(bytes.length == ((bitSet.length() / 8) + 1)); + Assert.assertEquals(bytes.length, (bitSet.length() + 7) / 8); } @Test (timeout=2000)
