Skip to content

Commit

Permalink
Fix test to work on Travis also and some small changes to MetricType …
Browse files Browse the repository at this point in the history
…handling
  • Loading branch information
Michael Burman committed Jul 8, 2015
1 parent 005de28 commit aeaafcf
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public void findMetrics(
allowableValues = "[gauge, availability, counter]")
@QueryParam("type") MetricType metricType,
@ApiParam(value = "List of tags", required = false) @QueryParam ("tags") Tags tags) {
if(metricType != null && !MetricType.userTypes().stream().filter(t -> metricType == t)
.findAny().isPresent()) {

if(metricType != null && !MetricType.userTypes().contains(metricType)) {
asyncResponse.resume(badRequest(new ApiError("Incorrect type param")));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@

import static com.google.common.base.Preconditions.checkArgument;

import java.util.Arrays;

import com.google.common.collect.ImmutableMap;
import java.util.List;
import java.util.Arrays;
import java.util.EnumSet;

/**
* An enumeration of the supported metric types.
Expand All @@ -37,6 +36,8 @@ public enum MetricType {
private int code;
private String text;

private static EnumSet<MetricType> userDefinableTypes = EnumSet.range(GAUGE, COUNTER);

MetricType(int code, String text) {
this.code = code;
this.text = text;
Expand Down Expand Up @@ -90,8 +91,7 @@ public static MetricType fromTextCode(String textCode) {
return type;
}

public static List<MetricType> userTypes() {
return Arrays.asList(Arrays.copyOf(MetricType.values(), 3));
public static EnumSet<MetricType> userTypes() {
return userDefinableTypes;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,21 @@ public interface MetricsService {

Observable<Metric> findMetric(String tenantId, MetricType type, MetricId id);

/**
* Returns tenant's metric definitions. The results can be filtered using a type.
*
* @param tenantId
* @param type If type is null, all user definable metric definitions are returned.
* @return
*/
Observable<Metric> findMetrics(String tenantId, MetricType type);

/**
* Returns tenant's metric definitions. The results can be filtered using a type and tags. Use findMetrics
* if you don't intend to use tags for filtering.
*
* @param tenantId
* @param tags
* @param tags Tag names and values that are used to filter definitions
* @param type Optional MetricType, if null is given all matching metrics are returned
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.hawkular.metrics.core.api;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertFalse;

import org.junit.Test;

Expand All @@ -28,8 +28,7 @@ public class MetricTypeTest {

@Test
public void testUserValues() {
MetricType.userTypes().stream().filter(metricType -> metricType == MetricType.COUNTER_RATE).forEach
(metricType -> fail("COUNTER_RATE is not user defined type"));
assertFalse("COUNTER_RATE is not user defined type", MetricType.userTypes().contains(MetricType.COUNTER_RATE));
assertEquals(3, MetricType.userTypes().size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package org.hawkular.metrics.rest

import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertNotNull
import static org.junit.Assert.assertTrue

import org.junit.Test

Expand Down Expand Up @@ -209,19 +210,19 @@ class TagsITest extends RESTTest {
query: [tags: "a22:22,b22:22,a1:A,d1:B"],
headers: [(tenantHeaderName): tenantId])
assertEquals(200, response.status)
assertEquals([
[
tenantId : tenantId,
id : 'A2',
tags : [a22: '22', b22: '22'],
dataRetention: 48
],
[
tenantId: tenantId,
id : 'N1',
tags : ['a1': 'A', 'd1': 'B']
]
], response.data)
assertTrue(response.data instanceof List)
assertEquals(response.data.size(), 2)
assertTrue(response.data.contains([
tenantId: tenantId,
id : 'N1',
tags : ['a1': 'A', 'd1': 'B']
]))
assertTrue(response.data.contains([
tenantId : tenantId,
id : 'A2',
tags : [a22: '22', b22: '22'],
dataRetention: 48
]))

// Fetch with tags & type
response = hawkularMetrics.get(path: "metrics",
Expand All @@ -230,8 +231,8 @@ class TagsITest extends RESTTest {
assertEquals(200, response.status)
assertEquals([[
tenantId: tenantId,
id : 'N1',
tags: ['a1': 'A', 'd1': 'B']
id : 'N1',
tags : ['a1': 'A', 'd1': 'B']
]], response.data)
}
}

0 comments on commit aeaafcf

Please sign in to comment.