boolean hasCapacity() {
    if (aggBuilder.getRecordsCount() == 0) {
      return true;
    }
    int avgSize = (sizeBytes - BASE_OVERHEAD) / aggBuilder.getRecordsCount();
    return sizeBytes + avgSize <= maxAggregatedBytes;
  }
@Test
  public void testHasCapacity() {
    aggregator = new RecordsAggregator(BASE_OVERHEAD + PARTITION_KEY_OVERHEAD + 100, new Instant());
    assertThat(aggregator.addRecord(PARTITION_KEY, null, new byte[30])).isTrue();
    assertThat(aggregator.hasCapacity()).isTrue(); // can fit next record of avg size
    assertThat(aggregator.addRecord(PARTITION_KEY, null, new byte[30])).isTrue();
    assertThat(aggregator.hasCapacity()).isFalse(); // can't fit next record of avg size (overhead)
    assertThat(aggregator.addRecord(PARTITION_KEY, null, new byte[30])).isFalse();
  }