use of io.lettuce.core.resource.ClientResources in project lettuce-core by lettuce-io.
the class RedisClusterClientCdiBean method create.
@Override
public RedisClusterClient create(CreationalContext<RedisClusterClient> creationalContext) {
CreationalContext<RedisURI> uriCreationalContext = beanManager.createCreationalContext(redisURIBean);
RedisURI redisURI = (RedisURI) beanManager.getReference(redisURIBean, RedisURI.class, uriCreationalContext);
if (clientResourcesBean != null) {
ClientResources clientResources = (ClientResources) beanManager.getReference(clientResourcesBean, ClientResources.class, uriCreationalContext);
return RedisClusterClient.create(clientResources, redisURI);
}
return RedisClusterClient.create(redisURI);
}
use of io.lettuce.core.resource.ClientResources in project lettuce-core by lettuce-io.
the class ConnectionFailureIntegrationTests method pingOnConnectFailureShouldCloseConnection.
@Test
void pingOnConnectFailureShouldCloseConnection() throws Exception {
AtomicReference<Channel> ref = new AtomicReference<>();
ClientResources clientResources = ClientResources.builder().nettyCustomizer(new NettyCustomizer() {
@Override
public void afterChannelInitialized(Channel channel) {
ref.set(channel);
}
}).build();
// Cluster node with auth
RedisURI redisUri = RedisURI.create(TestSettings.host(), 7385);
RedisClient client = RedisClient.create(clientResources);
client.setOptions(ClientOptions.builder().pingBeforeActivateConnection(true).build());
try {
client.connect(redisUri);
fail("Missing Exception");
} catch (Exception e) {
Wait.untilEquals(false, ref.get()::isRegistered).waitOrTimeout();
assertThat(ref.get().isOpen()).isFalse();
Wait.untilEquals(false, () -> ref.get().isRegistered()).waitOrTimeout();
} finally {
FastShutdown.shutdown(client);
FastShutdown.shutdown(clientResources);
}
}
use of io.lettuce.core.resource.ClientResources in project lettuce-core by lettuce-io.
the class ConnectionFailureIntegrationTests method emitEventOnReconnectFailure.
@Test
void emitEventOnReconnectFailure() throws Exception {
RandomResponseServer ts = getRandomResponseServer();
Queue<Event> queue = new ConcurrentLinkedQueue<>();
ClientResources clientResources = ClientResources.create();
RedisURI redisUri = RedisURI.create(defaultRedisUri.toURI());
RedisClient client = RedisClient.create(clientResources);
client.setOptions(ClientOptions.builder().build());
try {
RedisAsyncCommandsImpl<String, String> connection = (RedisAsyncCommandsImpl<String, String>) client.connect(redisUri).async();
ConnectionWatchdog connectionWatchdog = ConnectionTestUtil.getConnectionWatchdog(connection.getStatefulConnection());
redisUri.setPort(TestSettings.nonexistentPort());
client.getResources().eventBus().get().subscribe(queue::add);
connection.quit();
Wait.untilTrue(() -> !connection.getStatefulConnection().isOpen()).waitOrTimeout();
connectionWatchdog.run(0);
Delay.delay(Duration.ofMillis(500));
connection.getStatefulConnection().close();
assertThat(queue).isNotEmpty();
List<ReconnectFailedEvent> failures = queue.stream().filter(ReconnectFailedEvent.class::isInstance).map(ReconnectFailedEvent.class::cast).sorted(Comparator.comparingInt(ReconnectFailedEvent::getAttempt)).collect(Collectors.toList());
assertThat(failures.size()).isGreaterThanOrEqualTo(2);
ReconnectFailedEvent failure1 = failures.get(0);
assertThat(failure1.localAddress()).isEqualTo(LocalAddress.ANY);
assertThat(failure1.remoteAddress()).isInstanceOf(InetSocketAddress.class);
assertThat(failure1.getCause()).hasMessageContaining("Invalid first byte");
assertThat(failure1.getAttempt()).isZero();
ReconnectFailedEvent failure2 = failures.get(1);
assertThat(failure2.localAddress()).isEqualTo(LocalAddress.ANY);
assertThat(failure2.remoteAddress()).isInstanceOf(InetSocketAddress.class);
assertThat(failure2.getCause()).hasMessageContaining("Invalid first byte");
assertThat(failure2.getAttempt()).isOne();
} finally {
ts.shutdown();
FastShutdown.shutdown(client);
FastShutdown.shutdown(clientResources);
}
}
use of io.lettuce.core.resource.ClientResources in project lettuce-core by lettuce-io.
the class BraveTracingIntegrationTests method getAndSetWithTraceWithCommandArgsExcludedFromTags.
@Test
void getAndSetWithTraceWithCommandArgsExcludedFromTags() {
ClientResources clientResources = ClientResources.builder().tracing(BraveTracing.builder().tracing(clientTracing).excludeCommandArgsFromSpanTags().build()).build();
RedisClient client = RedisClient.create(clientResources, RedisURI.Builder.redis(host, port).build());
ScopedSpan trace = clientTracing.tracer().startScopedSpan("foo");
StatefulRedisConnection<String, String> connect = client.connect();
connect.sync().set("foo", "bar");
connect.sync().get("foo");
Wait.untilTrue(() -> spans.size() > 2).waitOrTimeout();
trace.finish();
List<Span> spans = new ArrayList<>(BraveTracingIntegrationTests.spans);
assertThat(spans.get(1).name()).isEqualTo("set");
assertThat(spans.get(1).tags()).doesNotContainKey("redis.args");
assertThat(spans.get(2).name()).isEqualTo("get");
assertThat(spans.get(2).tags()).doesNotContainKey("redis.args");
assertThat(spans.get(3).name()).isEqualTo("foo");
FastShutdown.shutdown(client);
FastShutdown.shutdown(clientResources);
}
Aggregations