Skip to content

Commit

Permalink
rename timeToLiveSeconds of cassandra property
Browse files Browse the repository at this point in the history
fix issue spring-projects#1728

Signed-off-by: jitokim <[email protected]>
  • Loading branch information
jitokim committed Nov 14, 2024
1 parent 7474852 commit 426bcb1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

/**
* @author Mick Semb Wever
* @author Jihoon Kim
* @since 1.0.0
*/
@AutoConfiguration(after = CassandraAutoConfiguration.class)
Expand All @@ -50,8 +51,8 @@ public CassandraChatMemory chatMemory(CassandraChatMemoryProperties properties,
if (!properties.isInitializeSchema()) {
builder = builder.disallowSchemaChanges();
}
if (null != properties.getTimeToLiveSeconds()) {
builder = builder.withTimeToLive(properties.getTimeToLiveSeconds());
if (null != properties.getTimeToLive()) {
builder = builder.withTimeToLive(properties.getTimeToLive());
}

return CassandraChatMemory.create(builder.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

/**
* @author Mick Semb Wever
* @author Jihoon Kim
* @since 1.0.0
*/
@ConfigurationProperties(CassandraChatMemoryProperties.CONFIG_PREFIX)
Expand All @@ -45,7 +46,7 @@ public class CassandraChatMemoryProperties extends CommonChatMemoryProperties {

private String userColumn = CassandraChatMemoryConfig.DEFAULT_USER_COLUMN_NAME;

private Duration timeToLiveSeconds = null;
private Duration timeToLive = null;

public String getKeyspace() {
return this.keyspace;
Expand Down Expand Up @@ -80,12 +81,12 @@ public void setUserColumn(String userColumn) {
}

@Nullable
public Duration getTimeToLiveSeconds() {
return this.timeToLiveSeconds;
public Duration getTimeToLive() {
return this.timeToLive;
}

public void setTimeToLiveSeconds(Duration timeToLiveSeconds) {
this.timeToLiveSeconds = timeToLiveSeconds;
public void setTimeToLive(Duration timeToLive) {
this.timeToLive = timeToLive;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.ai.autoconfigure.chat.memory.cassandra;

import java.time.Duration;
import java.util.List;

import com.datastax.driver.core.utils.UUIDs;
Expand Down Expand Up @@ -57,7 +58,7 @@ void addAndGet() {
this.contextRunner.withPropertyValues("spring.cassandra.contactPoints=" + getContactPointHost())
.withPropertyValues("spring.cassandra.port=" + getContactPointPort())
.withPropertyValues("spring.cassandra.localDatacenter=" + cassandraContainer.getLocalDatacenter())

.withPropertyValues("spring.ai.chat.memory.cassandra.time-to-live=" + getTimeToLive())
.run(context -> {
CassandraChatMemory memory = context.getBean(CassandraChatMemory.class);

Expand All @@ -84,6 +85,8 @@ void addAndGet() {
.isEqualTo(MessageType.ASSISTANT);
assertThat(memory.get(sessionId, Integer.MAX_VALUE).get(0).getContent()).isEqualTo("test answer");

CassandraChatMemoryProperties properties = context.getBean(CassandraChatMemoryProperties.class);
assertThat(properties.getTimeToLive()).isEqualTo(getTimeToLive());
});
}

Expand All @@ -95,4 +98,8 @@ private String getContactPointPort() {
return String.valueOf(cassandraContainer.getContactPoint().getPort());
}

private Duration getTimeToLive() {
return Duration.ofSeconds(12000);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

/**
* @author Mick Semb Wever
* @author Jihoon Kim
* @since 1.0.0
*/
class CassandraChatMemoryPropertiesTest {
Expand All @@ -37,7 +38,7 @@ void defaultValues() {
assertThat(props.getTable()).isEqualTo(CassandraChatMemoryConfig.DEFAULT_TABLE_NAME);
assertThat(props.getAssistantColumn()).isEqualTo(CassandraChatMemoryConfig.DEFAULT_ASSISTANT_COLUMN_NAME);
assertThat(props.getUserColumn()).isEqualTo(CassandraChatMemoryConfig.DEFAULT_USER_COLUMN_NAME);
assertThat(props.getTimeToLiveSeconds()).isNull();
assertThat(props.getTimeToLive()).isNull();
assertThat(props.isInitializeSchema()).isTrue();
}

Expand All @@ -48,14 +49,14 @@ void customValues() {
props.setTable("my_table");
props.setAssistantColumn("my_assistant_column");
props.setUserColumn("my_user_column");
props.setTimeToLiveSeconds(Duration.ofDays(1));
props.setTimeToLive(Duration.ofDays(1));
props.setInitializeSchema(false);

assertThat(props.getKeyspace()).isEqualTo("my_keyspace");
assertThat(props.getTable()).isEqualTo("my_table");
assertThat(props.getAssistantColumn()).isEqualTo("my_assistant_column");
assertThat(props.getUserColumn()).isEqualTo("my_user_column");
assertThat(props.getTimeToLiveSeconds()).isEqualTo(Duration.ofDays(1));
assertThat(props.getTimeToLive()).isEqualTo(Duration.ofDays(1));
assertThat(props.isInitializeSchema()).isFalse();
}

Expand Down

0 comments on commit 426bcb1

Please sign in to comment.