registeredIds = new HashSet<>();
13 | private final Object lock = new Object();
14 |
15 | private static final Logger LOGGER = LoggerFactory.getLogger(SharedResourceManager.class);
16 |
17 | SharedResourceManager(String type) {
18 | this.type = type;
19 | }
20 |
21 | abstract T create() throws Exception;
22 | abstract void close();
23 |
24 | /**
25 | * Register {@code key} to the shared resource.
26 | * If this is the first key to claim this shared resource, {@link #create()} the resource.
27 | * @param key the registration key of the caller that wants to use this resource
28 | * @return the shared resource
29 | * @throws Exception whatever exception that may be thrown by {@link #create()}
30 | */
31 | public T get(String key) throws Exception {
32 | synchronized (lock) {
33 | if (registeredIds.isEmpty()) {
34 | LOGGER.info("No {} exists, a new one will be created", type);
35 | sharedResource = create();
36 | } else {
37 | LOGGER.trace("A message {} already exists, reusing it", type);
38 | }
39 |
40 | registeredIds.add(key);
41 | }
42 |
43 | return sharedResource;
44 | }
45 |
46 | /**
47 | * De-register {@code key} from the shared resource.
48 | *
If this is the last {@code key} associated to the shared resource, {@link #close()} the resource.
49 | * @param key the registration key of the caller that is using the resource
50 | */
51 | public void release(String key) {
52 | synchronized (lock) {
53 | if (!registeredIds.contains(key)) return;
54 |
55 | if (registeredIds.size() <= 1) {
56 | LOGGER.info("{} is the last user, closing {}...", key, type);
57 | close();
58 | sharedResource = null;
59 | } else {
60 | LOGGER.info("{} is not the last user, persisting {}...", key, type);
61 | }
62 | registeredIds.remove(key);
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/solace-spring-cloud-stream-binder/solace-spring-cloud-stream-binder-core/src/main/java/com/solace/spring/cloud/stream/binder/util/SmfMessageHeaderWriteCompatibility.java:
--------------------------------------------------------------------------------
1 | package com.solace.spring.cloud.stream.binder.util;
2 |
3 | /**
4 | * The compatibility mode for message headers when they're being written to the SMF message.
5 | */
6 | public enum SmfMessageHeaderWriteCompatibility {
7 | /**
8 | * Only headers which are natively supported by SMF are allowed to be written.
9 | * Unsupported types will throw an exception.
10 | */
11 | NATIVE_ONLY,
12 |
13 | /**
14 | * Non-native and serializable headers will be serialized to a byte array then encoded into a string with the
15 | * corresponding {@link com.solace.spring.cloud.stream.binder.messaging.SolaceBinderHeaders#SERIALIZED_HEADERS} and
16 | * {@link com.solace.spring.cloud.stream.binder.messaging.SolaceBinderHeaders#SERIALIZED_HEADERS_ENCODING} headers
17 | * set accordingly.
18 | * Native payloads will be written as usual.
19 | */
20 | SERIALIZE_AND_ENCODE_NON_NATIVE_TYPES
21 | }
22 |
--------------------------------------------------------------------------------
/solace-spring-cloud-stream-binder/solace-spring-cloud-stream-binder-core/src/main/java/com/solace/spring/cloud/stream/binder/util/SmfMessagePayloadWriteCompatibility.java:
--------------------------------------------------------------------------------
1 | package com.solace.spring.cloud.stream.binder.util;
2 |
3 | /**
4 | * The compatibility mode for message payloads when they're being written to the SMF message.
5 | */
6 | public enum SmfMessagePayloadWriteCompatibility {
7 | /**
8 | * Only payloads which are natively supported by SMF are allowed to be written.
9 | * Unsupported types will throw an exception.
10 | */
11 | NATIVE_ONLY,
12 |
13 | /**
14 | * Non-native and serializable payloads will be serialized into a byte array with the corresponding
15 | * {@link com.solace.spring.cloud.stream.binder.messaging.SolaceBinderHeaders#SERIALIZED_PAYLOAD} header set
16 | * accordingly.
17 | * Native payloads will be written as usual.
18 | */
19 | SERIALIZE_NON_NATIVE_TYPES
20 | }
21 |
--------------------------------------------------------------------------------
/solace-spring-cloud-stream-binder/solace-spring-cloud-stream-binder-core/src/main/java/com/solace/spring/cloud/stream/binder/util/SolaceAcknowledgmentException.java:
--------------------------------------------------------------------------------
1 | package com.solace.spring.cloud.stream.binder.util;
2 |
3 | public class SolaceAcknowledgmentException extends RuntimeException {
4 | public SolaceAcknowledgmentException(String message, Throwable cause) {
5 | super(message, cause);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/solace-spring-cloud-stream-binder/solace-spring-cloud-stream-binder-core/src/main/java/com/solace/spring/cloud/stream/binder/util/SolaceBatchAcknowledgementException.java:
--------------------------------------------------------------------------------
1 | package com.solace.spring.cloud.stream.binder.util;
2 |
3 | import java.util.Set;
4 |
5 | public class SolaceBatchAcknowledgementException extends SolaceAcknowledgmentException {
6 |
7 | private final Set failedMessageIndexes;
8 |
9 | public SolaceBatchAcknowledgementException(Set failedMessageIndexes, String message,
10 | Throwable cause) {
11 | super(message, cause);
12 | this.failedMessageIndexes = failedMessageIndexes;
13 | }
14 |
15 | public Set getFailedMessageIndexes() {
16 | return failedMessageIndexes;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/solace-spring-cloud-stream-binder/solace-spring-cloud-stream-binder-core/src/main/java/com/solace/spring/cloud/stream/binder/util/SolaceFlowEventHandler.java:
--------------------------------------------------------------------------------
1 | package com.solace.spring.cloud.stream.binder.util;
2 |
3 | import com.solacesystems.jcsmp.FlowEvent;
4 | import com.solacesystems.jcsmp.FlowEventArgs;
5 | import com.solacesystems.jcsmp.FlowEventHandler;
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 |
9 | public class SolaceFlowEventHandler implements FlowEventHandler {
10 |
11 | private static final Logger LOGGER = LoggerFactory.getLogger(SolaceFlowEventHandler.class);
12 | private final XMLMessageMapper xmlMessageMapper;
13 | private final String flowReceiverContainerId;
14 |
15 | public SolaceFlowEventHandler(XMLMessageMapper xmlMessageMapper, String flowReceiverContainerId) {
16 | this.xmlMessageMapper = xmlMessageMapper;
17 | this.flowReceiverContainerId = flowReceiverContainerId;
18 | }
19 |
20 | @Override
21 | public void handleEvent(Object source, FlowEventArgs flowEventArgs) {
22 | LOGGER.debug("({}): Received Solace Flow event [{}].", source, flowEventArgs);
23 |
24 | if (flowEventArgs.getEvent() == FlowEvent.FLOW_RECONNECTED && xmlMessageMapper != null) {
25 | LOGGER.debug("Received flow event {} for flow receiver container {}. Will clear ignored properties.",
26 | flowEventArgs.getEvent().name(), flowReceiverContainerId);
27 | xmlMessageMapper.resetIgnoredProperties(flowReceiverContainerId);
28 | }
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/solace-spring-cloud-stream-binder/solace-spring-cloud-stream-binder-core/src/main/java/com/solace/spring/cloud/stream/binder/util/SolaceMessageConversionException.java:
--------------------------------------------------------------------------------
1 | package com.solace.spring.cloud.stream.binder.util;
2 |
3 | public class SolaceMessageConversionException extends RuntimeException {
4 | public SolaceMessageConversionException(String message) {
5 | super(message);
6 | }
7 |
8 | public SolaceMessageConversionException(Throwable throwable) {
9 | super(throwable);
10 | }
11 |
12 | public SolaceMessageConversionException(String message, Throwable throwable) {
13 | super(message, throwable);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/solace-spring-cloud-stream-binder/solace-spring-cloud-stream-binder-core/src/main/java/com/solace/spring/cloud/stream/binder/util/SolaceMessageHeaderErrorMessageStrategy.java:
--------------------------------------------------------------------------------
1 | package com.solace.spring.cloud.stream.binder.util;
2 |
3 | import org.springframework.core.AttributeAccessor;
4 | import org.springframework.integration.IntegrationMessageHeaderAccessor;
5 | import org.springframework.integration.support.ErrorMessageStrategy;
6 | import org.springframework.integration.support.ErrorMessageUtils;
7 | import org.springframework.messaging.Message;
8 | import org.springframework.messaging.support.ErrorMessage;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | public class SolaceMessageHeaderErrorMessageStrategy implements ErrorMessageStrategy {
14 | public static final String ATTR_SOLACE_RAW_MESSAGE = "solace_sourceData";
15 | public static final String ATTR_SOLACE_ACKNOWLEDGMENT_CALLBACK = "solace_acknowledgmentCallback";
16 |
17 | @Override
18 | public ErrorMessage buildErrorMessage(Throwable throwable, AttributeAccessor attributeAccessor) {
19 | Object inputMessage;
20 | Map headers = new HashMap<>();
21 | if (attributeAccessor == null) {
22 | inputMessage = null;
23 | } else {
24 | inputMessage = attributeAccessor.getAttribute(ErrorMessageUtils.INPUT_MESSAGE_CONTEXT_KEY);
25 | Object sourceData = attributeAccessor.getAttribute(ATTR_SOLACE_RAW_MESSAGE);
26 | if (sourceData != null) {
27 | headers.put(IntegrationMessageHeaderAccessor.SOURCE_DATA, sourceData);
28 | }
29 | Object ackCallback = attributeAccessor.getAttribute(ATTR_SOLACE_ACKNOWLEDGMENT_CALLBACK);
30 | if (ackCallback != null) {
31 | headers.put(IntegrationMessageHeaderAccessor.ACKNOWLEDGMENT_CALLBACK, ackCallback);
32 | }
33 | }
34 | return inputMessage instanceof Message ? new ErrorMessage(throwable, headers, (Message>) inputMessage) :
35 | new ErrorMessage(throwable, headers);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/solace-spring-cloud-stream-binder/solace-spring-cloud-stream-binder-core/src/main/java/com/solace/spring/cloud/stream/binder/util/StaticMessageHeaderMapAccessor.java:
--------------------------------------------------------------------------------
1 | package com.solace.spring.cloud.stream.binder.util;
2 |
3 | import java.util.Map;
4 |
5 | /**
6 | * Utility class to perform generic header accessing operations without needing to create a
7 | * {@link org.springframework.messaging.MessageHeaders MessageHeaders} object.
8 | */
9 | public final class StaticMessageHeaderMapAccessor {
10 | public static T get(Map headers, String key, Class type) {
11 | Object value = headers.get(key);
12 | if (value == null) {
13 | return null;
14 | }
15 | if (!type.isAssignableFrom(value.getClass())) {
16 | throw new IllegalArgumentException(String.format(
17 | "Incorrect type specified for header '%s'. Expected [%s] but actual type is [%s]",
18 | key, type, value.getClass()));
19 | }
20 |
21 | @SuppressWarnings("unchecked")
22 | T toReturn = (T) value;
23 |
24 | return toReturn;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/solace-spring-cloud-stream-binder/solace-spring-cloud-stream-binder-core/src/main/java/com/solace/spring/cloud/stream/binder/util/ToStringer.java:
--------------------------------------------------------------------------------
1 | package com.solace.spring.cloud.stream.binder.util;
2 |
3 | import com.solacesystems.jcsmp.ConsumerFlowProperties;
4 | import com.solacesystems.jcsmp.Endpoint;
5 | import com.solacesystems.jcsmp.EndpointProperties;
6 |
7 | /**
8 | * To string utility for 3'rd party classes that do not override toString in a meaningful way, to be used for logging or debugging purposes
9 | */
10 | public final class ToStringer {
11 |
12 | /**
13 | * provides a simplified toString for {@link EndpointProperties}
14 | * @param ep to tbe turned to String
15 | * @return string representation of the object
16 | */
17 | public static String toString(EndpointProperties ep) {
18 | if (ep== null)
19 | return "EndpointProperties{NULL}";
20 | return "EndpointProperties{" +
21 | "mAccessType=" + ep.getAccessType() +
22 | ", mMaxMsgSize=" + ep.getMaxMsgSize() +
23 | ", mPermission=" + ep.getPermission() +
24 | '}';
25 | }
26 |
27 | /**
28 | * provides a simplified toString for {@link Endpoint}
29 | * @param e to tbe turned to String
30 | * @return string representation of the object
31 | */
32 | public static String toString(Endpoint e) {
33 | if (e==null)
34 | return "Endpoint{NULL}";
35 | return "Endpoint{" +
36 | " class:" + e.getClass()+
37 | " _name='" + e.getName() + '\'' +
38 | ", _durable=" + e.isDurable() +
39 | '}';
40 | }
41 |
42 | /**
43 | * provides a simplified toString for {@link ConsumerFlowProperties}
44 | * @param cfp to tbe turned to String
45 | * @return string representation of the object
46 | */
47 | public static String toString(ConsumerFlowProperties cfp) {
48 |
49 | return "ConsumerFlowProperties{" +
50 | "endpoint=" + toString(cfp.getEndpoint()) +
51 | ", newSubscription=" + cfp.getNewSubscription() +
52 | ", sqlSelector='" + cfp.getSelector() + '\'' +
53 | ", startState=" + cfp.isStartState() +
54 | ", noLocal=" + cfp.isNoLocal() +
55 | ", activeFlowIndication=" + cfp.isActiveFlowIndication() +
56 | ", ackMode='" + cfp.getAckMode() + '\'' +
57 | ", windowSize=" + cfp.getTransportWindowSize() +
58 | ", ackTimerMs=" + cfp.getAckTimerInMsecs() +
59 | ", ackThreshold=" + cfp.getAckThreshold() +
60 | ", reconnectTries=" + cfp.getReconnectTries() +
61 | ", outcomes=" + cfp.getRequiredSettlementOutcomes() +
62 | ", flowSessionProps=" + cfp.getFlowSessionProps() +
63 | ", segmentFlow=" + cfp.isSegmentFlow() +
64 | '}';
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/solace-spring-cloud-stream-binder/solace-spring-cloud-stream-binder-core/src/main/java/com/solace/spring/cloud/stream/binder/util/UnboundFlowReceiverContainerException.java:
--------------------------------------------------------------------------------
1 | package com.solace.spring.cloud.stream.binder.util;
2 |
3 | /**
4 | * Flow receiver container is not bound to a flow receiver.
5 | * Typically caused by one of:
6 | *
7 | * - {@link FlowReceiverContainer#unbind()}
8 | *
9 | */
10 | public class UnboundFlowReceiverContainerException extends Exception {
11 | public UnboundFlowReceiverContainerException(String message) {
12 | super(message);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/solace-spring-cloud-stream-binder/solace-spring-cloud-stream-binder-core/src/test/java/com/solace/spring/cloud/stream/binder/health/base/SolaceHealthIndicatorTest.java:
--------------------------------------------------------------------------------
1 | package com.solace.spring.cloud.stream.binder.health.base;
2 |
3 | import com.solacesystems.jcsmp.FlowEvent;
4 | import com.solacesystems.jcsmp.FlowEventArgs;
5 | import org.junit.jupiter.api.BeforeEach;
6 | import org.junit.jupiter.api.Test;
7 | import org.springframework.boot.actuate.health.Health;
8 | import org.springframework.boot.actuate.health.Status;
9 |
10 | import static org.junit.jupiter.api.Assertions.assertEquals;
11 |
12 | class SolaceHealthIndicatorTest {
13 |
14 | private SolaceHealthIndicator solaceHealthIndicator;
15 |
16 | @BeforeEach
17 | void setUp() {
18 | this.solaceHealthIndicator = new SolaceHealthIndicator();
19 | }
20 |
21 | @Test
22 | void healthUp() {
23 | this.solaceHealthIndicator.healthUp();
24 | assertEquals(this.solaceHealthIndicator.health(), Health.up().build());
25 | }
26 |
27 | @Test
28 | void healthReconnecting() {
29 | this.solaceHealthIndicator.healthReconnecting(null);
30 | assertEquals(this.solaceHealthIndicator.health(), Health.status("RECONNECTING").build());
31 | }
32 |
33 | @Test
34 | void healthDown() {
35 | this.solaceHealthIndicator.healthDown(null);
36 | assertEquals(this.solaceHealthIndicator.health(), Health.down().build());
37 | }
38 |
39 | @Test
40 | void addFlowEventDetails() {
41 | // as SessionEventArgs constructor has package level access modifier, we have to test with FlowEventArgs only
42 | FlowEventArgs flowEventArgs = new FlowEventArgs(FlowEvent.FLOW_DOWN, "String_infoStr",
43 | new Exception("Test Exception"), 500);
44 | Health health = this.solaceHealthIndicator.addEventDetails(Health.down(),flowEventArgs).build();
45 |
46 | assertEquals(health.getStatus(), Status.DOWN);
47 | assertEquals(health.getDetails().get("error"), "java.lang.Exception: Test Exception");
48 | assertEquals(health.getDetails().get("responseCode"), 500);
49 | }
50 |
51 | @Test
52 | void getHealth() {
53 | this.solaceHealthIndicator.setHealth(Health.up().build());
54 | assertEquals(this.solaceHealthIndicator.health(), Health.up().build());
55 | }
56 |
57 | @Test
58 | void setHealth() {
59 | this.solaceHealthIndicator.setHealth(Health.down().build());
60 | assertEquals(this.solaceHealthIndicator.health(), Health.down().build());
61 | }
62 | }
--------------------------------------------------------------------------------
/solace-spring-cloud-stream-binder/solace-spring-cloud-stream-binder-core/src/test/java/com/solace/spring/cloud/stream/binder/inbound/InboundXMLMessageListenerTest.java:
--------------------------------------------------------------------------------
1 | package com.solace.spring.cloud.stream.binder.inbound;
2 |
3 | import com.solace.spring.cloud.stream.binder.util.FlowReceiverContainer;
4 | import com.solace.spring.cloud.stream.binder.util.UnboundFlowReceiverContainerException;
5 | import com.solacesystems.jcsmp.JCSMPException;
6 | import com.solacesystems.jcsmp.StaleSessionException;
7 | import org.junit.jupiter.api.Test;
8 | import org.junit.jupiter.api.extension.ExtendWith;
9 | import org.mockito.Mock;
10 | import org.mockito.Mockito;
11 | import org.mockito.junit.jupiter.MockitoExtension;
12 | import org.springframework.boot.test.system.CapturedOutput;
13 | import org.springframework.boot.test.system.OutputCaptureExtension;
14 | import org.springframework.cloud.stream.provisioning.ConsumerDestination;
15 |
16 | import static org.assertj.core.api.Assertions.assertThat;
17 | import static org.mockito.Mockito.verify;
18 | import static org.mockito.Mockito.when;
19 |
20 | @ExtendWith(MockitoExtension.class)
21 | @ExtendWith(OutputCaptureExtension.class)
22 | public class InboundXMLMessageListenerTest {
23 |
24 | @Mock
25 | private ConsumerDestination consumerDestination;
26 |
27 | @Test
28 | public void testListenerIsStoppedOnStaleSessionException(@Mock FlowReceiverContainer flowReceiverContainer, CapturedOutput output)
29 | throws UnboundFlowReceiverContainerException, JCSMPException {
30 |
31 | when(flowReceiverContainer.receive(Mockito.anyInt()))
32 | .thenThrow(new StaleSessionException("Session has become stale", new JCSMPException("Specific JCSMP exception")));
33 |
34 | BasicInboundXMLMessageListener inboundXMLMessageListener = new BasicInboundXMLMessageListener(
35 | flowReceiverContainer, consumerDestination, null, null, null, null, null, null,
36 | null, null, false);
37 |
38 | inboundXMLMessageListener.run();
39 |
40 | assertThat(output)
41 | .contains("Session has lost connection")
42 | .contains("Closing flow receiver to destination");
43 |
44 | verify(flowReceiverContainer).unbind();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/solace-spring-cloud-stream-binder/solace-spring-cloud-stream-binder-core/src/test/java/com/solace/spring/cloud/stream/binder/meter/SolaceMeterAccessorTest.java:
--------------------------------------------------------------------------------
1 | package com.solace.spring.cloud.stream.binder.meter;
2 |
3 | import com.solacesystems.jcsmp.BytesMessage;
4 | import com.solacesystems.jcsmp.JCSMPFactory;
5 | import org.junit.jupiter.api.Test;
6 | import org.junit.jupiter.api.extension.ExtendWith;
7 | import org.mockito.Mock;
8 | import org.mockito.Mockito;
9 | import org.mockito.junit.jupiter.MockitoExtension;
10 |
11 | @ExtendWith(MockitoExtension.class)
12 | public class SolaceMeterAccessorTest {
13 | @Test
14 | public void testRecordMessage(@Mock SolaceMessageMeterBinder messageMeterBinder) {
15 | SolaceMeterAccessor solaceMeterAccessor = new SolaceMeterAccessor(messageMeterBinder);
16 | String bindingName = "test-binding";
17 | BytesMessage message = JCSMPFactory.onlyInstance().createMessage(BytesMessage.class);
18 |
19 | solaceMeterAccessor.recordMessage(bindingName, message);
20 | Mockito.verify(messageMeterBinder).recordMessage(bindingName, message);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/solace-spring-cloud-stream-binder/solace-spring-cloud-stream-binder-core/src/test/java/com/solace/spring/cloud/stream/binder/properties/SmfMessageWriterPropertiesTest.java:
--------------------------------------------------------------------------------
1 | package com.solace.spring.cloud.stream.binder.properties;
2 |
3 | import com.solace.spring.cloud.stream.binder.util.SmfMessageHeaderWriteCompatibility;
4 | import com.solace.spring.cloud.stream.binder.util.SmfMessagePayloadWriteCompatibility;
5 | import org.junitpioneer.jupiter.cartesian.CartesianTest;
6 | import org.junitpioneer.jupiter.cartesian.CartesianTest.Values;
7 |
8 | import static org.assertj.core.api.Assertions.assertThat;
9 |
10 | class SmfMessageWriterPropertiesTest {
11 | @CartesianTest
12 | void testCreateFromSolaceProducerProperties(@Values(booleans = {false, true}) boolean defaultValues) {
13 | SolaceProducerProperties producerProperties = new SolaceProducerProperties();
14 |
15 | if (!defaultValues) {
16 | producerProperties.getHeaderExclusions().add("foobar");
17 | producerProperties.setHeaderTypeCompatibility(SmfMessageHeaderWriteCompatibility.NATIVE_ONLY);
18 | producerProperties.setPayloadTypeCompatibility(SmfMessagePayloadWriteCompatibility.NATIVE_ONLY);
19 | producerProperties.setNonserializableHeaderConvertToString(true);
20 | }
21 |
22 | SmfMessageWriterProperties smfMessageWriterProperties = new SmfMessageWriterProperties(producerProperties);
23 | assertThat(smfMessageWriterProperties.getHeaderExclusions())
24 | .containsExactlyInAnyOrderElementsOf(producerProperties.getHeaderExclusions());
25 | assertThat(smfMessageWriterProperties.getHeaderTypeCompatibility())
26 | .isSameAs(producerProperties.getHeaderTypeCompatibility());
27 | assertThat(smfMessageWriterProperties.getPayloadTypeCompatibility())
28 | .isSameAs(producerProperties.getPayloadTypeCompatibility());
29 | assertThat(smfMessageWriterProperties.isNonSerializableHeaderConvertToString())
30 | .isEqualTo(producerProperties.isNonserializableHeaderConvertToString());
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/solace-spring-cloud-stream-binder/solace-spring-cloud-stream-binder-core/src/test/java/com/solace/spring/cloud/stream/binder/properties/SolaceConsumerPropertiesTest.java:
--------------------------------------------------------------------------------
1 | package com.solace.spring.cloud.stream.binder.properties;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertEquals;
4 | import static org.junit.jupiter.api.Assertions.assertThrows;
5 | import static org.junit.jupiter.api.Assertions.assertTrue;
6 | import org.junit.jupiter.api.Test;
7 | import org.junit.jupiter.params.ParameterizedTest;
8 | import org.junit.jupiter.params.provider.ValueSource;
9 |
10 | public class SolaceConsumerPropertiesTest {
11 | @ParameterizedTest
12 | @ValueSource(ints = {1, 256})
13 | public void testSetBatchMaxSize(int batchMaxSize) {
14 | SolaceConsumerProperties consumerProperties = new SolaceConsumerProperties();
15 | consumerProperties.setBatchMaxSize(batchMaxSize);
16 | assertEquals(batchMaxSize, consumerProperties.getBatchMaxSize());
17 | }
18 |
19 | @ParameterizedTest
20 | @ValueSource(ints = {-1, 0})
21 | public void testFailSetBatchMaxSize(int batchMaxSize) {
22 | assertThrows(IllegalArgumentException.class, () -> new SolaceConsumerProperties()
23 | .setBatchMaxSize(batchMaxSize));
24 | }
25 |
26 | @ParameterizedTest
27 | @ValueSource(ints = {0, 1, 1000})
28 | public void testSetBatchTimeout(int batchTimeout) {
29 | SolaceConsumerProperties consumerProperties = new SolaceConsumerProperties();
30 | consumerProperties.setBatchTimeout(batchTimeout);
31 | assertEquals(batchTimeout, consumerProperties.getBatchTimeout());
32 | }
33 |
34 | @ParameterizedTest
35 | @ValueSource(ints = {-1})
36 | public void testFailSetBatchTimeout(int batchTimeout) {
37 | assertThrows(IllegalArgumentException.class, () -> new SolaceConsumerProperties()
38 | .setBatchTimeout(batchTimeout));
39 | }
40 |
41 | @Test
42 | void testDefaultHeaderExclusionsListIsEmpty() {
43 | assertTrue(new SolaceConsumerProperties().getHeaderExclusions().isEmpty());
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/solace-spring-cloud-stream-binder/solace-spring-cloud-stream-binder-core/src/test/java/com/solace/spring/cloud/stream/binder/test/junit/param/provider/SolaceSpringHeaderArgumentsProvider.java:
--------------------------------------------------------------------------------
1 | package com.solace.spring.cloud.stream.binder.test.junit.param.provider;
2 |
3 | import com.solace.spring.cloud.stream.binder.messaging.HeaderMeta;
4 | import com.solace.spring.cloud.stream.binder.messaging.SolaceBinderHeaderMeta;
5 | import com.solace.spring.cloud.stream.binder.messaging.SolaceBinderHeaders;
6 | import com.solace.spring.cloud.stream.binder.messaging.SolaceHeaderMeta;
7 | import com.solace.spring.cloud.stream.binder.messaging.SolaceHeaders;
8 | import org.junit.jupiter.api.extension.ExtensionContext;
9 | import org.junit.jupiter.params.provider.Arguments;
10 | import org.junit.jupiter.params.provider.ArgumentsProvider;
11 |
12 | import java.util.HashMap;
13 | import java.util.Map;
14 | import java.util.stream.Stream;
15 |
16 | public class SolaceSpringHeaderArgumentsProvider implements ArgumentsProvider {
17 | private static final Map, Map>> ARGS;
18 |
19 | static {
20 | ARGS = new HashMap<>();
21 | ARGS.put(SolaceHeaders.class, SolaceHeaderMeta.META);
22 | ARGS.put(SolaceBinderHeaders.class, SolaceBinderHeaderMeta.META);
23 | }
24 |
25 | @Override
26 | public Stream extends Arguments> provideArguments(ExtensionContext context) {
27 | return ARGS.entrySet().stream().map(e -> Arguments.of(e.getKey(), e.getValue()));
28 | }
29 |
30 | public static class ClassesOnly implements ArgumentsProvider {
31 | @Override
32 | public Stream extends Arguments> provideArguments(ExtensionContext context) {
33 | return ARGS.keySet().stream().map(Arguments::of);
34 | }
35 | }
36 |
37 | public static class MetaOnly implements ArgumentsProvider {
38 | @Override
39 | public Stream extends Arguments> provideArguments(ExtensionContext context) {
40 | return ARGS.values().stream().map(Arguments::of);
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/solace-spring-cloud-stream-binder/solace-spring-cloud-stream-binder-core/src/test/java/com/solace/spring/cloud/stream/binder/test/spring/BatchedMessageCollector.java:
--------------------------------------------------------------------------------
1 | package com.solace.spring.cloud.stream.binder.test.spring;
2 |
3 | import com.solace.spring.cloud.stream.binder.messaging.SolaceBinderHeaders;
4 | import org.springframework.integration.support.MessageBuilder;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 | import java.util.Map;
9 | import java.util.Set;
10 | import java.util.function.BiConsumer;
11 | import java.util.function.BinaryOperator;
12 | import java.util.function.Function;
13 | import java.util.function.Supplier;
14 | import java.util.stream.Collector;
15 |
16 | public class BatchedMessageCollector implements Collector>, MessageBuilder>> {
17 | private final Function getPayload;
18 | private final Function> getHeaders;
19 |
20 | public BatchedMessageCollector(Function getPayload, Function> getHeaders) {
21 | this.getPayload = getPayload;
22 | this.getHeaders = getHeaders;
23 | }
24 |
25 |
26 | @Override
27 | public Supplier>> supplier() {
28 | return () -> MessageBuilder.>withPayload(new ArrayList<>())
29 | .setHeader(SolaceBinderHeaders.BATCHED_HEADERS, new ArrayList