Class SolaceMessaging
java.lang.Object
com.solace.connector.test.resources.resource.SolaceMessaging
- All Implemented Interfaces:
org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource
public class SolaceMessaging
extends Object
implements org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource
A utility to either:
- generate traffic on a workflow in the `Solace -> Vendor` direction OR
- retrieve messages that were processed by a workflow in the `Vendor -> Solace` direction and assert for correctness
Currently, this utility assumes that the Solace input and output destinations are always Queues. This simplification is acceptable since the intent is not to test the Solace SCSt Binder. We can safely assume that the Solace SCSt Binder handles other destination types correctly. This means however, that Solace Bindings should bind to queues or proper subscriptions are in place.
- generate traffic on a workflow in the `Solace -> Vendor` direction OR
- retrieve messages that were processed by a workflow in the `Vendor -> Solace` direction and assert for correctness
Currently, this utility assumes that the Solace input and output destinations are always Queues. This simplification is acceptable since the intent is not to test the Solace SCSt Binder. We can safely assume that the Solace SCSt Binder handles other destination types correctly. This means however, that Solace Bindings should bind to queues or proper subscriptions are in place.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException that can be thrown by message validators to indicate that a specific message should be excluded from the expected message count. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionList<com.solacesystems.jcsmp.BytesXMLMessage>consumeAll(int workflowIndex) Retrieve all messages that were processed by a workflow in the `Vendor -> Solace` direction.List<com.solacesystems.jcsmp.BytesXMLMessage>consumeAll(com.solacesystems.jcsmp.Destination destination) Consume all messages from a Solace queue.voidconsumeAndAssert(int numMessages, int workflowIndex, Consumer<com.solacesystems.jcsmp.BytesXMLMessage> messageValidator) Retrieve messages that were processed by a workflow in the `Vendor -> Solace` direction and perform validations on those messages.voidconsumeAndAssert(int numMessages, int workflowIndex, Consumer<com.solacesystems.jcsmp.BytesXMLMessage> messageValidator, Duration timeout) Retrieve messages that were processed by a workflow in the `Vendor -> Solace` direction and perform validations on those messages.voidconsumeAndAssert(int numMessages, com.solacesystems.jcsmp.Destination destination, Consumer<com.solacesystems.jcsmp.BytesXMLMessage> messageValidator) Retrieve messages from a Solace queue and validate for correctness.voidconsumeAndAssert(int numMessages, com.solacesystems.jcsmp.Destination destination, Consumer<com.solacesystems.jcsmp.BytesXMLMessage> messageValidator, Duration timeout) Retrieve messages from a Solace queue and validate for correctness.com.solacesystems.jcsmp.DestinationgetInputDestination(int workflowIdx) Gets the input destination configured for a specific workflow.com.solacesystems.jcsmp.DestinationgetOutputDestination(int workflowIdx) Gets the output destination configured for a specific workflow.produceAsync(int numMessages, int workflowIndex, Supplier<com.solacesystems.jcsmp.BytesXMLMessage> messageSupplier) Asynchronously publish messages to the Solace queue which is feeding a specific workflow.produceAsync(int numMessages, com.solacesystems.jcsmp.Destination destination, Supplier<com.solacesystems.jcsmp.BytesXMLMessage> messageSupplier) Asynchronously publish messages to a Solace queue.
-
Field Details
-
JUNIT_STORE_KEY
- See Also:
-
-
Method Details
-
produceAsync
public CompletableFuture<Void> produceAsync(int numMessages, int workflowIndex, Supplier<com.solacesystems.jcsmp.BytesXMLMessage> messageSupplier) throws com.solacesystems.jcsmp.JCSMPException Asynchronously publish messages to the Solace queue which is feeding a specific workflow.
Use this method to generate traffic on a workflow in the `Solace -> Vendor` direction.
This method returns immediately while messages are published on a different thread.
This method must be used in combination with the @SolaceQueueresource.- Parameters:
numMessages- the number of messages to publishworkflowIndex- the index of the workflow (must be between 0 and 19 inclusive)messageSupplier- a supplier providing the message to publish- Returns:
- future for publishing that completes when all messages are published or fails if any publishing fails
- Throws:
com.solacesystems.jcsmp.JCSMPException- if there is an error publishing messages to SolaceIllegalStateException- if the input destination for the specified workflow hasn't been initializedIllegalArgumentException- if workflowIndex is not between 0 and 19 or numMessages is less than 1
-
produceAsync
public CompletableFuture<Void> produceAsync(int numMessages, com.solacesystems.jcsmp.Destination destination, Supplier<com.solacesystems.jcsmp.BytesXMLMessage> messageSupplier) throws com.solacesystems.jcsmp.JCSMPException Asynchronously publish messages to a Solace queue.
This method returns immediately while messages are published on a different thread.- Parameters:
numMessages- the number of messages to publishdestination- the destination to publish messages tomessageSupplier- a supplier providing the message to publish- Returns:
- future for publishing that completes when all messages are published or fails if any publishing fails
- Throws:
com.solacesystems.jcsmp.JCSMPException- if there is an error publishing messages to SolaceIllegalArgumentException- if numMessages is not greater than zero or messageSupplier is null
-
consumeAndAssert
public void consumeAndAssert(int numMessages, int workflowIndex, Consumer<com.solacesystems.jcsmp.BytesXMLMessage> messageValidator) throws com.solacesystems.jcsmp.JCSMPException Retrieve messages that were processed by a workflow in the `Vendor -> Solace` direction and perform validations on those messages. This method reads from the Solace queue which is the destination of the workflow's output binding.ExcludeMessageFromExpectedCountExceptioncan be thrown from themessageValidatorto exclude a particular message from the expected message count.
This method must be used in combination with the @SolaceQueueresource. This method uses a default timeout of 5 minutes.- Parameters:
numMessages- the number of messages to expectworkflowIndex- the index of the workflow that processed the messages (must be between 0 and 19 inclusive)messageValidator- a validator which asserts that the received messages are as expected- Throws:
com.solacesystems.jcsmp.JCSMPException- if there is an error consuming messages from SolaceIllegalStateException- if the output destination for the specified workflow hasn't been initializedIllegalArgumentException- if workflowIndex is not between 0 and 19 or numMessages is less than 1AssertionError- if the expected number of messages is not received within the timeout
-
consumeAndAssert
public void consumeAndAssert(int numMessages, int workflowIndex, Consumer<com.solacesystems.jcsmp.BytesXMLMessage> messageValidator, Duration timeout) throws com.solacesystems.jcsmp.JCSMPException Retrieve messages that were processed by a workflow in the `Vendor -> Solace` direction and perform validations on those messages. This method reads from the Solace queue which is the destination of the workflow's output binding.ExcludeMessageFromExpectedCountExceptioncan be thrown from themessageValidatorto exclude a particular message from the expected message count.
This method must be used in combination with the @SolaceQueueresource.- Parameters:
numMessages- the number of messages to expectworkflowIndex- the index of the workflow that processed the messages (must be between 0 and 19 inclusive)messageValidator- a validator which asserts that the received messages are as expectedtimeout- the duration to wait for all messages to be received- Throws:
com.solacesystems.jcsmp.JCSMPException- if there is an error consuming messages from SolaceIllegalStateException- if the output destination for the specified workflow hasn't been initializedIllegalArgumentException- if workflowIndex is not between 0 and 19 or numMessages is less than 1AssertionError- if the expected number of messages is not received within the timeout
-
consumeAndAssert
public void consumeAndAssert(int numMessages, com.solacesystems.jcsmp.Destination destination, Consumer<com.solacesystems.jcsmp.BytesXMLMessage> messageValidator) throws com.solacesystems.jcsmp.JCSMPException Retrieve messages from a Solace queue and validate for correctness.ExcludeMessageFromExpectedCountExceptioncan be thrown from themessageValidatorto exclude a particular message from the expected message count. Default timeout is 5 minutes.- Parameters:
numMessages- the number of messages to expectdestination- the queue to consume messages frommessageValidator- a validator which asserts that the received messages are as expected- Throws:
com.solacesystems.jcsmp.JCSMPException- if there is an error consuming messages from SolaceIllegalArgumentException- if numMessages is not greater than zero or messageValidator is nullUnsupportedOperationException- if destination is not a QueueAssertionError- if the expected number of messages is not received within the timeout
-
consumeAndAssert
public void consumeAndAssert(int numMessages, com.solacesystems.jcsmp.Destination destination, Consumer<com.solacesystems.jcsmp.BytesXMLMessage> messageValidator, Duration timeout) throws com.solacesystems.jcsmp.JCSMPException Retrieve messages from a Solace queue and validate for correctness.ExcludeMessageFromExpectedCountExceptioncan be thrown from themessageValidatorto exclude a particular message from the expected message count.- Parameters:
numMessages- the number of messages to expectdestination- the queue to consume messages frommessageValidator- a validator which asserts that the received messages are as expectedtimeout- the duration to wait for all messages to be received- Throws:
com.solacesystems.jcsmp.JCSMPException- if there is an error consuming messages from SolaceIllegalArgumentException- if numMessages is not greater than zero or messageValidator is nullUnsupportedOperationException- if destination is not a QueueAssertionError- if the expected number of messages is not received within the timeout
-
consumeAll
public List<com.solacesystems.jcsmp.BytesXMLMessage> consumeAll(int workflowIndex) throws com.solacesystems.jcsmp.JCSMPException Retrieve all messages that were processed by a workflow in the `Vendor -> Solace` direction. This method reads from the Solace queue which is the destination of the workflow's output binding.- Parameters:
workflowIndex- the index of the workflow that processed the messages (must be between 0 and 19 inclusive)- Returns:
- a list of all messages consumed from the queue
- Throws:
com.solacesystems.jcsmp.JCSMPException- if there is an error consuming messages from SolaceIllegalStateException- if the output destination for the specified workflow hasn't been initializedIllegalArgumentException- if workflowIndex is not between 0 and 19
-
consumeAll
public List<com.solacesystems.jcsmp.BytesXMLMessage> consumeAll(com.solacesystems.jcsmp.Destination destination) throws com.solacesystems.jcsmp.JCSMPException Consume all messages from a Solace queue.- Parameters:
destination- the queue to consume messages from- Returns:
- a list of all messages consumed from the queue
- Throws:
com.solacesystems.jcsmp.JCSMPException- if there is an error consuming messages from SolaceUnsupportedOperationException- if destination is not a Queue
-
getInputDestination
public com.solacesystems.jcsmp.Destination getInputDestination(int workflowIdx) Gets the input destination configured for a specific workflow.- Parameters:
workflowIdx- the index of the workflow- Returns:
- the input destination for the specified workflow, or null if not set
-
getOutputDestination
public com.solacesystems.jcsmp.Destination getOutputDestination(int workflowIdx) Gets the output destination configured for a specific workflow.- Parameters:
workflowIdx- the index of the workflow- Returns:
- the output destination for the specified workflow, or null if not set
-