blob: fb48b4455b51b9f1caf3dd2e8b8cfc145ec5f7b8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.jdisc.state;
import org.junit.Test;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.*;
public class MetricSnapshotTest {
/**
* Aggregate metrics are not cloned into new snapshot. In turn, a metric
* set with only aggregates will be added as an empty set if we do not
* filter these away at clone time. This test ensures that we do just that.
* If/when we start carrying aggregates across snapshots, this test will
* most likely be deprecated.
*/
@Test
public void emptyMetricSetNotAddedToClonedSnapshot() {
final StateMetricContext ctx = StateMetricContext.newInstance(null);
MetricSnapshot snapshot = new MetricSnapshot();
snapshot.add(ctx, "foo", 1234);
MetricSnapshot newSnapshot = snapshot.createSnapshot();
assertFalse(newSnapshot.iterator().hasNext());
}
@Test
public void testEquality() {
assertEquals(Collections.unmodifiableMap(new HashMap(0)).hashCode(), Collections.emptyMap().hashCode());
assertEquals(Collections.unmodifiableMap(new HashMap(0)), Collections.emptyMap());
}
@Test
public void testLookup() {
Map<Key, String> map = new HashMap<>();
map.put(new Key(), "a");
System.out.println("Lookup value after putting a: " + map.get(new Key()));
map.put(new Key(), "b");
System.out.println("Map content after putting b: ");
for (Map.Entry<Key, String> entry : map.entrySet())
System.out.println(" " + entry);
}
public static class Key {
@Override
public int hashCode() {
return 1;
}
@Override
public boolean equals(Object other) {
if (this == other) return true;
return false;
}
}
}
|