brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [14/50] brooklyn-server git commit: Fix HttpFeed so again reuses polls
Date Mon, 01 Feb 2016 17:49:00 GMT
Fix HttpFeed so again reuses polls

- If two sensors make the same http request (with just
  different post-processing on the result) then just poll
  once and pass the result to each.

  Was broken by switching to Supplier<URI> instead of just
  a simple URI, so hashcode/equals failed.

Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/0ea1a024
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/0ea1a024
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/0ea1a024

Branch: refs/heads/0.5.0
Commit: 0ea1a02443cd1dc54a934967d81169897dfb08eb
Parents: 64da3fc
Author: Aled Sage <aled.sage@gmail.com>
Authored: Tue Apr 9 14:26:10 2013 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Tue Apr 9 14:26:10 2013 +0100

----------------------------------------------------------------------
 .../java/brooklyn/event/feed/http/HttpFeed.java |  6 +--
 .../brooklyn/event/feed/http/HttpFeedTest.java  | 39 +++++++++++++++++++-
 2 files changed, 41 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/0ea1a024/core/src/main/java/brooklyn/event/feed/http/HttpFeed.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/event/feed/http/HttpFeed.java b/core/src/main/java/brooklyn/event/feed/http/HttpFeed.java
index 5872921..4133b58 100644
--- a/core/src/main/java/brooklyn/event/feed/http/HttpFeed.java
+++ b/core/src/main/java/brooklyn/event/feed/http/HttpFeed.java
@@ -34,11 +34,11 @@ import brooklyn.event.feed.AbstractFeed;
 import brooklyn.event.feed.AttributePollHandler;
 import brooklyn.event.feed.DelegatingPollHandler;
 import brooklyn.event.feed.Poller;
+import brooklyn.util.Suppliers2;
 import brooklyn.util.exceptions.Exceptions;
 
 import com.google.common.base.Objects;
 import com.google.common.base.Supplier;
-import com.google.common.base.Suppliers;
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
@@ -187,7 +187,7 @@ public class HttpFeed extends AbstractFeed {
         final byte[] body;
 
         private HttpPollIdentifier(String method, URI uri, Map<String,String> headers,
byte[] body) {
-            this(method, Suppliers.ofInstance(uri), headers, body);
+            this(method, Suppliers2.ofInstance(uri), headers, body);
         }
         private HttpPollIdentifier(String method, Supplier<URI> uriProvider, Map<String,String>
headers, byte[] body) {
             this.method = checkNotNull(method, "method").toLowerCase();
@@ -242,7 +242,7 @@ public class HttpFeed extends AbstractFeed {
                     throw new IllegalStateException("Not permitted to supply baseUri and
baseUriProvider");
                 Map<String,String> baseUriVars = ImmutableMap.copyOf(checkNotNull(builder.baseUriVars,
"baseUriVars"));
                 URI uri = config.buildUri(builder.baseUri, baseUriVars);
-                baseUriProvider = Suppliers.ofInstance(uri);
+                baseUriProvider = Suppliers2.ofInstance(uri);
             } else if (!builder.baseUriVars.isEmpty()) {
                 throw new IllegalStateException("Not permitted to supply URI vars when using
a URI provider");
             }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/0ea1a024/core/src/test/java/brooklyn/event/feed/http/HttpFeedTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/event/feed/http/HttpFeedTest.java b/core/src/test/java/brooklyn/event/feed/http/HttpFeedTest.java
index 5da0893..d1eeab7 100644
--- a/core/src/test/java/brooklyn/event/feed/http/HttpFeedTest.java
+++ b/core/src/test/java/brooklyn/event/feed/http/HttpFeedTest.java
@@ -46,7 +46,10 @@ public class HttpFeedTest {
     
     private MockWebServer server;
     private URL baseUrl;
-    
+
+    private MockWebServer server2;
+    private URL baseUrl2;
+
     private Location loc;
     private TestApplication app;
     private EntityLocal entity;
@@ -61,6 +64,13 @@ public class HttpFeedTest {
         server.play();
         baseUrl = server.getUrl("/");
 
+        server2 = new MockWebServer();
+        for (int i = 0; i < 100; i++) {
+            server2.enqueue(new MockResponse().setResponseCode(200).addHeader("content-type:
application/json").setBody(""+i));
+        }
+        server2.play();
+        baseUrl2 = server2.getUrl("/");
+
         loc = new LocalhostMachineProvisioningLocation();
         app = ApplicationBuilder.newManagedApp(TestApplication.class);
         entity = app.createAndManageChild(EntitySpecs.spec(TestEntity.class));
@@ -71,6 +81,7 @@ public class HttpFeedTest {
     public void tearDown() throws Exception {
         if (feed != null) feed.stop();
         if (server != null) server.shutdown();
+        if (server2 != null) server2.shutdown();
         if (app != null) Entities.destroyAll(app);
         feed = null;
     }
@@ -204,4 +215,30 @@ public class HttpFeedTest {
                 return null;
             }});
     }
+    
+    @Test
+    public void testPollSharedByMultipleSensors() throws Exception {
+        long bigPeriod = 60*1000;
+        final BasicAttributeSensor<String> attribute1 = new BasicAttributeSensor<String>(String.class,
"attrib1", "");
+        final BasicAttributeSensor<String> attribute2 = new BasicAttributeSensor<String>(String.class,
"attrib2", "");
+
+        feed = HttpFeed.builder()
+                .entity(entity)
+                .baseUrl(baseUrl2)
+                .period(bigPeriod)
+                .poll(new HttpPollConfig<String>(attribute1)
+                        .onSuccess(HttpValueFunctions.stringContentsFunction()))
+                .poll(new HttpPollConfig<String>(attribute2)
+                        .onSuccess(HttpValueFunctions.stringContentsFunction()))
+                .build();
+        
+        Asserts.succeedsEventually(MutableMap.of("timeout", TIMEOUT_MS), new Runnable() {
+           public void run() {
+               String val1 = entity.getAttribute(attribute1);
+               String val2 = entity.getAttribute(attribute2);
+               assertEquals(val1, "0", "attrib1="+val1+"; attrib2="+val2);
+               assertEquals(val2, "0", "attrib1="+val1+"; attrib2="+val2);
+           }
+        });
+    }
 }


Mime
View raw message