Merge pull request #31 from EvanDarwin/master

Silently handle socket errors in the UdpAdapter (closes #27), add tests
This commit is contained in:
Walter Dal Mut
2015-06-21 17:52:07 +02:00
2 changed files with 32 additions and 0 deletions
+9
View File
@@ -15,9 +15,18 @@ final class UdpAdapter extends AdapterAbstract
public function write($message)
{
// Create a handler in order to handle the 'Host is down' message
set_error_handler(function() {
// Suppress the error, this is the UDP adapter and if we can't send
// it then we shouldn't inturrupt their application.
});
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_sendto($socket, $message, strlen($message), 0, $this->getOptions()->getHost(), $this->getOptions()->getPort());
socket_close($socket);
// Remove our error handler.
restore_error_handler();
}
private function serialize(array $message)
+23
View File
@@ -359,6 +359,29 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(712423, $body["results"][0]["series"][0]["values"][0][2]);
}
/**
* Test that we handle socket problems correctly in the UDP
* adapter, and that they don't inturrupt the user's application.
*
* @group udp
*/
public function testReplicateIssue27()
{
$options = new \InfluxDB\Options();
// Configure options
$options->setHost('172.16.1.182');
$options->setPort(4444);
$options->setDatabase('...');
$options->setUsername('root');
$options->setPassword('root');
$httpAdapter = new \InfluxDB\Adapter\UdpAdapter($options);
$client = new \InfluxDB\Client($httpAdapter);
$client->mark("udp.test", ["mark" => "element"]);
}
public function testListActiveDatabses()
{
$databases = $this->object->getDatabases();