From 308aba881732333da80adb4a122ca6eebd417b29 Mon Sep 17 00:00:00 2001 From: Evan Darwin Date: Sat, 20 Jun 2015 13:03:09 -0700 Subject: [PATCH 1/3] Silently handle socket errors in the UdpAdapter (closes #27), add testcase --- src/Adapter/UdpAdapter.php | 9 +++++++++ tests/ClientTest.php | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/Adapter/UdpAdapter.php b/src/Adapter/UdpAdapter.php index e497b13b7..2f9930087 100644 --- a/src/Adapter/UdpAdapter.php +++ b/src/Adapter/UdpAdapter.php @@ -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) diff --git a/tests/ClientTest.php b/tests/ClientTest.php index ad5367b2e..34145d7ce 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -359,6 +359,30 @@ 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(); + $client->setAdapter($httpAdapter); + $client->mark("udp.test", ["mark" => "element"]); + } + public function testListActiveDatabses() { $databases = $this->object->getDatabases(); From 6b46bf5c6b3b554933d6fd461b6d058a055c9e59 Mon Sep 17 00:00:00 2001 From: Evan Darwin Date: Sat, 20 Jun 2015 13:07:40 -0700 Subject: [PATCH 2/3] Fix issue #27 test --- tests/ClientTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 34145d7ce..840930317 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -378,8 +378,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase $httpAdapter = new \InfluxDB\Adapter\UdpAdapter($options); - $client = new \InfluxDB\Client(); - $client->setAdapter($httpAdapter); + $client = new \InfluxDB\Client($httpAdapter); $client->mark("udp.test", ["mark" => "element"]); } From 8e57dd7eb22e231bbbbc417055db272e60e7b76b Mon Sep 17 00:00:00 2001 From: Walter Dal Mut Date: Sun, 21 Jun 2015 17:58:29 +0200 Subject: [PATCH 3/3] Bumped version 0.5.0 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 0bfccb080..8f0916f76 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.5 +0.5.0