Skip to content

DATAREDIS1142 - getReactiveConnection fallback to getReactiveClusterC… #529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
* @author Balázs Németh
* @author Ruben Cervilla
* @author Luis De Bello
* @author Andrea Como
*/
public class LettuceConnectionFactory
implements InitializingBean, DisposableBean, RedisConnectionFactory, ReactiveRedisConnectionFactory {
Expand Down Expand Up @@ -432,6 +433,10 @@ protected LettuceClusterConnection doCreateLettuceClusterConnection(
@Override
public LettuceReactiveRedisConnection getReactiveConnection() {

if (isClusterAware()) {
return getReactiveClusterConnection();
}

return getShareNativeConnection()
? new LettuceReactiveRedisConnection(getSharedReactiveConnection(), reactiveConnectionProvider)
: new LettuceReactiveRedisConnection(reactiveConnectionProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
* @author Balázs Németh
* @author Ruben Cervilla
* @author Luis De Bello
* @author Andrea Como
*/
public class LettuceConnectionFactoryUnitTests {

Expand Down Expand Up @@ -942,6 +943,25 @@ public void maxRedirectsShouldBeSetOnClusterClientOptions() {
assertThat(options.getTimeoutOptions().isApplyConnectionTimeout()).isFalse();
}

@Test // DATAREDIS-1142
public void shouldFallbackToReactiveRedisClusterConnectionWhenGetReactiveConnectionWithClusterConfig() {
LettuceConnectionProvider connectionProviderMock = mock(LettuceConnectionProvider.class);
StatefulConnection<?, ?> statefulConnection = mock(StatefulConnection.class);
when(connectionProviderMock.getConnection(any())).thenReturn(statefulConnection);
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(clusterConfig) {
@Override
protected LettuceConnectionProvider doCreateConnectionProvider(AbstractRedisClient client,
RedisCodec<?, ?> codec) {
return connectionProviderMock;
}
};
connectionFactory.afterPropertiesSet();

LettuceReactiveRedisConnection reactiveConnection = connectionFactory.getReactiveConnection();

assertThat(reactiveConnection).isInstanceOf(LettuceReactiveRedisClusterConnection.class);
}

@Data
@AllArgsConstructor
static class CustomRedisConfiguration implements RedisConfiguration, WithHostAndPort {
Expand Down