|
16 | 16 | */
|
17 | 17 | package org.apache.camel.component.salesforce.internal.streaming;
|
18 | 18 |
|
| 19 | +import java.lang.reflect.Field; |
19 | 20 | import java.util.Collections;
|
20 | 21 | import java.util.HashMap;
|
21 | 22 | import java.util.Map;
|
|
28 | 29 | import org.apache.camel.component.salesforce.SalesforceLoginConfig;
|
29 | 30 | import org.apache.camel.component.salesforce.api.SalesforceException;
|
30 | 31 | import org.apache.camel.component.salesforce.internal.SalesforceSession;
|
| 32 | +import org.apache.camel.util.ReflectionHelper; |
31 | 33 | import org.cometd.client.BayeuxClient;
|
32 | 34 | import org.hamcrest.MatcherAssert;
|
33 | 35 | import org.junit.jupiter.api.Test;
|
34 | 36 |
|
| 37 | +import static org.apache.camel.component.salesforce.internal.streaming.SubscriptionHelper.REPLAY_EXTENSION; |
35 | 38 | import static org.apache.camel.component.salesforce.internal.streaming.SubscriptionHelper.determineReplayIdFor;
|
36 | 39 | import static org.assertj.core.api.Assertions.assertThat;
|
37 | 40 | import static org.cometd.client.transport.ClientTransport.MAX_NETWORK_DELAY_OPTION;
|
@@ -187,4 +190,38 @@ public void defaultLongPollingTimeoutShouldBeGreaterThanSalesforceTimeout() thro
|
187 | 190 | MatcherAssert.assertThat(longPollingTimeout, instanceOf(Integer.class));
|
188 | 191 | MatcherAssert.assertThat((Integer) longPollingTimeout, greaterThan(110000));
|
189 | 192 | }
|
| 193 | + |
| 194 | + @Test |
| 195 | + public void fallbackReplyId() throws Exception { |
| 196 | + final SalesforceEndpointConfig componentConfig = new SalesforceEndpointConfig(); |
| 197 | + componentConfig.setFallBackReplayId(-2L); |
| 198 | + |
| 199 | + final SalesforceEndpointConfig endpointConfig = new SalesforceEndpointConfig(); |
| 200 | + endpointConfig.setDefaultReplayId(-1L); |
| 201 | + endpointConfig.setInitialReplayIdMap(Collections.singletonMap("my-topic-1", 2L)); |
| 202 | + |
| 203 | + final SalesforceComponent component = mock(SalesforceComponent.class); |
| 204 | + when(component.getConfig()).thenReturn(componentConfig); |
| 205 | + |
| 206 | + final SalesforceEndpoint endpoint = mock(SalesforceEndpoint.class); |
| 207 | + when(endpoint.getReplayId()).thenReturn(null); |
| 208 | + when(endpoint.getComponent()).thenReturn(component); |
| 209 | + when(endpoint.getConfiguration()).thenReturn(endpointConfig); |
| 210 | + |
| 211 | + assertEquals(Optional.of(2L), determineReplayIdFor(endpoint, "my-topic-1"), |
| 212 | + "Expecting replayId for `my-topic-1` to be 2, from initial reply id map"); |
| 213 | + |
| 214 | + REPLAY_EXTENSION.setReplayIdIfAbsent("my-topic-1", 3L); |
| 215 | + REPLAY_EXTENSION.setReplayIdIfAbsent("my-topic-1", 4L); |
| 216 | + |
| 217 | + // should still be 3L |
| 218 | + Field f = REPLAY_EXTENSION.getClass().getDeclaredField("dataMap"); |
| 219 | + Map m = (Map) ReflectionHelper.getField(f, REPLAY_EXTENSION); |
| 220 | + assertEquals(3L, m.get("my-topic-1")); |
| 221 | + |
| 222 | + // there is some subscription error due to INVALID_REPLAY_ID_PATTERN so we force setting another reply id |
| 223 | + REPLAY_EXTENSION.setReplayId("my-topic-1", -2L); |
| 224 | + assertEquals(-2L, m.get("my-topic-1")); |
| 225 | + } |
| 226 | + |
190 | 227 | }
|
0 commit comments