brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [1/2] git commit: rat fix, support period, and fix broken test (patching #48)
Date Fri, 18 Jul 2014 17:15:25 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 82f850665 -> cfb7a0cd8


rat fix, support period, and fix broken test (patching #48)


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

Branch: refs/heads/master
Commit: cfb7a0cd8f5e09117d0deb2321a0e32d4d37d0fc
Parents: 33aa6b6
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Fri Jul 18 13:00:00 2014 -0400
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Fri Jul 18 13:13:26 2014 -0400

----------------------------------------------------------------------
 .../brooklyn/entity/effector/AddSensor.java     |  1 +
 .../event/feed/http/JsonFunctionsTest.java      | 14 +++++++--
 .../entity/software/http/HttpRequestSensor.java | 23 +++++++++++++-
 .../software/http/HttpRequestSensorTest.java    | 33 +++++++++++++++-----
 4 files changed, 60 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cfb7a0cd/core/src/main/java/brooklyn/entity/effector/AddSensor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/effector/AddSensor.java b/core/src/main/java/brooklyn/entity/effector/AddSensor.java
index 8043c64..cdaa5df 100644
--- a/core/src/main/java/brooklyn/entity/effector/AddSensor.java
+++ b/core/src/main/java/brooklyn/entity/effector/AddSensor.java
@@ -59,6 +59,7 @@ public class AddSensor<RT,T extends Sensor<RT>> implements EntityInitializer
{
         return Sensors.newSensor(type, name);
     }
 
+    @SuppressWarnings("unchecked")
     public static <T> AttributeSensor<T> newSensor(ConfigBag params) {
         String name = Preconditions.checkNotNull(params.get(SENSOR_NAME), "name must be supplied
when defining a sensor");
         String className = getFullClassName(params.get(SENSOR_TYPE));

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cfb7a0cd/core/src/test/java/brooklyn/event/feed/http/JsonFunctionsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/event/feed/http/JsonFunctionsTest.java b/core/src/test/java/brooklyn/event/feed/http/JsonFunctionsTest.java
index 5aaa47e..e0140a6 100644
--- a/core/src/test/java/brooklyn/event/feed/http/JsonFunctionsTest.java
+++ b/core/src/test/java/brooklyn/event/feed/http/JsonFunctionsTest.java
@@ -31,6 +31,7 @@ import brooklyn.util.guava.Maybe;
 
 import com.google.gson.JsonElement;
 import com.google.gson.JsonParser;
+import com.jayway.jsonpath.PathNotFoundException;
 
 public class JsonFunctionsTest {
 
@@ -115,8 +116,15 @@ public class JsonFunctionsTest {
     }
 
     @Test
-    public void testGetPathWrong(){
-        Object obj = JsonFunctions.getPath("$.europe.spain.malaga").apply(europeMap());
-        Assert.assertNull(obj);
+    public void testGetMissingPathIsNullOrThrows(){
+        try {
+            // TODO is there a way to force this to return null if not found?
+            // for me (Alex) it throws but for others it seems to return null
+            Object obj = JsonFunctions.getPath("$.europe.spain.malaga").apply(europeMap());
+            Assert.assertNull(obj);
+        } catch (PathNotFoundException e) {
+            // not unexpected
+        }
     }
+    
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cfb7a0cd/software/base/src/main/java/brooklyn/entity/software/http/HttpRequestSensor.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/software/http/HttpRequestSensor.java
b/software/base/src/main/java/brooklyn/entity/software/http/HttpRequestSensor.java
index c16a739..cf78126 100644
--- a/software/base/src/main/java/brooklyn/entity/software/http/HttpRequestSensor.java
+++ b/software/base/src/main/java/brooklyn/entity/software/http/HttpRequestSensor.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package brooklyn.entity.software.http;
 
 import brooklyn.config.ConfigKey;
@@ -47,8 +65,11 @@ public final class HttpRequestSensor<T> extends AddSensor<T, AttributeSensor<T>>
     public void apply(final EntityLocal entity) {
         super.apply(entity);
 
-        Duration period = Duration.ONE_SECOND;
+        Duration period = entity.getConfig(SENSOR_PERIOD);
+        if (period==null) period = Duration.ONE_SECOND;
 
+        log.debug("Adding sensor "+sensor+" to "+entity+" polling "+uri+" for "+jsonPath);
+        
         HttpPollConfig<T> pollConfig = new HttpPollConfig<T>(sensor)
                 .checkSuccess(HttpValueFunctions.responseCodeEquals(200))
                 .onFailureOrException(Functions.constant((T) null))

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cfb7a0cd/software/base/src/test/java/brooklyn/entity/software/http/HttpRequestSensorTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/brooklyn/entity/software/http/HttpRequestSensorTest.java
b/software/base/src/test/java/brooklyn/entity/software/http/HttpRequestSensorTest.java
index 5f29e5d..8c796da 100644
--- a/software/base/src/test/java/brooklyn/entity/software/http/HttpRequestSensorTest.java
+++ b/software/base/src/test/java/brooklyn/entity/software/http/HttpRequestSensorTest.java
@@ -1,6 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package brooklyn.entity.software.http;
 
-import brooklyn.entity.basic.ApplicationBuilder;
+import static org.testng.Assert.assertEquals;
+
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
 import brooklyn.entity.basic.Attributes;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.EntityLocal;
@@ -12,12 +35,8 @@ import brooklyn.test.EntityTestUtils;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.config.ConfigBag;
-import com.google.common.collect.ImmutableList;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
 
-import static org.testng.Assert.assertEquals;
+import com.google.common.collect.ImmutableList;
 
 public class HttpRequestSensorTest {
     final static AttributeSensor<String> SENSOR_STRING = Sensors.newStringSensor("aString");
@@ -28,7 +47,7 @@ public class HttpRequestSensorTest {
 
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+        app = TestApplication.Factory.newManagedInstanceForTests();
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).location(app.newLocalhostProvisioningLocation().obtain()));
         app.start(ImmutableList.<Location>of());
     }


Mime
View raw message