use of org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession 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.hazelcast.HazelcastSessionRepository.HazelcastSession in project spring-session by spring-projects.
the class HazelcastSessionRepositoryTests method createSessionCustomMaxInactiveInterval.
@Test
public void createSessionCustomMaxInactiveInterval() throws Exception {
verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());
int interval = 1;
this.repository.setDefaultMaxInactiveInterval(interval);
HazelcastSession session = this.repository.createSession();
assertThat(session.getMaxInactiveInterval()).isEqualTo(Duration.ofSeconds(interval));
verifyZeroInteractions(this.sessions);
}
use of org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession in project spring-session by spring-projects.
the class HazelcastSessionRepositoryTests method saveUpdatedAttributeFlushModeImmediate.
@Test
public void saveUpdatedAttributeFlushModeImmediate() {
verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());
this.repository.setHazelcastFlushMode(HazelcastFlushMode.IMMEDIATE);
HazelcastSession session = this.repository.createSession();
session.setAttribute("testName", "testValue");
verify(this.sessions, times(1)).set(eq(session.getId()), eq(session.getDelegate()), isA(Long.class), eq(TimeUnit.SECONDS));
verify(this.sessions, times(1)).executeOnKey(eq(session.getId()), any(EntryProcessor.class));
this.repository.save(session);
verifyZeroInteractions(this.sessions);
}
use of org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession in project spring-session by spring-projects.
the class HazelcastSessionRepositoryTests method removeAttributeFlushModeImmediate.
@Test
public void removeAttributeFlushModeImmediate() {
verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());
this.repository.setHazelcastFlushMode(HazelcastFlushMode.IMMEDIATE);
HazelcastSession session = this.repository.createSession();
session.removeAttribute("testName");
verify(this.sessions, times(1)).set(eq(session.getId()), eq(session.getDelegate()), isA(Long.class), eq(TimeUnit.SECONDS));
verify(this.sessions, times(1)).executeOnKey(eq(session.getId()), any(EntryProcessor.class));
this.repository.save(session);
verifyZeroInteractions(this.sessions);
}
use of org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession 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);
}
Aggregations