-
Notifications
You must be signed in to change notification settings - Fork 362
Expand file tree
/
Copy pathBaseHashIdentityTest.java
More file actions
67 lines (53 loc) · 2.32 KB
/
Copy pathBaseHashIdentityTest.java
File metadata and controls
67 lines (53 loc) · 2.32 KB
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
63
64
65
66
67
package datadog.trace.api;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import datadog.trace.test.junit.utils.config.WithConfigExtension;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@ExtendWith(WithConfigExtension.class)
class BaseHashIdentityTest {
@BeforeEach
void setup() {
ProcessTags.reset();
}
@AfterEach
void cleanup() {
ProcessTags.reset();
}
@Test
void identityHashDependsOnServiceEnvAndPrimaryTag() {
// identityHash is calculated once (service/env/primaryTag are fixed for the JVM's
// lifetime), so this exercises the underlying hashing function directly rather than
// via Config + recalcBaseHash.
long base = BaseHash.calcIdentity("service", "env", "region-1");
assertNotEquals(base, BaseHash.calcIdentity("service-2", "env", "region-1"));
assertNotEquals(base, BaseHash.calcIdentity("service", "env-2", "region-1"));
assertNotEquals(base, BaseHash.calcIdentity("service", "env", "region-2"));
assertEquals(base, BaseHash.calcIdentity("service", "env", "region-1"));
}
@Test
void identityHashIsUnaffectedByContainerTagsHashOrProcessTags() {
BaseHash.recalcBaseHash(null);
long baseIdentityHash = BaseHash.getIdentityHash();
BaseHash.recalcBaseHash("some-container-tags-hash");
long withContainerTagsHash = BaseHash.getIdentityHash();
ProcessTags.addTag("foo", "bar");
long withProcessTags = BaseHash.getIdentityHash();
// DSM2-335: identity hash must not be perturbed by per-pod/per-rollout inputs
assertEquals(baseIdentityHash, withContainerTagsHash);
assertEquals(baseIdentityHash, withProcessTags);
}
@Test
void getIdentityHashRecalculatesFromConfigWhenUnset() {
// 0 means "not yet computed" - simulate that state, e.g. before this class is ever touched
BaseHash.updateIdentityHash(0L);
long recalculated = BaseHash.getIdentityHash();
assertNotEquals(0L, recalculated);
// once non-zero, later reads don't recalculate - a caller that needs a fresh value can
// still force one directly (e.g. tests via updateIdentityHash)
BaseHash.updateIdentityHash(42L);
assertEquals(42L, BaseHash.getIdentityHash());
}
}