summaryrefslogtreecommitdiffstats
path: root/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/CollectingMetric.java
diff options
context:
space:
mode:
Diffstat (limited to 'vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/CollectingMetric.java')
-rw-r--r--vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/CollectingMetric.java38
1 files changed, 38 insertions, 0 deletions
diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/CollectingMetric.java b/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/CollectingMetric.java
new file mode 100644
index 00000000000..1b9a5eb6381
--- /dev/null
+++ b/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/CollectingMetric.java
@@ -0,0 +1,38 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.http.server;
+
+import com.yahoo.jdisc.Metric;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * @author ollivir
+ */
+public final class CollectingMetric implements Metric {
+ private final Context DUMMY_CONTEXT = new Context() {};
+ private final Map<String, AtomicLong> values = new ConcurrentHashMap<>();
+
+ public CollectingMetric() {}
+
+ @Override
+ public void set(String key, Number val, Context ctx) {
+ values.computeIfAbsent(key, ignored -> new AtomicLong(0)).set(val.longValue());
+ }
+
+ @Override
+ public void add(String key, Number val, Context ctx) {
+ values.computeIfAbsent(key, ignored -> new AtomicLong(0)).addAndGet(val.longValue());
+ }
+
+ public long get(String key) {
+ return Optional.ofNullable(values.get(key)).map(AtomicLong::get).orElse(0L);
+ }
+
+ @Override
+ public Context createContext(Map<String, ?> properties) {
+ return DUMMY_CONTEXT;
+ }
+}