Search in sources :

Example 21 with ChannelRegistry

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();
}
Also used : EmitterConfiguration(io.smallrye.reactive.messaging.providers.extension.EmitterConfiguration) ChannelRegistry(io.smallrye.reactive.messaging.ChannelRegistry) DefaultMediatorConfiguration(io.smallrye.reactive.messaging.providers.DefaultMediatorConfiguration) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.jupiter.api.Test)

Example 22 with ChannelRegistry

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"));
}
Also used : EmitterConfiguration(io.smallrye.reactive.messaging.providers.extension.EmitterConfiguration) ChannelRegistry(io.smallrye.reactive.messaging.ChannelRegistry) ChannelConfiguration(io.smallrye.reactive.messaging.providers.extension.ChannelConfiguration) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.jupiter.api.Test)

Example 23 with ChannelRegistry

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);
}
Also used : ChannelRegistry(io.smallrye.reactive.messaging.ChannelRegistry) DefaultMediatorConfiguration(io.smallrye.reactive.messaging.providers.DefaultMediatorConfiguration) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.jupiter.api.Test)

Example 24 with ChannelRegistry

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();
}
Also used : ChannelRegistry(io.smallrye.reactive.messaging.ChannelRegistry) DefaultMediatorConfiguration(io.smallrye.reactive.messaging.providers.DefaultMediatorConfiguration) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.jupiter.api.Test)

Example 25 with ChannelRegistry

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"));
}
Also used : EmitterConfiguration(io.smallrye.reactive.messaging.providers.extension.EmitterConfiguration) ChannelRegistry(io.smallrye.reactive.messaging.ChannelRegistry) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.jupiter.api.Test)

Aggregations

ChannelRegistry (io.smallrye.reactive.messaging.ChannelRegistry)42 Test (org.junit.jupiter.api.Test)42 Bean (javax.enterprise.inject.spi.Bean)41 DefaultMediatorConfiguration (io.smallrye.reactive.messaging.providers.DefaultMediatorConfiguration)34 ChannelConfiguration (io.smallrye.reactive.messaging.providers.extension.ChannelConfiguration)22 EmitterConfiguration (io.smallrye.reactive.messaging.providers.extension.EmitterConfiguration)16 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 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.when (org.mockito.Mockito.when)1