use of io.lettuce.core.protocol.Command in project lettuce-core by lettuce-io.
the class CommandSegmentCommandFactory method createCommand.
@Override
public RedisCommand<Object, Object, Object> createCommand(Object[] parameters) {
MethodParametersAccessor parametersAccessor = new CodecAwareMethodParametersAccessor(new DefaultMethodParametersAccessor(commandMethod.getParameters(), parameters), typeContext);
CommandArgs<Object, Object> args = new CommandArgs<>(redisCodec);
CommandOutput<Object, Object, ?> output = outputFactory.create(redisCodec);
Command<Object, Object, ?> command = new Command<>(this.segments.getCommandType(), output, args);
parameterBinder.bind(args, redisCodec, segments, parametersAccessor);
return (Command) command;
}
use of io.lettuce.core.protocol.Command 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.protocol.Command 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();
}
use of io.lettuce.core.protocol.Command in project lettuce-core by lettuce-io.
the class BraveTracingUnitTests method shouldCustomizeSpan.
@Test
void shouldCustomizeSpan() {
BraveTracing tracing = BraveTracing.builder().tracing(clientTracing).spanCustomizer((command, span) -> span.tag("cmd", command.getType().name())).build();
BraveTracing.BraveSpan span = (BraveTracing.BraveSpan) tracing.getTracerProvider().getTracer().nextSpan();
span.start(new AsyncCommand<>(new Command<>(CommandType.AUTH, null)));
MutableSpan braveSpan = ReflectionTestUtils.getField(span.getSpan(), "state");
Object[] tags = ReflectionTestUtils.getField(braveSpan, "tags");
assertThat(tags).contains("cmd", "AUTH");
}
Aggregations