Search in sources :

Example 1 with PushMessage

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);
}
Also used : PushMessage(io.lettuce.core.api.push.PushMessage) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.jupiter.api.Test) EnabledOnCommand(io.lettuce.test.condition.EnabledOnCommand)

Example 2 with PushMessage

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);
}
Also used : PushMessage(io.lettuce.core.api.push.PushMessage) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.jupiter.api.Test) EnabledOnCommand(io.lettuce.test.condition.EnabledOnCommand)

Example 3 with PushMessage

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()));
}
Also used : DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) PushMessage(io.lettuce.core.api.push.PushMessage) ChannelPromise(io.netty.channel.ChannelPromise) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) Test(org.junit.jupiter.api.Test)

Example 4 with PushMessage

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()));
}
Also used : PushMessage(io.lettuce.core.api.push.PushMessage) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test) EnabledOnCommand(io.lettuce.test.condition.EnabledOnCommand)

Aggregations

PushMessage (io.lettuce.core.api.push.PushMessage)4 Test (org.junit.jupiter.api.Test)4 EnabledOnCommand (io.lettuce.test.condition.EnabledOnCommand)3 List (java.util.List)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ChannelPromise (io.netty.channel.ChannelPromise)1 DefaultChannelPromise (io.netty.channel.DefaultChannelPromise)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1