diff --git a/spec/InfluxDB/ClientSpec.php b/spec/InfluxDB/ClientSpec.php index 28a006d5d..888f21b8c 100644 --- a/spec/InfluxDB/ClientSpec.php +++ b/spec/InfluxDB/ClientSpec.php @@ -1,11 +1,12 @@ setAdapter($adapter); } + function it_is_initializable() { $this->shouldHaveType('InfluxDB\Client'); } - function it_should_send_data(\InfluxDB\Adapter\AdapterInterface $adapter) + function it_should_be_connectable(ConnectableInterface $adapter) + { + $adapter->connect()->willReturn(true)->shouldBeCalledTimes(1); + + $this->setAdapter($adapter); + $this->connect()->shouldReturn(true); + } + + function it_should_be_disconnectable(ConnectableInterface $adapter) + { + $adapter->disconnect()->willReturn(true)->shouldBeCalledTimes(1); + + $this->setAdapter($adapter); + $this->disconnect()->shouldReturn(true); + } + + function it_should_not_call_connect(AdapterInterface $adapter) + { + $this->setAdapter($adapter); + $this->connect()->shouldReturn(false); + } + + function it_should_send_data(AdapterInterface $adapter) { $adapter->send([[ "name" => "video.search", diff --git a/src/InfluxDB/Adapter/AdapterInterface.php b/src/InfluxDB/Adapter/AdapterInterface.php index 764bca1f6..d0b9e539a 100644 --- a/src/InfluxDB/Adapter/AdapterInterface.php +++ b/src/InfluxDB/Adapter/AdapterInterface.php @@ -1,5 +1,5 @@ [$this->options->getUsername(), $this->options->getPassword()], "body" => json_encode($message) ]; - $endpoint = $this->options->getHttpSeriesEndpoint(); + $endpoint = $this->options->getHttpSeriesEndpoint(); return $this->httpClient->post($endpoint, $httpMessage); } @@ -36,6 +36,7 @@ class GuzzleAdapter implements AdapterInterface, QueryableInterface "q" => $query, ] ]; + if ($timePrecision) { $options["query"]["time_precision"] = $timePrecision; } diff --git a/src/InfluxDB/Adapter/UdpAdapter.php b/src/InfluxDB/Adapter/UdpAdapter.php index 729be12c6..2cb026ede 100644 --- a/src/InfluxDB/Adapter/UdpAdapter.php +++ b/src/InfluxDB/Adapter/UdpAdapter.php @@ -1,5 +1,4 @@ getAdapter()->connect(); + $result = false; + if ($this->getAdapter() instanceOf ConnectableInterface) { + $result = $this->getAdapter()->connect(); + } + + return $result; } public function disconnect() { - return $this->getAdapter()->disconnect(); + $result = false; + if ($this->getAdapter() instanceOf ConnectableInterface) { + $result = $this->getAdapter()->disconnect(); + } + + return $result; } public function mark($name, array $values)