reactor.core.publisher.WorkQueueProcessor Java Examples

The following examples show how to use reactor.core.publisher.WorkQueueProcessor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EventSubscriptionManagerTest.java    From sourcerer with MIT License 5 votes vote down vote up
@Test
@Ignore // Manual only
public void testBackpressureWorking() {
    EventRepository<String> repository = mock(EventRepository.class);
    EventSubscriptionPositionSource positionSource =
            mock(EventSubscriptionPositionSource.class);

    WorkQueueProcessor<EventSubscriptionUpdate<String>> processor = WorkQueueProcessor.create();
    Flux<EventSubscriptionUpdate<String>> eventSource = Flux
            .fromStream(IntStream
                                .range(0, 1000000)
                                .mapToObj(this::wrapIntAsEvent)
                                .map(EventSubscriptionUpdate::ofEvent))
            .doOnNext(e -> {
                lastProducedValue = e.getEvent().getEvent();
            });
    eventSource.subscribe(processor);

    when(repository.getPublisher(any())).thenReturn(processor);
    when(positionSource.getSubscriptionPosition()).thenReturn(null);
    SlowSubscriptionHandler<String> subscriptionHandler = new SlowSubscriptionHandler<>();

    EventSubscriptionManager subscriptionManager = new EventSubscriptionManager<>(
            repository,
            positionSource,
            subscriptionHandler,
            new SubscriptionWorkerConfig().withBatchSize(64));

    SubscriptionToken token = subscriptionManager.start();
    sleep(5000);
    token.stop();

    logger.info(
            "Last produced value was {}, last seen {}, total events seen: {}",
            lastProducedValue,
            subscriptionHandler.getLastSeenValue(),
            subscriptionHandler.getTotalEvents());
}
 
Example #2
Source File: EventSubscriptionManagerTest.java    From sourcerer with MIT License 5 votes vote down vote up
@Test
@Ignore // Manual only
public void testRetriesOnHandlerError() {
    EventRepository<String> repository = mock(EventRepository.class);
    EventSubscriptionPositionSource positionSource =
            mock(EventSubscriptionPositionSource.class);

    when(repository.getPublisher(any())).then(position -> {
        WorkQueueProcessor<EventSubscriptionUpdate<String>> processor =
                WorkQueueProcessor.create();
        Flux<EventSubscriptionUpdate<String>> eventSource = Flux
                .fromStream(IntStream
                                    .range(0, 1000000)
                                    .mapToObj(this::wrapIntAsEvent)
                                    .map(EventSubscriptionUpdate::ofEvent))
                .doOnNext(e -> {
                    lastProducedValue = e.getEvent().getEvent();
                });
        eventSource.subscribe(processor);
        return processor;
    });

    when(positionSource.getSubscriptionPosition()).thenReturn(null);
    ErroringSubscriptionHandler<String> subscriptionHandler =
            new ErroringSubscriptionHandler<>(300);

    EventSubscriptionManager subscriptionManager = new EventSubscriptionManager<>(
            repository,
            positionSource,
            subscriptionHandler,
            new SubscriptionWorkerConfig().withBatchSize(64));

    SubscriptionToken token = subscriptionManager.start();
    sleep(100000);
    token.stop();
}
 
Example #3
Source File: EventSubscriptionManagerTest.java    From sourcerer with MIT License 5 votes vote down vote up
@Test
@Ignore // Manual only
public void testRetriesOnHandlerErrorWithBackoff() {
    EventRepository<String> repository = mock(EventRepository.class);
    EventSubscriptionPositionSource positionSource =
            mock(EventSubscriptionPositionSource.class);

    when(repository.getPublisher(any())).then(position -> {
        WorkQueueProcessor<EventRecord<String>> processor = WorkQueueProcessor.create();
        Flux<EventRecord<String>> eventSource = Flux
                .fromStream(IntStream.range(0, 1000000).mapToObj(this::wrapIntAsEvent))
                .doOnNext(e -> {
                    lastProducedValue = e.getEvent();
                });
        eventSource.subscribe(processor);
        return processor;
    });

    when(positionSource.getSubscriptionPosition()).thenReturn(null);
    ErroringSubscriptionHandler<String> subscriptionHandler =
            new ErroringSubscriptionHandler<>(0);

    EventSubscriptionManager subscriptionManager = new EventSubscriptionManager<>(
            repository,
            positionSource,
            subscriptionHandler,
            new SubscriptionWorkerConfig().withBatchSize(64));

    SubscriptionToken token = subscriptionManager.start();
    sleep(100000);
    token.stop();
}
 
Example #4
Source File: EventSubscriptionManagerTest.java    From sourcerer with MIT License 5 votes vote down vote up
@Test
@Ignore // Manual only
public void testRetriesOnStreamError() {
    EventRepository<String> repository = mock(EventRepository.class);
    EventSubscriptionPositionSource positionSource =
            mock(EventSubscriptionPositionSource.class);

    when(repository.getPublisher(any())).then(position -> {
        WorkQueueProcessor<EventRecord<String>> processor = WorkQueueProcessor.create();
        Flux<EventRecord<String>> eventSource = Flux
                .fromStream(IntStream.range(0, 1000000).mapToObj(this::wrapIntAsEvent))
                .doOnNext(e -> {
                    lastProducedValue = e.getEvent();
                });
        eventSource.subscribe(processor);
        return processor.take(100).thenMany(Flux.error(new RuntimeException("fail!")));
    });

    when(positionSource.getSubscriptionPosition()).thenReturn(null);
    SlowSubscriptionHandler<String> subscriptionHandler =
            new SlowSubscriptionHandler<>();

    EventSubscriptionManager subscriptionManager = new EventSubscriptionManager<>(
            repository,
            positionSource,
            subscriptionHandler,
            new SubscriptionWorkerConfig().withBatchSize(64));

    SubscriptionToken token = subscriptionManager.start();
    sleep(100000);
    token.stop();
}
 
Example #5
Source File: ReactorProxies.java    From RHub with Apache License 2.0 4 votes vote down vote up
public static ReactorProcProxy workQueueProcessorProxy() {
    return new ReactorProcProxy(WorkQueueProcessor.create(), PASS);
}
 
Example #6
Source File: ReactorProxies.java    From RHub with Apache License 2.0 4 votes vote down vote up
public static ReactorProcProxy serializedWorkQueueProcessorProxy() {
    return new ReactorProcProxy(WorkQueueProcessor.create().serialize(), PASS);
}
 
Example #7
Source File: ReactorProxies.java    From RHub with Apache License 2.0 4 votes vote down vote up
public static ReactorProcProxy safeWorkQueueProcessorProxy() {
    return new ReactorProcProxy(WorkQueueProcessor.create(), WRAP);
}
 
Example #8
Source File: ReactorProxies.java    From RHub with Apache License 2.0 4 votes vote down vote up
public static ReactorProcProxy safeSerializedWorkQueueProcessorProxy() {
    return new ReactorProcProxy(WorkQueueProcessor.create().serialize(), WRAP);
}