use of io.lettuce.core.api.push.PushMessage in project lettuce-core by lettuce-io.
the class ServerCommandIntegrationTests method clientTrackingPrefixes.
@Test
@EnabledOnCommand("ACL")
void clientTrackingPrefixes() {
redis.clientTracking(TrackingArgs.Builder.enabled(false));
redis.clientTracking(TrackingArgs.Builder.enabled().bcast().prefixes("foo", "bar"));
List<PushMessage> pushMessages = new CopyOnWriteArrayList<>();
redis.getStatefulConnection().addListener(pushMessages::add);
redis.get(key);
redis.set(key, value);
assertThat(pushMessages.isEmpty());
redis.set("foo", value);
Wait.untilEquals(1, pushMessages::size).waitOrTimeout();
assertThat(pushMessages).hasSize(1);
PushMessage message = pushMessages.get(0);
assertThat(message.getType()).isEqualTo("invalidate");
assertThat((List) message.getContent(StringCodec.UTF8::decodeKey).get(1)).containsOnly("foo");
redis.clientTracking(TrackingArgs.Builder.enabled().bcast().prefixes(key));
redis.set("foo", value);
Wait.untilEquals(2, pushMessages::size).waitOrTimeout();
assertThat(pushMessages).hasSize(2);
}
use of io.lettuce.core.api.push.PushMessage in project lettuce-core by lettuce-io.
the class ServerCommandIntegrationTests method clientTracking.
@Test
@EnabledOnCommand("ACL")
void clientTracking() {
redis.clientTracking(TrackingArgs.Builder.enabled(false));
redis.clientTracking(TrackingArgs.Builder.enabled());
List<PushMessage> pushMessages = new CopyOnWriteArrayList<>();
redis.getStatefulConnection().addListener(pushMessages::add);
redis.set(key, value);
assertThat(pushMessages.isEmpty());
redis.get(key);
redis.set(key, "value2");
Wait.untilEquals(1, pushMessages::size).waitOrTimeout();
assertThat(pushMessages).hasSize(1);
PushMessage message = pushMessages.get(0);
assertThat(message.getType()).isEqualTo("invalidate");
assertThat((List) message.getContent(StringCodec.UTF8::decodeKey).get(1)).containsOnly(key);
}
use of io.lettuce.core.api.push.PushMessage in project lettuce-core by lettuce-io.
the class CommandHandlerUnitTests method shouldNotifyPushListener.
@Test
void shouldNotifyPushListener() throws Exception {
ChannelPromise channelPromise = new DefaultChannelPromise(channel, ImmediateEventExecutor.INSTANCE);
channelPromise.setSuccess();
sut.channelRegistered(context);
sut.channelActive(context);
sut.channelRead(context, Unpooled.wrappedBuffer(">2\r\n+caching\r\n+foo\r\n".getBytes()));
ArgumentCaptor<PushMessage> messageCaptor = ArgumentCaptor.forClass(PushMessage.class);
verify(listener).onPushMessage(messageCaptor.capture());
PushMessage message = messageCaptor.getValue();
assertThat(message.getType()).isEqualTo("caching");
assertThat(message.getContent()).containsExactly(ByteBuffer.wrap("caching".getBytes()), ByteBuffer.wrap("foo".getBytes()));
}
use of io.lettuce.core.api.push.PushMessage in project lettuce-core by lettuce-io.
the class PubSubCommandTest method messageAsPushMessage.
@Test
@EnabledOnCommand("ACL")
void messageAsPushMessage() throws Exception {
pubsub.subscribe(channel);
assertThat(counts.take()).isNotNull();
AtomicReference<PushMessage> messageRef = new AtomicReference<>();
pubsub.getStatefulConnection().addListener(messageRef::set);
redis.publish(channel, message);
assertThat(messages.take()).isEqualTo(message);
Wait.untilTrue(() -> messageRef.get() != null).waitOrTimeout();
PushMessage pushMessage = messageRef.get();
assertThat(pushMessage).isNotNull();
assertThat(pushMessage.getType()).isEqualTo("message");
assertThat(pushMessage.getContent()).contains(ByteBuffer.wrap("message".getBytes()), ByteBuffer.wrap(message.getBytes()));
}
Aggregations