Search in sources :

Example 1 with DefaultMediatorConfiguration

use of io.smallrye.reactive.messaging.providers.DefaultMediatorConfiguration in project smallrye-reactive-messaging by smallrye.

the class CollectedMediatorMetadata method createMediatorConfiguration.

private MediatorConfiguration createMediatorConfiguration(Method met, Bean<?> bean) {
    DefaultMediatorConfiguration configuration = new DefaultMediatorConfiguration(met, bean);
    if (strict) {
        configuration.strict();
    }
    Incomings incomings = met.getAnnotation(Incomings.class);
    Incoming incoming = met.getAnnotation(Incoming.class);
    Outgoing outgoing = met.getAnnotation(Outgoing.class);
    Blocking blocking = met.getAnnotation(Blocking.class);
    if (incomings != null) {
        configuration.compute(incomings, outgoing, blocking);
    } else if (incoming != null) {
        configuration.compute(Collections.singletonList(incoming), outgoing, blocking);
    } else {
        configuration.compute(Collections.emptyList(), outgoing, blocking);
    }
    return configuration;
}
Also used : Incomings(io.smallrye.reactive.messaging.annotations.Incomings) Incoming(org.eclipse.microprofile.reactive.messaging.Incoming) Blocking(io.smallrye.reactive.messaging.annotations.Blocking) Outgoing(org.eclipse.microprofile.reactive.messaging.Outgoing) DefaultMediatorConfiguration(io.smallrye.reactive.messaging.providers.DefaultMediatorConfiguration)

Example 2 with DefaultMediatorConfiguration

use of io.smallrye.reactive.messaging.providers.DefaultMediatorConfiguration in project smallrye-reactive-messaging by smallrye.

the class WiringBroadcastTest method testWithConnectorWithBroadcast.

/**
 * connector - {a} -> process -> channel
 * -> channel
 */
@Test
public void testWithConnectorWithBroadcast() {
    ChannelRegistry registry = mock(ChannelRegistry.class);
    when(registry.getIncomingChannels()).thenReturn(Collections.singletonMap("a", true));
    Bean bean = mock(Bean.class);
    when(bean.getBeanClass()).thenReturn(WiringTest.class);
    DefaultMediatorConfiguration processor = new DefaultMediatorConfiguration(getMethod("process"), bean);
    processor.compute(Collections.singletonList(IncomingLiteral.of("a")), OutgoingLiteral.of("b"), null);
    ChannelConfiguration cc1 = new ChannelConfiguration("b");
    ChannelConfiguration cc2 = new ChannelConfiguration("a");
    Wiring wiring = new Wiring();
    wiring.prepare(false, registry, Collections.emptyList(), Arrays.asList(cc1, cc2), Collections.singletonList(processor));
    Graph graph = wiring.resolve();
    assertThat(graph.hasWiringErrors()).isFalse();
    assertThat(graph.getWiringErrors()).hasSize(0);
    assertThat(graph.isClosed()).isTrue();
    assertThat(graph.getInbound()).hasSize(1).allSatisfy(pc -> assertThat(pc.outgoing()).contains("a"));
    assertThat(graph.getOutbound()).hasSize(2);
}
Also used : ChannelRegistry(io.smallrye.reactive.messaging.ChannelRegistry) ChannelConfiguration(io.smallrye.reactive.messaging.providers.extension.ChannelConfiguration) DefaultMediatorConfiguration(io.smallrye.reactive.messaging.providers.DefaultMediatorConfiguration) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.jupiter.api.Test)

Example 3 with DefaultMediatorConfiguration

use of io.smallrye.reactive.messaging.providers.DefaultMediatorConfiguration in project smallrye-reactive-messaging by smallrye.

the class WiringBroadcastTest method testWithPublisherMethodWithBroadcastAndExactNumberOfSubscribers.

/**
 * Producer method emitting on the channel "a" with broadcast and two downstream subscribers (1 channel and one processor)
 * The @Broadcast sets the number of subscribers to 2.
 * <p>
 * produce - {a} -> processor - {b} -> channel
 * -> channel
 */
@Test
public void testWithPublisherMethodWithBroadcastAndExactNumberOfSubscribers() {
    ChannelRegistry registry = mock(ChannelRegistry.class);
    Bean bean = mock(Bean.class);
    when(bean.getBeanClass()).thenReturn(WiringTest.class);
    DefaultMediatorConfiguration producer = new DefaultMediatorConfiguration(getMethod("producerWithBroadcast2"), bean);
    producer.compute(Collections.emptyList(), OutgoingLiteral.of("a"), null);
    DefaultMediatorConfiguration processor = new DefaultMediatorConfiguration(getMethod("process"), bean);
    processor.compute(Collections.singletonList(IncomingLiteral.of("a")), OutgoingLiteral.of("b"), null);
    ChannelConfiguration cc1 = new ChannelConfiguration("b");
    ChannelConfiguration cc2 = new ChannelConfiguration("a");
    Wiring wiring = new Wiring();
    wiring.prepare(false, registry, Collections.emptyList(), Arrays.asList(cc1, cc2), Arrays.asList(processor, producer));
    Graph graph = wiring.resolve();
    assertThat(graph.getResolvedComponents()).hasSize(4);
    assertThat(graph.isClosed()).isTrue();
    assertThat(graph.hasWiringErrors()).isFalse();
    assertThat(graph.getInbound()).hasSize(1).allSatisfy(pc -> assertThat(pc.outgoing()).contains("a"));
    assertThat(graph.getOutbound()).hasSize(2);
}
Also used : ChannelRegistry(io.smallrye.reactive.messaging.ChannelRegistry) ChannelConfiguration(io.smallrye.reactive.messaging.providers.extension.ChannelConfiguration) DefaultMediatorConfiguration(io.smallrye.reactive.messaging.providers.DefaultMediatorConfiguration) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.jupiter.api.Test)

Example 4 with DefaultMediatorConfiguration

use of io.smallrye.reactive.messaging.providers.DefaultMediatorConfiguration in project smallrye-reactive-messaging by smallrye.

the class WiringBroadcastTest method testWithInvalidEmitterBroadcastAndHint.

@Test
public void testWithInvalidEmitterBroadcastAndHint() {
    ChannelRegistry registry = mock(ChannelRegistry.class);
    Bean bean = mock(Bean.class);
    when(bean.getBeanClass()).thenReturn(WiringTest.class);
    DefaultMediatorConfiguration processor = new DefaultMediatorConfiguration(getMethod("process"), bean);
    processor.compute(Collections.singletonList(IncomingLiteral.of("a")), OutgoingLiteral.of("b"), null);
    EmitterConfiguration ec = new EmitterConfiguration("a", false, null, null);
    ChannelConfiguration cc1 = new ChannelConfiguration("b");
    ChannelConfiguration cc2 = new ChannelConfiguration("a");
    Wiring wiring = new Wiring();
    wiring.prepare(false, registry, Collections.singletonList(ec), Arrays.asList(cc1, cc2), Collections.singletonList(processor));
    Graph graph = wiring.resolve();
    assertThat(graph.hasWiringErrors()).isTrue();
    assertThat(graph.getWiringErrors()).hasSize(1).allSatisfy(t -> assertThat(t).isInstanceOf(TooManyDownstreamCandidatesException.class).hasMessageContaining("channel:'a'").hasMessageContaining("@Broadcast"));
}
Also used : EmitterConfiguration(io.smallrye.reactive.messaging.providers.extension.EmitterConfiguration) ChannelRegistry(io.smallrye.reactive.messaging.ChannelRegistry) ChannelConfiguration(io.smallrye.reactive.messaging.providers.extension.ChannelConfiguration) DefaultMediatorConfiguration(io.smallrye.reactive.messaging.providers.DefaultMediatorConfiguration) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.jupiter.api.Test)

Example 5 with DefaultMediatorConfiguration

use of io.smallrye.reactive.messaging.providers.DefaultMediatorConfiguration in project smallrye-reactive-messaging by smallrye.

the class WiringBroadcastTest method testWithPublisherMethodWithBroadcastAnMoreSubscribersThanConfigured.

/**
 * Producer method emitting on the channel "a" with broadcast and three downstream subscribers (2 channels and one
 * processor)
 * The @Broadcast sets the number of subscribers to 2.
 * <p>
 * produce - {a} -> processor - {b} -> channel
 * -> channel
 * -> channel
 */
@Test
public void testWithPublisherMethodWithBroadcastAnMoreSubscribersThanConfigured() {
    ChannelRegistry registry = mock(ChannelRegistry.class);
    Bean bean = mock(Bean.class);
    when(bean.getBeanClass()).thenReturn(WiringTest.class);
    DefaultMediatorConfiguration producer = new DefaultMediatorConfiguration(getMethod("producerWithBroadcast2"), bean);
    producer.compute(Collections.emptyList(), OutgoingLiteral.of("a"), null);
    DefaultMediatorConfiguration processor = new DefaultMediatorConfiguration(getMethod("process"), bean);
    processor.compute(Collections.singletonList(IncomingLiteral.of("a")), OutgoingLiteral.of("b"), null);
    ChannelConfiguration cc1 = new ChannelConfiguration("b");
    ChannelConfiguration cc2 = new ChannelConfiguration("a");
    ChannelConfiguration cc3 = new ChannelConfiguration("a");
    Wiring wiring = new Wiring();
    wiring.prepare(false, registry, Collections.emptyList(), Arrays.asList(cc1, cc2, cc3), Arrays.asList(processor, producer));
    Graph graph = wiring.resolve();
    assertThat(graph.getResolvedComponents()).hasSize(5);
    assertThat(graph.isClosed()).isTrue();
    assertThat(graph.hasWiringErrors()).isTrue();
    assertThat(graph.getWiringErrors()).hasSize(1).allSatisfy(e -> assertThat(e).isInstanceOf(UnsatisfiedBroadcastException.class));
}
Also used : ChannelRegistry(io.smallrye.reactive.messaging.ChannelRegistry) ChannelConfiguration(io.smallrye.reactive.messaging.providers.extension.ChannelConfiguration) DefaultMediatorConfiguration(io.smallrye.reactive.messaging.providers.DefaultMediatorConfiguration) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultMediatorConfiguration (io.smallrye.reactive.messaging.providers.DefaultMediatorConfiguration)35 ChannelRegistry (io.smallrye.reactive.messaging.ChannelRegistry)34 Bean (javax.enterprise.inject.spi.Bean)34 Test (org.junit.jupiter.api.Test)34 ChannelConfiguration (io.smallrye.reactive.messaging.providers.extension.ChannelConfiguration)20 EmitterConfiguration (io.smallrye.reactive.messaging.providers.extension.EmitterConfiguration)12 Blocking (io.smallrye.reactive.messaging.annotations.Blocking)1 Incomings (io.smallrye.reactive.messaging.annotations.Incomings)1 Merge (io.smallrye.reactive.messaging.annotations.Merge)1 Method (java.lang.reflect.Method)1 Collections (java.util.Collections)1 NoSuchElementException (java.util.NoSuchElementException)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Incoming (org.eclipse.microprofile.reactive.messaging.Incoming)1 Outgoing (org.eclipse.microprofile.reactive.messaging.Outgoing)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.when (org.mockito.Mockito.when)1