use of io.lettuce.core.RedisChannelWriter in project lettuce-core by lettuce-io.
the class AtLeastOnceTest method commandNotFailedChannelClosesWhileFlush.
@Test
void commandNotFailedChannelClosesWhileFlush() {
assumeTrue(Version.identify().get("netty-transport").artifactVersion().startsWith("4.0.2"));
StatefulRedisConnection<String, String> connection = client.connect();
RedisCommands<String, String> verificationConnection = client.connect().sync();
RedisChannelWriter channelWriter = ConnectionTestUtil.getChannelWriter(connection);
RedisCommands<String, String> sync = connection.sync();
sync.set(key, "1");
assertThat(verificationConnection.get(key)).isEqualTo("1");
final CountDownLatch block = new CountDownLatch(1);
ConnectionWatchdog connectionWatchdog = ConnectionTestUtil.getConnectionWatchdog(connection);
AsyncCommand<String, String, Object> command = getBlockOnEncodeCommand(block);
channelWriter.write(command);
connectionWatchdog.setReconnectSuspended(true);
Channel channel = ConnectionTestUtil.getChannel(connection);
channel.unsafe().disconnect(channel.newPromise());
assertThat(channel.isOpen()).isFalse();
assertThat(command.isCancelled()).isFalse();
assertThat(command.isDone()).isFalse();
block.countDown();
assertThat(command.await(2, TimeUnit.SECONDS)).isFalse();
assertThat(command.isCancelled()).isFalse();
assertThat(command.isDone()).isFalse();
assertThat(verificationConnection.get(key)).isEqualTo("1");
assertThat(ConnectionTestUtil.getStack(connection)).isEmpty();
assertThat(ConnectionTestUtil.getCommandBuffer(connection)).isNotEmpty().contains(command);
connection.close();
}
use of io.lettuce.core.RedisChannelWriter in project lettuce-core by lettuce-io.
the class AtMostOnceTest method commandNotExecutedChannelClosesWhileFlush.
@Test
void commandNotExecutedChannelClosesWhileFlush() {
assumeTrue(Version.identify().get("netty-transport").artifactVersion().startsWith("4.0.2"));
StatefulRedisConnection<String, String> connection = client.connect();
RedisCommands<String, String> sync = connection.sync();
RedisCommands<String, String> verificationConnection = client.connect().sync();
RedisChannelWriter channelWriter = ConnectionTestUtil.getChannelWriter(connection);
sync.set(key, "1");
assertThat(verificationConnection.get(key)).isEqualTo("1");
final CountDownLatch block = new CountDownLatch(1);
AsyncCommand<String, String, Object> command = new AsyncCommand<String, String, Object>(new Command<>(CommandType.INCR, new IntegerOutput(StringCodec.UTF8), new CommandArgs<>(StringCodec.UTF8).addKey(key))) {
@Override
public void encode(ByteBuf buf) {
try {
block.await();
} catch (InterruptedException e) {
}
super.encode(buf);
}
};
channelWriter.write(command);
Channel channel = ConnectionTestUtil.getChannel(connection);
channel.unsafe().disconnect(channel.newPromise());
assertThat(channel.isOpen()).isFalse();
assertThat(command.isCancelled()).isFalse();
assertThat(command.isDone()).isFalse();
block.countDown();
assertThat(command.await(2, TimeUnit.SECONDS)).isTrue();
assertThat(command.isCancelled()).isFalse();
assertThat(command.isDone()).isTrue();
assertThat(verificationConnection.get(key)).isEqualTo("1");
assertThat(getStack(connection)).isEmpty();
assertThat(getCommandBuffer(connection)).isEmpty();
connection.close();
}
use of io.lettuce.core.RedisChannelWriter in project lettuce-core by lettuce-io.
the class AtMostOnceTest method commandNotExecutedFailsOnEncode.
@Test
void commandNotExecutedFailsOnEncode() {
StatefulRedisConnection<String, String> connection = client.connect();
RedisCommands<String, String> sync = client.connect().sync();
RedisChannelWriter channelWriter = ConnectionTestUtil.getChannelWriter(connection);
sync.set(key, "1");
AsyncCommand<String, String, String> working = new AsyncCommand<>(new Command<String, String, String>(CommandType.INCR, new IntegerOutput(StringCodec.UTF8), new CommandArgs<>(StringCodec.UTF8).addKey(key)));
channelWriter.write(working);
assertThat(working.await(2, TimeUnit.SECONDS)).isTrue();
assertThat(sync.get(key)).isEqualTo("2");
AsyncCommand<String, String, Object> command = new AsyncCommand<String, String, Object>(new Command<String, String, Object>(CommandType.INCR, new IntegerOutput(StringCodec.UTF8), new CommandArgs<>(StringCodec.UTF8).addKey(key))) {
@Override
public void encode(ByteBuf buf) {
throw new IllegalStateException("I want to break free");
}
};
channelWriter.write(command);
assertThat(command.await(2, TimeUnit.SECONDS)).isTrue();
assertThat(command.isCancelled()).isFalse();
assertThat(getException(command)).isInstanceOf(EncoderException.class);
Wait.untilTrue(() -> !ConnectionTestUtil.getStack(connection).isEmpty()).waitOrTimeout();
assertThat(ConnectionTestUtil.getStack(connection)).isNotEmpty();
ConnectionTestUtil.getStack(connection).clear();
assertThat(sync.get(key)).isEqualTo("2");
assertThat(ConnectionTestUtil.getStack(connection)).isEmpty();
assertThat(ConnectionTestUtil.getCommandBuffer(connection)).isEmpty();
connection.close();
}
Aggregations