Align behaviour of in-memory and redis mult repos

The in-memory version has to force the incoming metric keys to
start with the group name. Redis doesn't have that restriction
but normally we expect both to be used in such a way that
the metric keys already match the prefix. In that case the two
repositories behave the same now in terms of set and get.
This commit is contained in:
Dave Syer
2014-05-22 15:35:47 +01:00
parent 0dca2dd978
commit 1fabfaa259
3 changed files with 7 additions and 11 deletions

View File

@@ -144,12 +144,8 @@ public class RedisMultiMetricRepository implements MultiMetricRepository {
}
private Metric<?> deserialize(String group, String redisKey, String v, Double value) {
String prefix = group;
if (!group.endsWith(".")) {
prefix = group + ".";
}
Date timestamp = new Date(Long.valueOf(v));
return new Metric<Double>(prefix + nameFor(redisKey), value, timestamp);
return new Metric<Double>(nameFor(redisKey), value, timestamp);
}
private String serialize(Metric<?> entity) {

View File

@@ -82,9 +82,9 @@ public class InMemoryPrefixMetricRepositoryTests {
@Test
public void incrementGroup() {
this.repository.increment("foo", new Delta<Number>("bar", 1));
this.repository.increment("foo", new Delta<Number>("bar", 2));
this.repository.increment("foo", new Delta<Number>("spam", 1));
this.repository.increment("foo", new Delta<Number>("foo.bar", 1));
this.repository.increment("foo", new Delta<Number>("foo.bar", 2));
this.repository.increment("foo", new Delta<Number>("foo.spam", 1));
Set<String> names = new HashSet<String>();
for (Metric<?> metric : this.repository.findAll("foo")) {
names.add(metric.getName());

View File

@@ -116,9 +116,9 @@ public class RedisMultiMetricRepositoryTests {
@Test
public void increment() {
this.repository.increment("foo", new Delta<Number>("bar", 1));
this.repository.increment("foo", new Delta<Number>("bar", 2));
this.repository.increment("foo", new Delta<Number>("spam", 1));
this.repository.increment("foo", new Delta<Number>("foo.bar", 1));
this.repository.increment("foo", new Delta<Number>("foo.bar", 2));
this.repository.increment("foo", new Delta<Number>("foo.spam", 1));
Metric<?> bar = null;
Set<String> names = new HashSet<String>();
for (Metric<?> metric : this.repository.findAll("foo")) {