Package io.mats3.test
Interface MatsTestBrokerInterface
- All Known Implementing Classes:
MatsTestBrokerInterface.MatsTestBrokerInterface_JmsMatsFactory
public interface MatsTestBrokerInterface
Tool that makes it possible to query the underlying broker of a test MatsFactory for messages, in particular
"residual" messages and DLQs. DLQ-fetching is useful if the test is designed to fail a stage, i.e. that a stage under
test raises some
RuntimeException
, or the special MatsRefuseMessageException
due to some
internal validation performed.
Usage: If employing the Mats test tools, one of these should have been created for you. For the JUnit
Rule_Mats
, and JUnit Jupiter Extension_Mats
, there's a getter directly on the
rule/extension instance. For Spring, employing the @MatsTestContext
or corresponding
MatsTestInfrastructureConfiguration
, an instance is put into the Spring context for you. If you do not
use those tools, you will have to create a instance of this class as a Spring bean yourself - either directly by
using the create(..)
methods taking parameters, or indirectly by
using the createForLaterPopulation()
variant, and rely on the SpringJmsMatsFactoryWrapper
finding it from the Spring context and populating it for you.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
Representation of the Mats message that sat on the DLQ.static class
-
Method Summary
Modifier and TypeMethodDescription_latePopulate
(javax.jms.ConnectionFactory connectionFactory, MatsFactory matsFactory) This method is most probably not for you!.static MatsTestBrokerInterface
create
(javax.jms.ConnectionFactory connectionFactory, MatsFactory matsFactory) If you have both the JMS ConnectionFactory and a JmsMatsFactory available from start, then you can create a working instance right away.static MatsTestBrokerInterface
Special factory variant, where the needed parameters must be supplied by_latePopulate(ConnectionFactory, MatsFactory)
, which typically will be handled by theSpringJmsMatsFactoryWrapper
.getDlqMessage
(String endpointOrStageId) Waits a couple of seconds for a message to appear on the Dead Letter Queue for the provided endpoint- or stageId (Queue name "DLQ."+matsendpointPrefix+endpointOrStageId) - and also checks the standard common ActiveMQ DLQ (Queue name "ActiveMQ.DLQ") in case the broker is not configured with specific DLQs per Queue, which is relevant if you fire up an unmodified ActiveMQ distribution on the command line, check theMatsTestBroker
class JavaDoc for how to use an external MQ instead of the in-VM which otherwise is fired up.
-
Method Details
-
create
static MatsTestBrokerInterface create(javax.jms.ConnectionFactory connectionFactory, MatsFactory matsFactory) If you have both the JMS ConnectionFactory and a JmsMatsFactory available from start, then you can create a working instance right away. Otherwise, typically in a Spring bean context, check out_latePopulate(ConnectionFactory, MatsFactory)
. Note that the MatsFactory parameter currently needs to be aJmsMatsFactory
- read more at _latePopulate(). -
createForLaterPopulation
Special factory variant, where the needed parameters must be supplied by_latePopulate(ConnectionFactory, MatsFactory)
, which typically will be handled by theSpringJmsMatsFactoryWrapper
.- Returns:
- an empty, not still ready instance.
-
getDlqMessage
Waits a couple of seconds for a message to appear on the Dead Letter Queue for the provided endpoint- or stageId (Queue name "DLQ."+matsendpointPrefix+endpointOrStageId) - and also checks the standard common ActiveMQ DLQ (Queue name "ActiveMQ.DLQ") in case the broker is not configured with specific DLQs per Queue, which is relevant if you fire up an unmodified ActiveMQ distribution on the command line, check theMatsTestBroker
class JavaDoc for how to use an external MQ instead of the in-VM which otherwise is fired up. (NOTE: It is HIGHLY suggested to use the "specific DLQ" pattern in any production setting, as this is much easier to reason about when ugly things starts hitting fans).- Parameters:
endpointOrStageId
- the endpoint which is expected to generate a DLQ message.- Returns:
- the
MatsTrace
of the DLQ'ed message.
-
_latePopulate
MatsTestBrokerInterface _latePopulate(javax.jms.ConnectionFactory connectionFactory, MatsFactory matsFactory) This method is most probably not for you!. It is employed bySpringJmsMatsFactoryWrapper
, by reflection invocation when it is both on classpath and as an instance in the Spring context, to perform "late setting" of the properties which the tool needs to perform its job. (Reason for reflection: This class resides in the 'mats-test' project - which is for testing, while theSpringJmsMatsFactoryWrapper
is in the 'mats-spring-jms' project - which is for "production"). The matsFactory parameter currently needs to be a JmsMatsFactory. We need all of the following from itmatsFactory.getFactoryConfig().getMatsDestinationPrefix()
(standard MatsFactory)matsFactory.getFactoryConfig().getMatsTraceKey()
(standard MatsFactory)- The Mats Interceptor API (from
MatsInterceptable
, which JmsMatsFactory is) - The
MatsSerializer
to provide access to contents from messages (from JmsMatsFactory)
MatsFactory.MatsFactoryWrapper
, but it must resolve to aJmsMatsFactory
via theMatsFactory.unwrapFully()
! Otherwise, it'll throw anIllegalArgumentException
.- Returns:
this
-