Search in sources :

Example 1 with EmitterConfiguration

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

the class EmitterInjectionTest method testWeCanHaveSeveralSubscribers.

// Reproduce #511
@Test
public void testWeCanHaveSeveralSubscribers() {
    OnOverflow overflow = new OnOverflow() {

        @Override
        public Class<? extends Annotation> annotationType() {
            return OnOverflow.class;
        }

        @Override
        public Strategy value() {
            return OnOverflow.Strategy.BUFFER;
        }

        @Override
        public long bufferSize() {
            return 128;
        }
    };
    EmitterConfiguration config = new EmitterConfiguration("my-channel", false, overflow, null);
    EmitterImpl<String> emitter = new EmitterImpl<>(config, 128);
    Publisher<Message<? extends String>> publisher = emitter.getPublisher();
    TestSubscriber<Message<? extends String>> sub1 = new TestSubscriber<>();
    publisher.subscribe(sub1);
    TestSubscriber<Message<? extends String>> sub2 = new TestSubscriber<>();
    publisher.subscribe(sub2);
    sub1.assertNoErrors();
    sub2.assertNoErrors();
}
Also used : EmitterConfiguration(io.smallrye.reactive.messaging.providers.extension.EmitterConfiguration) EmitterImpl(io.smallrye.reactive.messaging.providers.extension.EmitterImpl) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Test(org.junit.jupiter.api.Test)

Example 2 with EmitterConfiguration

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

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

the class WiringBroadcastTest method testEmitterWithImmediateBroadcast.

/**
 * Emitter emitting on the channel "a" with broadcast and two downstream subscribers (1 channel and one processor)
 * The @Broadcast does not specify the number of subscribers.
 * <p>
 * emitter - {a} -> processor - {b} -> channel
 * emitter - {a} -> channel
 */
@Test
public void testEmitterWithImmediateBroadcast() {
    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, BroadcastLiteral.of(0));
    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.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 : 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 EmitterConfiguration

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

the class WiringBroadcastTest method testEmitterWithBroadcastAndExactNumberOfSubscribers.

/**
 * Emitter 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>
 * emitter - {a} -> processor - {b} -> channel
 * -> channel
 */
@Test
public void testEmitterWithBroadcastAndExactNumberOfSubscribers() {
    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, BroadcastLiteral.of(2));
    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.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 : 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 EmitterConfiguration

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

the class WiringBroadcastTest method testEmitterWithUnsatisfiedBroadcast.

/**
 * Emitter emitting on the channel "a" with broadcast and two downstream subscribers (1 channel and one processor)
 * The @Broadcast sets the number of subscribers to 3.
 * <p>
 * emitter - {a} -> processor - {b} -> channel
 * -> channel
 */
@Test
public void testEmitterWithUnsatisfiedBroadcast() {
    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, BroadcastLiteral.of(3));
    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.getResolvedComponents()).hasSize(4);
    assertThat(graph.isClosed()).isTrue();
    assertThat(graph.hasWiringErrors()).isTrue();
    assertThat(graph.getWiringErrors()).hasSize(1).allSatisfy(e -> assertThat(e).isInstanceOf(UnsatisfiedBroadcastException.class));
}
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)

Aggregations

EmitterConfiguration (io.smallrye.reactive.messaging.providers.extension.EmitterConfiguration)18 Test (org.junit.jupiter.api.Test)18 ChannelRegistry (io.smallrye.reactive.messaging.ChannelRegistry)16 Bean (javax.enterprise.inject.spi.Bean)16 DefaultMediatorConfiguration (io.smallrye.reactive.messaging.providers.DefaultMediatorConfiguration)12 ChannelConfiguration (io.smallrye.reactive.messaging.providers.extension.ChannelConfiguration)10 TestSubscriber (io.reactivex.subscribers.TestSubscriber)2 Merge (io.smallrye.reactive.messaging.annotations.Merge)1 EmitterImpl (io.smallrye.reactive.messaging.providers.extension.EmitterImpl)1 MutinyEmitterImpl (io.smallrye.reactive.messaging.providers.extension.MutinyEmitterImpl)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 Message (org.eclipse.microprofile.reactive.messaging.Message)1 OnOverflow (org.eclipse.microprofile.reactive.messaging.OnOverflow)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.when (org.mockito.Mockito.when)1