rawOptions = $options; $tcpOptions = $options["tcp"]; $options = new Options(); $options->setHost($tcpOptions["host"]); $options->setPort($tcpOptions["port"]); $options->setUsername($tcpOptions["username"]); $options->setPassword($tcpOptions["password"]); $options->setDatabase($tcpOptions["database"]); $this->options = $options; $guzzleHttp = new GuzzleHttpClient(); $adapter = new InfluxHttpAdapter($guzzleHttp, $options); $influx = new Client(); $influx->setAdapter($adapter); $this->object = $influx; $databases = $this->object->getDatabases(); if (array_key_exists("values", $databases["results"][0]["series"][0])) { foreach ($databases["results"][0]["series"][0]["values"] as $database) { $this->object->deleteDatabase($database[0]); } } $this->object->createDatabase($this->rawOptions["udp"]["database"]); $this->object->createDatabase($this->rawOptions["tcp"]["database"]); } /** * @group tcp */ public function testGuzzleHttpApiWorksCorrectly() { $t = $this->object->mark("tcp.test", ["mark" => "element"]); sleep(1); $body = $this->object->query("select * from \"tcp.test\""); $this->assertCount(1, $body["results"][0]["series"][0]["values"]); $this->assertEquals("mark", $body["results"][0]["series"][0]["columns"][1]); $this->assertEquals("element", $body["results"][0]["series"][0]["values"][0][1]); } /** * @group tcp */ public function testGuzzleHttpQueryApiWorksCorrectly() { $this->object->mark("tcp.test", ["mark" => "element"]); sleep(1); $body = $this->object->query("select * from \"tcp.test\""); $this->assertCount(1, $body["results"][0]["series"][0]["values"]); $this->assertEquals("mark", $body["results"][0]["series"][0]["columns"][1]); $this->assertEquals("element", $body["results"][0]["series"][0]["values"][0][1]); } /** * @group tcp */ public function testGuzzleHttpQueryApiWithMultipleData() { $this->object->mark("tcp.test", ["mark" => "element"]); $this->object->mark("tcp.test", ["mark" => "element2"]); $this->object->mark("tcp.test", ["mark" => "element3"]); sleep(1); $body = $this->object->query("select mark from \"tcp.test\"", "s"); $this->assertCount(3, $body["results"][0]["series"][0]["values"]); $this->assertEquals("mark", $body["results"][0]["series"][0]["columns"][1]); $this->assertEquals("element", $body["results"][0]["series"][0]["values"][0][1]); } /** * @group udp */ public function testUdpIpWriteData() { $rawOptions = $this->rawOptions; $options = new Options(); $options->setHost($rawOptions["udp"]["host"]); $options->setUsername($rawOptions["udp"]["username"]); $options->setPassword($rawOptions["udp"]["password"]); $options->setPort($rawOptions["udp"]["port"]); $options->setDatabase($rawOptions["udp"]["database"]); $adapter = new UdpAdapter($options); $object = new Client(); $object->setAdapter($adapter); $object->mark("udp.test", ["mark" => "element"]); $object->mark("udp.test", ["mark" => "element1"]); $object->mark("udp.test", ["mark" => "element2"]); $object->mark("udp.test", ["mark" => "element3"]); // Wait UDP/IP message arrives sleep(1); $this->options->setDatabase("udp.test"); $body = $this->object->query("select * from \"udp.test\""); $this->assertCount(4, $body["results"][0]["series"][0]["values"]); $this->assertEquals("mark", $body["results"][0]["series"][0]["columns"][1]); $this->assertEquals("element", $body["results"][0]["series"][0]["values"][0][1]); } public function testListActiveDatabses() { $databases = $this->object->getDatabases(); $this->assertCount(2, $databases["results"][0]["series"][0]["values"]); } public function testCreateANewDatabase() { $this->object->createDatabase("walter"); sleep(1); $databases = $this->object->getDatabases(); $this->assertCount(3, $databases["results"][0]["series"][0]["values"]); $this->object->deleteDatabase("walter"); } }