Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.google.adk.summarizer;

import com.google.auto.value.AutoBuilder;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import javax.annotation.Nullable;

/**
Expand All @@ -39,6 +41,35 @@ public record EventsCompactionConfig(
@Nullable Integer tokenThreshold,
@Nullable Integer eventRetentionSize) {

public static Builder builder() {
return new AutoBuilder_EventsCompactionConfig_Builder();
}

public Builder toBuilder() {
return new AutoBuilder_EventsCompactionConfig_Builder(this);
}

/** Builder for {@link EventsCompactionConfig}. */
@AutoBuilder
public abstract static class Builder {
@CanIgnoreReturnValue
public abstract Builder compactionInterval(@Nullable Integer compactionInterval);

@CanIgnoreReturnValue
public abstract Builder overlapSize(@Nullable Integer overlapSize);

@CanIgnoreReturnValue
public abstract Builder summarizer(@Nullable BaseEventSummarizer summarizer);

@CanIgnoreReturnValue
public abstract Builder tokenThreshold(@Nullable Integer tokenThreshold);

@CanIgnoreReturnValue
public abstract Builder eventRetentionSize(@Nullable Integer eventRetentionSize);

public abstract EventsCompactionConfig build();
}

public EventsCompactionConfig(int compactionInterval, int overlapSize) {
this(compactionInterval, overlapSize, null, null, null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.adk.summarizer;

import static com.google.common.truth.Truth.assertThat;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public final class EventsCompactionConfigTest {

@Test
public void builder_buildsConfig() {
EventsCompactionConfig config =
EventsCompactionConfig.builder()
.compactionInterval(10)
.overlapSize(2)
.tokenThreshold(100)
.eventRetentionSize(5)
.build();

assertThat(config.compactionInterval()).isEqualTo(10);
assertThat(config.overlapSize()).isEqualTo(2);
assertThat(config.tokenThreshold()).isEqualTo(100);
assertThat(config.eventRetentionSize()).isEqualTo(5);
assertThat(config.summarizer()).isNull();
}

@Test
public void toBuilder_rebuildsConfig() {
EventsCompactionConfig config =
EventsCompactionConfig.builder().compactionInterval(10).overlapSize(2).build();

EventsCompactionConfig rebuilt = config.toBuilder().compactionInterval(20).build();

assertThat(rebuilt.compactionInterval()).isEqualTo(20);
assertThat(rebuilt.overlapSize()).isEqualTo(2);
}
}