boolean addRecord(String partitionKey, @Nullable String explicitHashKey, byte[] record) {
    int recordSize = sizeIncrement(partitionKey, explicitHashKey, record);
    if (sizeBytes + recordSize > maxAggregatedBytes) {
      return false;
    }

    ByteString data = record != null ? ByteString.copyFrom(record) : ByteString.EMPTY;
    Record.Builder recordBuilder = Record.newBuilder().setData(data);

    recordBuilder.setPartitionKeyIndex(
        partitionKeys.computeIfAbsent(
            partitionKey,
            pk -> aggBuilder.addPartitionKeyTable(pk).getPartitionKeyTableCount() - 1));

    if (explicitHashKey != null) {
      recordBuilder.setExplicitHashKeyIndex(
          explicitHashKeys.computeIfAbsent(
              explicitHashKey,
              ehk -> aggBuilder.addExplicitHashKeyTable(ehk).getExplicitHashKeyTableCount() - 1));
    }

    aggBuilder.addRecords(recordBuilder.build());
    sizeBytes += recordSize;
    return true;
  }
@Test
  public void testRejectRecordIfSizeExceeded() {
    aggregator = new RecordsAggregator(BASE_OVERHEAD + PARTITION_KEY_OVERHEAD + 100, new Instant());
    // adding record fails due to encoding overhead
    assertThat(aggregator.addRecord(PARTITION_KEY, null, new byte[95])).isFalse();
    // but can fit if size is reduced
    assertThat(aggregator.addRecord(PARTITION_KEY, null, new byte[94])).isTrue();
  }