本文整理汇总了Java中com.lambdaworks.redis.event.EventBus类的典型用法代码示例。如果您正苦于以下问题:Java EventBus类的具体用法?Java EventBus怎么用?Java EventBus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EventBus类属于com.lambdaworks.redis.event包,在下文中一共展示了EventBus类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEventBus
import com.lambdaworks.redis.event.EventBus; //导入依赖的package包/类
@Test
public void testEventBus() throws Exception {
DefaultClientResources sut = DefaultClientResources.create();
EventBus eventBus = sut.eventBus();
final TestSubscriber<Event> subject = new TestSubscriber<>();
eventBus.get().subscribe(subject);
Event event = mock(Event.class);
eventBus.publish(event);
WaitFor.waitOrTimeout(new Condition() {
@Override
public boolean isSatisfied() {
return !subject.getOnNextEvents().isEmpty();
}
}, timeout(seconds(2)));
assertThat(subject.getOnNextEvents()).contains(event);
assertThat(sut.shutdown(0, 0, TimeUnit.MILLISECONDS).get()).isTrue();
}
示例2: testMetricsEvent
import com.lambdaworks.redis.event.EventBus; //导入依赖的package包/类
@Test
public void testMetricsEvent() throws Exception {
EventBus eventBus = client.getResources().eventBus();
MetricEventPublisher publisher = (MetricEventPublisher) ReflectionTestUtils.getField(client.getResources(),
"metricEventPublisher");
publisher.emitMetricsEvent();
TestSubscriber<CommandLatencyEvent> subscriber = new TestSubscriber<>();
Subscription subscription = eventBus.get().filter(redisEvent -> redisEvent instanceof CommandLatencyEvent).cast(CommandLatencyEvent.class).subscribe(subscriber);
generateTestData();
publisher.emitMetricsEvent();
WaitFor.waitOrTimeout(() -> !subscriber.getOnNextEvents().isEmpty(), timeout(seconds(5)));
subscription.unsubscribe();
subscriber.assertValueCount(1);
}
示例3: testMetricsEvent
import com.lambdaworks.redis.event.EventBus; //导入依赖的package包/类
@Test
public void testMetricsEvent() throws Exception {
EventBus eventBus = clientResources.eventBus();
MetricEventPublisher publisher = (MetricEventPublisher) ReflectionTestUtils.getField(clientResources,
"metricEventPublisher");
publisher.emitMetricsEvent();
final TestSubscriber<CommandLatencyEvent> subscriber = new TestSubscriber<CommandLatencyEvent>();
Subscription subscription = eventBus.get().filter(new Func1<Event, Boolean>() {
@Override
public Boolean call(Event redisEvent) {
return redisEvent instanceof CommandLatencyEvent;
}
}).cast(CommandLatencyEvent.class).subscribe(subscriber);
generateTestData();
publisher.emitMetricsEvent();
WaitFor.waitOrTimeout(new Condition() {
@Override
public boolean isSatisfied() {
return !subscriber.getOnNextEvents().isEmpty();
}
}, timeout(seconds(5)));
subscription.unsubscribe();
subscriber.assertValueCount(1);
CommandLatencyEvent event = subscriber.getOnNextEvents().get(0);
assertThat(event.getLatencies()).hasSize(2);
assertThat(event.toString()).contains("local:any ->");
assertThat(event.toString()).contains("commandType=PING");
}
示例4: DefaultCommandLatencyEventPublisher
import com.lambdaworks.redis.event.EventBus; //导入依赖的package包/类
public DefaultCommandLatencyEventPublisher(EventExecutorGroup eventExecutorGroup, EventPublisherOptions options,
EventBus eventBus, CommandLatencyCollector commandLatencyCollector) {
this.eventExecutorGroup = eventExecutorGroup;
this.options = options;
this.eventBus = eventBus;
this.commandLatencyCollector = commandLatencyCollector;
if (options.eventEmitInterval() > 0) {
scheduledFuture = this.eventExecutorGroup.scheduleAtFixedRate(EMITTER, options.eventEmitInterval(),
options.eventEmitInterval(), options.eventEmitIntervalUnit());
}
}
示例5: testProvidedResources
import com.lambdaworks.redis.event.EventBus; //导入依赖的package包/类
@Test
public void testProvidedResources() throws Exception {
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);
DefaultClientResources sut = new DefaultClientResources.Builder().eventExecutorGroup(executorMock)
.eventLoopGroupProvider(groupProviderMock).timer(timerMock).eventBus(eventBusMock)
.commandLatencyCollector(latencyCollectorMock)
.nettyCustomizer(nettyCustomizer)
.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.shutdown().get()).isTrue();
verifyZeroInteractions(executorMock);
verifyZeroInteractions(groupProviderMock);
verifyZeroInteractions(timerMock);
verify(latencyCollectorMock).isEnabled();
verifyNoMoreInteractions(latencyCollectorMock);
}
示例6: testMetrics
import com.lambdaworks.redis.event.EventBus; //导入依赖的package包/类
@Test
public void testMetrics() throws Exception {
EventBus eventBus = client.getResources().eventBus();
MetricEventPublisher publisher = (MetricEventPublisher) ReflectionTestUtils.getField(client.getResources(),
"metricEventPublisher");
publisher.emitMetricsEvent();
TestSubscriber<CommandLatencyEvent> subscriber = new TestSubscriber<>();
Subscription subscription = eventBus.get().filter(redisEvent -> redisEvent instanceof CommandLatencyEvent).cast(CommandLatencyEvent.class).subscribe(subscriber);
generateTestData();
publisher.emitMetricsEvent();
WaitFor.waitOrTimeout(() -> !subscriber.getOnNextEvents().isEmpty(), timeout(seconds(5)));
subscription.unsubscribe();
subscriber.assertValueCount(1);
CommandLatencyEvent event = subscriber.getOnNextEvents().get(0);
Set<CommandLatencyId> ids = event.getLatencies().keySet();
CommandMetrics commandMetrics = event.getLatencies().get(ids.iterator().next());
assertThat(commandMetrics.getCompletion().getMin()).isBetween(0L, TimeUnit.MILLISECONDS.toMicros(100));
assertThat(commandMetrics.getCompletion().getMax()).isBetween(0L, TimeUnit.MILLISECONDS.toMicros(200));
assertThat(commandMetrics.getFirstResponse().getMin()).isBetween(0L, TimeUnit.MILLISECONDS.toMicros(100));
assertThat(commandMetrics.getFirstResponse().getMax()).isBetween(0L, TimeUnit.MILLISECONDS.toMicros(200));
}
示例7: eventBus
import com.lambdaworks.redis.event.EventBus; //导入依赖的package包/类
@Override
public EventBus eventBus() {
return eventBus;
}
示例8: ConnectionEventTrigger
import com.lambdaworks.redis.event.EventBus; //导入依赖的package包/类
public ConnectionEventTrigger(ConnectionEvents connectionEvents, RedisChannelHandler<?, ?> connection, EventBus eventBus) {
this.connectionEvents = connectionEvents;
this.connection = connection;
this.eventBus = eventBus;
}
示例9: eventBus
import com.lambdaworks.redis.event.EventBus; //导入依赖的package包/类
@Override
public EventBus eventBus() {
return null;
}
示例10: eventBus
import com.lambdaworks.redis.event.EventBus; //导入依赖的package包/类
/**
* Returns the event bus used to publish events.
*
* @return the event bus
*/
EventBus eventBus();