From f7e408945e04e77d690148aabc618d8ba9e9e882 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 15 Jan 2018 10:57:18 +0000 Subject: [PATCH] Use Instant for Session creation and last accessed times Closes gh-10976 --- .../boot/actuate/session/SessionsEndpoint.java | 15 ++++++++------- .../actuate/session/SessionsEndpointTests.java | 13 +++++-------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/session/SessionsEndpoint.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/session/SessionsEndpoint.java index 10c29f69bd..33e2ec43cf 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/session/SessionsEndpoint.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/session/SessionsEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.springframework.boot.actuate.session; +import java.time.Instant; import java.util.List; import java.util.Map; import java.util.Set; @@ -101,9 +102,9 @@ public class SessionsEndpoint { private final Set attributeNames; - private final long creationTime; + private final Instant creationTime; - private final long lastAccessedTime; + private final Instant lastAccessedTime; private final long maxInactiveInterval; @@ -112,8 +113,8 @@ public class SessionsEndpoint { public SessionDescriptor(Session session) { this.id = session.getId(); this.attributeNames = session.getAttributeNames(); - this.creationTime = session.getCreationTime().toEpochMilli(); - this.lastAccessedTime = session.getLastAccessedTime().toEpochMilli(); + this.creationTime = session.getCreationTime(); + this.lastAccessedTime = session.getLastAccessedTime(); this.maxInactiveInterval = session.getMaxInactiveInterval().getSeconds(); this.expired = session.isExpired(); } @@ -126,11 +127,11 @@ public class SessionsEndpoint { return this.attributeNames; } - public long getCreationTime() { + public Instant getCreationTime() { return this.creationTime; } - public long getLastAccessedTime() { + public Instant getLastAccessedTime() { return this.lastAccessedTime; } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/session/SessionsEndpointTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/session/SessionsEndpointTests.java index b0dd0df047..a2d84eba2d 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/session/SessionsEndpointTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/session/SessionsEndpointTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,10 +57,9 @@ public class SessionsEndpointTests { assertThat(result.get(0).getId()).isEqualTo(session.getId()); assertThat(result.get(0).getAttributeNames()) .isEqualTo(session.getAttributeNames()); - assertThat(result.get(0).getCreationTime()) - .isEqualTo(session.getCreationTime().toEpochMilli()); + assertThat(result.get(0).getCreationTime()).isEqualTo(session.getCreationTime()); assertThat(result.get(0).getLastAccessedTime()) - .isEqualTo(session.getLastAccessedTime().toEpochMilli()); + .isEqualTo(session.getLastAccessedTime()); assertThat(result.get(0).getMaxInactiveInterval()) .isEqualTo(session.getMaxInactiveInterval().getSeconds()); assertThat(result.get(0).isExpired()).isEqualTo(session.isExpired()); @@ -72,10 +71,8 @@ public class SessionsEndpointTests { SessionDescriptor result = this.endpoint.getSession(session.getId()); assertThat(result.getId()).isEqualTo(session.getId()); assertThat(result.getAttributeNames()).isEqualTo(session.getAttributeNames()); - assertThat(result.getCreationTime()) - .isEqualTo(session.getCreationTime().toEpochMilli()); - assertThat(result.getLastAccessedTime()) - .isEqualTo(session.getLastAccessedTime().toEpochMilli()); + assertThat(result.getCreationTime()).isEqualTo(session.getCreationTime()); + assertThat(result.getLastAccessedTime()).isEqualTo(session.getLastAccessedTime()); assertThat(result.getMaxInactiveInterval()) .isEqualTo(session.getMaxInactiveInterval().getSeconds()); assertThat(result.isExpired()).isEqualTo(session.isExpired());