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