Class AbstractSessionRepositoryContractTests
java.lang.Object
org.springframework.ai.test.session.AbstractSessionRepositoryContractTests
Contract tests every
SessionRepository implementation must pass. Subclass it,
return your repository from createRepository(), and run the tests with the
JUnit Platform:
class RedisSessionRepositoryContractTests extends AbstractSessionRepositoryContractTests {
@Override
protected SessionRepository createRepository() {
return RedisSessionRepository.builder().connectionFactory(...).build();
}
}
Every test creates its own sessions with random ids, so createRepository() may
return a shared store. The tests cover session lifecycle, idempotent append, the read
contract of SessionRepository.findEvents(java.lang.String, org.springframework.ai.session.EventFilter) (pushdown or
EventFilter.apply(List) must give the same result, including a lastN
window that keeps turns whole), cross-session reads, the atomic
SessionRepository.appendEvents(java.lang.String, java.util.List<org.springframework.ai.session.SessionEvent>, long) and the active view a boundary defines.
- Since:
- 2.1.0
- Author:
- Christian Tzolov
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAppends each message as its own event.protected static Messageprotected voidcompact(String sessionId, List<SessionEvent> pinned, List<SessionEvent> summary, List<SessionEvent> preserved) Records a compaction the way the service does: appends a boundary naming the pinned, summary and preserved events, followed by the summary events, under the current version.protected abstract SessionRepositoryReturns the repository under test.protected static SessionEventprotected SessionfindSession(String id) The session with the given id, which must exist.ids(List<SessionEvent> events, String... labels) The ids of the events with the given labels.labels(List<SessionEvent> events) Event labels: the text, "Σ?"protected SessionnewSession(String principalName) Saves a new session with a random id for the given principal.protected static SessionprincipalSession(String id, String principalName) A session with the given id whose metadata names the principal.protected static SessionEventA status event, the simplest event that is not a message.protected static List<SessionEvent>summaryTurn(String sessionId, String summary) A synthetic shadow-prompt + summary pair, as the summarizing strategy produces.protected static SessionEventA synthetic event, as a compaction strategy would produce it.protected static Messagetexts(String sessionId, EventFilter filter) The texts of the message events matching the filter, in the order returned.protected static MessageAn assistant message that calls one tool.protected static MessagetoolResponse(String callId, String toolName, String data) The result of one tool call.protected static Message
-
Field Details
-
repository
-
-
Constructor Details
-
AbstractSessionRepositoryContractTests
public AbstractSessionRepositoryContractTests()
-
-
Method Details
-
createRepository
Returns the repository under test. Called before every test.- Returns:
- the repository
-
newSession
Saves a new session with a random id for the given principal. -
findSession
The session with the given id, which must exist. -
principalSession
A session with the given id whose metadata names the principal. -
append
Appends each message as its own event. -
texts
The texts of the message events matching the filter, in the order returned. -
event
-
status
A status event, the simplest event that is not a message. -
compact
protected void compact(String sessionId, List<SessionEvent> pinned, List<SessionEvent> summary, List<SessionEvent> preserved) Records a compaction the way the service does: appends a boundary naming the pinned, summary and preserved events, followed by the summary events, under the current version. -
synthetic
A synthetic event, as a compaction strategy would produce it. -
summaryTurn
A synthetic shadow-prompt + summary pair, as the summarizing strategy produces. -
labels
Event labels: the text, "Σ?" for a synthetic shadow prompt, "Σ:text" for a summary, "A[name]" for an assistant tool call, "T[name]" for a tool result, "⊥" for a compaction boundary and the status (or the type name) for any other event. -
ids
The ids of the events with the given labels. -
user
-
assistant
-
system
-
toolCall
An assistant message that calls one tool. -
toolResponse
The result of one tool call.
-