Search in sources :

Example 11 with HazelcastSession

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

the class HazelcastSessionRepositoryTests method findByIndexNameAndIndexValueUnknownIndexName.

@Test
public void findByIndexNameAndIndexValueUnknownIndexName() {
    verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());
    String indexValue = "testIndexValue";
    Map<String, HazelcastSession> sessions = this.repository.findByIndexNameAndIndexValue("testIndexName", indexValue);
    assertThat(sessions).isEmpty();
    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)

Example 12 with HazelcastSession

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

the class HazelcastSessionRepositoryTests method saveNewFlushModeImmediate.

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

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

the class AbstractHazelcastRepositoryITests method changeSessionIdWhenChangeTwice.

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

Example 14 with HazelcastSession

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

the class AbstractHazelcastRepositoryITests method createAndDestroySession.

@Test
public void createAndDestroySession() {
    HazelcastSession sessionToSave = this.repository.createSession();
    String sessionId = sessionToSave.getId();
    IMap<String, MapSession> hazelcastMap = this.hazelcast.getMap(HazelcastSessionRepository.DEFAULT_SESSION_MAP_NAME);
    assertThat(hazelcastMap.size()).isEqualTo(0);
    this.repository.save(sessionToSave);
    assertThat(hazelcastMap.size()).isEqualTo(1);
    assertThat(hazelcastMap.get(sessionId)).isEqualTo(sessionToSave);
    this.repository.deleteById(sessionId);
    assertThat(hazelcastMap.size()).isEqualTo(0);
}
Also used : MapSession(org.springframework.session.MapSession) HazelcastSession(org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession) Test(org.junit.Test)

Example 15 with HazelcastSession

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

the class AbstractHazelcastRepositoryITests method changeSessionIdWhenSetAttributeOnChangedSession.

@Test
public void changeSessionIdWhenSetAttributeOnChangedSession() throws Exception {
    String attrName = "changeSessionId";
    String attrValue = "changeSessionId-value";
    HazelcastSession toSave = this.repository.createSession();
    this.repository.save(toSave);
    HazelcastSession findById = this.repository.findById(toSave.getId());
    findById.setAttribute(attrName, 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)

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