PHP Class bandwidthThrottle\tokenBucket\TokenBucketTest

See also: TokenBucket
Author: Markus Malkusch ([email protected])
Inheritance: extends PHPUnit_Framework_TestCase
Show file Open project: bandwidth-throttle/token-bucket

Public Methods

Method Description
getTokensShouldReturnCapacityAfterWaitingLongerThanRefillPeriod ( ) After waiting longer than the complete refill period on an empty bucket, getTokens() should return the capacity of the bucket.
getTokensShouldReturnCapacityAfterWaitingRefillPeriod ( ) After waiting the complete refill period on an empty bucket, getTokens() should return the capacity of the bucket.
getTokensShouldReturnInitialAmountOnBootstrap ( ) After bootstraping, getTokens() should return the initial amount.
getTokensShouldReturnMoreAfterWaiting ( ) After waiting on an non full bucket, getTokens() should return more.
getTokensShouldReturnRemainingTokensAfterConsumption ( ) After one consumtion, getTokens() should return the initial amount - 1.
getTokensShouldReturnSameAfterConsumingTooMany ( ) After consuming too many, getTokens() should return the same as before.
getTokensShouldReturnZeroTokensAfterConsumingAll ( ) After consuming all, getTokens() should return 0.
provideTestBootstrapWithInitialTokens ( ) : int[][] Returns test cases for testBootstrapWithInitialTokens().
provideTestInvalidCapacity ( ) : array Provides tests cases for testInvalidCapacity().
testBootstrapOnce ( ) Tests bootstrap() is bootstraps not on already bootstrapped storages.
testBootstrapWithInitialTokens ( integer $capacity, integer $tokens ) Tests bootstrapping with tokens.
testCapacity ( ) Test the capacity limit of the bucket
testConsume ( ) Tests comsumption of cumulated tokens.
testConsumeInsufficientDontRemoveTokens ( ) Tests consuming insuficient tokens wont remove any token.
testConsumeSufficientRemoveTokens ( ) Tests consuming tokens.
testConsumeTooMany ( ) Tests consuming more than the capacity.
testDefaultBootstrap ( ) Tests bootstrapping sets to 0 tokens.
testInitialTokensTooMany ( ) Tests bootstrapping with too many tokens.
testInvalidCapacity ( $capacity ) Tests building a token bucket with an invalid caüacity fails.
testWaitCalculation ( ) Tests consume() returns the expected amount of seconds to wait.
testWaitingAddsTokens ( ) Test token rate.

Protected Methods

Method Description
setUp ( )
tearDown ( )

Method Details

getTokensShouldReturnCapacityAfterWaitingLongerThanRefillPeriod() public method

After waiting longer than the complete refill period on an empty bucket, getTokens() should return the capacity of the bucket.

getTokensShouldReturnCapacityAfterWaitingRefillPeriod() public method

After waiting the complete refill period on an empty bucket, getTokens() should return the capacity of the bucket.

getTokensShouldReturnInitialAmountOnBootstrap() public method

After bootstraping, getTokens() should return the initial amount.

getTokensShouldReturnMoreAfterWaiting() public method

After waiting on an non full bucket, getTokens() should return more.

getTokensShouldReturnRemainingTokensAfterConsumption() public method

After one consumtion, getTokens() should return the initial amount - 1.

getTokensShouldReturnSameAfterConsumingTooMany() public method

After consuming too many, getTokens() should return the same as before.

getTokensShouldReturnZeroTokensAfterConsumingAll() public method

After consuming all, getTokens() should return 0.

provideTestBootstrapWithInitialTokens() public method

Returns test cases for testBootstrapWithInitialTokens().
public provideTestBootstrapWithInitialTokens ( ) : int[][]
return int[][] Test cases.

provideTestInvalidCapacity() public method

Provides tests cases for testInvalidCapacity().
public provideTestInvalidCapacity ( ) : array
return array Test cases.

setUp() protected method

protected setUp ( )

tearDown() protected method

protected tearDown ( )

testBootstrapOnce() public method

Tests bootstrap() is bootstraps not on already bootstrapped storages.
public testBootstrapOnce ( )

testBootstrapWithInitialTokens() public method

Tests bootstrapping with tokens.
public testBootstrapWithInitialTokens ( integer $capacity, integer $tokens )
$capacity integer The capacity.
$tokens integer The initial amount of tokens.

testCapacity() public method

Test the capacity limit of the bucket
public testCapacity ( )

testConsume() public method

Tests comsumption of cumulated tokens.
public testConsume ( )

testConsumeInsufficientDontRemoveTokens() public method

Tests consuming insuficient tokens wont remove any token.

testConsumeSufficientRemoveTokens() public method

Tests consuming tokens.

testConsumeTooMany() public method

Tests consuming more than the capacity.
public testConsumeTooMany ( )

testDefaultBootstrap() public method

Tests bootstrapping sets to 0 tokens.

testInitialTokensTooMany() public method

Tests bootstrapping with too many tokens.

testInvalidCapacity() public method

Tests building a token bucket with an invalid caüacity fails.
public testInvalidCapacity ( $capacity )

testWaitCalculation() public method

Tests consume() returns the expected amount of seconds to wait.
public testWaitCalculation ( )

testWaitingAddsTokens() public method

Test token rate.