Search in sources :

Example 6 with ClientResources

use of io.lettuce.core.resource.ClientResources in project lettuce-core by lettuce-io.

the class RedisClientIntegrationTests method managedClientResources.

@Test
void managedClientResources() throws Exception {
    // given
    RedisClient redisClient1 = RedisClient.create(RedisURI.create(TestSettings.host(), TestSettings.port()));
    ClientResources clientResources = redisClient1.getResources();
    Map<Class<? extends EventExecutorGroup>, EventExecutorGroup> eventLoopGroups = getExecutors(clientResources);
    connectAndClose(redisClient1);
    // when
    EventExecutorGroup executor = eventLoopGroups.values().iterator().next();
    redisClient1.shutdown(0, 0, TimeUnit.MILLISECONDS);
    // then
    assertThat(eventLoopGroups).isEmpty();
    assertThat(executor.isShuttingDown()).isTrue();
    assertThat(clientResources.eventExecutorGroup().isShuttingDown()).isTrue();
}
Also used : EventExecutorGroup(io.netty.util.concurrent.EventExecutorGroup) ClientResources(io.lettuce.core.resource.ClientResources) TestClientResources(io.lettuce.test.resource.TestClientResources) DefaultClientResources(io.lettuce.core.resource.DefaultClientResources) Test(org.junit.jupiter.api.Test)

Example 7 with ClientResources

use of io.lettuce.core.resource.ClientResources in project spring-boot by spring-projects.

the class LettuceMetricsAutoConfigurationTests method whenThereIsAMeterRegistryThenCommandLatencyRecorderIsAdded.

@Test
void whenThereIsAMeterRegistryThenCommandLatencyRecorderIsAdded() {
    this.contextRunner.with(MetricsRun.simple()).withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class)).run((context) -> {
        ClientResources clientResources = context.getBean(LettuceConnectionFactory.class).getClientResources();
        assertThat(clientResources.commandLatencyRecorder()).isInstanceOf(MicrometerCommandLatencyRecorder.class);
    });
}
Also used : ClientResources(io.lettuce.core.resource.ClientResources) LettuceConnectionFactory(org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory) Test(org.junit.jupiter.api.Test)

Example 8 with ClientResources

use of io.lettuce.core.resource.ClientResources in project spring-boot by spring-projects.

the class LettuceMetricsAutoConfigurationTests method whenThereIsNoMeterRegistryThenClientResourcesCustomizationBacksOff.

@Test
void whenThereIsNoMeterRegistryThenClientResourcesCustomizationBacksOff() {
    this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class)).run((context) -> {
        ClientResources clientResources = context.getBean(LettuceConnectionFactory.class).getClientResources();
        assertThat(clientResources.commandLatencyRecorder()).isNotInstanceOf(MicrometerCommandLatencyRecorder.class);
    });
}
Also used : ClientResources(io.lettuce.core.resource.ClientResources) LettuceConnectionFactory(org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory) Test(org.junit.jupiter.api.Test)

Example 9 with ClientResources

use of io.lettuce.core.resource.ClientResources in project lettuce-core by lettuce-io.

the class LettuceCdiExtension method processBean.

/**
 * Implementation of a an observer which checks for RedisURI beans and stores them in {@link #redisUris} for later
 * association with corresponding repository beans.
 *
 * @param <T> The type.
 * @param processBean The annotated type as defined by CDI.
 */
@SuppressWarnings("unchecked")
<T> void processBean(@Observes ProcessBean<T> processBean) {
    Bean<T> bean = processBean.getBean();
    for (Type type : bean.getTypes()) {
        if (!(type instanceof Class<?>)) {
            continue;
        }
        // Check if the bean is an RedisURI.
        if (RedisURI.class.isAssignableFrom((Class<?>) type)) {
            Set<Annotation> qualifiers = LettuceSets.newHashSet(bean.getQualifiers());
            if (bean.isAlternative() || !redisUris.containsKey(qualifiers)) {
                LOGGER.debug(String.format("Discovered '%s' with qualifiers %s.", RedisURI.class.getName(), qualifiers));
                redisUris.put(qualifiers, (Bean<RedisURI>) bean);
            }
        }
        if (ClientResources.class.isAssignableFrom((Class<?>) type)) {
            Set<Annotation> qualifiers = LettuceSets.newHashSet(bean.getQualifiers());
            if (bean.isAlternative() || !clientResources.containsKey(qualifiers)) {
                LOGGER.debug(String.format("Discovered '%s' with qualifiers %s.", ClientResources.class.getName(), qualifiers));
                clientResources.put(qualifiers, (Bean<ClientResources>) bean);
            }
        }
    }
}
Also used : Type(java.lang.reflect.Type) RedisURI(io.lettuce.core.RedisURI) ClientResources(io.lettuce.core.resource.ClientResources) Annotation(java.lang.annotation.Annotation)

Example 10 with ClientResources

use of io.lettuce.core.resource.ClientResources in project lettuce-core by lettuce-io.

the class RedisClientCdiBean method create.

@Override
public RedisClient create(CreationalContext<RedisClient> 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 RedisClient.create(clientResources, redisURI);
    }
    return RedisClient.create(redisURI);
}
Also used : RedisURI(io.lettuce.core.RedisURI) ClientResources(io.lettuce.core.resource.ClientResources)

Aggregations

ClientResources (io.lettuce.core.resource.ClientResources)14 Test (org.junit.jupiter.api.Test)7 RedisURI (io.lettuce.core.RedisURI)6 DefaultClientResources (io.lettuce.core.resource.DefaultClientResources)4 RedisClient (io.lettuce.core.RedisClient)2 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)2 NettyCustomizer (io.lettuce.core.resource.NettyCustomizer)2 Channel (io.netty.channel.Channel)2 EventExecutorGroup (io.netty.util.concurrent.EventExecutorGroup)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 LettuceConnectionFactory (org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory)2 ScopedSpan (brave.ScopedSpan)1 ClientOptions (io.lettuce.core.ClientOptions)1 ConnectionFuture (io.lettuce.core.ConnectionFuture)1 RedisConnectionException (io.lettuce.core.RedisConnectionException)1 RedisException (io.lettuce.core.RedisException)1 SocketOptions (io.lettuce.core.SocketOptions)1