jeremyross commented on code in PR #14778:
URL: https://github.com/apache/camel/pull/14778#discussion_r1674952542


##########
components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/internal/streaming/SubscriptionHelperManualIT.java:
##########
@@ -285,14 +293,70 @@ void shouldResubscribeOnConnectionFailures() throws 
InterruptedException {
                      + "]");
 
         // assert last message was received, recovery can take a bit
-        verify(consumer, 
timeout(10000)).processMessage(any(ClientSessionChannel.class),
+        verify(consumer, 
timeout(15000)).processMessage(any(ClientSessionChannel.class),
                 
messageForAccountCreationWithName("shouldResubscribeOnConnectionFailures 2"));
 
         verify(consumer, atLeastOnce()).getEndpoint();
         verify(consumer, atLeastOnce()).getTopicName();
         verifyNoMoreInteractions(consumer);
     }
 
+    @Test
+    void shouldResubscribeOnSubscriptionFailure() {
+        var subscribeAttempts = new AtomicInteger(0);
+        subscription.start();
+        subscription.client.getChannel("/meta/subscribe").addListener(
+                (MessageListener) (clientSessionChannel, message) -> 
subscribeAttempts.incrementAndGet());
+        var endpoint = mock(SalesforceEndpoint.class, 
"shouldResubscribeOnSubscriptionFailure:endpoint");
+        when(endpoint.getConfiguration()).thenReturn(config);
+        when(endpoint.getComponent()).thenReturn(salesforce);
+        when(endpoint.getTopicName()).thenReturn("Contact");
+        var consumer = toUnsubscribe = mock(StreamingApiConsumer.class, 
"shouldResubscribeOnSubscriptionFailure:consumer");
+        when(consumer.getTopicName()).thenReturn("Contact");
+        when(consumer.getEndpoint()).thenReturn(endpoint);
+
+        server.replyTo("POST", "/cometd/" + 
SalesforceEndpointConfig.DEFAULT_VERSION + "/subscribe",
+                s -> s.contains("/topic/Contact"),
+                """
+                        [
+                          {
+                            "clientId": "5ra4927ikfky6cb12juthkpofeu8",
+                            "channel": "/meta/subscribe",
+                            "id": "$id",
+                            "subscription": "/topic/Contact",
+                            "successful": false
+                          }
+                        ]""");
+        subscription.subscribe("Contact", consumer);
+        await().atMost(10, SECONDS).until(() -> subscribeAttempts.get() == 1);
+        
assertThat(subscription.client.getChannel("/topic/Contact").getSubscribers(), 
hasSize(0));
+
+        server.reset();
+        server.replyTo("POST", "/cometd/" + 
SalesforceEndpointConfig.DEFAULT_VERSION + "/subscribe",
+                s -> s.contains("/topic/Contact"),
+                """
+                        [
+                          {
+                            "clientId": "5ra4927ikfky6cb12juthkpofeu8",
+                            "channel": "/meta/subscribe",
+                            "id": "$id",
+                            "subscription": "/topic/Contact",
+                            "successful": true
+                          }
+                        ]""");
+        messages.add("""
+                [
+                  {
+                    "clientId": "5ra4927ikfky6cb12juthkpofeu8",
+                    "channel": "/meta/connect",
+                    "id": "$id",
+                    "successful": true
+                  }
+                ]""");
+        await().atMost(10, SECONDS).until(() -> subscribeAttempts.get() == 2);
+        
assertThat(subscription.client.getChannel("/topic/Contact").getSubscribers(), 
hasSize(1));
+    }
+
     @Test
     void shouldResubscribeOnHelperRestart() {

Review Comment:
   This test seems flaky. Fails for me when the whole test class is run, but 
succeeds if only shouldResubscribeOnHelperRestart is run.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to