Skip to content
Open
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 @@ -163,8 +163,8 @@ public Maybe<Session> getSession(
}

// Helper to get event timestamp as epoch seconds
private long getEventTimestampEpochSeconds(Event event) {
return event.timestamp() / 1000L;
private double getEventTimestampEpochSeconds(Event event) {
return event.timestamp() / 1000.0;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.adk.events.Event;
import com.google.adk.events.EventActions;
import io.reactivex.rxjava3.core.Single;
import java.time.Instant;
import java.util.HashMap;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -214,6 +215,24 @@ public void appendEvent_removesState() {
assertThat(retrievedSessionRemove.state()).doesNotContainKey("temp:tempKey");
}

@Test
public void appendEvent_updatesSessionTimestampWithFractionalSeconds() {
InMemorySessionService sessionService = new InMemorySessionService();
Session session =
sessionService.createSession("app", "user", new HashMap<>(), "session1").blockingGet();

// Add an event with a timestamp that contains a fractional second
Event eventAdd = Event.builder().timestamp(5500).build();
var unused = sessionService.appendEvent(session, eventAdd).blockingGet();

// Verify the last modified timestamp contains a fractional second
Session retrievedSession =
sessionService
.getSession(session.appName(), session.userId(), session.id(), Optional.empty())
.blockingGet();
assertThat(retrievedSession.lastUpdateTime()).isEqualTo(Instant.ofEpochSecond(5, 500000000L));
}

@Test
public void sequentialAgents_shareTempState() {
InMemorySessionService sessionService = new InMemorySessionService();
Expand Down