use of io.lettuce.core.output.ValueListOutput in project lettuce-core by lettuce-io.
the class ReactiveBackpressurePropagationUnitTests method writeCommandAndCancelInTheMiddle.
@Test
void writeCommandAndCancelInTheMiddle() throws Exception {
Command<String, String, List<String>> lrange = new Command<>(CommandType.LRANGE, new ValueListOutput<>(StringCodec.UTF8));
RedisPublisher<String, String, String> publisher = new RedisPublisher<>(lrange, statefulConnection, true, ImmediateEventExecutor.INSTANCE);
CountDownLatch pressureArrived = new CountDownLatch(1);
CountDownLatch buildPressure = new CountDownLatch(1);
CountDownLatch waitForPressureReduced = new CountDownLatch(2);
Disposable cancellation = Flux.from(publisher).limitRate(2).publishOn(Schedulers.single()).doOnNext(s -> {
try {
pressureArrived.countDown();
buildPressure.await();
} catch (InterruptedException e) {
}
waitForPressureReduced.countDown();
}).subscribe();
assertThat(embeddedChannel.config().isAutoRead()).isTrue();
// produce some back pressure
embeddedChannel.writeInbound(Unpooled.wrappedBuffer(RESP.arrayHeader(4)));
embeddedChannel.writeInbound(Unpooled.wrappedBuffer(RESP.bulkString("one")));
pressureArrived.await();
assertThat(embeddedChannel.config().isAutoRead()).isTrue();
embeddedChannel.writeInbound(Unpooled.wrappedBuffer(RESP.bulkString("two")));
embeddedChannel.writeInbound(Unpooled.wrappedBuffer(RESP.bulkString("three")));
assertThat(embeddedChannel.config().isAutoRead()).isFalse();
cancellation.dispose();
assertThat(embeddedChannel.config().isAutoRead()).isTrue();
// allow processing
buildPressure.countDown();
// emit the last item
embeddedChannel.writeInbound(Unpooled.wrappedBuffer(RESP.bulkString("four")));
// done
assertThat(embeddedChannel.config().isAutoRead()).isTrue();
}
use of io.lettuce.core.output.ValueListOutput in project lettuce-core by lettuce-io.
the class ReactiveBackpressurePropagationUnitTests method writeCommand.
@Test
void writeCommand() throws Exception {
Command<String, String, List<String>> lrange = new Command<>(CommandType.LRANGE, new ValueListOutput<>(StringCodec.UTF8));
RedisPublisher<String, String, String> publisher = new RedisPublisher<>((Command) lrange, statefulConnection, true, ImmediateEventExecutor.INSTANCE);
CountDownLatch pressureArrived = new CountDownLatch(1);
CountDownLatch buildPressure = new CountDownLatch(1);
CountDownLatch waitForPressureReduced = new CountDownLatch(2);
CountDownLatch waitForWorkCompleted = new CountDownLatch(4);
Flux.from(publisher).limitRate(2).publishOn(Schedulers.single()).doOnNext(s -> {
try {
pressureArrived.countDown();
buildPressure.await();
} catch (InterruptedException e) {
}
waitForPressureReduced.countDown();
waitForWorkCompleted.countDown();
}).subscribe();
assertThat(embeddedChannel.config().isAutoRead()).isTrue();
// produce some back pressure
embeddedChannel.writeInbound(Unpooled.wrappedBuffer(RESP.arrayHeader(4)));
embeddedChannel.writeInbound(Unpooled.wrappedBuffer(RESP.bulkString("one")));
pressureArrived.await();
assertThat(embeddedChannel.config().isAutoRead()).isTrue();
embeddedChannel.writeInbound(Unpooled.wrappedBuffer(RESP.bulkString("two")));
embeddedChannel.writeInbound(Unpooled.wrappedBuffer(RESP.bulkString("three")));
assertThat(embeddedChannel.config().isAutoRead()).isFalse();
// allow processing
buildPressure.countDown();
// wait until processing caught up
waitForPressureReduced.await();
assertThat(embeddedChannel.config().isAutoRead()).isTrue();
// emit the last item
embeddedChannel.writeInbound(Unpooled.wrappedBuffer(RESP.bulkString("four")));
// done
waitForWorkCompleted.await();
assertThat(embeddedChannel.config().isAutoRead()).isTrue();
}
Aggregations