use of org.springframework.data.redis.connection.DefaultMessage in project spring-session by spring-projects.
the class RedisOperationsSessionRepositoryTests method onMessageCreated.
@Test
public void onMessageCreated() throws Exception {
MapSession session = this.cached;
byte[] pattern = "".getBytes("UTF-8");
String channel = "spring:session:event:created:" + session.getId();
JdkSerializationRedisSerializer defaultSerailizer = new JdkSerializationRedisSerializer();
this.redisRepository.setDefaultSerializer(defaultSerailizer);
byte[] body = defaultSerailizer.serialize(new HashMap());
DefaultMessage message = new DefaultMessage(channel.getBytes("UTF-8"), body);
this.redisRepository.setApplicationEventPublisher(this.publisher);
this.redisRepository.onMessage(message, pattern);
verify(this.publisher).publishEvent(this.event.capture());
assertThat(this.event.getValue().getSessionId()).isEqualTo(session.getId());
}
use of org.springframework.data.redis.connection.DefaultMessage in project spring-session by spring-projects.
the class RedisOperationsSessionRepositoryITests method findBySecurityPrincipalNameExpireRemovesIndex.
@Test
public void findBySecurityPrincipalNameExpireRemovesIndex() throws Exception {
RedisSession toSave = this.repository.createSession();
toSave.setAttribute(SPRING_SECURITY_CONTEXT, this.context);
this.repository.save(toSave);
String body = "RedisOperationsSessionRepositoryITests:sessions:expires:" + toSave.getId();
String channel = ":expired";
DefaultMessage message = new DefaultMessage(channel.getBytes("UTF-8"), body.getBytes("UTF-8"));
byte[] pattern = new byte[] {};
this.repository.onMessage(message, pattern);
Map<String, RedisSession> findByPrincipalName = this.repository.findByIndexNameAndIndexValue(INDEX_NAME, getSecurityName());
assertThat(findByPrincipalName).hasSize(0);
assertThat(findByPrincipalName.keySet()).doesNotContain(toSave.getId());
}
use of org.springframework.data.redis.connection.DefaultMessage in project spring-session by spring-projects.
the class RedisOperationsSessionRepositoryITests method findByPrincipalNameExpireRemovesIndex.
@Test
public void findByPrincipalNameExpireRemovesIndex() throws Exception {
String principalName = "findByPrincipalNameExpireRemovesIndex" + UUID.randomUUID();
RedisSession toSave = this.repository.createSession();
toSave.setAttribute(INDEX_NAME, principalName);
this.repository.save(toSave);
String body = "RedisOperationsSessionRepositoryITests:sessions:expires:" + toSave.getId();
String channel = ":expired";
DefaultMessage message = new DefaultMessage(channel.getBytes("UTF-8"), body.getBytes("UTF-8"));
byte[] pattern = new byte[] {};
this.repository.onMessage(message, pattern);
Map<String, RedisSession> findByPrincipalName = this.repository.findByIndexNameAndIndexValue(INDEX_NAME, principalName);
assertThat(findByPrincipalName).hasSize(0);
assertThat(findByPrincipalName.keySet()).doesNotContain(toSave.getId());
}
use of org.springframework.data.redis.connection.DefaultMessage in project camel by apache.
the class RedisConsumerTest method consumerReceivesMessages.
@Test
public void consumerReceivesMessages() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(2);
ArgumentCaptor<MessageListener> messageListenerCaptor = ArgumentCaptor.forClass(MessageListener.class);
verify(listenerContainer).addMessageListener(messageListenerCaptor.capture(), any(Collection.class));
MessageListener messageListener = messageListenerCaptor.getValue();
messageListener.onMessage(new DefaultMessage(null, null), null);
messageListener.onMessage(new DefaultMessage(null, null), null);
mock.assertIsSatisfied();
}
use of org.springframework.data.redis.connection.DefaultMessage in project spring-session by spring-projects.
the class RedisOperationsSessionRepositoryTests method onMessageCreatedCustomSerializer.
// gh-309
@Test
public void onMessageCreatedCustomSerializer() throws Exception {
MapSession session = this.cached;
byte[] pattern = "".getBytes("UTF-8");
byte[] body = new byte[0];
String channel = "spring:session:event:created:" + session.getId();
given(this.defaultSerializer.deserialize(body)).willReturn(new HashMap<String, Object>());
DefaultMessage message = new DefaultMessage(channel.getBytes("UTF-8"), body);
this.redisRepository.setApplicationEventPublisher(this.publisher);
this.redisRepository.onMessage(message, pattern);
verify(this.publisher).publishEvent(this.event.capture());
assertThat(this.event.getValue().getSessionId()).isEqualTo(session.getId());
verify(this.defaultSerializer).deserialize(body);
}
Aggregations