modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/MetricHandlerBean.java
| 10 +
modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/MetricsTest.java
| 56 ++++++++++
2 files changed, 63 insertions(+), 3 deletions(-)
New commits:
commit 038fc8ede73d595fec7b3b5cd2db28b8367052b6
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Tue Oct 29 21:25:30 2013 +0100
BZ 1024348 - Allow to find values that happen at startTime=endTime
(cherry picked from commit 9867a690d70346e01606440f53fc286d29d68a49)
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/MetricHandlerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/MetricHandlerBean.java
index fb927ec..b33db05 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/MetricHandlerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/MetricHandlerBean.java
@@ -663,6 +663,10 @@ public class MetricHandlerBean extends AbstractRestBean {
if (startTime < now - SEVEN_DAYS)
throw new IllegalArgumentException("(Computed) start time is older than
7 days");
+ if (startTime == endTime) {
+ endTime++; // add 1ms, as otherwise the backend fails to find a value at the
startTime
+ }
+
// Check if the schedule exists
obtainSchedule(scheduleId, false, DataType.MEASUREMENT);
@@ -885,9 +889,9 @@ public class MetricHandlerBean extends AbstractRestBean {
}
/**
- * Write the numeric data points to the output stream in JSON encoding
- * without creating tons of objects in the middle to have them marshalled
- * by JAX-RS
+ * Write the numeric data points to the output stream in the encoding
+ * requested from the mediaType without creating tons of objects in the
+ * middle to have them marshalled by JAX-RS
*/
private class RawNumericStreamingOutput implements StreamingOutput {
diff --git
a/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/MetricsTest.java
b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/MetricsTest.java
index 04bcef3..6e945a6 100644
---
a/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/MetricsTest.java
+++
b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/MetricsTest.java
@@ -342,6 +342,62 @@ public class MetricsTest extends AbstractBase {
}
+ /**
+ * Submit data points for arbitrary metrics, identified by
+ * their schedule ids. We want to exactly retrieve that one
+ * data point submitted
+ *
+ * @throws Exception on error
+ */
+ @Test
+ public void testPostGetRawData3() throws Exception {
+
+ long now = System.currentTimeMillis();
+
+ MDataPoint dataPoint = new MDataPoint();
+ dataPoint.setScheduleId(numericScheduleId);
+ dataPoint.setTimeStamp(now);
+ dataPoint.setValue(1.5);
+ List<MDataPoint> points = new ArrayList<MDataPoint>(1);
+ points.add(dataPoint);
+
+ given()
+ .header(acceptJson)
+ .contentType(ContentType.JSON)
+ .body(points)
+ .expect()
+ .statusCode(204)
+ .log().ifError()
+ .when()
+ .post("/metric/data/raw");
+
+ Response response =
+ given()
+ .header(acceptJson)
+ .pathParam("id", numericScheduleId)
+ .queryParam("startTime",now)
+ .queryParam("endTime",now)
+ .expect()
+ .statusCode(200)
+ .log().ifError()
+ .body("", not(emptyIterable()))
+ .when()
+ .get("/metric/data/{id}/raw");
+
+ List<Map<String,Object>> list = response.as(List.class);
+ assert list.size()>0 : "No data retrieved";
+
+ boolean found = false;
+ for (Map<String, Object> map : list) {
+ MDataPoint mp = new MDataPoint(map);
+ if (mp.equals(dataPoint))
+ found = true;
+ }
+ assert found;
+
+ }
+
+
@Test
public void testUpdateSchedule() throws Exception {
Show replies by date