Search in sources :

Example 1 with CommandLatencyEvent

use of io.lettuce.core.event.metrics.CommandLatencyEvent in project lettuce-core by lettuce-io.

the class JfrEventRecorderUnitTests method shouldNotEmitEventForAbsentJfrEventType.

@Test
void shouldNotEmitEventForAbsentJfrEventType() throws IOException {
    Recording recording = new Recording();
    recording.start();
    EventRecorder.getInstance().record(new CommandLatencyEvent(Collections.emptyMap()));
    recording.stop();
    File temp = getFile(recording);
    RecordingFile input = new RecordingFile(temp.toPath());
    assertThat(input.hasMoreEvents()).isFalse();
    input.close();
}
Also used : Recording(jdk.jfr.Recording) RecordingFile(jdk.jfr.consumer.RecordingFile) CommandLatencyEvent(io.lettuce.core.event.metrics.CommandLatencyEvent) RecordingFile(jdk.jfr.consumer.RecordingFile) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 2 with CommandLatencyEvent

use of io.lettuce.core.event.metrics.CommandLatencyEvent 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)

Aggregations

CommandLatencyEvent (io.lettuce.core.event.metrics.CommandLatencyEvent)2 Test (org.junit.jupiter.api.Test)2 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)1 RedisCommands (io.lettuce.core.api.sync.RedisCommands)1 EventBus (io.lettuce.core.event.EventBus)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 File (java.io.File)1 Collection (java.util.Collection)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 Inject (javax.inject.Inject)1 Recording (jdk.jfr.Recording)1 RecordingFile (jdk.jfr.consumer.RecordingFile)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 Disposable (reactor.core.Disposable)1