org.eclipse.microprofile.reactive.streams.operators.spi.UnsupportedStageException Java Examples

The following examples show how to use org.eclipse.microprofile.reactive.streams.operators.spi.UnsupportedStageException. 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: Engine.java    From smallrye-mutiny with Apache License 2.0 6 votes vote down vote up
@Override
public <T, R> SubscriberWithCompletionStage<T, R> buildSubscriber(Graph graph) {
    Processor<T, T> processor = new ConnectableProcessor<>();
    Multi<T> flowable = Multi.createFrom().publisher(processor);
    for (Stage stage : graph.getStages()) {
        Operator operator = Stages.lookup(stage);
        if (operator instanceof ProcessorOperator) {
            flowable = applyProcessors(flowable, stage, (ProcessorOperator) operator);
        } else if (operator instanceof TerminalOperator) {
            CompletionStage<R> result = applySubscriber(Transformer.apply(flowable), stage,
                    (TerminalOperator) operator);
            return new DefaultSubscriberWithCompletionStage<>(processor, result);
        } else {
            throw new UnsupportedStageException(stage);
        }
    }

    throw new IllegalArgumentException("The graph does not have a valid final stage");
}
 
Example #2
Source File: Engine.java    From smallrye-reactive-streams-operators with Apache License 2.0 6 votes vote down vote up
@Override
public <T, R> SubscriberWithCompletionStage<T, R> buildSubscriber(Graph graph) {
    Processor<T, T> processor = new ConnectableProcessor<>();
    Flowable<T> flowable = Flowable.fromPublisher(processor);
    for (Stage stage : graph.getStages()) {
        Operator operator = Stages.lookup(stage);
        if (operator instanceof ProcessorOperator) {
            flowable = applyProcessors(flowable, stage, (ProcessorOperator) operator);
        } else if (operator instanceof TerminalOperator) {
            CompletionStage<R> result = applySubscriber(Transformer.apply(flowable), stage,
                    (TerminalOperator) operator);
            return new DefaultSubscriberWithCompletionStage<>(processor, result);
        } else {
            throw new UnsupportedStageException(stage);
        }
    }

    throw new IllegalArgumentException("The graph does not have a valid final stage");
}
 
Example #3
Source File: EngineTest.java    From smallrye-mutiny with Apache License 2.0 5 votes vote down vote up
@Test(expected = UnsupportedStageException.class)
public void testUnknownTerminalStage() {
    engine = new Engine();
    List<Stage> stages = new ArrayList<>();
    stages.add((Stage.Map) () -> i -> (int) i + 1);
    stages.add(new Stage() {
        // Unknown stage
    });
    Graph graph = () -> stages;
    engine.buildSubscriber(graph);
}
 
Example #4
Source File: EngineTest.java    From smallrye-mutiny with Apache License 2.0 5 votes vote down vote up
@Test(expected = UnsupportedStageException.class)
public void testCompletionWithUnknownStage() {
    engine = new Engine();
    List<Stage> stages = new ArrayList<>();
    stages.add((Stage.PublisherStage) () -> Multi.createFrom().empty());
    stages.add((Stage.Map) () -> i -> (int) i + 1);
    stages.add(new Stage() {
        // Unknown stage.
    });
    stages.add(new Stage.FindFirst() {
    });
    Graph graph = () -> stages;
    assertThat(engine.buildCompletion(graph)).isNotNull();
}
 
Example #5
Source File: EngineTest.java    From smallrye-mutiny with Apache License 2.0 5 votes vote down vote up
@Test(expected = UnsupportedStageException.class)
public void testCreatingPublisherWithUnknownStage() {
    engine = new Engine();
    List<Stage> stages = new ArrayList<>();
    stages.add(new Stage() {
        // Unknown stage.
    });
    stages.add((Stage.Map) () -> i -> (int) i + 1);
    Graph graph = () -> stages;
    engine.buildPublisher(graph);
}
 
Example #6
Source File: EngineTest.java    From smallrye-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
@Test(expected = UnsupportedStageException.class)
public void testUnknownTerminalStage() {
    engine = new Engine();
    List<Stage> stages = new ArrayList<>();
    stages.add((Stage.Map) () -> i -> (int) i + 1);
    stages.add(new Stage() {
        // Unknown stage
    });
    Graph graph = () -> stages;
    engine.buildSubscriber(graph);
}
 
Example #7
Source File: EngineTest.java    From smallrye-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
@Test(expected = UnsupportedStageException.class)
public void testCompletionWithUnknownStage() {
    engine = new Engine();
    List<Stage> stages = new ArrayList<>();
    stages.add((Stage.PublisherStage) Flowable::empty);
    stages.add((Stage.Map) () -> i -> (int) i + 1);
    stages.add(new Stage() {
        // Unknown stage.
    });
    stages.add(new Stage.FindFirst() {
    });
    Graph graph = () -> stages;
    assertThat(engine.buildCompletion(graph)).isNotNull();
}
 
Example #8
Source File: EngineTest.java    From smallrye-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
@Test(expected = UnsupportedStageException.class)
public void testCreatingPublisherWithUnknownStage() {
    engine = new Engine();
    List<Stage> stages = new ArrayList<>();
    stages.add(new Stage() {
        // Unknown stage.
    });
    stages.add((Stage.Map) () -> i -> (int) i + 1);
    Graph graph = () -> stages;
    engine.buildPublisher(graph);
}
 
Example #9
Source File: Stages.java    From smallrye-mutiny with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T extends Stage> Operator<T> lookup(T stage) {
    Objects.requireNonNull(stage, "The stage must not be `null`");
    return ALL.stream().filter(p -> p.test(stage)).findAny()
            .orElseThrow(() -> new UnsupportedStageException(stage));
}
 
Example #10
Source File: Stages.java    From smallrye-reactive-streams-operators with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T extends Stage> Operator<T> lookup(T stage) {
    Objects.requireNonNull(stage, "The stage must not be `null`");
    return ALL.stream().filter(p -> p.test(stage)).findAny()
            .orElseThrow(() -> new UnsupportedStageException(stage));
}