|
@@ -21,8 +21,11 @@ import org.elasticsearch.test.ESTestCase;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import static org.hamcrest.Matchers.both;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
+import static org.hamcrest.Matchers.greaterThan;
|
|
|
import static org.hamcrest.Matchers.is;
|
|
|
+import static org.hamcrest.Matchers.lessThan;
|
|
|
|
|
|
public class BlockBuilderTests extends ESTestCase {
|
|
|
@ParametersFactory
|
|
@@ -58,6 +61,10 @@ public class BlockBuilderTests extends ESTestCase {
|
|
|
for (int i = 0; i < numEntries; i++) {
|
|
|
builder.appendNull();
|
|
|
}
|
|
|
+ assertThat(
|
|
|
+ builder.estimatedBytes(),
|
|
|
+ both(greaterThan(blockFactory.breaker().getUsed() - 1024)).and(lessThan(blockFactory.breaker().getUsed() + 1024))
|
|
|
+ );
|
|
|
try (Block block = builder.build()) {
|
|
|
assertThat(block.getPositionCount(), is(numEntries));
|
|
|
for (int p = 0; p < numEntries; p++) {
|
|
@@ -113,6 +120,10 @@ public class BlockBuilderTests extends ESTestCase {
|
|
|
try (Block.Builder builder = elementType.newBlockBuilder(randomBoolean() ? size : 1, blockFactory)) {
|
|
|
BasicBlockTests.RandomBlock random = BasicBlockTests.randomBlock(elementType, size, nullable, 1, maxValueCount, 0, 0);
|
|
|
builder.copyFrom(random.block(), 0, random.block().getPositionCount());
|
|
|
+ assertThat(
|
|
|
+ builder.estimatedBytes(),
|
|
|
+ both(greaterThan(blockFactory.breaker().getUsed() - 1024)).and(lessThan(blockFactory.breaker().getUsed() + 1024))
|
|
|
+ );
|
|
|
try (Block built = builder.build()) {
|
|
|
assertThat(built, equalTo(random.block()));
|
|
|
assertThat(blockFactory.breaker().getUsed(), equalTo(built.ramBytesUsed()));
|