use of io.lettuce.core.output.StatusOutput in project lettuce-core by lettuce-io.
the class ClientOptionsIntegrationTests method authenticatedPingBeforeConnectWithQueuedCommandsAndReconnect.
@Test
void authenticatedPingBeforeConnectWithQueuedCommandsAndReconnect() {
WithPassword.run(client, () -> {
RedisURI redisURI = RedisURI.Builder.redis(host, port).withPassword(passwd).withDatabase(5).build();
StatefulRedisConnection<String, String> controlConnection = client.connect(redisURI);
StatefulRedisConnection<String, String> redisConnection = client.connect(redisURI);
redisConnection.async().set("key1", "value1");
redisConnection.async().set("key2", "value2");
RedisFuture<String> sleep = (RedisFuture<String>) controlConnection.dispatch(new AsyncCommand<>(new Command<>(CommandType.DEBUG, new StatusOutput<>(StringCodec.UTF8), new CommandArgs<>(StringCodec.UTF8).add("SLEEP").add(2))));
sleep.await(100, TimeUnit.MILLISECONDS);
Channel channel = getChannel(redisConnection);
ConnectionWatchdog connectionWatchdog = getConnectionWatchdog(redisConnection);
connectionWatchdog.setReconnectSuspended(true);
TestFutures.awaitOrTimeout(channel.close());
TestFutures.awaitOrTimeout(sleep);
redisConnection.async().get(key).cancel(true);
RedisFuture<String> getFuture1 = redisConnection.async().get("key1");
RedisFuture<String> getFuture2 = redisConnection.async().get("key2");
getFuture1.await(100, TimeUnit.MILLISECONDS);
connectionWatchdog.setReconnectSuspended(false);
connectionWatchdog.scheduleReconnect();
assertThat(TestFutures.getOrTimeout(getFuture1)).isEqualTo("value1");
assertThat(TestFutures.getOrTimeout(getFuture2)).isEqualTo("value2");
controlConnection.close();
redisConnection.close();
});
}
use of io.lettuce.core.output.StatusOutput in project lettuce-core by lettuce-io.
the class ClientOptionsIntegrationTests method requestQueueSizeOvercommittedReconnect.
@Test
void requestQueueSizeOvercommittedReconnect() {
client.setOptions(ClientOptions.builder().requestQueueSize(10).build());
StatefulRedisConnection<String, String> connection = client.connect();
ConnectionWatchdog watchdog = getConnectionWatchdog(connection);
watchdog.setListenOnChannelInactive(false);
Queue<Object> buffer = getStack(connection);
List<RedisFuture<String>> pings = new ArrayList<>();
for (int i = 0; i < 11; i++) {
AsyncCommand<String, String, String> command = new AsyncCommand<>(new Command<>(CommandType.PING, new StatusOutput<>(StringCodec.UTF8)));
pings.add(command);
buffer.add(command);
}
getChannel(connection).disconnect();
Wait.untilTrue(() -> !connection.isOpen()).waitOrTimeout();
watchdog.setListenOnChannelInactive(true);
watchdog.scheduleReconnect();
for (int i = 0; i < 10; i++) {
assertThat(TestFutures.getOrTimeout(pings.get(i))).isEqualTo("PONG");
}
assertThatThrownBy(() -> TestFutures.awaitOrTimeout(pings.get(10))).hasCauseInstanceOf(IllegalStateException.class).hasMessage("java.lang.IllegalStateException: Queue full");
connection.close();
}
use of io.lettuce.core.output.StatusOutput in project lettuce-core by lettuce-io.
the class ClientOptionsIntegrationTests method pingBeforeConnectWithQueuedCommandsAndReconnect.
@Test
void pingBeforeConnectWithQueuedCommandsAndReconnect() throws Exception {
StatefulRedisConnection<String, String> controlConnection = client.connect();
StatefulRedisConnection<String, String> redisConnection = client.connect(RedisURI.create("redis://localhost:6479/5"));
redisConnection.async().set("key1", "value1");
redisConnection.async().set("key2", "value2");
RedisFuture<String> sleep = (RedisFuture<String>) controlConnection.dispatch(new AsyncCommand<>(new Command<>(CommandType.DEBUG, new StatusOutput<>(StringCodec.UTF8), new CommandArgs<>(StringCodec.UTF8).add("SLEEP").add(2))));
sleep.await(100, TimeUnit.MILLISECONDS);
Channel channel = getChannel(redisConnection);
ConnectionWatchdog connectionWatchdog = getConnectionWatchdog(redisConnection);
connectionWatchdog.setReconnectSuspended(true);
TestFutures.awaitOrTimeout(channel.close());
TestFutures.awaitOrTimeout(sleep);
redisConnection.async().get(key).cancel(true);
RedisFuture<String> getFuture1 = redisConnection.async().get("key1");
RedisFuture<String> getFuture2 = redisConnection.async().get("key2");
getFuture1.await(100, TimeUnit.MILLISECONDS);
connectionWatchdog.setReconnectSuspended(false);
connectionWatchdog.scheduleReconnect();
assertThat(TestFutures.getOrTimeout(getFuture1)).isEqualTo("value1");
assertThat(TestFutures.getOrTimeout(getFuture2)).isEqualTo("value2");
controlConnection.close();
redisConnection.close();
}
use of io.lettuce.core.output.StatusOutput in project lettuce-core by lettuce-io.
the class CommandHandlerUnitTests method shouldDiscardReadBytes.
@Test
void shouldDiscardReadBytes() throws Exception {
ChannelPromise channelPromise = new DefaultChannelPromise(channel, ImmediateEventExecutor.INSTANCE);
channelPromise.setSuccess();
sut.channelRegistered(context);
sut.channelActive(context);
sut.getStack().add(new Command<>(CommandType.PING, new StatusOutput<>(StringCodec.UTF8)));
sut.getStack().add(new Command<>(CommandType.PING, new StatusOutput<>(StringCodec.UTF8)));
sut.getStack().add(new Command<>(CommandType.PING, new StatusOutput<>(StringCodec.UTF8)));
// set the command handler buffer capacity to 30, make it easy to test
ByteBuf internalBuffer = context.alloc().buffer(30);
sut.setBuffer(internalBuffer);
// mock a multi reply, which will reach the buffer usage ratio
ByteBuf msg = context.alloc().buffer(100);
msg.writeBytes("*1\r\n+OK\r\n".getBytes());
msg.writeBytes("*1\r\n+OK\r\n".getBytes());
msg.writeBytes("*1\r\n+OK\r\n".getBytes());
sut.channelRead(context, msg);
assertThat(internalBuffer.readerIndex()).isEqualTo(0);
assertThat(internalBuffer.writerIndex()).isEqualTo(0);
sut.channelUnregistered(context);
}
use of io.lettuce.core.output.StatusOutput 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