This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git


The following commit(s) were added to refs/heads/master by this push:
     new 31f3537  fix tests broken by change in sensor coercion/logging
31f3537 is described below

commit 31f3537b6308c63a591bf8f4b7bb6c9c86c5c81b
Author: Alex Heneveld <[email protected]>
AuthorDate: Tue Dec 8 01:50:22 2020 +0000

    fix tests broken by change in sensor coercion/logging
---
 .../java/org/apache/brooklyn/core/feed/Poller.java  |  6 +++---
 .../core/sensor/http/HttpRequestSensor.java         | 21 +++++++++++++--------
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/core/src/main/java/org/apache/brooklyn/core/feed/Poller.java 
b/core/src/main/java/org/apache/brooklyn/core/feed/Poller.java
index 581c865..ce12a0f 100644
--- a/core/src/main/java/org/apache/brooklyn/core/feed/Poller.java
+++ b/core/src/main/java/org/apache/brooklyn/core/feed/Poller.java
@@ -72,17 +72,17 @@ public class Poller<V> {
                 public void run() {
                     try {
                         V val = job.call();
-                        loggedPreviousException = false;
                         if (handler.checkSuccess(val)) {
                             handler.onSuccess(val);
                         } else {
                             handler.onFailure(val);
                         }
+                        loggedPreviousException = false;
                     } catch (Exception e) {
                         if (loggedPreviousException) {
-                            if (log.isTraceEnabled()) log.trace("PollJob for 
{}, repeated consecutive failures, handling {} using {}", new Object[] {job, e, 
handler});
+                            if (log.isTraceEnabled()) log.trace("PollJob for 
{}, repeated consecutive failures, handling {} using {}", job, e, handler);
                         } else {
-                            if (log.isDebugEnabled()) log.debug("PollJob for 
{} handling {} using {}", new Object[] {job, e, handler}, e);
+                            if (log.isDebugEnabled()) log.debug("PollJob for 
{}, repeated consecutive failures, handling {} using {}", job, e, handler);
                             loggedPreviousException = true;
                         }
                         handler.onException(e);
diff --git 
a/core/src/main/java/org/apache/brooklyn/core/sensor/http/HttpRequestSensor.java
 
b/core/src/main/java/org/apache/brooklyn/core/sensor/http/HttpRequestSensor.java
index 2c1c4ea..4b66d17 100644
--- 
a/core/src/main/java/org/apache/brooklyn/core/sensor/http/HttpRequestSensor.java
+++ 
b/core/src/main/java/org/apache/brooklyn/core/sensor/http/HttpRequestSensor.java
@@ -119,14 +119,7 @@ public final class HttpRequestSensor<T> extends 
AbstractAddSensorFeed<T> {
                 // if sensor type was not set (default string) but the type is 
not a string/primitive, 
                 // then convert it to a json string (otherwise it just makes 
an error).
                 // (TODO perhaps the default type shouldn't be string for this 
initializer?!)
-                successFunction = (Function) 
Functionals.chain(successFunction, 
-                    x -> {
-                        try {
-                            return x instanceof Map || x instanceof Collection 
? new ObjectMapper().writeValueAsString(x) : x;
-                        } catch (JsonProcessingException e) {
-                            throw Exceptions.propagate(e);
-                        }
-                    } );
+                successFunction = (Function) 
Functionals.chain(successFunction, new ToJsonStringForCollections());
             }
         }
         
@@ -153,6 +146,18 @@ public final class HttpRequestSensor<T> extends 
AbstractAddSensorFeed<T> {
         entity.addFeed(feed);
     }
 
+    // lambda becomes null after persistence (odd); say introduce a proper 
class
+    static class ToJsonStringForCollections implements Function<Object,Object> 
{
+        @Override
+        public Object apply(Object x) {
+            try {
+                return x instanceof Map || x instanceof Collection ? new 
ObjectMapper().writeValueAsString(x) : x;
+            } catch (JsonProcessingException e) {
+                throw Exceptions.propagate(e);
+            }
+        }
+    }
+
     // TODO this will cause `allConfig` to be persisted inside the 
UriSupplier, which is not ideal.
     // However, it's hard to avoid, given we don't know what config is needed 
to later resolve the URI.
     static class UriSupplier implements Supplier<URI> {

Reply via email to