Search in sources :

Example 1 with HazelcastSession

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

the class AbstractHazelcastRepositoryITests method changeSessionIdWhenOnlyChangeId.

@Test
public void changeSessionIdWhenOnlyChangeId() throws Exception {
    String attrName = "changeSessionId";
    String attrValue = "changeSessionId-value";
    HazelcastSession toSave = this.repository.createSession();
    toSave.setAttribute(attrName, attrValue);
    this.repository.save(toSave);
    HazelcastSession findById = this.repository.findById(toSave.getId());
    assertThat(findById.<String>getAttribute(attrName)).isEqualTo(attrValue);
    String originalFindById = findById.getId();
    String changeSessionId = findById.changeSessionId();
    this.repository.save(findById);
    assertThat(this.repository.findById(originalFindById)).isNull();
    HazelcastSession findByChangeSessionId = this.repository.findById(changeSessionId);
    assertThat(findByChangeSessionId.<String>getAttribute(attrName)).isEqualTo(attrValue);
    this.repository.deleteById(changeSessionId);
}
Also used : HazelcastSession(org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession) Test(org.junit.Test)

Example 2 with HazelcastSession

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

the class AbstractHazelcastRepositoryITests method changeSessionIdWhenHasNotSaved.

@Test
public void changeSessionIdWhenHasNotSaved() throws Exception {
    String attrName = "changeSessionId";
    String attrValue = "changeSessionId-value";
    HazelcastSession toSave = this.repository.createSession();
    String originalId = toSave.getId();
    toSave.changeSessionId();
    this.repository.save(toSave);
    assertThat(this.repository.findById(toSave.getId())).isNotNull();
    assertThat(this.repository.findById(originalId)).isNull();
    this.repository.deleteById(toSave.getId());
}
Also used : HazelcastSession(org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession) Test(org.junit.Test)

Example 3 with HazelcastSession

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

the class HazelcastSessionRepositoryTests method saveUpdatedMaxInactiveIntervalInSecondsFlushModeOnSave.

@Test
public void saveUpdatedMaxInactiveIntervalInSecondsFlushModeOnSave() {
    verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());
    HazelcastSession session = this.repository.createSession();
    session.setMaxInactiveInterval(Duration.ofSeconds(1));
    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 4 with HazelcastSession

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

the class HazelcastSessionRepositoryTests method findByIndexNameAndIndexValuePrincipalIndexNameNotFound.

@Test
public void findByIndexNameAndIndexValuePrincipalIndexNameNotFound() {
    verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());
    String principal = "username";
    Map<String, HazelcastSession> sessions = this.repository.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principal);
    assertThat(sessions).isEmpty();
    verify(this.sessions, times(1)).values(isA(EqualPredicate.class));
    verifyZeroInteractions(this.sessions);
}
Also used : MapListener(com.hazelcast.map.listener.MapListener) EqualPredicate(com.hazelcast.query.impl.predicates.EqualPredicate) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HazelcastSession(org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession) Test(org.junit.Test)

Example 5 with HazelcastSession

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

the class HazelcastSessionRepositoryTests method saveUpdatedMaxInactiveIntervalInSecondsFlushModeImmediate.

@Test
public void saveUpdatedMaxInactiveIntervalInSecondsFlushModeImmediate() {
    verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());
    this.repository.setHazelcastFlushMode(HazelcastFlushMode.IMMEDIATE);
    HazelcastSession session = this.repository.createSession();
    session.setMaxInactiveInterval(Duration.ofSeconds(1));
    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)

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