Skip to content

Commit a7a1804

Browse files
jitokimmarkpollack
authored andcommitted
Rename Cassandra TTL Property for Clarity
Rename `timeToLiveSeconds` to `timeToLive` in `CassandraChatMemoryProperties` and associated code to prevent misleading interpretation. This change addresses issue #1728, as the property previously suggested values in seconds but expected milliseconds. Improve readability and ensure accurate configuration by aligning the name with its behavior. Include updates to test cases to validate the new property name and verify ISO 8601 format handling. Fixes #1728 Signed-off-by: Jihoon Kim <pigberger70@gmail.com>
1 parent 432954d commit a7a1804

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/chat/memory/cassandra/CassandraChatMemoryAutoConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* {@link AutoConfiguration Auto-configuration} for {@link CassandraChatMemory}.
3232
*
3333
* @author Mick Semb Wever
34+
* @author Jihoon Kim
3435
* @since 1.0.0
3536
*/
3637
@AutoConfiguration(after = CassandraAutoConfiguration.class)
@@ -52,8 +53,8 @@ public CassandraChatMemory chatMemory(CassandraChatMemoryProperties properties,
5253
if (!properties.isInitializeSchema()) {
5354
builder = builder.disallowSchemaChanges();
5455
}
55-
if (null != properties.getTimeToLiveSeconds()) {
56-
builder = builder.withTimeToLive(properties.getTimeToLiveSeconds());
56+
if (null != properties.getTimeToLive()) {
57+
builder = builder.withTimeToLive(properties.getTimeToLive());
5758
}
5859

5960
return CassandraChatMemory.create(builder.build());

spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/chat/memory/cassandra/CassandraChatMemoryProperties.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* Configuration properties for Cassandra chat memory.
3131
*
3232
* @author Mick Semb Wever
33+
* @author Jihoon Kim
3334
* @since 1.0.0
3435
*/
3536
@ConfigurationProperties(CassandraChatMemoryProperties.CONFIG_PREFIX)
@@ -47,7 +48,7 @@ public class CassandraChatMemoryProperties extends CommonChatMemoryProperties {
4748

4849
private String userColumn = CassandraChatMemoryConfig.DEFAULT_USER_COLUMN_NAME;
4950

50-
private Duration timeToLiveSeconds = null;
51+
private Duration timeToLive = null;
5152

5253
public String getKeyspace() {
5354
return this.keyspace;
@@ -82,12 +83,12 @@ public void setUserColumn(String userColumn) {
8283
}
8384

8485
@Nullable
85-
public Duration getTimeToLiveSeconds() {
86-
return this.timeToLiveSeconds;
86+
public Duration getTimeToLive() {
87+
return this.timeToLive;
8788
}
8889

89-
public void setTimeToLiveSeconds(Duration timeToLiveSeconds) {
90-
this.timeToLiveSeconds = timeToLiveSeconds;
90+
public void setTimeToLive(Duration timeToLive) {
91+
this.timeToLive = timeToLive;
9192
}
9293

9394
}

spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/chat/memory/cassandra/CassandraChatMemoryAutoConfigurationIT.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

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

19+
import java.time.Duration;
1920
import java.util.List;
2021

2122
import com.datastax.driver.core.utils.UUIDs;
@@ -37,6 +38,7 @@
3738

3839
/**
3940
* @author Mick Semb Wever
41+
* @author Jihoon Kim
4042
* @since 1.0.0
4143
*/
4244
@Testcontainers
@@ -57,7 +59,7 @@ void addAndGet() {
5759
this.contextRunner.withPropertyValues("spring.cassandra.contactPoints=" + getContactPointHost())
5860
.withPropertyValues("spring.cassandra.port=" + getContactPointPort())
5961
.withPropertyValues("spring.cassandra.localDatacenter=" + cassandraContainer.getLocalDatacenter())
60-
62+
.withPropertyValues("spring.ai.chat.memory.cassandra.time-to-live=" + getTimeToLive())
6163
.run(context -> {
6264
CassandraChatMemory memory = context.getBean(CassandraChatMemory.class);
6365

@@ -84,6 +86,20 @@ void addAndGet() {
8486
.isEqualTo(MessageType.ASSISTANT);
8587
assertThat(memory.get(sessionId, Integer.MAX_VALUE).get(0).getContent()).isEqualTo("test answer");
8688

89+
CassandraChatMemoryProperties properties = context.getBean(CassandraChatMemoryProperties.class);
90+
assertThat(properties.getTimeToLive()).isEqualTo(getTimeToLive());
91+
});
92+
}
93+
94+
@Test
95+
void compareTimeToLive_ISO8601Format() {
96+
this.contextRunner.withPropertyValues("spring.cassandra.contactPoints=" + getContactPointHost())
97+
.withPropertyValues("spring.cassandra.port=" + getContactPointPort())
98+
.withPropertyValues("spring.cassandra.localDatacenter=" + cassandraContainer.getLocalDatacenter())
99+
.withPropertyValues("spring.ai.chat.memory.cassandra.time-to-live=" + getTimeToLiveString())
100+
.run(context -> {
101+
CassandraChatMemoryProperties properties = context.getBean(CassandraChatMemoryProperties.class);
102+
assertThat(properties.getTimeToLive()).isEqualTo(Duration.parse(getTimeToLiveString()));
87103
});
88104
}
89105

@@ -95,4 +111,12 @@ private String getContactPointPort() {
95111
return String.valueOf(cassandraContainer.getContactPoint().getPort());
96112
}
97113

114+
private Duration getTimeToLive() {
115+
return Duration.ofSeconds(12000);
116+
}
117+
118+
private String getTimeToLiveString() {
119+
return "PT1M";
120+
}
121+
98122
}

spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/chat/memory/cassandra/CassandraChatMemoryPropertiesTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
/**
2828
* @author Mick Semb Wever
29+
* @author Jihoon Kim
2930
* @since 1.0.0
3031
*/
3132
class CassandraChatMemoryPropertiesTest {
@@ -37,7 +38,7 @@ void defaultValues() {
3738
assertThat(props.getTable()).isEqualTo(CassandraChatMemoryConfig.DEFAULT_TABLE_NAME);
3839
assertThat(props.getAssistantColumn()).isEqualTo(CassandraChatMemoryConfig.DEFAULT_ASSISTANT_COLUMN_NAME);
3940
assertThat(props.getUserColumn()).isEqualTo(CassandraChatMemoryConfig.DEFAULT_USER_COLUMN_NAME);
40-
assertThat(props.getTimeToLiveSeconds()).isNull();
41+
assertThat(props.getTimeToLive()).isNull();
4142
assertThat(props.isInitializeSchema()).isTrue();
4243
}
4344

@@ -48,14 +49,14 @@ void customValues() {
4849
props.setTable("my_table");
4950
props.setAssistantColumn("my_assistant_column");
5051
props.setUserColumn("my_user_column");
51-
props.setTimeToLiveSeconds(Duration.ofDays(1));
52+
props.setTimeToLive(Duration.ofDays(1));
5253
props.setInitializeSchema(false);
5354

5455
assertThat(props.getKeyspace()).isEqualTo("my_keyspace");
5556
assertThat(props.getTable()).isEqualTo("my_table");
5657
assertThat(props.getAssistantColumn()).isEqualTo("my_assistant_column");
5758
assertThat(props.getUserColumn()).isEqualTo("my_user_column");
58-
assertThat(props.getTimeToLiveSeconds()).isEqualTo(Duration.ofDays(1));
59+
assertThat(props.getTimeToLive()).isEqualTo(Duration.ofDays(1));
5960
assertThat(props.isInitializeSchema()).isFalse();
6061
}
6162

0 commit comments

Comments
 (0)