forked from open-telemetry/opentelemetry-java-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsistentVariableThresholdSamplerTest.java
More file actions
49 lines (43 loc) · 1.82 KB
/
ConsistentVariableThresholdSamplerTest.java
File metadata and controls
49 lines (43 loc) · 1.82 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
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.contrib.sampler.consistent56;
import static io.opentelemetry.contrib.sampler.consistent56.ConsistentSamplingUtil.calculateThreshold;
import static io.opentelemetry.contrib.sampler.consistent56.ConsistentSamplingUtil.getMaxThreshold;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
class ConsistentVariableThresholdSamplerTest {
@Test
void testSetSamplingProbability() {
double probability = 0.5;
ConsistentVariableThresholdSampler sampler =
new ConsistentVariableThresholdSampler(probability);
testSetSamplingProbability(probability, sampler, /* updateProbability= */ false);
testSetSamplingProbability(0.25, sampler, /* updateProbability= */ true);
testSetSamplingProbability(0.0, sampler, /* updateProbability= */ true);
testSetSamplingProbability(1.0, sampler, /* updateProbability= */ true);
}
private static void testSetSamplingProbability(
double probability, ConsistentVariableThresholdSampler sampler, boolean updateProbability) {
long threshold = calculateThreshold(probability);
String thresholdString =
ConsistentSamplingUtil.appendLast56BitHexEncodedWithoutTrailingZeros(
new StringBuilder(), threshold)
.toString();
if (threshold == getMaxThreshold()) {
thresholdString = "max";
}
if (updateProbability) {
sampler.setSamplingProbability(probability);
}
assertThat(sampler.getThreshold()).isEqualTo(threshold);
assertThat(sampler.getDescription())
.isEqualTo(
"ConsistentVariableThresholdSampler{threshold="
+ thresholdString
+ ", sampling probability="
+ probability
+ "}");
}
}