use of io.lettuce.core.pubsub.StatefulRedisPubSubConnection in project lettuce-core by lettuce-io.
the class SentinelTopologyRefresh method initializeSentinels.
/**
* Initialize/extend connections to Sentinel servers.
*
* @return
*/
private CompletionStage<Void> initializeSentinels() {
if (closed) {
return closeFuture;
}
Duration timeout = getTimeout();
List<ConnectionFuture<StatefulRedisPubSubConnection<String, String>>> connectionFutures = potentiallyConnectSentinels();
if (connectionFutures.isEmpty()) {
return CompletableFuture.completedFuture(null);
}
if (closed) {
return closeAsync();
}
SentinelTopologyRefreshConnections collector = collectConnections(connectionFutures);
CompletionStage<SentinelTopologyRefreshConnections> completionStage = collector.getOrTimeout(timeout, redisClient.getResources().eventExecutorGroup());
return completionStage.whenComplete((aVoid, throwable) -> {
if (throwable != null) {
closeAsync();
}
}).thenApply(noop -> (Void) null);
}
use of io.lettuce.core.pubsub.StatefulRedisPubSubConnection in project lettuce-core by lettuce-io.
the class SentinelTopologyRefresh method potentiallyConnectSentinels.
/**
* Inspect whether additional Sentinel connections are required based on the which Sentinels are currently connected.
*
* @return list of futures that are notified with the connection progress.
*/
private List<ConnectionFuture<StatefulRedisPubSubConnection<String, String>>> potentiallyConnectSentinels() {
List<ConnectionFuture<StatefulRedisPubSubConnection<String, String>>> connectionFutures = new ArrayList<>();
for (RedisURI sentinel : sentinels) {
if (pubSubConnections.containsKey(sentinel)) {
continue;
}
ConnectionFuture<StatefulRedisPubSubConnection<String, String>> future = redisClient.connectPubSubAsync(CODEC, sentinel);
pubSubConnections.put(sentinel, future);
future.whenComplete((connection, throwable) -> {
if (throwable != null || closed) {
pubSubConnections.remove(sentinel);
}
if (closed) {
connection.closeAsync();
}
});
connectionFutures.add(future);
}
return connectionFutures;
}
use of io.lettuce.core.pubsub.StatefulRedisPubSubConnection in project lettuce-core by lettuce-io.
the class SentinelTopologyRefreshUnitTests method bindWithSecondSentinelFails.
@Test
void bindWithSecondSentinelFails() {
sut = new SentinelTopologyRefresh(redisClient, "mymaster", Arrays.asList(host1, host2));
when(redisClient.connectPubSubAsync(any(StringCodec.class), eq(host2))).thenReturn(ConnectionFuture.from(null, Futures.failed(new RedisConnectionException("err"))));
sut.bind(refreshRunnable);
Map<RedisURI, StatefulRedisPubSubConnection<String, String>> connections = (Map) ReflectionTestUtils.getField(sut, "pubSubConnections");
assertThat(connections).containsKey(host1).hasSize(1);
}
Aggregations