use of io.smallrye.reactive.messaging.ChannelRegistry in project smallrye-reactive-messaging by smallrye.
the class WiringTest method testEmitterNoProcessorSubscriberChain.
/**
* Use an emitter, and a subscriber method, but no processor
* emitter -> X -> c
*/
@Test
public void testEmitterNoProcessorSubscriberChain() {
ChannelRegistry registry = mock(ChannelRegistry.class);
Bean bean = mock(Bean.class);
when(bean.getBeanClass()).thenReturn(WiringTest.class);
DefaultMediatorConfiguration subscriber = new DefaultMediatorConfiguration(getMethod("consume"), bean);
subscriber.compute(Collections.singletonList(IncomingLiteral.of("b")), null, null);
Wiring wiring = new Wiring();
wiring.prepare(false, registry, Collections.singletonList(new EmitterConfiguration("a", false, null, null)), Collections.emptyList(), Collections.singletonList(subscriber));
Graph graph = wiring.resolve();
assertThat(graph.getResolvedComponents()).hasSize(1);
assertThat(graph.isClosed()).isFalse();
assertThat(graph.hasWiringErrors()).isFalse();
assertThat(graph.getInbound()).isEmpty();
assertThat(graph.getOutbound()).isEmpty();
}
use of io.smallrye.reactive.messaging.ChannelRegistry in project smallrye-reactive-messaging by smallrye.
the class WiringTest method testEmitterToChannelChain.
/**
* Use an emitter, directly connected to an injected channel.
* emitter -> b -> channel
*/
@Test
public void testEmitterToChannelChain() {
ChannelRegistry registry = mock(ChannelRegistry.class);
Bean bean = mock(Bean.class);
when(bean.getBeanClass()).thenReturn(WiringTest.class);
Wiring wiring = new Wiring();
wiring.prepare(false, registry, Collections.singletonList(new EmitterConfiguration("a", false, null, null)), Collections.singletonList(new ChannelConfiguration("a")), Collections.emptyList());
Graph graph = wiring.resolve();
assertThat(graph.getResolvedComponents()).hasSize(2);
assertThat(graph.isClosed()).isTrue();
assertThat(graph.hasWiringErrors()).isFalse();
assertThat(graph.getInbound()).hasSize(1).allSatisfy(pc -> assertThat(pc.outgoing()).contains("a"));
assertThat(graph.getOutbound()).hasSize(1).allSatisfy(pc -> assertThat(pc.incomings()).containsExactly("a"));
}
use of io.smallrye.reactive.messaging.ChannelRegistry in project smallrye-reactive-messaging by smallrye.
the class WiringTest method testDirectCycle.
/**
* A processor consuming "a" and producing "b" and another processor consuming "b" and producing "a"
*/
@Test
public void testDirectCycle() {
ChannelRegistry registry = mock(ChannelRegistry.class);
Bean bean = mock(Bean.class);
when(bean.getBeanClass()).thenReturn(WiringTest.class);
DefaultMediatorConfiguration processor1 = new DefaultMediatorConfiguration(getMethod("process"), bean);
processor1.compute(Collections.singletonList(IncomingLiteral.of("a")), OutgoingLiteral.of("b"), null);
DefaultMediatorConfiguration processor2 = new DefaultMediatorConfiguration(getMethod("process"), bean);
processor2.compute(Collections.singletonList(IncomingLiteral.of("b")), OutgoingLiteral.of("a"), null);
Wiring wiring = new Wiring();
wiring.prepare(false, registry, Collections.emptyList(), Collections.emptyList(), Arrays.asList(processor1, processor2));
assertThatThrownBy(wiring::resolve).isInstanceOf(CycleException.class);
}
use of io.smallrye.reactive.messaging.ChannelRegistry in project smallrye-reactive-messaging by smallrye.
the class WiringTest method testProducerNoProcessorSubscriberChain.
/**
* Only use methods (producer, consumer)
* a -> X -> c
*/
@Test
public void testProducerNoProcessorSubscriberChain() {
ChannelRegistry registry = mock(ChannelRegistry.class);
Bean bean = mock(Bean.class);
when(bean.getBeanClass()).thenReturn(WiringTest.class);
DefaultMediatorConfiguration subscriber = new DefaultMediatorConfiguration(getMethod("consume"), bean);
subscriber.compute(Collections.singletonList(IncomingLiteral.of("b")), null, null);
DefaultMediatorConfiguration producer = new DefaultMediatorConfiguration(getMethod("producer"), bean);
producer.compute(Collections.emptyList(), OutgoingLiteral.of("a"), null);
Wiring wiring = new Wiring();
wiring.prepare(false, registry, Collections.emptyList(), Collections.emptyList(), Arrays.asList(subscriber, producer));
Graph graph = wiring.resolve();
// Only one resolved component (producer)
assertThat(graph.getResolvedComponents()).hasSize(1);
assertThat(graph.getUnresolvedComponents()).hasSize(1);
assertThat(graph.isClosed()).isFalse();
assertThat(graph.hasWiringErrors()).isFalse();
assertThat(graph.getInbound()).isEmpty();
assertThat(graph.getOutbound()).isEmpty();
}
use of io.smallrye.reactive.messaging.ChannelRegistry in project smallrye-reactive-messaging by smallrye.
the class WiringMergeTest method testInvalidMergeWithOutgoingConnector.
@Test
public void testInvalidMergeWithOutgoingConnector() {
ChannelRegistry registry = mock(ChannelRegistry.class);
when(registry.getIncomingChannels()).thenReturn(Collections.singletonMap("a", true));
when(registry.getOutgoingChannels()).thenReturn(Collections.singletonMap("a", false));
Bean bean = mock(Bean.class);
when(bean.getBeanClass()).thenReturn(WiringTest.class);
EmitterConfiguration ec = new EmitterConfiguration("a", false, null, null);
Wiring wiring = new Wiring();
wiring.prepare(false, registry, Collections.singletonList(ec), Collections.emptyList(), Collections.emptyList());
Graph graph = wiring.resolve();
assertThat(graph.hasWiringErrors()).isTrue();
assertThat(graph.getWiringErrors()).hasSize(1).allSatisfy(e -> assertThat(e).isInstanceOf(TooManyUpstreamCandidatesException.class).hasMessageContaining("mp.messaging.outgoing.a.merge"));
}
Aggregations