88import static io .opentelemetry .contrib .sampler .consistent .OtelTraceState .getInvalidP ;
99import static io .opentelemetry .contrib .sampler .consistent .OtelTraceState .getInvalidR ;
1010import static org .assertj .core .api .Assertions .assertThat ;
11- import static org .junit .jupiter .api .Assertions .assertEquals ;
12- import static org .junit .jupiter .api .Assertions .assertFalse ;
13- import static org .junit .jupiter .api .Assertions .assertThrows ;
11+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
1412
1513import io .opentelemetry .api .common .Attributes ;
1614import io .opentelemetry .api .trace .Span ;
@@ -32,45 +30,45 @@ class ConsistentSamplerTest {
3230
3331 @ Test
3432 void testGetSamplingRate () {
35- assertThrows (
36- IllegalArgumentException . class , () -> ConsistentSampler . getSamplingProbability (- 1 ) );
33+ assertThatThrownBy (() -> ConsistentSampler . getSamplingProbability (- 1 ))
34+ . isInstanceOf ( IllegalArgumentException . class );
3735 for (int i = 0 ; i < OtelTraceState .getMaxP () - 1 ; i += 1 ) {
38- assertEquals ( Math .pow (0.5 , i ), ConsistentSampler . getSamplingProbability ( i ));
36+ assertThat ( ConsistentSampler . getSamplingProbability ( i )). isEqualTo ( Math .pow (0.5 , i ));
3937 }
40- assertEquals ( 0. , ConsistentSampler .getSamplingProbability (OtelTraceState .getMaxP ()));
41- assertThrows (
42- IllegalArgumentException . class ,
43- () -> ConsistentSampler . getSamplingProbability ( OtelTraceState . getMaxP () + 1 ) );
38+ assertThat ( ConsistentSampler .getSamplingProbability (OtelTraceState .getMaxP ())). isEqualTo ( 0. );
39+ assertThatThrownBy (
40+ () -> ConsistentSampler . getSamplingProbability ( OtelTraceState . getMaxP () + 1 ))
41+ . isInstanceOf ( IllegalArgumentException . class );
4442 }
4543
4644 @ Test
4745 void testGetLowerBoundP () {
48- assertEquals ( 0 , ConsistentSampler .getLowerBoundP (1.0 ));
49- assertEquals ( 0 , ConsistentSampler .getLowerBoundP (Math .nextDown (1.0 )));
46+ assertThat ( ConsistentSampler .getLowerBoundP (1.0 )). isEqualTo ( 0 );
47+ assertThat ( ConsistentSampler .getLowerBoundP (Math .nextDown (1.0 ))). isEqualTo ( 0 );
5048 for (int i = 1 ; i < OtelTraceState .getMaxP () - 1 ; i += 1 ) {
5149 double samplingProbability = Math .pow (0.5 , i );
52- assertEquals ( i , ConsistentSampler .getLowerBoundP (samplingProbability ));
53- assertEquals ( i - 1 , ConsistentSampler .getLowerBoundP (Math .nextUp (samplingProbability )));
54- assertEquals ( i , ConsistentSampler .getLowerBoundP (Math .nextDown (samplingProbability )));
50+ assertThat ( ConsistentSampler .getLowerBoundP (samplingProbability )). isEqualTo ( i );
51+ assertThat ( ConsistentSampler .getLowerBoundP (Math .nextUp (samplingProbability ))). isEqualTo ( i - 1 );
52+ assertThat ( ConsistentSampler .getLowerBoundP (Math .nextDown (samplingProbability ))). isEqualTo ( i );
5553 }
56- assertEquals ( OtelTraceState .getMaxP () - 1 , ConsistentSampler . getLowerBoundP ( Double . MIN_NORMAL ) );
57- assertEquals ( OtelTraceState .getMaxP () - 1 , ConsistentSampler . getLowerBoundP ( Double . MIN_VALUE ) );
58- assertEquals ( OtelTraceState . getMaxP (), ConsistentSampler .getLowerBoundP (0.0 ));
54+ assertThat ( ConsistentSampler . getLowerBoundP ( Double . MIN_NORMAL )). isEqualTo ( OtelTraceState .getMaxP () - 1 );
55+ assertThat ( ConsistentSampler . getLowerBoundP ( Double . MIN_VALUE )). isEqualTo ( OtelTraceState .getMaxP () - 1 );
56+ assertThat ( ConsistentSampler .getLowerBoundP (0.0 )). isEqualTo ( OtelTraceState . getMaxP ( ));
5957 }
6058
6159 @ Test
6260 void testGetUpperBoundP () {
63- assertEquals ( 0 , ConsistentSampler .getUpperBoundP (1.0 ));
64- assertEquals ( 1 , ConsistentSampler .getUpperBoundP (Math .nextDown (1.0 )));
61+ assertThat ( ConsistentSampler .getUpperBoundP (1.0 )). isEqualTo ( 0 );
62+ assertThat ( ConsistentSampler .getUpperBoundP (Math .nextDown (1.0 ))). isEqualTo ( 1 );
6563 for (int i = 1 ; i < OtelTraceState .getMaxP () - 1 ; i += 1 ) {
6664 double samplingProbability = Math .pow (0.5 , i );
67- assertEquals ( i , ConsistentSampler .getUpperBoundP (samplingProbability ));
68- assertEquals ( i , ConsistentSampler .getUpperBoundP (Math .nextUp (samplingProbability )));
69- assertEquals ( i + 1 , ConsistentSampler .getUpperBoundP (Math .nextDown (samplingProbability )));
65+ assertThat ( ConsistentSampler .getUpperBoundP (samplingProbability )). isEqualTo ( i );
66+ assertThat ( ConsistentSampler .getUpperBoundP (Math .nextUp (samplingProbability ))). isEqualTo ( i );
67+ assertThat ( ConsistentSampler .getUpperBoundP (Math .nextDown (samplingProbability ))). isEqualTo ( i + 1 );
7068 }
71- assertEquals ( OtelTraceState . getMaxP (), ConsistentSampler .getUpperBoundP (Double .MIN_NORMAL ));
72- assertEquals ( OtelTraceState . getMaxP (), ConsistentSampler .getUpperBoundP (Double .MIN_VALUE ));
73- assertEquals ( OtelTraceState . getMaxP (), ConsistentSampler .getUpperBoundP (0.0 ));
69+ assertThat ( ConsistentSampler .getUpperBoundP (Double .MIN_NORMAL )). isEqualTo ( OtelTraceState . getMaxP ( ));
70+ assertThat ( ConsistentSampler .getUpperBoundP (Double .MIN_VALUE )). isEqualTo ( OtelTraceState . getMaxP ( ));
71+ assertThat ( ConsistentSampler .getUpperBoundP (0.0 )). isEqualTo ( OtelTraceState . getMaxP ( ));
7472 }
7573
7674 @ Test
@@ -168,18 +166,18 @@ private static void assertConsistentSampling(
168166 SamplingResult samplingResult =
169167 sampler .shouldSample (parentContext , traceId , name , spanKind , attributes , parentLinks );
170168
171- assertEquals ( expectSampled , getSampledFlag (samplingResult ));
169+ assertThat ( getSampledFlag (samplingResult )). isEqualTo ( expectSampled );
172170 OptionalInt p = getP (samplingResult , parentContext );
173171 if (OtelTraceState .isValidP (expectedP )) {
174- assertEquals ( expectedP , p .getAsInt ());
172+ assertThat ( p .getAsInt ()). isEqualTo ( expectedP );
175173 } else {
176- assertFalse (p .isPresent ());
174+ assertThat (p .isPresent ()). isFalse ( );
177175 }
178176 OptionalInt r = getR (samplingResult , parentContext );
179177 if (OtelTraceState .isValidR (expectedR )) {
180- assertEquals ( expectedR , r .getAsInt ());
178+ assertThat ( r .getAsInt ()). isEqualTo ( expectedR );
181179 } else {
182- assertFalse (r .isPresent ());
180+ assertThat (r .isPresent ()). isFalse ( );
183181 }
184182 }
185183
0 commit comments