Skip to content

Commit

Permalink
Updated GaugeHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
tsegismont committed Jul 20, 2015
1 parent e3a3205 commit f27e003
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public void addDataForMetric(
@ApiParam(value = "List of datapoints containing timestamp and value", required = true)
List<GaugeDataPoint> data
) {
if (data.isEmpty()) {
if (data == null || data.isEmpty()) {
asyncResponse.resume(emptyPayload());
} else {
Metric<Double> metric = new Metric<>(tenantId, GAUGE, new MetricId(id), requestToGaugeDataPoints(data));
Expand All @@ -222,7 +222,7 @@ public void addDataForMetric(
public void addGaugeData(@Suspended final AsyncResponse asyncResponse,
@ApiParam(value = "List of metrics", required = true) List<Gauge> gauges) {

if (gauges.isEmpty()) {
if (gauges == null || gauges.isEmpty()) {
asyncResponse.resume(emptyPayload());
} else {
Observable<Metric<Double>> metrics = requestToGauges(tenantId, gauges);
Expand Down Expand Up @@ -410,12 +410,19 @@ public void findTaggedGaugeData(
@POST
@Path("/{id}/tag")
@ApiOperation(value = "Add or update gauge metric's tags.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Tags were modified successfully."),
@ApiResponse(code = 500, message = "Processing tags failed") })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Tags were modified successfully."),
@ApiResponse(code = 400, message = "Missing or invalid payload", response = ApiError.class),
@ApiResponse(code = 500, message = "Processing tags failed")
})
public void tagGaugeData(
@Suspended final AsyncResponse asyncResponse,
@PathParam("id") final String id, @ApiParam(required = true) TagRequest params
) {
if (params == null) {
asyncResponse.resume(emptyPayload());
return;
}
Observable<Void> resultSetObservable;
Metric<Double> metric = new Metric<>(tenantId, GAUGE, new MetricId(id));
if (params.getTimestamp() != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* Copyright 2014-2015 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed 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 org.hawkular.metrics.rest

import org.junit.Test

import static org.junit.Assert.assertEquals

/**
* @author Thomas Segismont
*/
class GaugesITest extends RESTTest {

@Test
void shouldNotCreateMetricWithEmptyPayload() {
def tenantId = nextTenantId()

badPost(path: "gauges", headers: [(tenantHeaderName): tenantId], body: "" /* Empty Body */) { exception ->
assertEquals(400, exception.response.status)
}
}

@Test
void shouldNotAddDataForMetricWithEmptyPayload() {
def tenantId = nextTenantId()

badPost(path: "gauges/pimpo/data", headers: [(tenantHeaderName): tenantId],
body: "" /* Empty Body */) { exception ->
assertEquals(400, exception.response.status)
}

badPost(path: "gauges/pimpo/data", headers: [(tenantHeaderName): tenantId],
body: [] /* Empty List */) { exception ->
assertEquals(400, exception.response.status)
}
}

@Test
void shouldNotAddGaugeDataWithEmptyPayload() {
def tenantId = nextTenantId()

badPost(path: "gauges/data", headers: [(tenantHeaderName): tenantId],
body: "" /* Empty Body */) { exception ->
assertEquals(400, exception.response.status)
}

badPost(path: "gauges/data", headers: [(tenantHeaderName): tenantId],
body: [] /* Empty List */) { exception ->
assertEquals(400, exception.response.status)
}
}

@Test
void shouldNotTagGaugeDataWithEmptyPayload() {
def tenantId = nextTenantId()

badPost(path: "gauges/pimpo/tag", headers: [(tenantHeaderName): tenantId],
body: "" /* Empty Body */) { exception ->
assertEquals(400, exception.response.status)
}
}

}

0 comments on commit f27e003

Please sign in to comment.