Skip to content

Commit 5d9dd90

Browse files
committed
rename timeToLiveSeconds of cassandra property
fix issue #1728 Signed-off-by: jitokim <[email protected]>
1 parent 7474852 commit 5d9dd90

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
@@ -29,6 +29,7 @@
2929

3030
/**
3131
* @author Mick Semb Wever
32+
* @author Jihoon Kim
3233
* @since 1.0.0
3334
*/
3435
@AutoConfiguration(after = CassandraAutoConfiguration.class)
@@ -50,8 +51,8 @@ public CassandraChatMemory chatMemory(CassandraChatMemoryProperties properties,
5051
if (!properties.isInitializeSchema()) {
5152
builder = builder.disallowSchemaChanges();
5253
}
53-
if (null != properties.getTimeToLiveSeconds()) {
54-
builder = builder.withTimeToLive(properties.getTimeToLiveSeconds());
54+
if (null != properties.getTimeToLive()) {
55+
builder = builder.withTimeToLive(properties.getTimeToLive());
5556
}
5657

5758
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
@@ -28,6 +28,7 @@
2828

2929
/**
3030
* @author Mick Semb Wever
31+
* @author Jihoon Kim
3132
* @since 1.0.0
3233
*/
3334
@ConfigurationProperties(CassandraChatMemoryProperties.CONFIG_PREFIX)
@@ -45,7 +46,7 @@ public class CassandraChatMemoryProperties extends CommonChatMemoryProperties {
4546

4647
private String userColumn = CassandraChatMemoryConfig.DEFAULT_USER_COLUMN_NAME;
4748

48-
private Duration timeToLiveSeconds = null;
49+
private Duration timeToLive = null;
4950

5051
public String getKeyspace() {
5152
return this.keyspace;
@@ -80,12 +81,12 @@ public void setUserColumn(String userColumn) {
8081
}
8182

8283
@Nullable
83-
public Duration getTimeToLiveSeconds() {
84-
return this.timeToLiveSeconds;
84+
public Duration getTimeToLive() {
85+
return this.timeToLive;
8586
}
8687

87-
public void setTimeToLiveSeconds(Duration timeToLiveSeconds) {
88-
this.timeToLiveSeconds = timeToLiveSeconds;
88+
public void setTimeToLive(Duration timeToLive) {
89+
this.timeToLive = timeToLive;
8990
}
9091

9192
}

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)