Search in sources :

Example 6 with AsyncCommand

use of io.lettuce.core.protocol.AsyncCommand in project lettuce-core by lettuce-io.

the class BatchExecutableCommand method execute.

@Override
public Object execute(Object[] parameters) throws ExecutionException, InterruptedException {
    RedisCommand<Object, Object, Object> command = commandFactory.createCommand(parameters);
    CommandBatching batching = null;
    if (this.parameters.hasCommandBatchingIndex()) {
        batching = (CommandBatching) parameters[this.parameters.getCommandBatchingIndex()];
    }
    AsyncCommand<Object, Object, Object> asyncCommand = new AsyncCommand<>(command);
    if (async) {
        batcher.batch(asyncCommand, batching);
        return asyncCommand;
    }
    BatchTasks batchTasks = batcher.batch(asyncCommand, batching);
    return synchronize(batchTasks, connection);
}
Also used : CommandBatching(io.lettuce.core.dynamic.batch.CommandBatching) AsyncCommand(io.lettuce.core.protocol.AsyncCommand)

Example 7 with AsyncCommand

use of io.lettuce.core.protocol.AsyncCommand in project lettuce-core by lettuce-io.

the class PooledClusterConnectionProviderUnitTests method shouldAvoidReplicaWithReplOffsetZero.

@Test
void shouldAvoidReplicaWithReplOffsetZero() {
    for (RedisClusterNode partition : partitions) {
        partition.setReplOffset(0);
    }
    AsyncCommand<String, String, String> async = new AsyncCommand<>(new Command<>(CommandType.READONLY, null, null));
    async.complete();
    when(asyncCommandsMock.readOnly()).thenReturn(async);
    sut.setReadFrom(ReadFrom.REPLICA);
    assertThatExceptionOfType(PartitionSelectorException.class).isThrownBy(() -> sut.getConnection(Intent.READ, 1));
}
Also used : RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) AsyncCommand(io.lettuce.core.protocol.AsyncCommand) Test(org.junit.jupiter.api.Test)

Example 8 with AsyncCommand

use of io.lettuce.core.protocol.AsyncCommand in project lettuce-core by lettuce-io.

the class RedisClusterClientIntegrationTests method testClusterRedirectionLimit.

@Test
@SuppressWarnings({ "rawtypes" })
void testClusterRedirectionLimit() throws Exception {
    clusterClient.setOptions(ClusterClientOptions.builder().maxRedirects(0).build());
    RedisAdvancedClusterAsyncCommands<String, String> connection = clusterClient.connect().async();
    Partitions partitions = clusterClient.getPartitions();
    for (RedisClusterNode partition : partitions) {
        if (partition.getSlots().contains(15495)) {
            partition.setSlots(Collections.emptyList());
        } else {
            partition.setSlots(IntStream.range(0, SlotHash.SLOT_COUNT).boxed().collect(Collectors.toList()));
        }
    }
    partitions.updateCache();
    // gets redirection to node 3
    RedisFuture<String> setA = connection.set(ClusterTestSettings.KEY_A, value);
    assertThat(setA instanceof AsyncCommand).isTrue();
    setA.await(10, TimeUnit.SECONDS);
    assertThat(setA.getError()).isEqualTo("MOVED 15495 127.0.0.1:7380");
    connection.getStatefulConnection().close();
}
Also used : Partitions(io.lettuce.core.cluster.models.partitions.Partitions) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) AsyncCommand(io.lettuce.core.protocol.AsyncCommand) Test(org.junit.jupiter.api.Test)

Example 9 with AsyncCommand

use of io.lettuce.core.protocol.AsyncCommand 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");
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Tracing(brave.Tracing) Tracer(brave.Tracer) CommandType(io.lettuce.core.protocol.CommandType) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Span(zipkin2.Span) CurrentTraceContext(brave.propagation.CurrentTraceContext) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Command(io.lettuce.core.protocol.Command) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) List(java.util.List) AsyncCommand(io.lettuce.core.protocol.AsyncCommand) BeforeAll(org.junit.jupiter.api.BeforeAll) MutableSpan(brave.handler.MutableSpan) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) Tag(brave.Tag) Queue(java.util.Queue) TestSupport(io.lettuce.core.TestSupport) ReflectionTestUtils(io.lettuce.test.ReflectionTestUtils) MutableSpan(brave.handler.MutableSpan) Command(io.lettuce.core.protocol.Command) AsyncCommand(io.lettuce.core.protocol.AsyncCommand) Test(org.junit.jupiter.api.Test)

Example 10 with AsyncCommand

use of io.lettuce.core.protocol.AsyncCommand in project lettuce-core by lettuce-io.

the class AtLeastOnceTest method commandFailsDuringDecode.

@Test
void commandFailsDuringDecode() {
    RedisCommands<String, String> connection = client.connect().sync();
    RedisChannelWriter channelWriter = ConnectionTestUtil.getChannelWriter(connection.getStatefulConnection());
    RedisCommands<String, String> verificationConnection = client.connect().sync();
    connection.set(key, "1");
    AsyncCommand<String, String, String> command = new AsyncCommand(new Command<>(CommandType.INCR, new StatusOutput<>(StringCodec.UTF8), new CommandArgs<>(StringCodec.UTF8).addKey(key)));
    channelWriter.write(command);
    assertThat(command.await(2, TimeUnit.SECONDS)).isTrue();
    assertThat(command.isCancelled()).isFalse();
    assertThat(command.isDone()).isTrue();
    assertThat(getException(command)).isInstanceOf(UnsupportedOperationException.class);
    assertThat(verificationConnection.get(key)).isEqualTo("2");
    assertThat(connection.get(key)).isEqualTo("2");
    connection.getStatefulConnection().close();
    verificationConnection.getStatefulConnection().close();
}
Also used : AsyncCommand(io.lettuce.core.protocol.AsyncCommand) RedisChannelWriter(io.lettuce.core.RedisChannelWriter) StatusOutput(io.lettuce.core.output.StatusOutput) AbstractRedisClientTest(io.lettuce.core.AbstractRedisClientTest) Test(org.junit.jupiter.api.Test)

Aggregations

AsyncCommand (io.lettuce.core.protocol.AsyncCommand)12 Test (org.junit.jupiter.api.Test)10 AbstractRedisClientTest (io.lettuce.core.AbstractRedisClientTest)5 RedisChannelWriter (io.lettuce.core.RedisChannelWriter)5 IntegerOutput (io.lettuce.core.output.IntegerOutput)3 ByteBuf (io.netty.buffer.ByteBuf)3 RedisClusterNode (io.lettuce.core.cluster.models.partitions.RedisClusterNode)2 StatusOutput (io.lettuce.core.output.StatusOutput)2 Command (io.lettuce.core.protocol.Command)2 Tag (brave.Tag)1 Tracer (brave.Tracer)1 Tracing (brave.Tracing)1 MutableSpan (brave.handler.MutableSpan)1 CurrentTraceContext (brave.propagation.CurrentTraceContext)1 RedisConnectionException (io.lettuce.core.RedisConnectionException)1 RedisURI (io.lettuce.core.RedisURI)1 TestSupport (io.lettuce.core.TestSupport)1 TransactionResult (io.lettuce.core.TransactionResult)1 Partitions (io.lettuce.core.cluster.models.partitions.Partitions)1 CommandBatching (io.lettuce.core.dynamic.batch.CommandBatching)1