-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from Vinelab/enhancement/dynamic-timeout-varia…
…bles Dynamic timeout variables
- Loading branch information
Showing
4 changed files
with
123 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
/** | ||
* @author Ali Issa <[email protected]> | ||
* @author Kinane Domloje <[email protected]> | ||
* @author Charalampos Raftopoulos <[email protected]> | ||
*/ | ||
class BowlerServiceProvider extends ServiceProvider | ||
{ | ||
|
@@ -29,13 +30,17 @@ public function register() | |
return $app['vinelab.bowler.registrator']; | ||
}); | ||
|
||
// Bind connection to env configuration | ||
$rbmqHost = config('queue.connections.rabbitmq.host'); | ||
$rbmqPort = config('queue.connections.rabbitmq.port'); | ||
$rbmqUsername = config('queue.connections.rabbitmq.username'); | ||
$rbmqPassword = config('queue.connections.rabbitmq.password'); | ||
$this->app->bind(Connection::class, function () use ($rbmqHost, $rbmqPort, $rbmqUsername, $rbmqPassword) { | ||
return new Connection($rbmqHost, $rbmqPort, $rbmqUsername, $rbmqPassword); | ||
$this->app->bind(Connection::class, function () { | ||
// Bind connection to env configuration | ||
$rbmqHost = config('queue.connections.rabbitmq.host'); | ||
$rbmqPort = config('queue.connections.rabbitmq.port'); | ||
$rbmqUsername = config('queue.connections.rabbitmq.username'); | ||
$rbmqPassword = config('queue.connections.rabbitmq.password'); | ||
$rbmqConnectionTimeout = config('queue.connections.rabbitmq.connection_timeout') ? (int) config('queue.connections.rabbitmq.connection_timeout') : 30; | ||
$rbmqReadWriteTimeout = config('queue.connections.rabbitmq.read_write_timeout') ? (int) config('queue.connections.rabbitmq.read_write_timeout') : 30; | ||
$rbmqHeartbeat = config('queue.connections.rabbitmq.heartbeat') ? (int) config('queue.connections.rabbitmq.heartbeat') : 15; | ||
|
||
return new Connection($rbmqHost, $rbmqPort, $rbmqUsername, $rbmqPassword, $rbmqConnectionTimeout, $rbmqReadWriteTimeout, $rbmqHeartbeat); | ||
}); | ||
|
||
$this->app->bind( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,13 @@ | |
namespace Vinelab\Bowler\Tests; | ||
|
||
use Mockery as M; | ||
use ReflectionClass; | ||
use Vinelab\Bowler\Connection; | ||
use PhpAmqpLib\Wire\IO\StreamIO; | ||
use Illuminate\Broadcasting\Channel; | ||
use Illuminate\Support\Facades\Config; | ||
use Vinelab\Http\Client as HTTPClient; | ||
use PhpAmqpLib\Connection\AMQPStreamConnection; | ||
|
||
/** | ||
* @author Abed Halawi <[email protected]> | ||
|
@@ -21,7 +26,7 @@ public function test_fetching_consumers_default() | |
$queueName = 'the-queue'; | ||
$mClient = M::mock(HTTPClient::class); | ||
$request = [ | ||
'url' => 'localhost:15672/api/queues/%2F/'.$queueName, | ||
'url' => 'localhost:15672/api/queues/%2F/' . $queueName, | ||
'params' => ['columns' => 'consumer_details.consumer_tag'], | ||
'auth' => [ | ||
'username' => 'guest', | ||
|
@@ -46,4 +51,45 @@ public function test_fetching_consumers_default() | |
|
||
$this->assertEquals('response', $response); | ||
} | ||
|
||
public function test_set_default_configurations_values() | ||
{ | ||
$mConnection = $this->getMockBuilder(Connection::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->app->bind(Connection::class, function () use ($mConnection) { | ||
return $mConnection; | ||
}); | ||
$connection = $this->app[Connection::class]; | ||
|
||
$this->assertAttributeEquals(15, 'heartbeat', $connection); | ||
$this->assertAttributeEquals(30, 'readWriteTimeout', $connection); | ||
$this->assertAttributeEquals(30, 'connectionTimeout', $connection); | ||
} | ||
|
||
public function test_set_altered_configurations_values() | ||
{ | ||
Config::set('queue.connections.rabbitmq.host', 'notlocal'); | ||
Config::set('queue.connections.rabbitmq.port', 6666); | ||
Config::set('queue.connections.rabbitmq.read_write_timeout', 60); | ||
Config::set('queue.connections.rabbitmq.connection_timeout', 60); | ||
Config::set('queue.connections.rabbitmq.heartbeat', 30); | ||
|
||
$mAMQPStreamConnection = M::mock(AMQPStreamConnection::class); | ||
$this->app->bind(AMQPStreamConnection::class, function () use ($mAMQPStreamConnection) { | ||
return $mAMQPStreamConnection; | ||
}); | ||
|
||
$mChannel = M::mock(Channel::class); | ||
$mAMQPStreamConnection->shouldReceive('channel')->once()->withNoArgs()->andReturn($mChannel); | ||
$mAMQPStreamConnection->shouldReceive('close')->once()->withNoArgs(); | ||
$mChannel->shouldReceive('close')->once()->withNoArgs(); | ||
|
||
$connection = $this->app[Connection::class]; | ||
|
||
$this->assertAttributeEquals(30, 'heartbeat', $connection); | ||
$this->assertAttributeEquals(60, 'readWriteTimeout', $connection); | ||
$this->assertAttributeEquals(60, 'connectionTimeout', $connection); | ||
} | ||
} |