Skip to content

Commit

Permalink
getter for BatchedDogStatsd::$bufferLength
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmastech committed Jul 3, 2024
1 parent 0efdd1c commit 1c2859c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/BatchedDogStatsd.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,12 @@ public function flushBuffer()
static::$buffer = array();
static::$bufferLength = 0;
}

/**
* @return int
*/
public static function getBufferLength()
{
return self::$bufferLength;
}
}
31 changes: 31 additions & 0 deletions tests/UnitTests/BatchedDogStatsdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace DataDog\UnitTests;

use A\B;
use DataDog\BatchedDogStatsd;
use DataDog\TestHelpers\SocketSpy;
use DataDog\TestHelpers\SocketSpyTestCase;
Expand Down Expand Up @@ -74,4 +75,34 @@ public function testReportSendsOnceBufferIsFilled()
array("metrics" => 3)
);
}

public function testGetBufferLength() {
// Given
$batchedDog = new BatchedDogStatsd();

// assert pre-condition
$this->assertEquals(0, BatchedDogStatsd::getBufferLength());

// When
$batchedDog->gauge("some-value", 1);

// Then
$this->assertEquals(1, BatchedDogStatsd::getBufferLength());
}

public function testGetBufferLengthAfterExceedingMaxBufferLength()
{
// Given
BatchedDogStatsd::$maxBufferLength = 2;

// And
$batchedDog = new BatchedDogStatsd();

// When
$batchedDog->increment(["first-value", "another-value", "yet-another-value"]);
$batchedDog->gauge("some-value", 1);

// Then
$this->assertEquals(1, BatchedDogStatsd::getBufferLength());
}
}

0 comments on commit 1c2859c

Please sign in to comment.