diff options
Diffstat (limited to 'vendor/jonahgeorge/jaeger-client-php/tests/Jaeger/Sampler')
3 files changed, 159 insertions, 0 deletions
diff --git a/vendor/jonahgeorge/jaeger-client-php/tests/Jaeger/Sampler/ConstSamplerTest.php b/vendor/jonahgeorge/jaeger-client-php/tests/Jaeger/Sampler/ConstSamplerTest.php new file mode 100644 index 000000000..85cb80504 --- /dev/null +++ b/vendor/jonahgeorge/jaeger-client-php/tests/Jaeger/Sampler/ConstSamplerTest.php @@ -0,0 +1,43 @@ +<?php + +namespace Jaeger\Tests\Sampler; + +use Jaeger\Sampler\ConstSampler; +use PHPUnit\Framework\TestCase; +use const Jaeger\SAMPLER_PARAM_TAG_KEY; +use const Jaeger\SAMPLER_TYPE_CONST; +use const Jaeger\SAMPLER_TYPE_TAG_KEY; + +class ConstSamplerTest extends TestCase +{ + /** + * @test + * @dataProvider samplerProvider + * @param bool $decision + * @param mixed $traceId + */ + public function shouldDetermineWhetherOrTraceShouldBeSampled($decision, $traceId) + { + $sampler = new ConstSampler($decision); + + list($sampled, $tags) = $sampler->isSampled($traceId); + + $this->assertEquals($decision, $sampled); + $this->assertEquals([ + SAMPLER_TYPE_TAG_KEY => SAMPLER_TYPE_CONST, + SAMPLER_PARAM_TAG_KEY => $decision, + ], $tags); + + $sampler->close(); + } + + public function samplerProvider() + { + return [ + [true, 1], + [true, PHP_INT_MAX], + [false, 1], + [false, PHP_INT_MAX], + ]; + } +} diff --git a/vendor/jonahgeorge/jaeger-client-php/tests/Jaeger/Sampler/ProbablisticSamplerTest.php b/vendor/jonahgeorge/jaeger-client-php/tests/Jaeger/Sampler/ProbablisticSamplerTest.php new file mode 100644 index 000000000..2840ebf8c --- /dev/null +++ b/vendor/jonahgeorge/jaeger-client-php/tests/Jaeger/Sampler/ProbablisticSamplerTest.php @@ -0,0 +1,68 @@ +<?php + +namespace Jaeger\Tests\Sampler; + +use Jaeger\Sampler\ProbabilisticSampler; +use OutOfBoundsException; +use PHPUnit\Framework\TestCase; +use const Jaeger\SAMPLER_PARAM_TAG_KEY; +use const Jaeger\SAMPLER_TYPE_PROBABILISTIC; +use const Jaeger\SAMPLER_TYPE_TAG_KEY; + +class ProbablisticSamplerTest extends TestCase +{ + /** + * @test + * @dataProvider samplerProvider + * @param float $rate + * @param mixed $traceId + * @param bool $decision + */ + public function shouldDetermineWhetherOrTraceShouldBeSampled($rate, $traceId, $decision) + { + $sampler = new ProbabilisticSampler($rate); + + list($sampled, $tags) = $sampler->isSampled($traceId); + + $this->assertEquals($decision, $sampled); + $this->assertEquals([ + SAMPLER_TYPE_TAG_KEY => SAMPLER_TYPE_PROBABILISTIC, + SAMPLER_PARAM_TAG_KEY => $rate, + ], $tags); + + $sampler->close(); + } + + public function samplerProvider() + { + return [ + [1.0, PHP_INT_MAX-1, true], + [0, 0, false], + [0.5, PHP_INT_MIN + 10, true], + [0.5, PHP_INT_MAX - 10, false], + ]; + } + + /** + * @test + * @dataProvider rateProvider + * @param mixed $rate + */ + public function shouldThrowOutOfBoundsExceptionInCaseOfInvalidRate($rate) + { + $this->expectException(OutOfBoundsException::class); + $this->expectExceptionMessage('Sampling rate must be between 0.0 and 1.0.'); + + new ProbabilisticSampler($rate); + } + + public function rateProvider() + { + return [ + [1.1], + [-0.1], + [PHP_INT_MAX], + [PHP_INT_MIN], + ]; + } +} diff --git a/vendor/jonahgeorge/jaeger-client-php/tests/Jaeger/Sampler/RateLimitSamplerTest.php b/vendor/jonahgeorge/jaeger-client-php/tests/Jaeger/Sampler/RateLimitSamplerTest.php new file mode 100644 index 000000000..4f6b8a632 --- /dev/null +++ b/vendor/jonahgeorge/jaeger-client-php/tests/Jaeger/Sampler/RateLimitSamplerTest.php @@ -0,0 +1,48 @@ +<?php + +namespace Jaeger\Tests\Sampler; + +use Cache\Adapter\PHPArray\ArrayCachePool; +use Jaeger\Sampler\RateLimitingSampler; +use Jaeger\Util\RateLimiter; +use PHPUnit\Framework\TestCase; +use const Jaeger\SAMPLER_PARAM_TAG_KEY; +use const Jaeger\SAMPLER_TYPE_RATE_LIMITING; +use const Jaeger\SAMPLER_TYPE_TAG_KEY; + +class RateLimitSamplerTest extends TestCase +{ + /** + * @test + * @dataProvider maxRateProvider + * @param integer $maxTracesPerSecond + * @param bool $decision + * @throws + */ + public function shouldDetermineWhetherOrTraceShouldBeSampled($maxTracesPerSecond, $decision) + { + $sampler = new RateLimitingSampler( + $maxTracesPerSecond, + new RateLimiter(new ArrayCachePool(), 'balance', 'lastTick') + ); + + $sampler->isSampled(); + list($sampled, $tags) = $sampler->isSampled(); + $this->assertEquals($decision, $sampled); + $this->assertEquals([ + SAMPLER_TYPE_TAG_KEY => SAMPLER_TYPE_RATE_LIMITING, + SAMPLER_PARAM_TAG_KEY => $maxTracesPerSecond, + ], $tags); + + $sampler->close(); + } + + public function maxRateProvider() + { + return [ + [1000000, true], + [1, false], + [0, false], + ]; + } +} |