Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix UT
  • Loading branch information
clockfly committed Jun 30, 2016
commit 943f7de62204af5fee228e938d293e3283f4b395
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,16 @@ public BufferHolder(UnsafeRow row, int initialSize) {
* Grows the buffer by at least neededSize and points the row to the buffer.
*/
public void grow(int neededSize) {
if (neededSize > Integer.MAX_VALUE / 2 - totalSize()) {
if (neededSize > Integer.MAX_VALUE - totalSize()) {
throw new UnsupportedOperationException(
"Cannot grow BufferHolder by size " + neededSize + " because the size after growing " +
"exceeds size limitation " + Integer.MAX_VALUE / 2);
"exceeds size limitation " + Integer.MAX_VALUE);
}
final int length = totalSize() + neededSize;
if (buffer.length < length) {
// This will not happen frequently, because the buffer is re-used.
final byte[] tmp = new byte[length * 2];
int newLength = length < Integer.MAX_VALUE / 2 ? length * 2 : Integer.MAX_VALUE;
final byte[] tmp = new byte[newLength];
Platform.copyMemory(
buffer,
Platform.BYTE_ARRAY_OFFSET,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ class BufferHolderSuite extends SparkFunSuite {
var e = intercept[UnsupportedOperationException] {
new BufferHolder(new UnsafeRow(Int.MaxValue / 8))
}
assert(e.getMessage.contains("it is too big"))
assert(e.getMessage.contains("too many fields"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this string be defined in BufferHolder and referenced here so that the test wouldn't break if the exception message is modified ?


val holder = new BufferHolder(new UnsafeRow(1000))
holder.reset()
holder.grow(1000)
e = intercept[UnsupportedOperationException] {
holder.grow(2e10.toInt)
holder.grow(Integer.MAX_VALUE)
}
assert(e.getMessage.contains("exceeds size limitation"))
}
Expand Down