Skip to content

Commit de76ef1

Browse files
committed
Polish "Provide an Actuator endpoint for non-indexed session repositories"
See gh-32046
1 parent 6a9eb77 commit de76ef1

File tree

3 files changed

+12
-62
lines changed

3 files changed

+12
-62
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/session/SessionsEndpoint.java

+1-55
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,10 +16,8 @@
1616

1717
package org.springframework.boot.actuate.session;
1818

19-
import java.time.Instant;
2019
import java.util.List;
2120
import java.util.Map;
22-
import java.util.Set;
2321

2422
import org.springframework.boot.actuate.endpoint.OperationResponseBody;
2523
import org.springframework.boot.actuate.endpoint.annotation.DeleteOperation;
@@ -97,56 +95,4 @@ public List<SessionDescriptor> getSessions() {
9795

9896
}
9997

100-
/**
101-
* Description of user's {@link Session session}.
102-
*/
103-
public static final class SessionDescriptor implements OperationResponseBody {
104-
105-
private final String id;
106-
107-
private final Set<String> attributeNames;
108-
109-
private final Instant creationTime;
110-
111-
private final Instant lastAccessedTime;
112-
113-
private final long maxInactiveInterval;
114-
115-
private final boolean expired;
116-
117-
public SessionDescriptor(Session session) {
118-
this.id = session.getId();
119-
this.attributeNames = session.getAttributeNames();
120-
this.creationTime = session.getCreationTime();
121-
this.lastAccessedTime = session.getLastAccessedTime();
122-
this.maxInactiveInterval = session.getMaxInactiveInterval().getSeconds();
123-
this.expired = session.isExpired();
124-
}
125-
126-
public String getId() {
127-
return this.id;
128-
}
129-
130-
public Set<String> getAttributeNames() {
131-
return this.attributeNames;
132-
}
133-
134-
public Instant getCreationTime() {
135-
return this.creationTime;
136-
}
137-
138-
public Instant getLastAccessedTime() {
139-
return this.lastAccessedTime;
140-
}
141-
142-
public long getMaxInactiveInterval() {
143-
return this.maxInactiveInterval;
144-
}
145-
146-
public boolean isExpired() {
147-
return this.expired;
148-
}
149-
150-
}
151-
15298
}

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/session/ReactiveSessionsEndpointTests.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.boot.actuate.session;
1818

19+
import java.time.Duration;
20+
1921
import org.junit.jupiter.api.Test;
2022
import reactor.core.publisher.Mono;
2123
import reactor.test.StepVerifier;
@@ -53,21 +55,23 @@ void getSession() {
5355
assertThat(result.getLastAccessedTime()).isEqualTo(session.getLastAccessedTime());
5456
assertThat(result.getMaxInactiveInterval()).isEqualTo(session.getMaxInactiveInterval().getSeconds());
5557
assertThat(result.isExpired()).isEqualTo(session.isExpired());
56-
}).verifyComplete();
58+
}).expectComplete().verify(Duration.ofSeconds(1));
5759
then(this.sessionRepository).should().findById(session.getId());
5860
}
5961

6062
@Test
6163
void getSessionWithIdNotFound() {
6264
given(this.sessionRepository.findById("not-found")).willReturn(Mono.empty());
63-
StepVerifier.create(this.endpoint.getSession("not-found")).verifyComplete();
65+
StepVerifier.create(this.endpoint.getSession("not-found")).expectComplete().verify(Duration.ofSeconds(1));
6466
then(this.sessionRepository).should().findById("not-found");
6567
}
6668

6769
@Test
6870
void deleteSession() {
6971
given(this.sessionRepository.deleteById(session.getId())).willReturn(Mono.empty());
70-
StepVerifier.create(this.endpoint.deleteSession(session.getId())).verifyComplete();
72+
StepVerifier.create(this.endpoint.deleteSession(session.getId()))
73+
.expectComplete()
74+
.verify(Duration.ofSeconds(1));
7175
then(this.sessionRepository).should().deleteById(session.getId());
7276
}
7377

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/session/SessionsEndpointTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -54,7 +54,7 @@ class SessionsEndpointTests {
5454
void sessionsForUsername() {
5555
given(this.indexedSessionRepository.findByPrincipalName("user"))
5656
.willReturn(Collections.singletonMap(session.getId(), session));
57-
List<SessionsEndpoint.SessionDescriptor> result = this.endpoint.sessionsForUsername("user").getSessions();
57+
List<SessionDescriptor> result = this.endpoint.sessionsForUsername("user").getSessions();
5858
assertThat(result).hasSize(1);
5959
assertThat(result.get(0).getId()).isEqualTo(session.getId());
6060
assertThat(result.get(0).getAttributeNames()).isEqualTo(session.getAttributeNames());
@@ -74,7 +74,7 @@ void sessionsForUsernameWhenNoIndexedRepository() {
7474
@Test
7575
void getSession() {
7676
given(this.sessionRepository.findById(session.getId())).willReturn(session);
77-
SessionsEndpoint.SessionDescriptor result = this.endpoint.getSession(session.getId());
77+
SessionDescriptor result = this.endpoint.getSession(session.getId());
7878
assertThat(result.getId()).isEqualTo(session.getId());
7979
assertThat(result.getAttributeNames()).isEqualTo(session.getAttributeNames());
8080
assertThat(result.getCreationTime()).isEqualTo(session.getCreationTime());

0 commit comments

Comments
 (0)