Search in sources :

Example 1 with EventBus

use of io.lettuce.core.event.EventBus in project lettuce-core by lettuce-io.

the class DefaultClientResourcesUnitTests method testEventBus.

@Test
void testEventBus() {
    DefaultClientResources sut = DefaultClientResources.create();
    EventBus eventBus = sut.eventBus();
    Event event = mock(Event.class);
    StepVerifier.create(eventBus.get()).then(() -> eventBus.publish(event)).expectNext(event).thenCancel().verify();
    assertThat(TestFutures.getOrTimeout(sut.shutdown(0, 0, TimeUnit.MILLISECONDS))).isTrue();
}
Also used : Event(io.lettuce.core.event.Event) EventBus(io.lettuce.core.event.EventBus) Test(org.junit.jupiter.api.Test)

Example 2 with EventBus

use of io.lettuce.core.event.EventBus in project lettuce-core by lettuce-io.

the class ClientMetricsIntegrationTests method testMetricsEvent.

@Test
@Inject
void testMetricsEvent(RedisClient client, StatefulRedisConnection<String, String> connection) {
    Collection<CommandLatencyEvent> events = new LinkedBlockingQueue<>();
    EventBus eventBus = client.getResources().eventBus();
    MetricEventPublisher publisher = (MetricEventPublisher) ReflectionTestUtils.getField(client.getResources(), "metricEventPublisher");
    publisher.emitMetricsEvent();
    Disposable disposable = eventBus.get().filter(redisEvent -> redisEvent instanceof CommandLatencyEvent).cast(CommandLatencyEvent.class).doOnNext(events::add).subscribe();
    generateTestData(connection.sync());
    publisher.emitMetricsEvent();
    Wait.untilTrue(() -> !events.isEmpty()).waitOrTimeout();
    assertThat(events).isNotEmpty();
    disposable.dispose();
}
Also used : Disposable(reactor.core.Disposable) Disposable(reactor.core.Disposable) CommandLatencyEvent(io.lettuce.core.event.metrics.CommandLatencyEvent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collection(java.util.Collection) LettuceExtension(io.lettuce.test.LettuceExtension) RedisCommands(io.lettuce.core.api.sync.RedisCommands) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Inject(javax.inject.Inject) Test(org.junit.jupiter.api.Test) EventBus(io.lettuce.core.event.EventBus) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection) MetricEventPublisher(io.lettuce.core.event.metrics.MetricEventPublisher) Wait(io.lettuce.test.Wait) ReflectionTestUtils(io.lettuce.test.ReflectionTestUtils) EventBus(io.lettuce.core.event.EventBus) MetricEventPublisher(io.lettuce.core.event.metrics.MetricEventPublisher) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) CommandLatencyEvent(io.lettuce.core.event.metrics.CommandLatencyEvent) Inject(javax.inject.Inject) Test(org.junit.jupiter.api.Test)

Example 3 with EventBus

use of io.lettuce.core.event.EventBus in project lettuce-core by lettuce-io.

the class DefaultClientResourcesUnitTests method testProvidedResources.

@Test
void testProvidedResources() {
    EventExecutorGroup executorMock = mock(EventExecutorGroup.class);
    EventLoopGroupProvider groupProviderMock = mock(EventLoopGroupProvider.class);
    Timer timerMock = mock(Timer.class);
    EventBus eventBusMock = mock(EventBus.class);
    CommandLatencyCollector latencyCollectorMock = mock(CommandLatencyCollector.class);
    NettyCustomizer nettyCustomizer = mock(NettyCustomizer.class);
    AddressResolverGroup<?> addressResolverGroup = mock(AddressResolverGroup.class);
    DefaultClientResources sut = DefaultClientResources.builder().eventExecutorGroup(executorMock).eventLoopGroupProvider(groupProviderMock).timer(timerMock).eventBus(eventBusMock).commandLatencyRecorder(latencyCollectorMock).nettyCustomizer(nettyCustomizer).addressResolverGroup(addressResolverGroup).build();
    assertThat(sut.eventExecutorGroup()).isSameAs(executorMock);
    assertThat(sut.eventLoopGroupProvider()).isSameAs(groupProviderMock);
    assertThat(sut.timer()).isSameAs(timerMock);
    assertThat(sut.eventBus()).isSameAs(eventBusMock);
    assertThat(sut.nettyCustomizer()).isSameAs(nettyCustomizer);
    assertThat(sut.addressResolverGroup()).isSameAs(addressResolverGroup);
    assertThat(TestFutures.getOrTimeout(sut.shutdown())).isTrue();
    verifyNoMoreInteractions(executorMock);
    verifyNoMoreInteractions(groupProviderMock);
    verifyNoMoreInteractions(timerMock);
    verify(latencyCollectorMock).isEnabled();
    verifyNoMoreInteractions(latencyCollectorMock);
}
Also used : EventExecutorGroup(io.netty.util.concurrent.EventExecutorGroup) HashedWheelTimer(io.netty.util.HashedWheelTimer) Timer(io.netty.util.Timer) CommandLatencyCollector(io.lettuce.core.metrics.CommandLatencyCollector) EventBus(io.lettuce.core.event.EventBus) Test(org.junit.jupiter.api.Test)

Example 4 with EventBus

use of io.lettuce.core.event.EventBus in project lettuce-core by lettuce-io.

the class DefaultClientResourcesUnitTests method mutateResources.

@Test
void mutateResources() {
    EventExecutorGroup executorMock = mock(EventExecutorGroup.class);
    EventLoopGroupProvider groupProviderMock = mock(EventLoopGroupProvider.class);
    Timer timerMock = mock(Timer.class);
    Timer timerMock2 = mock(Timer.class);
    EventBus eventBusMock = mock(EventBus.class);
    CommandLatencyCollector latencyCollectorMock = mock(CommandLatencyCollector.class);
    AddressResolverGroup<?> addressResolverGroupMock = mock(AddressResolverGroup.class);
    ClientResources sut = ClientResources.builder().eventExecutorGroup(executorMock).eventLoopGroupProvider(groupProviderMock).timer(timerMock).eventBus(eventBusMock).commandLatencyRecorder(latencyCollectorMock).addressResolverGroup(addressResolverGroupMock).build();
    ClientResources copy = sut.mutate().timer(timerMock2).build();
    assertThat(sut.eventExecutorGroup()).isSameAs(executorMock);
    assertThat(sut.eventLoopGroupProvider()).isSameAs(groupProviderMock);
    assertThat(sut.timer()).isSameAs(timerMock);
    assertThat(copy.timer()).isSameAs(timerMock2).isNotSameAs(timerMock);
    assertThat(sut.eventBus()).isSameAs(eventBusMock);
    assertThat(sut.addressResolverGroup()).isSameAs(addressResolverGroupMock);
    assertThat(TestFutures.getOrTimeout(sut.shutdown())).isTrue();
    assertThat(sut).hasFieldOrPropertyWithValue("shutdownCheck", false);
    assertThat(copy).hasFieldOrPropertyWithValue("shutdownCheck", true);
    verifyNoMoreInteractions(executorMock);
    verifyNoMoreInteractions(groupProviderMock);
    verifyNoMoreInteractions(timerMock);
}
Also used : EventExecutorGroup(io.netty.util.concurrent.EventExecutorGroup) HashedWheelTimer(io.netty.util.HashedWheelTimer) Timer(io.netty.util.Timer) CommandLatencyCollector(io.lettuce.core.metrics.CommandLatencyCollector) EventBus(io.lettuce.core.event.EventBus) Test(org.junit.jupiter.api.Test)

Aggregations

EventBus (io.lettuce.core.event.EventBus)4 Test (org.junit.jupiter.api.Test)4 CommandLatencyCollector (io.lettuce.core.metrics.CommandLatencyCollector)2 HashedWheelTimer (io.netty.util.HashedWheelTimer)2 Timer (io.netty.util.Timer)2 EventExecutorGroup (io.netty.util.concurrent.EventExecutorGroup)2 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)1 RedisCommands (io.lettuce.core.api.sync.RedisCommands)1 Event (io.lettuce.core.event.Event)1 CommandLatencyEvent (io.lettuce.core.event.metrics.CommandLatencyEvent)1 MetricEventPublisher (io.lettuce.core.event.metrics.MetricEventPublisher)1 LettuceExtension (io.lettuce.test.LettuceExtension)1 ReflectionTestUtils (io.lettuce.test.ReflectionTestUtils)1 Wait (io.lettuce.test.Wait)1 Collection (java.util.Collection)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 Inject (javax.inject.Inject)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 Disposable (reactor.core.Disposable)1