Skip to content

Commit

Permalink
Fixed #5 : SizeBucket.add throws IOOBE
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelmay committed Sep 17, 2017
1 parent 6cbfd82 commit 3aa4beb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public SizeBucket(BucketModel bucketModel) {
public void add(long size) {
int bucket = bucketModel.computeBucket(size);
if (bucket >= fileSizeBuckets.length) {
long[] newFileSizeBuckets = new long[bucket];
long[] newFileSizeBuckets = new long[bucket + 1];
System.arraycopy(fileSizeBuckets, 0, newFileSizeBuckets, 0, fileSizeBuckets.length);
fileSizeBuckets = newFileSizeBuckets;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class SizeBucketTest {

Expand Down Expand Up @@ -32,7 +31,7 @@ public void testBucketAdd() {
sizeBucket.add(size);
expected[i + 3]++;
assertArrayEquals(expected, sizeBucket.get());
assertEquals(i+3, sizeBucket.findMaxNumBucket());
assertEquals(i + 3, sizeBucket.findMaxNumBucket());
}

sizeBucket.add(0L);
Expand All @@ -47,6 +46,12 @@ public void testBucketAdd() {
sizeBucket.add(2L * 1024L * 1024L);
expected[3]++;
assertArrayEquals(expected, sizeBucket.get());

// Trigger resize
sizeBucket.add(300L * 1024L * 1024L * 1024L);
assertArrayEquals(new long[]{
2, 2, 2, 2, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1}, sizeBucket.get());
}

@Test
Expand Down

0 comments on commit 3aa4beb

Please sign in to comment.