当前位置: 首页>>代码示例>>Java>>正文


Java EventBus类代码示例

本文整理汇总了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();
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:25,代码来源:DefaultClientResourcesTest.java

示例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);
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:21,代码来源:ClientMetricsTest.java

示例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");
}
 
开发者ID:mp911de,项目名称:spinach,代码行数:39,代码来源:ClientMetricsTest.java

示例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());
    }
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:13,代码来源:DefaultCommandLatencyEventPublisher.java

示例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);
    }
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:31,代码来源:DefaultClientResourcesTest.java

示例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));
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:30,代码来源:ClientMetricsTest.java

示例7: eventBus

import com.lambdaworks.redis.event.EventBus; //导入依赖的package包/类
@Override
public EventBus eventBus() {
    return eventBus;
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:5,代码来源:DefaultClientResources.java

示例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;
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:6,代码来源:ConnectionEventTrigger.java

示例9: eventBus

import com.lambdaworks.redis.event.EventBus; //导入依赖的package包/类
@Override
public EventBus eventBus() {
    return null;
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:5,代码来源:EmptyClientResources.java

示例10: eventBus

import com.lambdaworks.redis.event.EventBus; //导入依赖的package包/类
/**
 * Returns the event bus used to publish events.
 *
 * @return the event bus
 */
EventBus eventBus();
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:7,代码来源:ClientResources.java


注:本文中的com.lambdaworks.redis.event.EventBus类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。