Class InMemoryConnector

    • Constructor Detail

      • InMemoryConnector

        public InMemoryConnector()
    • Method Detail

      • switchIncomingChannelsToInMemory

        public static Map<String,​String> switchIncomingChannelsToInMemory​(String... channels)
        Switch the given incoming channel to in-memory. It replaces the previously used connector with the in-memory connector.

        This method is generally used before tests to avoid using an external broker for a specific channel. You can then retrieve the InMemorySource using:

             @Inject @Any
             InMemoryConnector connector;
        
             //...
        
             @Before
             public void setup() {
                 InMemoryConnector.switchIncomingChannelsToInMemory("my-channel");
             }
        
             // ..
        
             InMemorySource<Integer> channel = connector.source("my-channel");
             channel.send(1);
             channel.send(2);
        
         

        Parameters:
        channels - the channels to switch, must not be null, must not contain null, must not contain a blank value
        Returns:
        The map of properties that have been defined. The method sets the system properties, but give you this map to pass the properties around if needed.
      • switchOutgoingChannelsToInMemory

        public static Map<String,​String> switchOutgoingChannelsToInMemory​(String... channels)
        Switch the given outgoing channel to in-memory. It replaces the previously used connector with the in-memory connector.

        This method is generally used before tests to avoid using an external broker for a specific channel. You can then retrieve the InMemorySink using:

             @Inject @Any
             InMemoryConnector connector;
        
             //...
        
             @Before
             public void setup() {
                 InMemoryConnector.switchOutgoingChannelsToInMemory("my-channel");
             }
        
             // ..
        
             InMemorySink<Integer> channel = connector.sink("my-channel");
             assertThat(channel.received()).hasSize(3).extracting(Message::getPayload).containsExactly(1, 2);
        
         

        Parameters:
        channels - the channels to switch, must not be null, must not contain null, must not contain a blank value
        Returns:
        The map of properties that have been defined. The method sets the system properties, but give you this map to pass these properties around if needed.
      • clear

        public static void clear()
        Switch back the channel to their original connector.

        This method is generally used after tests to reset the original configuration.

      • getPublisherBuilder

        public org.eclipse.microprofile.reactive.streams.operators.PublisherBuilder<? extends Message<?>> getPublisherBuilder​(org.eclipse.microprofile.config.Config config)
        Description copied from interface: IncomingConnectorFactory
        Creates a channel for the given configuration. The channel's configuration is associated with a specific connector, using the Connector qualifier's parameter indicating a key to which IncomingConnectorFactory to use.

        Note that the connection to the transport or broker is generally postponed until the subscription occurs.

        Specified by:
        getPublisherBuilder in interface IncomingConnectorFactory
        Parameters:
        config - the configuration, must not be null, must contain the ConnectorFactory.CHANNEL_NAME_ATTRIBUTE attribute.
        Returns:
        the created PublisherBuilder, will not be null.
      • getSubscriberBuilder

        public org.eclipse.microprofile.reactive.streams.operators.SubscriberBuilder<? extends Message<?>,​Void> getSubscriberBuilder​(org.eclipse.microprofile.config.Config config)
        Description copied from interface: OutgoingConnectorFactory
        Creates a channel for the given configuration. The channel's configuration is associated with a specific connector, using the Connector qualifier's parameter indicating a key to which Outgoing to use.

        Note that the connection to the transport or broker is generally postponed until the subscription.

        Specified by:
        getSubscriberBuilder in interface OutgoingConnectorFactory
        Parameters:
        config - the configuration, never null, must contain the ConnectorFactory.CHANNEL_NAME_ATTRIBUTE attribute.
        Returns:
        the created SubscriberBuilder, must not be null.
      • source

        public <T> InMemorySource<T> source​(String channel)
        Retrieves an InMemorySource associated to the channel named channel. This channel must use the in-memory connected.

        The returned InMemorySource lets you send messages or payloads to the channel, mocking the real interactions.

        Type Parameters:
        T - the type of message or payload sent to the channel
        Parameters:
        channel - the name of the channel, must not be null
        Returns:
        the source
        Throws:
        IllegalArgumentException - if the channel name is null or if the channel is not associated with the in-memory connector.
        See Also:
        switchIncomingChannelsToInMemory(String...)
      • sink

        public <T> InMemorySink<T> sink​(String channel)
        Retrieves an InMemorySink associated to the channel named channel. This channel must use the in-memory connected.

        The returned InMemorySink lets you checks the messages sent to the channel.

        Type Parameters:
        T - the type of payload received by the channel
        Parameters:
        channel - the name of the channel, must not be null
        Returns:
        the sink
        Throws:
        IllegalArgumentException - if the channel name is null or if the channel is not associated with the in-memory connector.
        See Also:
        switchOutgoingChannelsToInMemory(String...)