Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisHegarty committed Sep 20, 2023
1 parent 199617e commit 4666513
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void testIntBlock() {
if (positionCount > 1) {
assertNullValues(
positionCount,
size -> IntBlock.newBlockBuilder(size),
size -> IntBlock.newBlockBuilder(size, blockFactory),
(bb, value) -> bb.appendInt(value),
position -> position,
IntBlock.Builder::build,
Expand All @@ -191,16 +191,19 @@ public void testIntBlock() {
);
}

IntBlock.Builder blockBuilder = IntBlock.newBlockBuilder(1);
IntBlock.Builder blockBuilder = IntBlock.newBlockBuilder(1, blockFactory);
IntBlock copy = blockBuilder.copyFrom(block, 0, block.getPositionCount()).build();
assertThat(copy, equalTo(block));
releaseAndAssertBreaker(copy);

IntVector.Builder vectorBuilder = IntVector.newVectorBuilder(
randomBoolean() ? randomIntBetween(1, positionCount) : positionCount
randomBoolean() ? randomIntBetween(1, positionCount) : positionCount,
blockFactory
);
IntStream.range(0, positionCount).forEach(vectorBuilder::appendInt);
IntVector vector = vectorBuilder.build();
assertSingleValueDenseBlock(vector.asBlock());
releaseAndAssertBreaker(vector);
}
}

Expand Down Expand Up @@ -294,6 +297,10 @@ public void testConstantLongBlock() {
}
}

// TODO: continue to update the test, as above.
// Try to not complicate the "basic" test any more than necessary, but it already has great coverage
// for building all types of blocks!!

public void testDoubleBlock() {
for (int i = 0; i < 1000; i++) {
int positionCount = randomIntBetween(1, 16 * 1024);
Expand Down Expand Up @@ -876,6 +883,7 @@ private static <B extends Block, BB extends Block.Builder, T> void assertNullVal
asserter.accept(randomNonNullPosition, block);
assertTrue(block.isNull(randomNullPosition));
assertFalse(block.isNull(randomNonNullPosition));
releaseAndAssertBreaker(block, block.blockFactory().breaker());
}

void assertZeroPositionsAndRelease(Block block) {
Expand All @@ -889,6 +897,10 @@ void assertZeroPositionsAndRelease(Vector vector) {
}

<T extends Releasable & Accountable> void releaseAndAssertBreaker(T data) {
releaseAndAssertBreaker(data, breaker);
}

static <T extends Releasable & Accountable> void releaseAndAssertBreaker(T data, CircuitBreaker breaker) {
Releasables.closeExpectNoException(data);
assertThat(breaker.getUsed(), is(0L));
}
Expand Down

0 comments on commit 4666513

Please sign in to comment.