use of org.springframework.session.MapSession in project spring-session by spring-projects.
the class ReactiveRedisOperationsSessionRepositoryTests method getSessionFound.
@Test
@SuppressWarnings("unchecked")
public void getSessionFound() {
given(this.redisOperations.opsForHash()).willReturn(this.hashOperations);
String attrName = "attrName";
MapSession expected = new MapSession();
expected.setLastAccessedTime(Instant.now().minusSeconds(60));
expected.setAttribute(attrName, "attrValue");
Map map = map(RedisOperationsSessionRepository.getSessionAttrNameKey(attrName), expected.getAttribute(attrName), RedisOperationsSessionRepository.CREATION_TIME_ATTR, expected.getCreationTime().toEpochMilli(), RedisOperationsSessionRepository.MAX_INACTIVE_ATTR, (int) expected.getMaxInactiveInterval().getSeconds(), RedisOperationsSessionRepository.LAST_ACCESSED_ATTR, expected.getLastAccessedTime().toEpochMilli());
given(this.hashOperations.entries(anyString())).willReturn(Flux.fromIterable(map.entrySet()));
Mono<ReactiveRedisOperationsSessionRepository.RedisSession> session = this.repository.findById("test");
StepVerifier.create(session).expectNextMatches(predicate -> {
assertThat(predicate.getId()).isEqualTo(expected.getId());
assertThat(predicate.getAttributeNames()).isEqualTo(expected.getAttributeNames());
assertThat(predicate.<String>getAttribute(attrName)).isEqualTo(expected.getAttribute(attrName));
assertThat(predicate.getCreationTime()).isEqualTo(expected.getCreationTime());
assertThat(predicate.getMaxInactiveInterval()).isEqualTo(expected.getMaxInactiveInterval());
assertThat(predicate.getLastAccessedTime()).isEqualTo(expected.getLastAccessedTime());
return true;
});
}
use of org.springframework.session.MapSession in project spring-session by spring-projects.
the class RedisSessionExpirationPolicyTests method setup.
@Before
public void setup() {
RedisOperationsSessionRepository repository = new RedisOperationsSessionRepository(this.sessionRedisOperations);
this.policy = new RedisSessionExpirationPolicy(this.sessionRedisOperations, repository::getExpirationsKey, repository::getSessionKey);
this.session = new MapSession();
this.session.setLastAccessedTime(Instant.ofEpochMilli(1429116694675L));
this.session.setId("12345");
given(this.sessionRedisOperations.boundSetOps(anyString())).willReturn(this.setOperations);
given(this.sessionRedisOperations.boundHashOps(anyString())).willReturn(this.hashOperations);
given(this.sessionRedisOperations.boundValueOps(anyString())).willReturn(this.valueOperations);
}
use of org.springframework.session.MapSession in project spring-session by spring-projects.
the class HazelcastSessionRepositoryTests method getSessionFound.
@Test
public void getSessionFound() {
verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());
MapSession saved = new MapSession();
saved.setAttribute("savedName", "savedValue");
given(this.sessions.get(eq(saved.getId()))).willReturn(saved);
HazelcastSession session = this.repository.findById(saved.getId());
assertThat(session.getId()).isEqualTo(saved.getId());
assertThat(session.<String>getAttribute("savedName")).isEqualTo("savedValue");
verify(this.sessions, times(1)).get(eq(saved.getId()));
verifyZeroInteractions(this.sessions);
}
use of org.springframework.session.MapSession in project spring-session by spring-projects.
the class HazelcastSessionRepositoryTests method getSessionExpired.
@Test
public void getSessionExpired() {
verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());
MapSession expired = new MapSession();
expired.setLastAccessedTime(Instant.now().minusSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS + 1));
given(this.sessions.get(eq(expired.getId()))).willReturn(expired);
HazelcastSession session = this.repository.findById(expired.getId());
assertThat(session).isNull();
verify(this.sessions, times(1)).get(eq(expired.getId()));
verify(this.sessions, times(1)).remove(eq(expired.getId()));
verifyZeroInteractions(this.sessions);
}
use of org.springframework.session.MapSession in project spring-session by spring-projects.
the class IndexDocTests method repositoryDemo.
@Test
public void repositoryDemo() {
RepositoryDemo<MapSession> demo = new RepositoryDemo<>();
demo.repository = new MapSessionRepository(new ConcurrentHashMap<>());
demo.demo();
}
Aggregations