Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/main/java/io/lettuce/core/RedisHandshake.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,12 @@ private CompletionStage<?> tryHandshakeResp3(Channel channel) {
handshake.completeExceptionally(throwable);
}
} else {
onHelloResponse(settings);
handshake.complete(null);
try {
onHelloResponse(settings);
handshake.complete(null);
} catch (RuntimeException e) {
handshake.completeExceptionally(e);
}
}
});

Expand Down
41 changes: 37 additions & 4 deletions src/test/java/io/lettuce/core/RedisHandshakeUnitTests.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.lettuce.core;

import static io.lettuce.TestTags.UNIT_TEST;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static io.lettuce.TestTags.*;
import static java.util.concurrent.TimeUnit.*;
import static org.assertj.core.api.Assertions.*;

import java.nio.ByteBuffer;
Expand All @@ -13,12 +13,12 @@
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import reactor.core.publisher.Mono;
import reactor.core.publisher.Sinks;
import io.lettuce.core.output.CommandOutput;
import io.lettuce.core.protocol.AsyncCommand;
import io.lettuce.core.protocol.ProtocolVersion;
import io.netty.channel.embedded.EmbeddedChannel;
import reactor.core.publisher.Mono;
import reactor.core.publisher.Sinks;

/**
* Unit tests for {@link RedisHandshake}.
Expand Down Expand Up @@ -110,6 +110,23 @@ void handshakeFireAndForgetPostHandshake() {
assertThat(handshakeInit.toCompletableFuture().isCompletedExceptionally()).isFalse();
}

@Test
void handshakeWithInvalidResponseShouldPropagateException() {

EmbeddedChannel channel = new EmbeddedChannel(true, false);

ConnectionState state = new ConnectionState();
state.setCredentialsProvider(new StaticCredentialsProvider(null, null));
RedisHandshake handshake = new RedisHandshake(null, false, state);
CompletionStage<Void> handshakeInit = handshake.initialize(channel);

AsyncCommand<String, String, Map<String, String>> hello = channel.readOutbound();
helloStringIdResponse(hello.getOutput());
hello.complete();

assertThat(handshakeInit.toCompletableFuture().isCompletedExceptionally()).isTrue();
}

@Test
void handshakeDelayedCredentialProvider() {

Expand Down Expand Up @@ -176,6 +193,22 @@ private static void helloResponse(CommandOutput<String, String, Map<String, Stri
output.set(ByteBuffer.wrap("1.2.3".getBytes()));
}

private static void helloStringIdResponse(CommandOutput<String, String, Map<String, String>> output) {

output.multiMap(8);
output.set(ByteBuffer.wrap("id".getBytes()));
output.set(ByteBuffer.wrap("1".getBytes()));

output.set(ByteBuffer.wrap("mode".getBytes()));
output.set(ByteBuffer.wrap("master".getBytes()));

output.set(ByteBuffer.wrap("role".getBytes()));
output.set(ByteBuffer.wrap("master".getBytes()));

output.set(ByteBuffer.wrap("version".getBytes()));
output.set(ByteBuffer.wrap("1.2.3".getBytes()));
}

static class DelayedRedisCredentialsProvider implements RedisCredentialsProvider {

private final Sinks.One<RedisCredentials> credentialsSink = Sinks.one();
Expand Down
Loading