Search in sources :

Example 6 with HazelcastSession

use of org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession in project spring-session by spring-projects.

the class HazelcastSessionRepositoryTests method saveNewFlushModeOnSave.

@Test
public void saveNewFlushModeOnSave() {
    verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());
    HazelcastSession session = this.repository.createSession();
    verifyZeroInteractions(this.sessions);
    this.repository.save(session);
    verify(this.sessions, times(1)).set(eq(session.getId()), eq(session.getDelegate()), isA(Long.class), eq(TimeUnit.SECONDS));
    verifyZeroInteractions(this.sessions);
}
Also used : MapListener(com.hazelcast.map.listener.MapListener) HazelcastSession(org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession) Test(org.junit.Test)

Example 7 with HazelcastSession

use of org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession in project spring-session by spring-projects.

the class HazelcastSessionRepositoryTests method saveUpdatedLastAccessedTimeFlushModeImmediate.

@Test
public void saveUpdatedLastAccessedTimeFlushModeImmediate() {
    verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());
    this.repository.setHazelcastFlushMode(HazelcastFlushMode.IMMEDIATE);
    HazelcastSession session = this.repository.createSession();
    session.setLastAccessedTime(Instant.now());
    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 8 with HazelcastSession

use of org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession in project spring-session by spring-projects.

the class HazelcastSessionRepositoryTests method createSessionDefaultMaxInactiveInterval.

@Test
public void createSessionDefaultMaxInactiveInterval() throws Exception {
    verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());
    HazelcastSession session = this.repository.createSession();
    assertThat(session.getMaxInactiveInterval()).isEqualTo(new MapSession().getMaxInactiveInterval());
    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)

Example 9 with HazelcastSession

use of org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession in project spring-session by spring-projects.

the class HazelcastSessionRepositoryTests method findByIndexNameAndIndexValuePrincipalIndexNameFound.

@Test
public void findByIndexNameAndIndexValuePrincipalIndexNameFound() {
    verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());
    String principal = "username";
    Authentication authentication = new UsernamePasswordAuthenticationToken(principal, "notused", AuthorityUtils.createAuthorityList("ROLE_USER"));
    List<MapSession> saved = new ArrayList<>(2);
    MapSession saved1 = new MapSession();
    saved1.setAttribute(SPRING_SECURITY_CONTEXT, authentication);
    saved.add(saved1);
    MapSession saved2 = new MapSession();
    saved2.setAttribute(SPRING_SECURITY_CONTEXT, authentication);
    saved.add(saved2);
    given(this.sessions.values(isA(EqualPredicate.class))).willReturn(saved);
    Map<String, HazelcastSession> sessions = this.repository.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principal);
    assertThat(sessions).hasSize(2);
    verify(this.sessions, times(1)).values(isA(EqualPredicate.class));
    verifyZeroInteractions(this.sessions);
}
Also used : MapListener(com.hazelcast.map.listener.MapListener) Authentication(org.springframework.security.core.Authentication) ArrayList(java.util.ArrayList) EqualPredicate(com.hazelcast.query.impl.predicates.EqualPredicate) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MapSession(org.springframework.session.MapSession) HazelcastSession(org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession) Test(org.junit.Test)

Example 10 with HazelcastSession

use of org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession in project spring-session by spring-projects.

the class HazelcastSessionRepositoryTests method getSessionNotFound.

@Test
public void getSessionNotFound() {
    verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());
    String sessionId = "testSessionId";
    HazelcastSession session = this.repository.findById(sessionId);
    assertThat(session).isNull();
    verify(this.sessions, times(1)).get(eq(sessionId));
    verifyZeroInteractions(this.sessions);
}
Also used : MapListener(com.hazelcast.map.listener.MapListener) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) 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