From aa25eae8651b9c6975be8620220788e6cfce61e9 Mon Sep 17 00:00:00 2001 From: danibrutal Date: Fri, 19 Jun 2015 09:49:58 +0200 Subject: [PATCH] Adding Point class to handle Points --- src/Leaseweb/InfluxDB/Database.php | 11 ++++++ src/Leaseweb/InfluxDB/Point.php | 55 ++++++++++++++++++++++++++++++ tests/unit/DatabaseTest.php | 23 +++++++++++-- tests/unit/PointTest.php | 32 +++++++++++++++++ 4 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 src/Leaseweb/InfluxDB/Point.php create mode 100644 tests/unit/PointTest.php diff --git a/src/Leaseweb/InfluxDB/Database.php b/src/Leaseweb/InfluxDB/Database.php index 37ca65cb9..d4de7b973 100644 --- a/src/Leaseweb/InfluxDB/Database.php +++ b/src/Leaseweb/InfluxDB/Database.php @@ -92,6 +92,17 @@ class Database } } + /** + * Writes points into INfluxdb + * @param Point[] $points + */ + public function writePoints(array $points) + { + foreach ($points as $point) { + $point->a(); + } + } + /** * @param RetentionPolicy $retentionPolicy */ diff --git a/src/Leaseweb/InfluxDB/Point.php b/src/Leaseweb/InfluxDB/Point.php new file mode 100644 index 000000000..b324c9a56 --- /dev/null +++ b/src/Leaseweb/InfluxDB/Point.php @@ -0,0 +1,55 @@ +measurement = $measurement; + $this->tags = $tags; + $this->fields = $fields; + $this->timestamp = $timestamp; + } + + /** + * @see: https://influxdb.com/docs/v0.9/concepts/reading_and_writing_data.html + * + * Should return this format + * 'cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000' + */ + public function __toString() + { + return ""; + /*return sprintf( + '%s,%s %s %s', + $this->measurement, + implode() + );*/ + } + + public function a(){ + + } +} \ No newline at end of file diff --git a/tests/unit/DatabaseTest.php b/tests/unit/DatabaseTest.php index 336ce3a7e..2d357c89e 100644 --- a/tests/unit/DatabaseTest.php +++ b/tests/unit/DatabaseTest.php @@ -5,6 +5,7 @@ namespace Leaseweb\InfluxDB\Test; use Leaseweb\InfluxDB\Client; use Leaseweb\InfluxDB\Database; +use Leaseweb\InfluxDB\Point; class DatabaseTest extends \PHPUnit_Framework_TestCase { @@ -30,13 +31,31 @@ class DatabaseTest extends \PHPUnit_Framework_TestCase $this->db = new Database('influx_test_db', $this->mockClient); $this->dataToInsert = file_get_contents(dirname(__FILE__) . '/input.example.json'); - } + /** + * todo: + */ public function testWrite() { + $point1 = new Point( + 'cpu_load_short', + array('host' =>'server01', 'region'=>'us-west'), + array('value' => 0.64), + 'myTime' + ); + + $point2 = new Point( + 'cpu_load_short', + array('host' =>'server01', 'region'=>'us-west'), + array('value' => 0.84), + 'myTime' + ); + + $this->db->writePoints(array($point1, $point2)); + $this->assertTrue( - 'mockClient' + true ); } } \ No newline at end of file diff --git a/tests/unit/PointTest.php b/tests/unit/PointTest.php new file mode 100644 index 000000000..32916d2a8 --- /dev/null +++ b/tests/unit/PointTest.php @@ -0,0 +1,32 @@ +'server01', 'region'=>'us-west'), + array('value' => 0.64), + 'myTime' + ); + + + $this->assertEquals($expected, (string) $point); + } + +} \ No newline at end of file