You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/03/06 03:58:22 UTC

[GitHub] dubeejw closed pull request #255: check for 204 before attempting to fetch response json

dubeejw closed pull request #255: check for 204 before attempting to fetch response json
URL: https://github.com/apache/incubator-openwhisk-package-kafka/pull/255
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/provider/consumer.py b/provider/consumer.py
index a8427d0..f9aaef2 100644
--- a/provider/consumer.py
+++ b/provider/consumer.py
@@ -354,11 +354,15 @@ def __fireTrigger(self, messages):
                     # Manually commit offset if the trigger was fired successfully. Retry firing the trigger
                     # for a select set of status codes
                     if status_code in range(200, 300):
-                        response_json = response.json()
-                        if 'activationId' in response_json and response_json['activationId'] is not None:
-                            logging.info("[{}] Fired trigger with activation {}".format(self.trigger, response_json['activationId']))
-                        else:
+                        if status_code == 204:
                             logging.info("[{}] Successfully fired trigger".format(self.trigger))
+                        else:
+                            response_json = response.json()
+                            if 'activationId' in response_json and response_json['activationId'] is not None:
+                                logging.info("[{}] Fired trigger with activation {}".format(self.trigger, response_json['activationId']))
+                            else:
+                                logging.info("[{}] Successfully fired trigger".format(self.trigger))
+                        # the consumer may have consumed messages that did not make it into the messages array.
                         # the consumer may have consumed messages that did not make it into the messages array.
                         # be sure to only commit to the messages that were actually fired.
                         self.consumer.commit(offsets=self.__getOffsetList(messages), async=False)
diff --git a/tests/src/test/scala/system/packages/MessageHubFeedTests.scala b/tests/src/test/scala/system/packages/MessageHubFeedTests.scala
index 9cd1e2f..1b8db83 100644
--- a/tests/src/test/scala/system/packages/MessageHubFeedTests.scala
+++ b/tests/src/test/scala/system/packages/MessageHubFeedTests.scala
@@ -44,7 +44,6 @@ import ActionHelper._
 
 import java.util.Base64
 import java.nio.charset.StandardCharsets
-import java.time.{Clock, Instant}
 
 import whisk.utils.retry
 
@@ -414,8 +413,6 @@ class MessageHubFeedTests
       println("Giving the consumer a moment to get ready")
       Thread.sleep(consumerInitTime)
 
-      val first = Instant.now(Clock.systemUTC())
-
       println("Producing a message")
       withActivation(wsk.activation, wsk.action.invoke(s"$messagingPackage/$messageHubProduce", Map(
         "user" -> kafkaUtils.getAsJson("user"),
@@ -428,7 +425,7 @@ class MessageHubFeedTests
         _.response.success shouldBe true
       }
 
-      checkForActivations(triggerName, first, topic, key, currentTime)
+      checkForActivations(1, triggerName, topic, key, currentTime)
 
       println("Updating trigger")
 
@@ -446,7 +443,6 @@ class MessageHubFeedTests
       println("Giving the consumer a moment to get ready")
       Thread.sleep(consumerInitTime)
 
-      val second = Instant.now(Clock.systemUTC())
       val encodedCurrentTime = Base64.getEncoder.encodeToString(currentTime.getBytes(StandardCharsets.UTF_8))
 
       println("Producing a message")
@@ -461,7 +457,7 @@ class MessageHubFeedTests
         _.response.success shouldBe true
       }
 
-      checkForActivations(triggerName, second, topic, key, encodedCurrentTime)
+      checkForActivations(2, triggerName, topic, key, encodedCurrentTime)
   }
 
   def createTrigger(assetHelper: AssetCleaner, name: String, parameters: Map[String, spray.json.JsValue]) = {
@@ -477,10 +473,10 @@ class MessageHubFeedTests
     }
   }
 
-  def checkForActivations(triggerName: String, since: Instant, topic: String, key: String, value: String) = {
+  def checkForActivations(numActivations: Int, triggerName: String, topic: String, key: String, value: String) = {
     retry({
       println("Polling for activations")
-      val activations = wsk.activation.pollFor(N = 1, Some(triggerName), since = Some(since), retries = maxRetries)
+      val activations = wsk.activation.pollFor(N = numActivations, Some(triggerName), retries = maxRetries)
       assert(activations.nonEmpty)
 
       println("Validating content of activation(s)")


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services