Search in sources :

Example 1 with ChannelConfiguration

use of io.smallrye.reactive.messaging.providers.extension.ChannelConfiguration 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 2 with ChannelConfiguration

use of io.smallrye.reactive.messaging.providers.extension.ChannelConfiguration 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 3 with ChannelConfiguration

use of io.smallrye.reactive.messaging.providers.extension.ChannelConfiguration 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 4 with ChannelConfiguration

use of io.smallrye.reactive.messaging.providers.extension.ChannelConfiguration 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)

Example 5 with ChannelConfiguration

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

the class WiringBroadcastTest method testWithPublishingMethodAndMissingBroadcastAndHint.

/**
 * Test missing broadcast on publisher method
 */
@Test
public void testWithPublishingMethodAndMissingBroadcastAndHint() {
    ChannelRegistry registry = mock(ChannelRegistry.class);
    Bean bean = mock(Bean.class);
    when(bean.getBeanClass()).thenReturn(WiringTest.class);
    DefaultMediatorConfiguration producer = new DefaultMediatorConfiguration(getMethod("producer"), 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.hasWiringErrors()).isTrue();
    assertThat(graph.getResolvedComponents()).hasSize(4);
    assertThat(graph.isClosed()).isTrue();
    assertThat(graph.getWiringErrors()).hasSize(1).allSatisfy(e -> assertThat(e).isInstanceOf(TooManyDownstreamCandidatesException.class).hasMessageContaining("@Broadcast"));
    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)

Aggregations

ChannelConfiguration (io.smallrye.reactive.messaging.providers.extension.ChannelConfiguration)23 ChannelRegistry (io.smallrye.reactive.messaging.ChannelRegistry)22 Bean (javax.enterprise.inject.spi.Bean)22 Test (org.junit.jupiter.api.Test)22 DefaultMediatorConfiguration (io.smallrye.reactive.messaging.providers.DefaultMediatorConfiguration)20 EmitterConfiguration (io.smallrye.reactive.messaging.providers.extension.EmitterConfiguration)10 BeanInfo (io.quarkus.arc.processor.BeanInfo)1 GeneratedClassGizmoAdaptor (io.quarkus.deployment.GeneratedClassGizmoAdaptor)1 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 Record (io.quarkus.deployment.annotations.Record)1 ReflectiveClassBuildItem (io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem)1 ClassOutput (io.quarkus.gizmo.ClassOutput)1 InjectedChannelBuildItem (io.quarkus.smallrye.reactivemessaging.deployment.items.InjectedChannelBuildItem)1 InjectedEmitterBuildItem (io.quarkus.smallrye.reactivemessaging.deployment.items.InjectedEmitterBuildItem)1 MediatorBuildItem (io.quarkus.smallrye.reactivemessaging.deployment.items.MediatorBuildItem)1 QuarkusMediatorConfiguration (io.quarkus.smallrye.reactivemessaging.runtime.QuarkusMediatorConfiguration)1 SmallRyeReactiveMessagingContext (io.quarkus.smallrye.reactivemessaging.runtime.SmallRyeReactiveMessagingRecorder.SmallRyeReactiveMessagingContext)1 WorkerConfiguration (io.quarkus.smallrye.reactivemessaging.runtime.WorkerConfiguration)1 EmitterConfiguration (io.smallrye.reactive.messaging.EmitterConfiguration)1 Merge (io.smallrye.reactive.messaging.annotations.Merge)1