Search in sources :

Example 16 with HazelcastSession

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);
}
Also used : MapListener(com.hazelcast.map.listener.MapListener) MapSession(org.springframework.session.MapSession) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HazelcastSession(org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession) Test(org.junit.Test)

Example 17 with HazelcastSession

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);
}
Also used : MapListener(com.hazelcast.map.listener.MapListener) HazelcastSession(org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession) Test(org.junit.Test)

Example 18 with HazelcastSession

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);
}
Also used : EntryProcessor(com.hazelcast.map.EntryProcessor) MapListener(com.hazelcast.map.listener.MapListener) HazelcastSession(org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession) Test(org.junit.Test)

Example 19 with HazelcastSession

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);
}
Also used : EntryProcessor(com.hazelcast.map.EntryProcessor) MapListener(com.hazelcast.map.listener.MapListener) HazelcastSession(org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession) Test(org.junit.Test)

Example 20 with HazelcastSession

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);
}
Also used : MapListener(com.hazelcast.map.listener.MapListener) MapSession(org.springframework.session.MapSession) HazelcastSession(org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)25 HazelcastSession (org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession)25 MapListener (com.hazelcast.map.listener.MapListener)20 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 MapSession (org.springframework.session.MapSession)5 EntryProcessor (com.hazelcast.map.EntryProcessor)4 EqualPredicate (com.hazelcast.query.impl.predicates.EqualPredicate)2 ArrayList (java.util.ArrayList)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1