Adding Point class to handle Points

This commit is contained in:
danibrutal
2015-06-19 09:49:58 +02:00
parent 74219895ef
commit aa25eae865
4 changed files with 119 additions and 2 deletions
+11
View File
@@ -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
*/
+55
View File
@@ -0,0 +1,55 @@
<?php
namespace Leaseweb\InfluxDB;
class Point
{
private $measurement;
/**
* @var array
*/
private $tags;
/**
* @var array
*/
private $fields;
/**
* @var string
*/
private $timestamp;
/**
* @param $measurement
* @param array $tags
* @param array $fields
* @param string $timestamp
*/
public function __construct($measurement, array $tags, array $fields, $timestamp = '')
{
$this->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(){
}
}
+21 -2
View File
@@ -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
);
}
}
+32
View File
@@ -0,0 +1,32 @@
<?php
/**
* Created by PhpStorm.
* User: dmartinez
* Date: 18-6-15
* Time: 17:39
*/
namespace Leaseweb\InfluxDB\Test;
use Leaseweb\InfluxDB\Point;
class PointTest extends \PHPUnit_Framework_TestCase
{
public function testPointStringRepresentation()
{
$expected = 'cpu_load_short,host=server01,region=us-west value=0.64 mytime';
$point = new Point(
'cpu_load_short',
array('host' =>'server01', 'region'=>'us-west'),
array('value' => 0.64),
'myTime'
);
$this->assertEquals($expected, (string) $point);
}
}