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);
}
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));
}
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();
}
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");
}
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();
}
Aggregations