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;
}
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);
}
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);
}
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"));
}
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));
}
Aggregations