org.springframework.data.redis.connection.DefaultMessage Java Examples
The following examples show how to use
org.springframework.data.redis.connection.DefaultMessage.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedisIndexedSessionRepositoryITests.java From spring-session with Apache License 2.0 | 6 votes |
@Test void findBySecurityPrincipalNameExpireRemovesIndex() { RedisSession toSave = this.repository.createSession(); toSave.setAttribute(SPRING_SECURITY_CONTEXT, this.context); this.repository.save(toSave); String body = "RedisIndexedSessionRepositoryITests:sessions:expires:" + toSave.getId(); String channel = "__keyevent@0__:expired"; DefaultMessage message = new DefaultMessage(channel.getBytes(StandardCharsets.UTF_8), body.getBytes(StandardCharsets.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()); }
Example #2
Source File: RedisIndexedSessionRepositoryTests.java From spring-session with Apache License 2.0 | 6 votes |
@Test void onMessageExpiredInOtherDatabase() { JdkSerializationRedisSerializer serializer = new JdkSerializationRedisSerializer(); this.redisRepository.setApplicationEventPublisher(this.publisher); this.redisRepository.setDefaultSerializer(serializer); MapSession session = this.cached; String channel = "__keyevent@1__:expired"; String body = "spring:session:sessions:expires:" + session.getId(); DefaultMessage message = new DefaultMessage(channel.getBytes(StandardCharsets.UTF_8), body.getBytes(StandardCharsets.UTF_8)); this.redisRepository.onMessage(message, "".getBytes(StandardCharsets.UTF_8)); assertThat(this.event.getAllValues()).isEmpty(); verifyZeroInteractions(this.publisher); }
Example #3
Source File: RedisIndexedSessionRepositoryTests.java From spring-session with Apache License 2.0 | 6 votes |
@Test void onMessageDeletedInOtherDatabase() { JdkSerializationRedisSerializer serializer = new JdkSerializationRedisSerializer(); this.redisRepository.setApplicationEventPublisher(this.publisher); this.redisRepository.setDefaultSerializer(serializer); MapSession session = this.cached; String channel = "__keyevent@1__:del"; String body = "spring:session:sessions:expires:" + session.getId(); DefaultMessage message = new DefaultMessage(channel.getBytes(StandardCharsets.UTF_8), body.getBytes(StandardCharsets.UTF_8)); this.redisRepository.onMessage(message, "".getBytes(StandardCharsets.UTF_8)); assertThat(this.event.getAllValues()).isEmpty(); verifyZeroInteractions(this.publisher); }
Example #4
Source File: RedisIndexedSessionRepositoryTests.java From spring-session with Apache License 2.0 | 6 votes |
@Test void onMessageCreatedInOtherDatabase() { JdkSerializationRedisSerializer serializer = new JdkSerializationRedisSerializer(); this.redisRepository.setApplicationEventPublisher(this.publisher); this.redisRepository.setDefaultSerializer(serializer); MapSession session = this.cached; String channel = "spring:session:event:created:1:" + session.getId(); byte[] body = serializer.serialize(new HashMap()); DefaultMessage message = new DefaultMessage(channel.getBytes(StandardCharsets.UTF_8), body); this.redisRepository.onMessage(message, "".getBytes(StandardCharsets.UTF_8)); assertThat(this.event.getAllValues()).isEmpty(); verifyZeroInteractions(this.publisher); }
Example #5
Source File: RedisIndexedSessionRepositoryTests.java From spring-session with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") void onMessageExpiredSessionNotFound() { String expiredId = "expired-id"; given(this.redisOperations.boundHashOps(getKey(expiredId))).willReturn(this.boundHashOperations); given(this.boundHashOperations.entries()).willReturn(map()); String channel = "__keyevent@0__:expired"; String body = "spring:session:sessions:expires:" + expiredId; DefaultMessage message = new DefaultMessage(channel.getBytes(StandardCharsets.UTF_8), body.getBytes(StandardCharsets.UTF_8)); this.redisRepository.setApplicationEventPublisher(this.publisher); this.redisRepository.onMessage(message, "".getBytes(StandardCharsets.UTF_8)); verify(this.redisOperations).boundHashOps(eq(getKey(expiredId))); verify(this.boundHashOperations).entries(); verifyZeroInteractions(this.defaultSerializer); verifyZeroInteractions(this.publisher); verifyZeroInteractions(this.redisOperations); verifyZeroInteractions(this.boundHashOperations); }
Example #6
Source File: RedisIndexedSessionRepositoryTests.java From spring-session with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") void onMessageExpiredSessionFound() { String expiredId = "expired-id"; given(this.redisOperations.boundHashOps(getKey(expiredId))).willReturn(this.boundHashOperations); Map map = map(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, 1, RedisSessionMapper.LAST_ACCESSED_TIME_KEY, System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(5)); given(this.boundHashOperations.entries()).willReturn(map); String channel = "__keyevent@0__:expired"; String body = "spring:session:sessions:expires:" + expiredId; DefaultMessage message = new DefaultMessage(channel.getBytes(StandardCharsets.UTF_8), body.getBytes(StandardCharsets.UTF_8)); this.redisRepository.setApplicationEventPublisher(this.publisher); this.redisRepository.onMessage(message, "".getBytes(StandardCharsets.UTF_8)); verify(this.redisOperations).boundHashOps(eq(getKey(expiredId))); verify(this.boundHashOperations).entries(); verify(this.publisher).publishEvent(this.event.capture()); assertThat(this.event.getValue().getSessionId()).isEqualTo(expiredId); verifyZeroInteractions(this.defaultSerializer); verifyZeroInteractions(this.publisher); verifyZeroInteractions(this.redisOperations); verifyZeroInteractions(this.boundHashOperations); }
Example #7
Source File: RedisIndexedSessionRepositoryTests.java From spring-session with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") void onMessageDeletedSessionNotFound() { String deletedId = "deleted-id"; given(this.redisOperations.boundHashOps(getKey(deletedId))).willReturn(this.boundHashOperations); given(this.boundHashOperations.entries()).willReturn(map()); String channel = "__keyevent@0__:del"; String body = "spring:session:sessions:expires:" + deletedId; DefaultMessage message = new DefaultMessage(channel.getBytes(StandardCharsets.UTF_8), body.getBytes(StandardCharsets.UTF_8)); this.redisRepository.setApplicationEventPublisher(this.publisher); this.redisRepository.onMessage(message, "".getBytes(StandardCharsets.UTF_8)); verify(this.redisOperations).boundHashOps(eq(getKey(deletedId))); verify(this.boundHashOperations).entries(); verifyZeroInteractions(this.defaultSerializer); verifyZeroInteractions(this.publisher); verifyZeroInteractions(this.redisOperations); verifyZeroInteractions(this.boundHashOperations); }
Example #8
Source File: RedisIndexedSessionRepositoryTests.java From spring-session with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") void onMessageDeletedSessionFound() { String deletedId = "deleted-id"; given(this.redisOperations.boundHashOps(getKey(deletedId))).willReturn(this.boundHashOperations); Map map = map(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, 0, RedisSessionMapper.LAST_ACCESSED_TIME_KEY, System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(5)); given(this.boundHashOperations.entries()).willReturn(map); String channel = "__keyevent@0__:del"; String body = "spring:session:sessions:expires:" + deletedId; DefaultMessage message = new DefaultMessage(channel.getBytes(StandardCharsets.UTF_8), body.getBytes(StandardCharsets.UTF_8)); this.redisRepository.setApplicationEventPublisher(this.publisher); this.redisRepository.onMessage(message, "".getBytes(StandardCharsets.UTF_8)); verify(this.redisOperations).boundHashOps(eq(getKey(deletedId))); verify(this.boundHashOperations).entries(); verify(this.publisher).publishEvent(this.event.capture()); assertThat(this.event.getValue().getSessionId()).isEqualTo(deletedId); verifyZeroInteractions(this.defaultSerializer); verifyZeroInteractions(this.publisher); verifyZeroInteractions(this.redisOperations); verifyZeroInteractions(this.boundHashOperations); }
Example #9
Source File: RedisIndexedSessionRepositoryTests.java From spring-session with Apache License 2.0 | 6 votes |
@Test // gh-309 void onMessageCreatedCustomSerializer() { MapSession session = this.cached; byte[] pattern = "".getBytes(StandardCharsets.UTF_8); byte[] body = new byte[0]; String channel = "spring:session:event:0:created:" + session.getId(); given(this.defaultSerializer.deserialize(body)).willReturn(new HashMap<String, Object>()); DefaultMessage message = new DefaultMessage(channel.getBytes(StandardCharsets.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); }
Example #10
Source File: RedisIndexedSessionRepositoryTests.java From spring-session with Apache License 2.0 | 6 votes |
@Test void onMessageCreated() { MapSession session = this.cached; byte[] pattern = "".getBytes(StandardCharsets.UTF_8); String channel = "spring:session:event:0:created:" + session.getId(); JdkSerializationRedisSerializer defaultSerailizer = new JdkSerializationRedisSerializer(); this.redisRepository.setDefaultSerializer(defaultSerailizer); byte[] body = defaultSerailizer.serialize(new HashMap()); DefaultMessage message = new DefaultMessage(channel.getBytes(StandardCharsets.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()); }
Example #11
Source File: RedisIndexedSessionRepositoryITests.java From spring-session with Apache License 2.0 | 6 votes |
@Test void findByPrincipalNameExpireRemovesIndex() { String principalName = "findByPrincipalNameExpireRemovesIndex" + UUID.randomUUID(); RedisSession toSave = this.repository.createSession(); toSave.setAttribute(INDEX_NAME, principalName); this.repository.save(toSave); String body = "RedisIndexedSessionRepositoryITests:sessions:expires:" + toSave.getId(); String channel = "__keyevent@0__:expired"; DefaultMessage message = new DefaultMessage(channel.getBytes(StandardCharsets.UTF_8), body.getBytes(StandardCharsets.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()); }
Example #12
Source File: RedissonSubscription.java From redisson with Apache License 2.0 | 6 votes |
@Override protected void doSubscribe(byte[]... channels) { List<RFuture<?>> list = new ArrayList<RFuture<?>>(); for (byte[] channel : channels) { RFuture<PubSubConnectionEntry> f = subscribeService.subscribe(ByteArrayCodec.INSTANCE, new ChannelName(channel), new BaseRedisPubSubListener() { @Override public void onMessage(CharSequence ch, Object message) { if (!Arrays.equals(((ChannelName) ch).getName(), channel)) { return; } DefaultMessage msg = new DefaultMessage(((ChannelName) ch).getName(), (byte[])message); getListener().onMessage(msg, null); } }); list.add(f); } for (RFuture<?> future : list) { connectionManager.getCommandExecutor().syncSubscription(future); } }
Example #13
Source File: RedissonSubscription.java From redisson with Apache License 2.0 | 6 votes |
@Override protected void doSubscribe(byte[]... channels) { List<RFuture<?>> list = new ArrayList<RFuture<?>>(); for (byte[] channel : channels) { RFuture<PubSubConnectionEntry> f = subscribeService.subscribe(ByteArrayCodec.INSTANCE, new ChannelName(channel), new BaseRedisPubSubListener() { @Override public void onMessage(CharSequence ch, Object message) { if (!Arrays.equals(((ChannelName) ch).getName(), channel)) { return; } DefaultMessage msg = new DefaultMessage(((ChannelName) ch).getName(), (byte[])message); getListener().onMessage(msg, null); } }); list.add(f); } for (RFuture<?> future : list) { connectionManager.getCommandExecutor().syncSubscription(future); } }
Example #14
Source File: RedissonSubscription.java From redisson with Apache License 2.0 | 6 votes |
@Override protected void doSubscribe(byte[]... channels) { List<RFuture<?>> list = new ArrayList<RFuture<?>>(); for (byte[] channel : channels) { RFuture<PubSubConnectionEntry> f = subscribeService.subscribe(ByteArrayCodec.INSTANCE, new ChannelName(channel), new BaseRedisPubSubListener() { @Override public void onMessage(CharSequence ch, Object message) { if (!Arrays.equals(((ChannelName) ch).getName(), channel)) { return; } DefaultMessage msg = new DefaultMessage(((ChannelName) ch).getName(), (byte[])message); getListener().onMessage(msg, null); } }); list.add(f); } for (RFuture<?> future : list) { connectionManager.getCommandExecutor().syncSubscription(future); } }
Example #15
Source File: RedissonSubscription.java From redisson with Apache License 2.0 | 6 votes |
@Override protected void doSubscribe(byte[]... channels) { List<RFuture<?>> list = new ArrayList<RFuture<?>>(); for (byte[] channel : channels) { RFuture<PubSubConnectionEntry> f = subscribeService.subscribe(ByteArrayCodec.INSTANCE, new ChannelName(channel), new BaseRedisPubSubListener() { @Override public void onMessage(CharSequence ch, Object message) { if (!Arrays.equals(((ChannelName) ch).getName(), channel)) { return; } DefaultMessage msg = new DefaultMessage(((ChannelName) ch).getName(), (byte[])message); getListener().onMessage(msg, null); } }); list.add(f); } for (RFuture<?> future : list) { connectionManager.getCommandExecutor().syncSubscription(future); } }
Example #16
Source File: RedissonSubscription.java From redisson with Apache License 2.0 | 6 votes |
@Override protected void doSubscribe(byte[]... channels) { List<RFuture<?>> list = new ArrayList<RFuture<?>>(); for (byte[] channel : channels) { RFuture<PubSubConnectionEntry> f = subscribeService.subscribe(ByteArrayCodec.INSTANCE, new ChannelName(channel), new BaseRedisPubSubListener() { @Override public void onMessage(CharSequence ch, Object message) { if (!Arrays.equals(((ChannelName) ch).getName(), channel)) { return; } DefaultMessage msg = new DefaultMessage(((ChannelName) ch).getName(), (byte[])message); getListener().onMessage(msg, null); } }); list.add(f); } for (RFuture<?> future : list) { connectionManager.getCommandExecutor().syncSubscription(future); } }
Example #17
Source File: RedissonSubscription.java From redisson with Apache License 2.0 | 6 votes |
@Override protected void doSubscribe(byte[]... channels) { List<RFuture<?>> list = new ArrayList<RFuture<?>>(); for (byte[] channel : channels) { RFuture<PubSubConnectionEntry> f = subscribeService.subscribe(ByteArrayCodec.INSTANCE, new ChannelName(channel), new BaseRedisPubSubListener() { @Override public void onMessage(CharSequence ch, Object message) { if (!Arrays.equals(((ChannelName) ch).getName(), channel)) { return; } DefaultMessage msg = new DefaultMessage(((ChannelName) ch).getName(), (byte[])message); getListener().onMessage(msg, null); } }); list.add(f); } for (RFuture<?> future : list) { connectionManager.getCommandExecutor().syncSubscription(future); } }
Example #18
Source File: RedissonSubscription.java From redisson with Apache License 2.0 | 6 votes |
@Override protected void doSubscribe(byte[]... channels) { List<RFuture<?>> list = new ArrayList<RFuture<?>>(); for (byte[] channel : channels) { RFuture<PubSubConnectionEntry> f = subscribeService.subscribe(ByteArrayCodec.INSTANCE, new ChannelName(channel), new BaseRedisPubSubListener() { @Override public void onMessage(CharSequence ch, Object message) { if (!Arrays.equals(((ChannelName) ch).getName(), channel)) { return; } DefaultMessage msg = new DefaultMessage(((ChannelName) ch).getName(), (byte[])message); getListener().onMessage(msg, null); } }); list.add(f); } for (RFuture<?> future : list) { connectionManager.getCommandExecutor().syncSubscription(future); } }
Example #19
Source File: DelayedMessageSchedulerTest.java From rqueue with Apache License 2.0 | 5 votes |
@Test public void onMessageListenerTest() throws Exception { doReturn(5000L).when(rqueueSchedulerConfig).getDelayedMessageTimeInterval(); doReturn(1).when(rqueueSchedulerConfig).getDelayedMessageThreadPoolSize(); doReturn(true).when(rqueueSchedulerConfig).isAutoStart(); doReturn(true).when(rqueueSchedulerConfig).isRedisEnabled(); doReturn(redisMessageListenerContainer) .when(rqueueRedisListenerContainerFactory) .getContainer(); messageScheduler.onApplicationEvent(new RqueueBootstrapEvent("Test", true)); MessageListener messageListener = (MessageListener) FieldUtils.readField(messageScheduler, "messageSchedulerListener", true); // invalid channel messageListener.onMessage(new DefaultMessage(slowQueue.getBytes(), "312".getBytes()), null); Thread.sleep(50); assertEquals(2, messageScheduler.scheduleList.stream().filter(e -> !e).count()); // invalid body messageListener.onMessage( new DefaultMessage( slowQueueDetail.getDelayedQueueChannelName().getBytes(), "sss".getBytes()), null); Thread.sleep(50); assertEquals(2, messageScheduler.scheduleList.stream().filter(e -> !e).count()); // both are correct messageListener.onMessage( new DefaultMessage( slowQueueDetail.getDelayedQueueChannelName().getBytes(), String.valueOf(System.currentTimeMillis()).getBytes()), null); Thread.sleep(50); assertEquals(3, messageScheduler.scheduleList.stream().filter(e -> !e).count()); messageScheduler.destroy(); }